Changed TaskViewer to prvent the addition of a duplicate task. eric7

Sun, 03 Oct 2021 18:36:41 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Oct 2021 18:36:41 +0200
branch
eric7
changeset 8664
5aa1070daa48
parent 8663
a925267d1545
child 8666
3a62b4009df9

Changed TaskViewer to prvent the addition of a duplicate task.

eric7/APIs/Python3/eric7.api file | annotate | diff | comparison | revisions
eric7/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric7/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
eric7/Documentation/Source/eric7.Tasks.TaskViewer.html file | annotate | diff | comparison | revisions
eric7/EricXML/TasksReader.py file | annotate | diff | comparison | revisions
eric7/Tasks/TaskViewer.py file | annotate | diff | comparison | revisions
eric7/Tasks/TasksFile.py file | annotate | diff | comparison | revisions
--- a/eric7/APIs/Python3/eric7.api	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/APIs/Python3/eric7.api	Sun Oct 03 18:36:41 2021 +0200
@@ -9015,6 +9015,7 @@
 eric7.Tasks.TaskViewer.TaskViewer.clearFileTasks?4(filename, conditionally=False)
 eric7.Tasks.TaskViewer.TaskViewer.clearProjectTasks?4(fileOnly=False)
 eric7.Tasks.TaskViewer.TaskViewer.clearTasks?4()
+eric7.Tasks.TaskViewer.TaskViewer.containsTask?4(taskToTest)
 eric7.Tasks.TaskViewer.TaskViewer.displayFile?7
 eric7.Tasks.TaskViewer.TaskViewer.findParentTask?4(parentUid)
 eric7.Tasks.TaskViewer.TaskViewer.getGlobalTasks?4()
Binary file eric7/Documentation/Help/source.qch has changed
--- a/eric7/Documentation/Help/source.qhp	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/Documentation/Help/source.qhp	Sun Oct 03 18:36:41 2021 +0200
@@ -15275,6 +15275,7 @@
       <keyword name="TaskViewer.clearFileTasks" id="TaskViewer.clearFileTasks" ref="eric7.Tasks.TaskViewer.html#TaskViewer.clearFileTasks" />
       <keyword name="TaskViewer.clearProjectTasks" id="TaskViewer.clearProjectTasks" ref="eric7.Tasks.TaskViewer.html#TaskViewer.clearProjectTasks" />
       <keyword name="TaskViewer.clearTasks" id="TaskViewer.clearTasks" ref="eric7.Tasks.TaskViewer.html#TaskViewer.clearTasks" />
+      <keyword name="TaskViewer.containsTask" id="TaskViewer.containsTask" ref="eric7.Tasks.TaskViewer.html#TaskViewer.containsTask" />
       <keyword name="TaskViewer.findParentTask" id="TaskViewer.findParentTask" ref="eric7.Tasks.TaskViewer.html#TaskViewer.findParentTask" />
       <keyword name="TaskViewer.getGlobalTasks" id="TaskViewer.getGlobalTasks" ref="eric7.Tasks.TaskViewer.html#TaskViewer.getGlobalTasks" />
       <keyword name="TaskViewer.getProjectTasks" id="TaskViewer.getProjectTasks" ref="eric7.Tasks.TaskViewer.html#TaskViewer.getProjectTasks" />
--- a/eric7/Documentation/Source/eric7.Tasks.TaskViewer.html	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/Documentation/Source/eric7.Tasks.TaskViewer.html	Sun Oct 03 18:36:41 2021 +0200
@@ -288,6 +288,10 @@
 <td>Public slot to clear all tasks from display.</td>
 </tr>
 <tr>
+<td><a href="#TaskViewer.containsTask">containsTask</a></td>
+<td>Public method to test, if a task is already in the tasks list.</td>
+</tr>
+<tr>
 <td><a href="#TaskViewer.findParentTask">findParentTask</a></td>
 <td>Public method to find a parent task by its ID.</td>
 </tr>
@@ -684,6 +688,32 @@
 <p>
         Public slot to clear all tasks from display.
 </p>
