diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.form b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.form new file mode 100644 index 000000000000..aa4527c401e5 --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.form @@ -0,0 +1,63 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.java new file mode 100644 index 000000000000..79362bdec5be --- /dev/null +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/EditTaskDialog.java @@ -0,0 +1,132 @@ +/* + * 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.openapi.project.Project; +import com.intellij.openapi.ui.ComboBox; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vcs.AbstractVcs; +import com.intellij.openapi.vcs.VcsTaskHandler; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.LocalChangeList; +import com.intellij.tasks.BranchInfo; +import com.intellij.tasks.ChangeListInfo; +import com.intellij.tasks.TaskManager; +import com.intellij.tasks.impl.LocalTaskImpl; +import com.intellij.ui.CollectionComboBoxModel; +import com.intellij.ui.components.JBLabel; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.List; + +/** + * @author Dmitry Avdeev + */ +public class EditTaskDialog extends DialogWrapper { + + private final LocalTaskImpl myTask; + + private JPanel myPanel; + private JTextField mySummary; + private JBLabel myBranchLabel; + private ComboBox myBranch; + private JBLabel myChangelistLabel; + private ComboBox myChangelist; + + public static void editTask(LocalTaskImpl task, Project project) { + new EditTaskDialog(project, task).show(); + } + + protected EditTaskDialog(Project project, LocalTaskImpl task) { + super(project); + myTask = task; + setTitle("Edit Task " + task.getId()); + +// mySummary.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, ""); + mySummary.setText(task.getSummary()); + + AbstractVcs vcs = TaskManager.getManager(project).getActiveVcs(); + if (vcs == null) { + myBranchLabel.setVisible(false); + myBranch.setVisible(false); + myChangelistLabel.setVisible(false); + myChangelist.setVisible(false); + } + else { + ChangeListManager changeListManager = ChangeListManager.getInstance(project); + List changeLists = changeListManager.getChangeLists(); + myChangelist.setModel(new CollectionComboBoxModel(changeLists)); + final List lists = task.getChangeLists(); + if (!lists.isEmpty()) { + LocalChangeList list = changeListManager.getChangeList(lists.get(0).id); + myChangelist.setSelectedItem(list); + } + + VcsTaskHandler[] handlers = VcsTaskHandler.getAllHandlers(project); + if (handlers.length == 0) { + myBranchLabel.setVisible(false); + myBranch.setVisible(false); + } + else { + VcsTaskHandler.TaskInfo[] tasks = handlers[0].getAllExistingTasks(); + myBranch.setModel(new DefaultComboBoxModel(tasks)); + final List branches = task.getBranches(); + if (!branches.isEmpty()) { + VcsTaskHandler.TaskInfo info = ContainerUtil.find(tasks, new Condition() { + @Override + public boolean value(VcsTaskHandler.TaskInfo info) { + return branches.get(0).name.equals(info.getName()); + } + }); + myBranch.setSelectedItem(info); + } + } + } + init(); + } + + @Override + protected void doOKAction() { + myTask.setSummary(mySummary.getText()); + if (myChangelist.isVisible()) { + List changeLists = myTask.getChangeLists(); + changeLists.clear(); + ChangeListInfo item = (ChangeListInfo)myChangelist.getSelectedItem(); + if (item != null) { + changeLists.add(item); + } + } + if (myBranch.isVisible()) { + // todo + } + close(OK_EXIT_CODE); + } + + @Nullable + @Override + public JComponent getPreferredFocusedComponent() { + return mySummary; + } + + @Nullable + @Override + protected JComponent createCenterPanel() { + return myPanel; + } +} diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java index 84bc2bbbe933..4ae1ccbabcea 100644 --- a/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java +++ b/plugins/tasks/tasks-core/src/com/intellij/tasks/actions/SwitchTaskAction.java @@ -41,6 +41,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -149,6 +150,12 @@ public class SwitchTaskAction extends BaseTaskAction { manager.activateTask(task, !shiftPressed.get()); } }); + group.add(new AnAction("&Edit") { + @Override + public void actionPerformed(AnActionEvent e) { + EditTaskDialog.editTask(task, project); + } + }); } final AnAction remove = new AnAction("&Remove") { @Override @@ -161,6 +168,7 @@ public class SwitchTaskAction extends BaseTaskAction { } } }; + remove.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)), null); group.add(remove); return group;