tasks: remove duplicated action

This commit is contained in:
Aleksey Pivovarov
2017-03-02 18:39:05 +03:00
committed by Aleksey Pivovarov
parent ed4232de35
commit 73c1f2555c
4 changed files with 68 additions and 109 deletions
@@ -78,9 +78,7 @@
<group id="tasks.toolbar.group" text="Tasks toolbar">
<separator/>
<action id="tasks.switch.toolbar" class="com.intellij.tasks.actions.SwitchTaskCombo" text="Switch Task">
<keyboard-shortcut keymap="$default" first-keystroke="alt shift T"/>
</action>
<reference id="tasks.switch"/>
<add-to-group group-id="MainToolBar" anchor="last"/>
<add-to-group group-id="NavBarToolBarOthers" anchor="last"/>
</group>
@@ -19,17 +19,22 @@ package com.intellij.tasks.actions;
import com.intellij.ide.DataManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.playback.commands.ActionCommand;
import com.intellij.openapi.ui.popup.*;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.tasks.ChangeListInfo;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.TaskManager;
import com.intellij.tasks.config.TaskSettings;
import com.intellij.tasks.impl.LocalTaskImpl;
import com.intellij.tasks.impl.TaskManagerImpl;
import com.intellij.tools.SimpleActionGroup;
@@ -50,7 +55,61 @@ import java.util.List;
/**
* @author Dmitry Avdeev
*/
public class SwitchTaskAction extends BaseTaskAction {
public class SwitchTaskAction extends ComboBoxAction implements DumbAware {
public JComponent createCustomComponent(final Presentation presentation) {
ComboBoxButton button = new ComboBoxButton(presentation) {
@Override
protected JBPopup createPopup(Runnable onDispose) {
return SwitchTaskAction.createPopup(DataManager.getInstance().getDataContext(this), onDispose, false);
}
};
button.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
return button;
}
@NotNull
@Override
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
return new DefaultActionGroup();
}
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null || project.isDefault() || project.isDisposed()) {
presentation.setEnabled(false);
presentation.setText("");
presentation.setIcon(null);
}
else {
TaskManager taskManager = TaskManager.getManager(project);
LocalTask activeTask = taskManager.getActiveTask();
presentation.setVisible(true);
presentation.setEnabled(true);
if (isImplicit(activeTask) &&
taskManager.getAllRepositories().length == 0 &&
!TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO) {
presentation.setVisible(false);
}
else {
String s = getText(activeTask);
presentation.setText(s);
presentation.setIcon(activeTask.getIcon());
presentation.setDescription(activeTask.getSummary());
}
}
}
private static boolean isImplicit(LocalTask activeTask) {
return activeTask.isDefault() && Comparing.equal(activeTask.getCreated(), activeTask.getUpdated());
}
private static String getText(LocalTask activeTask) {
String text = activeTask.getPresentableName();
return StringUtil.first(text, 50, true);
}
@Override
public void actionPerformed(AnActionEvent e) {
@@ -61,9 +120,9 @@ public class SwitchTaskAction extends BaseTaskAction {
popup.showCenteredInCurrentWindow(project);
}
public static ListPopupImpl createPopup(final DataContext dataContext,
@Nullable final Runnable onDispose,
boolean withTitle) {
private static ListPopupImpl createPopup(final DataContext dataContext,
@Nullable final Runnable onDispose,
boolean withTitle) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Ref<Boolean> shiftPressed = Ref.create(false);
final Ref<JComponent> componentRef = Ref.create();
@@ -1,97 +0,0 @@
/*
* Copyright 2000-2015 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.
*/
package com.intellij.tasks.actions;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.tasks.LocalTask;
import com.intellij.tasks.TaskManager;
import com.intellij.tasks.config.TaskSettings;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author Dmitry Avdeev
*/
public class SwitchTaskCombo extends ComboBoxAction implements DumbAware {
public JComponent createCustomComponent(final Presentation presentation) {
ComboBoxButton button = new ComboBoxButton(presentation) {
@Override
protected JBPopup createPopup(Runnable onDispose) {
return SwitchTaskAction.createPopup(DataManager.getInstance().getDataContext(this), onDispose, false);
}
};
button.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2));
return button;
}
@NotNull
@Override
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
return new DefaultActionGroup();
}
@Override
public void update(AnActionEvent e) {
Presentation presentation = e.getPresentation();
Project project = e.getData(CommonDataKeys.PROJECT);
ComboBoxButton button = (ComboBoxButton)presentation.getClientProperty(CUSTOM_COMPONENT_PROPERTY);
if (project == null || project.isDefault() || project.isDisposed() || button == null) {
presentation.setEnabled(false);
presentation.setText("");
presentation.setIcon(null);
}
else {
TaskManager taskManager = TaskManager.getManager(project);
LocalTask activeTask = taskManager.getActiveTask();
presentation.setVisible(true);
presentation.setEnabled(true);
if (isImplicit(activeTask) &&
taskManager.getAllRepositories().length == 0 &&
!TaskSettings.getInstance().ALWAYS_DISPLAY_COMBO) {
presentation.setVisible(false);
}
else {
String s = getText(activeTask);
presentation.setText(s);
presentation.setIcon(activeTask.getIcon());
presentation.setDescription(activeTask.getSummary());
}
}
}
private static boolean isImplicit(LocalTask activeTask) {
return activeTask.isDefault() && Comparing.equal(activeTask.getCreated(), activeTask.getUpdated());
}
private static String getText(LocalTask activeTask) {
String text = activeTask.getPresentableName();
return StringUtil.first(text, 50, true);
}
}
@@ -18,9 +18,8 @@ package com.intellij.tasks;
import com.intellij.ide.ui.customization.CustomActionsSchema;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
import com.intellij.tasks.actions.SwitchTaskCombo;
import com.intellij.tasks.actions.SwitchTaskAction;
import com.intellij.tasks.config.TaskSettings;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.testFramework.TestActionEvent;
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
@@ -32,7 +31,7 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
public void testTaskComboVisible() throws Exception {
SwitchTaskCombo combo = null;
SwitchTaskAction combo = null;
ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
AnAction[] children = group.getChildren(new TestActionEvent());
@@ -40,8 +39,8 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
if (child instanceof ActionGroup) {
AnAction[] actions = ((ActionGroup)child).getChildren(new TestActionEvent());
for (AnAction action : actions) {
if (action instanceof SwitchTaskCombo) {
combo = (SwitchTaskCombo)action;
if (action instanceof SwitchTaskAction) {
combo = (SwitchTaskAction)action;
}
}
}