ShowModulesAction cleanup

This commit is contained in:
Sergey Malenkov
2018-06-14 22:50:33 +03:00
parent 40c080144c
commit 3e1f6a512c
3 changed files with 32 additions and 50 deletions
@@ -180,13 +180,7 @@ public class PackageViewPane extends AbstractProjectViewPSIPane {
@Override
public void addToolbarActions(DefaultActionGroup actionGroup) {
actionGroup.addAction(new ShowModulesAction(myProject){
@NotNull
@Override
protected String getId() {
return PackageViewPane.this.getId();
}
}).setAsSecondary(true);
actionGroup.addAction(new ShowModulesAction(myProject, ID)).setAsSecondary(true);
actionGroup.addAction(createFlattenModulesAction(() -> true)).setAsSecondary(true);
actionGroup.addAction(new ShowLibraryContentsAction()).setAsSecondary(true);
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2014 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-2018 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.projectView.impl;
import com.intellij.icons.AllIcons;
@@ -21,44 +7,52 @@ import com.intellij.ide.projectView.ProjectView;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.util.PlatformUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author anna
* @since 8/5/11
*/
public abstract class ShowModulesAction extends ToggleAction {
public final class ShowModulesAction extends ToggleAction implements DumbAware {
private final Project myProject;
private final String myId;
public ShowModulesAction(Project project) {
super(IdeBundle.message("action.show.modules"), IdeBundle.message("action.description.show.modules"),
AllIcons.Actions.GroupByModule);
public ShowModulesAction(@NotNull Project project, @NotNull String id) {
super(IdeBundle.message("action.show.modules"), IdeBundle.message("action.description.show.modules"), AllIcons.Actions.GroupByModule);
myProject = project;
myId = id;
}
@Override
public boolean isSelected(AnActionEvent event) {
return ProjectView.getInstance(myProject).isShowModules(getId());
}
@NotNull
protected abstract String getId();
@Override
public void setSelected(AnActionEvent event, boolean flag) {
final ProjectViewImpl projectView = (ProjectViewImpl)ProjectView.getInstance(myProject);
projectView.setShowModules(flag, getId());
public boolean isSelected(@NotNull AnActionEvent event) {
ProjectView view = getProjectView();
return view != null && view.isShowModules(myId);
}
@Override
public void update(AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
final ProjectViewImpl projectView = (ProjectViewImpl)ProjectView.getInstance(myProject);
presentation.setVisible(hasModules() && Comparing.strEqual(projectView.getCurrentViewId(), getId()));
public void setSelected(@NotNull AnActionEvent event, boolean flag) {
ProjectView view = getProjectView();
if (view != null) view.setShowModules(flag, myId);
}
@Override
public void update(@NotNull AnActionEvent event) {
super.update(event);
Presentation presentation = event.getPresentation();
presentation.setEnabledAndVisible(hasModules() && isCurrentViewSelected(getProjectView()));
}
@Nullable
private ProjectView getProjectView() {
return myProject.isDisposed() ? null : ProjectView.getInstance(myProject);
}
private boolean isCurrentViewSelected(@Nullable ProjectView view) {
return view != null && myId.equals(view.getCurrentViewId());
}
public static boolean hasModules() {
@@ -316,13 +316,7 @@ public final class ScopeViewPane extends AbstractProjectViewPane {
@Override
public void addToolbarActions(DefaultActionGroup actionGroup) {
actionGroup.add(ActionManager.getInstance().getAction("ScopeView.EditScopes"));
actionGroup.addAction(new ShowModulesAction(myProject) {
@NotNull
@Override
protected String getId() {
return ID;
}
}).setAsSecondary(true);
actionGroup.addAction(new ShowModulesAction(myProject, ID)).setAsSecondary(true);
actionGroup.addAction(createFlattenModulesAction(() -> true)).setAsSecondary(true);
}