[latexila] Build Tools: copy button to duplicate a build tool



commit f5beb2eb9d952fa64f48f20e0f871866e3ba8ead
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Thu Jun 23 18:49:01 2011 +0200

    Build Tools: copy button to duplicate a build tool
    
    We can modify the copy and keep the original.

 TODO                        |    2 -
 src/build_tools.vala        |   10 +++++-
 src/preferences_dialog.vala |   83 ++++++++++++++++++++++++++----------------
 3 files changed, 60 insertions(+), 35 deletions(-)
---
diff --git a/TODO b/TODO
index 0622eab..0d337d6 100644
--- a/TODO
+++ b/TODO
@@ -19,8 +19,6 @@ LaTeXila 2.2
 	  subsections becomes sections, etc.).
 
 - Build Tools:
-	- build tools: copy button to make a copy of a build tool,
-	  so we can modify the copy and keep the original
 	- right click menu in bottom panel: copy the line to the clipboard
 
 - Write some documentation:
diff --git a/src/build_tools.vala b/src/build_tools.vala
index 68d21bf..c864c0f 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -156,8 +156,16 @@ public class BuildTools
     {
         return_if_fail (build_tools != null);
 
+        insert (build_tools.size, tool);
+    }
+
+    public void insert (int pos, BuildTool tool)
+    {
+        return_if_fail (build_tools != null);
+        return_if_fail (0 <= pos && pos <= build_tools.size);
+
         tool.compilation = is_compilation (tool.icon);
-        build_tools.add (tool);
+        build_tools.insert (pos, tool);
         update_all_menus ();
     }
 
diff --git a/src/preferences_dialog.vala b/src/preferences_dialog.vala
index ca2a383..ed06764 100644
--- a/src/preferences_dialog.vala
+++ b/src/preferences_dialog.vala
@@ -293,49 +293,39 @@ public class PreferencesDialog : Dialog
         var build_tools_view = (TreeView) builder.get_object ("build_tools_treeview");
         init_build_tools_treeview (build_tools_view);
 
-        Button bt_new = (Button) builder.get_object ("build_tool_new");
-        bt_new.clicked.connect (() =>
+        Button bt_properties = builder.get_object ("build_tool_properties") as Button;
+        bt_properties.clicked.connect (() =>
         {
-            run_build_tool_dialog (-1);
+            int num = Utils.get_selected_row (build_tools_view);
+            if (0 <= num)
+                run_build_tool_dialog (num);
         });
 
-        Button bt_properties = (Button) builder.get_object ("build_tool_properties");
-        bt_properties.clicked.connect (() =>
+        Button bt_new = builder.get_object ("build_tool_new") as Button;
+        bt_new.clicked.connect (() =>
         {
-            int num = Utils.get_selected_row (build_tools_view);
-            run_build_tool_dialog (num);
+            run_build_tool_dialog (-1);
         });
 
-        Button bt_delete = (Button) builder.get_object ("build_tool_delete");
-        bt_delete.clicked.connect (() =>
+        Button bt_copy = builder.get_object ("build_tool_copy") as Button;
+        bt_copy.clicked.connect (() =>
         {
-            TreeIter iter;
-            int i = Utils.get_selected_row (build_tools_view, out iter);
-            if (i == -1)
+            int selected_row = Utils.get_selected_row (build_tools_view);
+            if (selected_row < 0)
                 return;
 
-            string label;
-            TreeModel model = (TreeModel) build_tools_store;
-            model.get (iter, BuildToolColumn.LABEL, out label, -1);
-
-            Dialog dialog = new MessageDialog (this, DialogFlags.DESTROY_WITH_PARENT,
-                MessageType.QUESTION, ButtonsType.NONE,
-                _("Do you really want to delete the build tool \"%s\"?"),
-                label);
-
-            dialog.add_buttons (Stock.CANCEL, ResponseType.CANCEL,
-                Stock.DELETE, ResponseType.YES);
+            BuildTools build_tools = BuildTools.get_default ();
+            BuildTool? tool = build_tools.get (selected_row);
+            return_if_fail (tool != null);
 
-            if (dialog.run () == ResponseType.YES)
-            {
-                build_tools_store.remove (iter);
-                BuildTools.get_default ().delete (i);
-            }
+            tool.show = false;
+            tool.label = _("%s [copy]").printf (tool.label);
+            build_tools.insert (selected_row + 1, tool);
 
-            dialog.destroy ();
+            update_build_tools_store ();
         });
 
-        Button bt_up = (Button) builder.get_object ("build_tool_up");
+        Button bt_up = builder.get_object ("build_tool_up") as Button;
         bt_up.clicked.connect (() =>
         {
             TreeIter iter1, iter2;
@@ -351,7 +341,7 @@ public class PreferencesDialog : Dialog
             }
         });
 
-        Button bt_down = (Button) builder.get_object ("build_tool_down");
+        Button bt_down = builder.get_object ("build_tool_down") as Button;
         bt_down.clicked.connect (() =>
         {
             TreeIter iter1, iter2;
@@ -367,7 +357,36 @@ public class PreferencesDialog : Dialog
             }
         });
 
-        Button bt_reset = (Button) builder.get_object ("build_tool_reset");
+        Button bt_delete = builder.get_object ("build_tool_delete") as Button;
+        bt_delete.clicked.connect (() =>
+        {
+            TreeIter iter;
+            int selected_row = Utils.get_selected_row (build_tools_view, out iter);
+            if (selected_row == -1)
+                return;
+
+            string label;
+            TreeModel model = (TreeModel) build_tools_store;
+            model.get (iter, BuildToolColumn.LABEL, out label, -1);
+
+            Dialog dialog = new MessageDialog (this, DialogFlags.DESTROY_WITH_PARENT,
+                MessageType.QUESTION, ButtonsType.NONE,
+                _("Do you really want to delete the build tool \"%s\"?"),
+                label);
+
+            dialog.add_buttons (Stock.CANCEL, ResponseType.CANCEL,
+                Stock.DELETE, ResponseType.YES);
+
+            if (dialog.run () == ResponseType.YES)
+            {
+                build_tools_store.remove (iter);
+                BuildTools.get_default ().delete (selected_row);
+            }
+
+            dialog.destroy ();
+        });
+
+        Button bt_reset = builder.get_object ("build_tool_reset") as Button;
         bt_reset.clicked.connect (() =>
         {
             Dialog dialog = get_reset_all_confirm_dialog (



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