eric6/UI/UserInterface.py

branch
jsonfiles
changeset 8011
630a173cb137
parent 8009
29818ac4853c
child 8019
5fb467ac4233
--- a/eric6/UI/UserInterface.py	Wed Jan 27 15:11:03 2021 +0100
+++ b/eric6/UI/UserInterface.py	Wed Jan 27 18:27:52 2021 +0100
@@ -53,6 +53,8 @@
 
 from Sessions.SessionFile import SessionFile
 
+from Tasks.TasksFile import TasksFile
+
 from E5Network.E5NetworkProxyFactory import (
     E5NetworkProxyFactory, proxyAuthenticationRequired
 )
@@ -614,6 +616,7 @@
         
         # create the various JSON file interfaces
         self.__sessionFile = SessionFile(True)
+        self.__tasksFile = TasksFile(True)
         
         # Initialize the actions, menus, toolbars and statusbar
         splash.showMessage(self.tr("Initializing Actions..."))
@@ -6477,47 +6480,37 @@
     
     def __writeTasks(self):
         """
-        Private slot to write the tasks data to an XML file (.e6t).
-        """
-        fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.e6t")
-        f = QFile(fn)
-        ok = f.open(QIODevice.WriteOnly)
-        if not ok:
-            E5MessageBox.critical(
-                self,
-                self.tr("Save tasks"),
-                self.tr(
-                    "<p>The tasks file <b>{0}</b> could not be written.</p>")
-                .format(fn))
-            return
-        
-        from E5XML.TasksWriter import TasksWriter
-        TasksWriter(f, False).writeXML()
-        f.close()
-        
+        Private slot to write the tasks data to a JSON file (.etj).
+        """
+        fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.etj")
+        self.__tasksFile.writeFile(fn)
+    
     def __readTasks(self):
         """
-        Private slot to read in the tasks file (.e6t).
-        """
-        fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.e6t")
-        if not os.path.exists(fn):
-            # try again with the old extension
-            fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.e4t")
-            if not os.path.exists(fn):
-                return
-        f = QFile(fn)
-        if f.open(QIODevice.ReadOnly):
-            from E5XML.TasksReader import TasksReader
-            reader = TasksReader(f, viewer=self.taskViewer)
-            reader.readXML()
-            f.close()
+        Private slot to read in the tasks file (.etj or .e6t).
+        """
+        fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.etj")
+        if os.path.exists(fn):
+            # try new style JSON file first
+            self.__tasksFile.readFile(fn)
         else:
-            E5MessageBox.critical(
-                self,
-                self.tr("Read tasks"),
-                self.tr(
-                    "<p>The tasks file <b>{0}</b> could not be read.</p>")
-                .format(fn))
+            # try old style XML file second
+            fn = os.path.join(Utilities.getConfigDir(), "eric6tasks.e6t")
+            if os.path.exists(fn):
+                f = QFile(fn)
+                if f.open(QIODevice.ReadOnly):
+                    from E5XML.TasksReader import TasksReader
+                    reader = TasksReader(f, viewer=self.taskViewer)
+                    reader.readXML()
+                    f.close()
+                else:
+                    E5MessageBox.critical(
+                        self,
+                        self.tr("Read Tasks"),
+                        self.tr(
+                            "<p>The tasks file <b>{0}</b> could not be"
+                            " read.</p>")
+                        .format(fn))
         
     def __writeSession(self, filename="", crashSession=False):
         """

eric ide

mercurial