ShowUsagesSettings — do not write defaults

This commit is contained in:
Vladimir Krivosheev
2017-12-21 12:21:01 +01:00
parent 1a6fc4bc64
commit 9f98e652bc
15 changed files with 66 additions and 105 deletions
@@ -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();
@@ -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);
});
@@ -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;
@@ -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;
@@ -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;
@@ -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);
}
@@ -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);
}
@@ -28,7 +28,8 @@ public interface ExporterToTextFile {
@NotNull
String getDefaultFilePath();
void exportedTo(String filePath);
default void exportedTo(@NotNull String filePath) {
}
boolean canExport();
}
@@ -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;
}
@@ -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);
}
}
@@ -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" +
@@ -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<UsageViewSettings> {
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<ShowUsageViewSettings> {
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)
@@ -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<UsageViewSettings> {
open class UsageViewSettings(
isGroupByFileStructure: Boolean = true,
isGroupByModule: Boolean = true,
isGroupByPackage: Boolean = true,
isGroupByUsageType: Boolean = true,
isGroupByScope: Boolean = false
) : BaseState(), PersistentStateComponent<UsageViewSettings> {
companion object {
@JvmStatic
val instance: UsageViewSettings
@@ -43,22 +51,22 @@ class UsageViewSettings : BaseState(), PersistentStateComponent<UsageViewSetting
var previewUsagesSplitterProportion by property(0.5f)
@get:OptionTag("GROUP_BY_USAGE_TYPE")
var isGroupByUsageType by property(true)
var isGroupByUsageType by property(isGroupByUsageType)
@get:OptionTag("GROUP_BY_MODULE")
var isGroupByModule by property(true)
var isGroupByModule by property(isGroupByModule)
@get:OptionTag("FLATTEN_MODULES")
var isFlattenModules by property(true)
@get:OptionTag("GROUP_BY_PACKAGE")
var isGroupByPackage by property(true)
var isGroupByPackage by property(isGroupByPackage)
@get:OptionTag("GROUP_BY_FILE_STRUCTURE")
var isGroupByFileStructure by property(true)
var isGroupByFileStructure by property(isGroupByFileStructure)
@get:OptionTag("GROUP_BY_SCOPE")
var isGroupByScope: Boolean by property(false)
var isGroupByScope: Boolean by property(isGroupByScope)
var exportFileName: String?
@Transient
@@ -69,7 +77,7 @@ class UsageViewSettings : BaseState(), PersistentStateComponent<UsageViewSetting
override fun getState() = this
override fun loadState(`object`: UsageViewSettings) {
XmlSerializerUtil.copyBean(`object`, this)
override fun loadState(state: UsageViewSettings) {
copyFrom(state)
}
}
@@ -18,9 +18,12 @@ import java.util.Enumeration;
*/
public class ExporterToTextFile implements com.intellij.ide.ExporterToTextFile {
private final UsageViewImpl myUsageView;
@NotNull
private final UsageViewSettings myUsageViewSettings;
public ExporterToTextFile(@NotNull UsageViewImpl usageView) {
public ExporterToTextFile(@NotNull UsageViewImpl usageView, @NotNull UsageViewSettings usageViewSettings) {
myUsageView = usageView;
myUsageViewSettings = usageViewSettings;
}
@NotNull
@@ -86,12 +89,12 @@ public class ExporterToTextFile implements com.intellij.ide.ExporterToTextFile {
@NotNull
@Override
public String getDefaultFilePath() {
return UsageViewSettings.getInstance().getExportFileName();
return myUsageViewSettings.getExportFileName();
}
@Override
public void exportedTo(String filePath) {
UsageViewSettings.getInstance().setExportFileName(filePath);
public void exportedTo(@NotNull String filePath) {
myUsageViewSettings.setExportFileName(filePath);
}
@Override
@@ -103,7 +103,7 @@ public class UsageViewImpl implements UsageView {
private final Project myProject;
private volatile boolean mySearchInProgress = true;
private final ExporterToTextFile myTextFileExporter = new ExporterToTextFile(this);
private final ExporterToTextFile myTextFileExporter = new ExporterToTextFile(this, UsageViewSettings.getInstance());
private final Alarm myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD);
private final ExclusionHandler<DefaultMutableTreeNode> myExclusionHandler;