Templates/TemplateViewer.py

changeset 584
b5d4c116952a
parent 564
b3d966393ba9
child 587
3078a9781573
diff -r 08bc660d6a15 -r b5d4c116952a Templates/TemplateViewer.py
--- a/Templates/TemplateViewer.py	Fri Sep 10 12:41:55 2010 +0200
+++ b/Templates/TemplateViewer.py	Fri Sep 10 20:03:59 2010 +0200
@@ -858,20 +858,20 @@
         
         @param filename name of a templates file to read (string)
         """
-        try:
-            if filename is None:
-                filename = os.path.join(Utilities.getConfigDir(), "eric5templates.e4c")
-            f = open(filename, "w", encoding = "utf-8")
-            
-            TemplatesWriter(f, self).writeXML()
-            
-            f.close()
-        except IOError:
+        if filename is None:
+            filename = os.path.join(Utilities.getConfigDir(), "eric5templates.e4c")
+        f = QFile(filename)
+        ok = f.open(QIODevice.WriteOnly)
+        if not ok:
             E5MessageBox.critical(self,
                 self.trUtf8("Save templates"),
                 self.trUtf8("<p>The templates file <b>{0}</b> could not be written.</p>")
                     .format(filename))
+            return
         
+        TemplatesWriter(f, self).writeXML()
+        f.close()
+    
     def readTemplates(self, filename = None):
         """
         Public method to read in the templates file (.e4c)
@@ -962,4 +962,4 @@
         names = []
         for group in list(self.groups.values()):
             names.extend(group.getEntryNames(start))
-        return sorted(names)
\ No newline at end of file
+        return sorted(names)

eric ide

mercurial