From 9f98e652bc8bcb65c4157fb23879bea4175de92f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 20 Dec 2017 16:41:33 +0100 Subject: [PATCH] =?UTF-8?q?ShowUsagesSettings=20=E2=80=94=20do=20not=20wri?= =?UTF-8?q?te=20defaults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/unscramble/ThreadDumpPanel.java | 5 ---- .../find/actions/ShowUsagesAction.java | 6 ++-- .../FavoritesTreeViewPanel.java | 4 --- .../ExporterToTextFileHierarchy.java | 2 +- .../ui/DependenciesPanel.java | 4 --- .../slicer/SliceToTextFileExporter.java | 2 +- .../intellij/ide/CommonActionsManager.java | 27 +++++++---------- .../com/intellij/ide/ExporterToTextFile.java | 3 +- .../impl/ErrorViewTextExporter.java | 17 +---------- .../ide/impl/CommonActionsManagerImpl.java | 17 ++--------- .../intellij/usages/impl/UsageViewTest.java | 16 ++-------- .../com/intellij/usages/ShowUsagesSettings.kt | 29 ++++++++++--------- .../com/intellij/usages/UsageViewSettings.kt | 26 +++++++++++------ .../usages/impl/ExporterToTextFile.java | 11 ++++--- .../intellij/usages/impl/UsageViewImpl.java | 2 +- 15 files changed, 66 insertions(+), 105 deletions(-) diff --git a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java index 788e63162302..dfc315d97499 100644 --- a/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java +++ b/java/java-impl/src/com/intellij/unscramble/ThreadDumpPanel.java @@ -425,11 +425,6 @@ public class ThreadDumpPanel extends JPanel implements DataProvider { return ""; } - @Override - public void exportedTo(String filePath) { - - } - @Override public boolean canExport() { return !myThreadStates.isEmpty(); diff --git a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java index 29d6428d4405..c654cac6a303 100644 --- a/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java +++ b/platform/lang-impl/src/com/intellij/find/actions/ShowUsagesAction.java @@ -1,4 +1,6 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +/* + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + */ package com.intellij.find.actions; import com.intellij.codeInsight.TargetElementUtil; @@ -240,7 +242,7 @@ public class ShowUsagesAction extends AnAction implements PopupAction { } Disposer.register(usageView, () -> { - showUsagesSettings.loadState(usageViewSettings); + showUsagesSettings.applyUsageViewSettings(usageViewSettings); usageViewSettings.loadState(savedGlobalSettings); }); diff --git a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java index 8da40f904d3d..b514c164168a 100644 --- a/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/favoritesTreeView/FavoritesTreeViewPanel.java @@ -299,10 +299,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider, Dock return myProject.getBasePath() + File.separator + "Favorites.txt"; } - @Override - public void exportedTo(String filePath) { - } - @Override public boolean canExport() { return true; diff --git a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java index 1b4414bf9318..fe89256bc2f2 100644 --- a/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java +++ b/platform/lang-impl/src/com/intellij/ide/hierarchy/ExporterToTextFileHierarchy.java @@ -57,7 +57,7 @@ class ExporterToTextFileHierarchy implements ExporterToTextFile { } @Override - public void exportedTo(String filePath) { + public void exportedTo(@NotNull String filePath) { final HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myHierarchyBrowserBase.myProject).getState(); if (state != null) { state.EXPORT_FILE_PATH = filePath; diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java index 2f40c8ebe8c3..655acd3e4767 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ui/DependenciesPanel.java @@ -707,10 +707,6 @@ public class DependenciesPanel extends JPanel implements Disposable, DataProvide return ""; } - @Override - public void exportedTo(String filePath) { - } - @Override public boolean canExport() { return true; diff --git a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java index b08c55ca4a65..7c08bf71fe26 100644 --- a/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java +++ b/platform/lang-impl/src/com/intellij/slicer/SliceToTextFileExporter.java @@ -54,7 +54,7 @@ public class SliceToTextFileExporter implements ExporterToTextFile { } @Override - public void exportedTo(String filePath) { + public void exportedTo(@NotNull String filePath) { UsageViewSettings.getInstance().setExportFileName(filePath); } diff --git a/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java b/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java index 852764a65a26..a7dafcac3b2e 100644 --- a/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java +++ b/platform/platform-api/src/com/intellij/ide/CommonActionsManager.java @@ -1,23 +1,12 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -30,28 +19,34 @@ public abstract class CommonActionsManager { } public abstract AnAction createPrevOccurenceAction(OccurenceNavigator navigator); + public abstract AnAction createNextOccurenceAction(OccurenceNavigator navigator); @Deprecated public abstract AnAction createExpandAllAction(TreeExpander expander); + public abstract AnAction createExpandAllAction(TreeExpander expander, JComponent component); + public abstract AnAction createExpandAllHeaderAction(JTree tree); @Deprecated public abstract AnAction createCollapseAllAction(TreeExpander expander); + public abstract AnAction createCollapseAllAction(TreeExpander expander, JComponent component); + public abstract AnAction createCollapseAllHeaderAction(JTree tree); public abstract AnAction createHelpAction(String helpId); /** * Installs autoscroll capability support to JTree passed. Toggle action returned. + * * @param project - * @return toggle action to be inserted to appropriate toolbar - * @param tree should provide DataConstants.NAVIGATABLE for handler to work on + * @param tree should provide DataConstants.NAVIGATABLE for handler to work on * @param optionProvider get/set API to externalizable property. + * @return toggle action to be inserted to appropriate toolbar */ public abstract AnAction installAutoscrollToSourceHandler(Project project, JTree tree, AutoScrollToSourceOptionProvider optionProvider); - public abstract AnAction createExportToTextFileAction(ExporterToTextFile exporter); + public abstract AnAction createExportToTextFileAction(@NotNull ExporterToTextFile exporter); } diff --git a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java index 90dc48cff6a1..c8db680fbf4e 100644 --- a/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java +++ b/platform/platform-api/src/com/intellij/ide/ExporterToTextFile.java @@ -28,7 +28,8 @@ public interface ExporterToTextFile { @NotNull String getDefaultFilePath(); - void exportedTo(String filePath); + default void exportedTo(@NotNull String filePath) { + } boolean canExport(); } diff --git a/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java b/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java index e2d6e31151a1..0963518e3e5c 100644 --- a/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java +++ b/platform/platform-impl/src/com/intellij/ide/errorTreeView/impl/ErrorViewTextExporter.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.errorTreeView.impl; @@ -70,9 +58,6 @@ public class ErrorViewTextExporter implements ExporterToTextFile { return ""; } - public void exportedTo(String filePath) { - } - public boolean canExport() { return true; } diff --git a/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java index a48aa7a49421..9aadad239b37 100644 --- a/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/impl/CommonActionsManagerImpl.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.ide.impl; @@ -21,6 +9,7 @@ import com.intellij.ide.actions.*; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.project.Project; import com.intellij.ui.AutoScrollToSourceHandler; +import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -90,7 +79,7 @@ public class CommonActionsManagerImpl extends CommonActionsManager { return handler.createToggleAction(); } - public AnAction createExportToTextFileAction(ExporterToTextFile exporter) { + public AnAction createExportToTextFileAction(@NotNull ExporterToTextFile exporter) { return new ExportToTextFileToolbarAction(exporter); } } diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java index 14cb9f85209e..5f10b4de9fbb 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.usages.impl; @@ -207,7 +195,7 @@ public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { assertEmpty(excluded); - String text = new ExporterToTextFile(usageView).getReportText(); + String text = new ExporterToTextFile(usageView, UsageViewSettings.getInstance()).getReportText(); assertEquals("Found usages (1 usage found)\n" + " Unclassified usage (1 usage found)\n" + " light_idea_test_case (1 usage found)\n" + diff --git a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt index b415eedef1cb..7f6996f33383 100644 --- a/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt +++ b/platform/usageView/src/com/intellij/usages/ShowUsagesSettings.kt @@ -7,23 +7,26 @@ import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage -import com.intellij.util.xmlb.XmlSerializerUtil @State(name = "ShowUsagesSettings", storages = arrayOf(Storage("usageView.xml"))) -class ShowUsagesSettings : PersistentStateComponent { - private val myState = UsageViewSettings(false, false, false, false, false) - - override fun getState(): UsageViewSettings? { - return myState - } - - override fun loadState(state: UsageViewSettings) { - XmlSerializerUtil.copyBean(state, myState) - } - +class ShowUsagesSettings : PersistentStateComponent { companion object { - + @JvmStatic val instance: ShowUsagesSettings get() = ServiceManager.getService(ShowUsagesSettings::class.java) } + + private var state = ShowUsageViewSettings() + + override fun getState() = state + + override fun loadState(state: ShowUsageViewSettings) { + this.state = state + } + + fun applyUsageViewSettings(otherState: UsageViewSettings) { + state.copyFrom(otherState) + } } + +class ShowUsageViewSettings : UsageViewSettings(false, false, false, false, false) diff --git a/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt b/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt index 3101faba29a5..bb79bc4d9e72 100644 --- a/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt +++ b/platform/usageView/src/com/intellij/usages/UsageViewSettings.kt @@ -5,12 +5,20 @@ package com.intellij.usages import com.intellij.openapi.components.* import com.intellij.util.PathUtil -import com.intellij.util.xmlb.XmlSerializerUtil import com.intellij.util.xmlb.annotations.OptionTag import com.intellij.util.xmlb.annotations.Transient +/** + * Passed params will be used as default values, so, do not use constructor if instance will be used as a state (unless you want to change defaults) + */ @State(name = "UsageViewSettings", storages = arrayOf(Storage("usageView.xml"), Storage(value = "other.xml", deprecated = true))) -class UsageViewSettings : BaseState(), PersistentStateComponent { +open class UsageViewSettings( + isGroupByFileStructure: Boolean = true, + isGroupByModule: Boolean = true, + isGroupByPackage: Boolean = true, + isGroupByUsageType: Boolean = true, + isGroupByScope: Boolean = false +) : BaseState(), PersistentStateComponent { companion object { @JvmStatic val instance: UsageViewSettings @@ -43,22 +51,22 @@ class UsageViewSettings : BaseState(), PersistentStateComponent myExclusionHandler;