mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tasks: remove duplicated action
This commit is contained in:
committed by
Aleksey Pivovarov
parent
ed4232de35
commit
73c1f2555c
@@ -78,9 +78,7 @@
|
|||||||
|
|
||||||
<group id="tasks.toolbar.group" text="Tasks toolbar">
|
<group id="tasks.toolbar.group" text="Tasks toolbar">
|
||||||
<separator/>
|
<separator/>
|
||||||
<action id="tasks.switch.toolbar" class="com.intellij.tasks.actions.SwitchTaskCombo" text="Switch Task">
|
<reference id="tasks.switch"/>
|
||||||
<keyboard-shortcut keymap="$default" first-keystroke="alt shift T"/>
|
|
||||||
</action>
|
|
||||||
<add-to-group group-id="MainToolBar" anchor="last"/>
|
<add-to-group group-id="MainToolBar" anchor="last"/>
|
||||||
<add-to-group group-id="NavBarToolBarOthers" anchor="last"/>
|
<add-to-group group-id="NavBarToolBarOthers" anchor="last"/>
|
||||||
</group>
|
</group>
|
||||||
|
|||||||
@@ -19,17 +19,22 @@ package com.intellij.tasks.actions;
|
|||||||
import com.intellij.ide.DataManager;
|
import com.intellij.ide.DataManager;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.actionSystem.*;
|
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.project.Project;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import com.intellij.openapi.ui.playback.commands.ActionCommand;
|
import com.intellij.openapi.ui.playback.commands.ActionCommand;
|
||||||
import com.intellij.openapi.ui.popup.*;
|
import com.intellij.openapi.ui.popup.*;
|
||||||
|
import com.intellij.openapi.util.Comparing;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.Ref;
|
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.ChangeListManager;
|
||||||
import com.intellij.openapi.vcs.changes.LocalChangeList;
|
import com.intellij.openapi.vcs.changes.LocalChangeList;
|
||||||
import com.intellij.tasks.ChangeListInfo;
|
import com.intellij.tasks.ChangeListInfo;
|
||||||
import com.intellij.tasks.LocalTask;
|
import com.intellij.tasks.LocalTask;
|
||||||
import com.intellij.tasks.TaskManager;
|
import com.intellij.tasks.TaskManager;
|
||||||
|
import com.intellij.tasks.config.TaskSettings;
|
||||||
import com.intellij.tasks.impl.LocalTaskImpl;
|
import com.intellij.tasks.impl.LocalTaskImpl;
|
||||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||||
import com.intellij.tools.SimpleActionGroup;
|
import com.intellij.tools.SimpleActionGroup;
|
||||||
@@ -50,7 +55,61 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Dmitry Avdeev
|
* @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
|
@Override
|
||||||
public void actionPerformed(AnActionEvent e) {
|
public void actionPerformed(AnActionEvent e) {
|
||||||
@@ -61,9 +120,9 @@ public class SwitchTaskAction extends BaseTaskAction {
|
|||||||
popup.showCenteredInCurrentWindow(project);
|
popup.showCenteredInCurrentWindow(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ListPopupImpl createPopup(final DataContext dataContext,
|
private static ListPopupImpl createPopup(final DataContext dataContext,
|
||||||
@Nullable final Runnable onDispose,
|
@Nullable final Runnable onDispose,
|
||||||
boolean withTitle) {
|
boolean withTitle) {
|
||||||
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||||
final Ref<Boolean> shiftPressed = Ref.create(false);
|
final Ref<Boolean> shiftPressed = Ref.create(false);
|
||||||
final Ref<JComponent> componentRef = Ref.create();
|
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.ide.ui.customization.CustomActionsSchema;
|
||||||
import com.intellij.openapi.actionSystem.*;
|
import com.intellij.openapi.actionSystem.*;
|
||||||
import com.intellij.openapi.actionSystem.impl.ActionToolbarImpl;
|
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.tasks.config.TaskSettings;
|
||||||
import com.intellij.testFramework.IdeaTestCase;
|
|
||||||
import com.intellij.testFramework.TestActionEvent;
|
import com.intellij.testFramework.TestActionEvent;
|
||||||
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
|
|||||||
|
|
||||||
public void testTaskComboVisible() throws Exception {
|
public void testTaskComboVisible() throws Exception {
|
||||||
|
|
||||||
SwitchTaskCombo combo = null;
|
SwitchTaskAction combo = null;
|
||||||
ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
|
ActionGroup group = (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_MAIN_TOOLBAR);
|
||||||
ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
|
ActionToolbarImpl toolbar = (ActionToolbarImpl)ActionManager.getInstance().createActionToolbar(ActionPlaces.MAIN_TOOLBAR, group, true);
|
||||||
AnAction[] children = group.getChildren(new TestActionEvent());
|
AnAction[] children = group.getChildren(new TestActionEvent());
|
||||||
@@ -40,8 +39,8 @@ public class TaskUiTest extends CodeInsightFixtureTestCase {
|
|||||||
if (child instanceof ActionGroup) {
|
if (child instanceof ActionGroup) {
|
||||||
AnAction[] actions = ((ActionGroup)child).getChildren(new TestActionEvent());
|
AnAction[] actions = ((ActionGroup)child).getChildren(new TestActionEvent());
|
||||||
for (AnAction action : actions) {
|
for (AnAction action : actions) {
|
||||||
if (action instanceof SwitchTaskCombo) {
|
if (action instanceof SwitchTaskAction) {
|
||||||
combo = (SwitchTaskCombo)action;
|
combo = (SwitchTaskAction)action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user