[latexila] Use Utils.save_file() (simplify the code)



commit 35e7db380a454070652a6a7fc10a9820cfde6144
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Sat Mar 10 21:14:45 2012 +0100

    Use Utils.save_file() (simplify the code)

 src/build_tools.vala       |   20 +++-----------------
 src/most_used_symbols.vala |   15 +--------------
 src/projects.vala          |   15 +--------------
 3 files changed, 5 insertions(+), 45 deletions(-)
---
diff --git a/src/build_tools.vala b/src/build_tools.vala
index e905f93..65dd50b 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -420,23 +420,9 @@ public class BuildTools
         }
         content += "</tools>\n";
 
-        try
-        {
-            File file = get_user_config_file ();
-
-            // check if parent directories exist, if not, create it
-            File parent = file.get_parent ();
-            if (parent != null && ! parent.query_exists ())
-                parent.make_directory_with_parents ();
-
-            // a backup is made
-            file.replace_contents (content.data, null, true,
-                FileCreateFlags.NONE, null, null);
-        }
-        catch (Error e)
-        {
-            warning ("Impossible to save build tools: %s", e.message);
-        }
+        // save the file
+        File file = get_user_config_file ();
+        Utils.save_file (file, content, true);
     }
 
     private File get_user_config_file ()
diff --git a/src/most_used_symbols.vala b/src/most_used_symbols.vala
index 645a099..976aacc 100644
--- a/src/most_used_symbols.vala
+++ b/src/most_used_symbols.vala
@@ -242,19 +242,6 @@ public class MostUsedSymbols : GLib.Object
         }
         content += "</symbols>\n";
 
-        try
-        {
-            // check if parent directories exist, if not, create it
-            File parent = file.get_parent ();
-            if (parent != null && ! parent.query_exists ())
-                parent.make_directory_with_parents ();
-
-            file.replace_contents (content.data, null, false,
-                FileCreateFlags.NONE, null, null);
-        }
-        catch (Error e)
-        {
-            warning ("Impossible to save the most used symbols: %s", e.message);
-        }
+        Utils.save_file (file, content);
     }
 }
diff --git a/src/projects.vala b/src/projects.vala
index 110d35f..f4feeb0 100644
--- a/src/projects.vala
+++ b/src/projects.vala
@@ -251,20 +251,7 @@ public class Projects
         }
         content += "</projects>\n";
 
-        try
-        {
-            // check if parent directories exist, if not, create it
-            File parent = file.get_parent ();
-            if (parent != null && ! parent.query_exists ())
-                parent.make_directory_with_parents ();
-
-            file.replace_contents (content.data, null, false,
-                FileCreateFlags.NONE, null, null);
-        }
-        catch (Error e)
-        {
-            warning ("Impossible to save the projects: %s", e.message);
-        }
+        Utils.save_file (file, content);
     }
 
     // returns true if dir1 is a subdirectory of dir2, or inversely



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]