tasks: saving context on commit
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Thu, 29 Dec 2011 14:46:58 +0000 (18:46 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Fri, 30 Dec 2011 11:02:57 +0000 (15:02 +0400)
plugins/tasks/tasks-core/src/META-INF/plugin.xml
plugins/tasks/tasks-core/src/com/intellij/tasks/config/TaskConfigurable.form
plugins/tasks/tasks-core/src/com/intellij/tasks/config/TaskConfigurable.java
plugins/tasks/tasks-core/src/com/intellij/tasks/context/WorkingContextManager.java
plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCheckinHandlerFactory.java [new file with mode: 0644]
plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskManagerImpl.java

index f038f640e5ebaadd1439c4111b49ca6f61874faa..6ad70bca3fb8940b57ec573870060f143ccf3493 100644 (file)
@@ -15,9 +15,7 @@
     <component>
       <interface-class>com.intellij.tasks.TaskManager</interface-class>
       <implementation-class>com.intellij.tasks.impl.TaskManagerImpl</implementation-class>
-      <skipForDefaultProject/>
     </component>
-
   </project-components>
 
   <actions>
     <tasks.repositoryType implementation="com.intellij.tasks.redmine.RedmineRepositoryType"/>
     <tasks.repositoryType implementation="com.intellij.tasks.trac.TracRepositoryType"/>
 
+    <checkinHandlerFactory implementation="com.intellij.tasks.impl.TaskCheckinHandlerFactory"/>
     <!--<tasks.repositoryType implementation="com.intellij.tasks.mantis.MantisRepositoryType"/>-->
   </extensions>
 
index 001f2d52ad5dd0d5d6323c34d519d043c766fdaf..ad72e0947e23537af53cc67fcd2f9893238f99cc 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.tasks.config.TaskConfigurable">
-  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
       <xy x="20" y="20" width="555" height="400"/>
     <children>
       <component id="e53da" class="javax.swing.JCheckBox" binding="myUpdateCheckBox" default-binding="true">
         <constraints>
-          <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+          <grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties>
-          <text value="Enable issue cache"/>
+          <text value="Enable issue &amp;cache"/>
         </properties>
       </component>
       <component id="9f69d" class="javax.swing.JFormattedTextField" binding="myHistoryLength">
         </constraints>
         <properties>
           <horizontalAlignment value="4"/>
-          <text value="Task history length:"/>
+          <text value="Task history &amp;length:"/>
         </properties>
       </component>
       <vspacer id="3f700">
         <constraints>
-          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
       </vspacer>
       <grid id="e4d1f" binding="myCacheSettings" layout-manager="GridLayoutManager" row-count="1" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
-          <grid row="2" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
+          <grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false"/>
         </constraints>
         <properties/>
         <clientProperties>
           <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
         </constraints>
       </hspacer>
+      <component id="6f93" class="javax.swing.JCheckBox" binding="mySaveContextOnCommit">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="&amp;Save context on commit"/>
+        </properties>
+      </component>
     </children>
   </grid>
 </form>
index 342c13c2343345e3d5d8714017b91f5c9e87df39..389a9e515f16d0b1bd0f6318d5b59605a1c4d951 100644 (file)
@@ -41,6 +41,9 @@ public class TaskConfigurable extends BindableConfigurable implements Searchable
   private JTextField myHistoryLength;
   private JPanel myCacheSettings;
 
+  @BindControl("saveContextOnCommit")
+  private JCheckBox mySaveContextOnCommit;
+
   private final Project myProject;
   private Configurable[] myConfigurables;
   private final NotNullLazyValue<ControlBinder> myControlBinder = new NotNullLazyValue<ControlBinder>() {
index 26f35e80abecda6f0e99e9ec3e81cf6d458fd86e..a3e4cfb3f47b3358ddc2f3fc07608fb69dbbb337 100644 (file)
@@ -107,7 +107,7 @@ public class WorkingContextManager {
     saveContext(entryName, TASKS_ZIP_POSTFIX, task.getSummary());
   }
 
-  public void saveContext(String entryName, @Nullable String comment) {
+  public void saveContext(@Nullable String entryName, @Nullable String comment) {
     saveContext(entryName, CONTEXT_ZIP_POSTFIX, comment);
   }
 
diff --git a/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCheckinHandlerFactory.java b/plugins/tasks/tasks-core/src/com/intellij/tasks/impl/TaskCheckinHandlerFactory.java
new file mode 100644 (file)
index 0000000..db91fce
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+package com.intellij.tasks.impl;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.vcs.CheckinProjectPanel;
+import com.intellij.openapi.vcs.changes.CommitContext;
+import com.intellij.openapi.vcs.checkin.CheckinHandler;
+import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
+import com.intellij.tasks.TaskManager;
+import com.intellij.tasks.context.WorkingContextManager;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+
+/**
+ * @author Dmitry Avdeev
+ *         Date: 12/29/11
+ */
+public class TaskCheckinHandlerFactory extends CheckinHandlerFactory {
+
+  @NotNull
+  @Override
+  public CheckinHandler createHandler(final CheckinProjectPanel panel, final CommitContext commitContext) {
+    return new CheckinHandler() {
+      @Override
+      public void checkinSuccessful() {
+        final String message = panel.getCommitMessage();
+        if (message != null) {
+          final Project project = panel.getProject();
+          TaskManagerImpl manager = (TaskManagerImpl)TaskManager.getManager(project);
+          if (manager.getState().saveContextOnCommit) {
+            SwingUtilities.invokeLater(new Runnable() {
+              @Override
+              public void run() {
+                WorkingContextManager.getInstance(project).saveContext(null, message);
+              }
+            });
+          }
+        }
+      }
+    };
+  }
+}
index aa4ddaba161e046b4b09e91e751d174e58663083..f881ce53ca45d4763048225bc6a55a41d1aec599 100644 (file)
@@ -782,6 +782,7 @@ public class TaskManagerImpl extends TaskManager implements ProjectComponent, Pe
 
     public boolean clearContext = true;
     public boolean createChangelist = true;
+    public boolean saveContextOnCommit = true;
     public boolean trackContextForNewChangelist = true;
     public boolean markAsInProgress = false;