+<a NAME="TaskViewer.containsTask" ID="TaskViewer.containsTask"></a>
+<h4>TaskViewer.containsTask</h4>
+<b>containsTask</b>(<i>taskToTest</i>)
+
+<p>
+        Public method to test, if a task is already in the tasks list.
+</p>
+<dl>
+
+<dt><i>taskToTest</i> (Task)</dt>
+<dd>
+task to look for
+</dd>
+</dl>
+<dl>
+<dt>Return:</dt>
+<dd>
+flag indicating the existence of the task
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
 <a NAME="TaskViewer.findParentTask" ID="TaskViewer.findParentTask"></a>
 <h4>TaskViewer.findParentTask</h4>
 <b>findParentTask</b>(<i>parentUid</i>)
--- a/eric7/EricXML/TasksReader.py	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/EricXML/TasksReader.py	Sun Oct 03 18:36:41 2021 +0200
@@ -122,7 +122,8 @@
                     isProjectTask=self.forProject, taskType=task["type"],
                     description=task["description"], uid=task["uid"],
                     parentTask=parentTask)
-                self.tasks.append((addedTask, expanded))
+                if addedTask:
+                    self.tasks.append((addedTask, expanded))
                 break
             
             if self.isStartElement():
--- a/eric7/Tasks/TaskViewer.py	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/Tasks/TaskViewer.py	Sun Oct 03 18:36:41 2021 +0200
@@ -229,6 +229,26 @@
         
         return parentTask
     
+    def containsTask(self, taskToTest):
+        """
+        Public method to test, if a task is already in the tasks list.
+        
+        @param taskToTest task to look for
+        @type Task
+        @return flag indicating the existence of the task
+        @rtype bool
+        """
+        if taskToTest is None:
+            # play it safe
+            return False
+        
+        return any(
+            (task.summary == taskToTest.summary) and
+            (task.filename == taskToTest.filename) and
+            (task.lineno == taskToTest.lineno)
+            for task in self.tasks
+        )
+    
     def __refreshDisplay(self):
         """
         Private method to refresh the display.
@@ -369,24 +389,27 @@
         task = Task(summary, priority, filename, lineno, completed,
                     _time, isProjectTask, taskType,
                     self.project, description, uid, parentUid)
-        self.tasks.append(task)
-        if parentTask:
-            parentTask.addChild(task)
-            parentTask.setExpanded(True)
-        elif filename:
-            self.__extractedItem.addChild(task)
+        if not self.containsTask(task):
+            self.tasks.append(task)
+            if parentTask:
+                parentTask.addChild(task)
+                parentTask.setExpanded(True)
+            elif filename:
+                self.__extractedItem.addChild(task)
+            else:
+                self.__manualItem.addChild(task)
+            task.setHidden(not self.taskFilter.showTask(task))
+            
+            self.__checkTopLevelItems()
+            self.__resort()
+            self.__resizeColumns()
+            
+            if isProjectTask:
+                self.__projectTasksSaveTimer.changeOccurred()
+            
+            return task
         else:
-            self.__manualItem.addChild(task)
-        task.setHidden(not self.taskFilter.showTask(task))
-        
-        self.__checkTopLevelItems()
-        self.__resort()
-        self.__resizeColumns()
-        
-        if isProjectTask:
-            self.__projectTasksSaveTimer.changeOccurred()
-        
-        return task
+            return None
     
     def addFileTask(self, summary, filename, lineno, taskType=TaskType.TODO,
                     description=""):
--- a/eric7/Tasks/TasksFile.py	Sun Oct 03 17:25:49 2021 +0200
+++ b/eric7/Tasks/TasksFile.py	Sun Oct 03 18:36:41 2021 +0200
@@ -144,7 +144,8 @@
                 taskType=TaskType(task["type"]),
                 description=task["description"], uid=task["uid"],
                 parentTask=task["parent_uid"])
-            addedTasks.append((addedTask, task["expanded"]))
+            if addedTask:
+                addedTasks.append((addedTask, task["expanded"]))
         
         for task, expanded in addedTasks:
             task.setExpanded(expanded)

eric ide

mercurial