[latexila] Build Tools: various code cleanup
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Build Tools: various code cleanup
- Date: Sun, 8 Jul 2012 17:30:15 +0000 (UTC)
commit 9fd67f07ec030f825a2b7a5e30ef7bbe99f93671
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Sun Jul 8 19:28:09 2012 +0200
Build Tools: various code cleanup
Build tool: s/show/enabled/
BuildTools: GLib.Object class (-> s/get()/get_by_id()/)
Explicitly use Gee
Remove dead code
...
src/build_tool_dialog.vala | 6 ++--
src/build_tool_runner.vala | 2 -
src/build_tools.vala | 51 ++++++++++++++++++++------------------
src/build_tools_preferences.vala | 36 ++++++++++++++------------
src/main_window.vala | 8 +++---
5 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/src/build_tool_dialog.vala b/src/build_tool_dialog.vala
index a0313f8..3af4964 100644
--- a/src/build_tool_dialog.vala
+++ b/src/build_tool_dialog.vala
@@ -92,7 +92,7 @@ private class BuildToolDialog : Dialog
return_val_if_fail (_instance != null, false);
BuildTools build_tools = BuildTools.get_default ();
- BuildTool? build_tool = build_tools[build_tool_num];
+ BuildTool? build_tool = build_tools.get_by_id (build_tool_num);
return_val_if_fail (build_tool != null, false);
@@ -103,7 +103,7 @@ private class BuildToolDialog : Dialog
if (ok)
{
BuildTool new_build_tool = _instance.retrieve_build_tool ();
- new_build_tool.show = build_tool.show;
+ new_build_tool.enabled = build_tool.enabled;
build_tools.update (build_tool_num, new_build_tool);
}
@@ -124,7 +124,7 @@ private class BuildToolDialog : Dialog
if (ok)
{
BuildTool new_build_tool = _instance.retrieve_build_tool ();
- new_build_tool.show = true;
+ new_build_tool.enabled = true;
BuildTools build_tools = BuildTools.get_default ();
build_tools.add (new_build_tool);
diff --git a/src/build_tool_runner.vala b/src/build_tool_runner.vala
index be697b2..62ee54d 100644
--- a/src/build_tool_runner.vala
+++ b/src/build_tool_runner.vala
@@ -29,7 +29,6 @@ public class BuildToolRunner : GLib.Object
private string output = "";
private BuildView view;
- private bool compilation;
private string document_view_program;
private bool latexmk_show_all;
private Gtk.Action action_stop_exec;
@@ -52,7 +51,6 @@ public class BuildToolRunner : GLib.Object
Gtk.Action action_stop_exec)
{
this.file = file;
- this.compilation = tool.compilation;
this.action_stop_exec = action_stop_exec;
filename = file.get_parse_name ();
diff --git a/src/build_tools.vala b/src/build_tools.vala
index a03f9cb..7a05906 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -1,7 +1,7 @@
/*
* This file is part of LaTeXila.
*
- * Copyright  2010-2011 SÃbastien Wilmet
+ * Copyright  2010-2012 SÃbastien Wilmet
*
* LaTeXila is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -15,10 +15,10 @@
*
* You should have received a copy of the GNU General Public License
* along with LaTeXila. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: SÃbastien Wilmet
*/
-using Gee;
-
public enum PostProcessorType
{
// please keep these items sorted in alphabetical order (for the build tool dialog)
@@ -32,19 +32,19 @@ public enum PostProcessorType
public struct BuildJob
{
- public PostProcessorType post_processor;
- public string command;
+ PostProcessorType post_processor;
+ string command;
}
public struct BuildTool
{
- public string description;
- public string extensions;
- public string label;
- public string icon;
- public bool show;
- public bool compilation;
- public ArrayList<BuildJob?> jobs;
+ string description;
+ string extensions;
+ string label;
+ string icon;
+ bool enabled;
+ bool compilation;
+ Gee.ArrayList<BuildJob?> jobs;
}
public enum DocType
@@ -55,7 +55,7 @@ public enum DocType
LAST
}
-public class BuildTools
+public class BuildTools : GLib.Object
{
private static BuildTools _instance = null;
@@ -68,7 +68,7 @@ public class BuildTools
"rubber"
};
- private LinkedList<BuildTool?> _build_tools;
+ private Gee.LinkedList<BuildTool?> _build_tools;
private BuildTool _cur_tool;
private BuildJob _cur_job;
@@ -86,15 +86,15 @@ public class BuildTools
return _instance;
}
- public BuildTool? get (int id)
+ public BuildTool? get_by_id (int id)
{
- return_val_if_fail (id >= 0 && id < _build_tools.size, null);
+ return_val_if_fail (0 <= id && id < _build_tools.size, null);
return _build_tools[id];
}
- public Iterator<BuildTool?> iterator ()
+ public Gee.Iterator<BuildTool?> iterator ()
{
- return (Iterator<BuildTool?>) _build_tools.iterator ();
+ return _build_tools.iterator ();
}
public BuildTool? get_view_doc (DocType type)
@@ -193,7 +193,7 @@ public class BuildTools
private bool is_equal (BuildTool tool1, BuildTool tool2)
{
- if (tool1.show != tool2.show
+ if (tool1.enabled != tool2.enabled
|| tool1.label != tool2.label
|| tool1.description != tool2.description
|| tool1.extensions != tool2.extensions
@@ -243,7 +243,7 @@ public class BuildTools
private void load ()
{
- _build_tools = new LinkedList<BuildTool?> ();
+ _build_tools = new Gee.LinkedList<BuildTool?> ();
// First, try to load the user config file if it exists.
// Otherwise try to load the default file (from most desirable to least desirable,
@@ -297,14 +297,16 @@ public class BuildTools
case "tool":
_cur_tool = BuildTool ();
_cur_tool.compilation = false;
- _cur_tool.jobs = new ArrayList<BuildJob?> ();
+ _cur_tool.jobs = new Gee.ArrayList<BuildJob?> ();
for (int i = 0 ; i < attr_names.length ; i++)
{
switch (attr_names[i])
{
+ // 'show' was the previous name of 'enabled'
case "show":
- _cur_tool.show = bool.parse (attr_values[i]);
+ case "enabled":
+ _cur_tool.enabled = bool.parse (attr_values[i]);
break;
case "extensions":
_cur_tool.extensions = attr_values[i];
@@ -401,8 +403,9 @@ public class BuildTools
string content = "<tools>";
foreach (BuildTool tool in _build_tools)
{
- content += "\n <tool show=\"%s\" extensions=\"%s\" icon=\"%s\">\n".printf (
- tool.show.to_string (), tool.extensions, tool.icon);
+ content += "\n <tool enabled=\"%s\"".printf (tool.enabled.to_string ());
+ content += " extensions=\"%s\"".printf (tool.extensions);
+ content += " icon=\"%s\">\n".printf (tool.icon);
content += Markup.printf_escaped (" <label>%s</label>\n", tool.label);
content += Markup.printf_escaped (" <description>%s</description>\n",
diff --git a/src/build_tools_preferences.vala b/src/build_tools_preferences.vala
index 1e65024..9d7b8ce 100644
--- a/src/build_tools_preferences.vala
+++ b/src/build_tools_preferences.vala
@@ -29,7 +29,7 @@ public class BuildToolsPreferences : Grid
{
private enum BuildToolColumn
{
- ENABLE,
+ ENABLED,
PIXBUF,
LABEL,
DESCRIPTION,
@@ -79,7 +79,7 @@ public class BuildToolsPreferences : Grid
private void init_list_store ()
{
_list_store = new ListStore (BuildToolColumn.N_COLUMNS,
- typeof (bool), // enable
+ typeof (bool), // enabled
typeof (string), // pixbuf (stock-id)
typeof (string), // label
typeof (string) // description
@@ -93,14 +93,14 @@ public class BuildToolsPreferences : Grid
_tree_view = new TreeView.with_model (_list_store);
_tree_view.set_rules_hint (true);
- TreeViewColumn enable_column = new TreeViewColumn ();
- enable_column.set_title (_("Enable"));
- _tree_view.append_column (enable_column);
+ TreeViewColumn enabled_column = new TreeViewColumn ();
+ enabled_column.set_title (_("Enabled"));
+ _tree_view.append_column (enabled_column);
CellRendererToggle toggle_renderer = new CellRendererToggle ();
- enable_column.pack_start (toggle_renderer, false);
- enable_column.set_attributes (toggle_renderer,
- "active", BuildToolColumn.ENABLE);
+ enabled_column.pack_start (toggle_renderer, false);
+ enabled_column.set_attributes (toggle_renderer,
+ "active", BuildToolColumn.ENABLED);
TreeViewColumn label_column = new TreeViewColumn ();
label_column.set_title (_("Label"));
@@ -127,17 +127,19 @@ public class BuildToolsPreferences : Grid
TreeIter iter;
_list_store.get_iter_from_string (out iter, path_string);
- bool enable;
+ bool enabled;
TreeModel model = _list_store as TreeModel;
- model.get (iter, BuildToolColumn.ENABLE, out enable);
+ model.get (iter, BuildToolColumn.ENABLED, out enabled);
- enable = ! enable;
- _list_store.set (iter, BuildToolColumn.ENABLE, enable);
+ enabled = ! enabled;
+ _list_store.set (iter, BuildToolColumn.ENABLED, enabled);
int num = int.parse (path_string);
BuildTools build_tools = BuildTools.get_default ();
- BuildTool build_tool = build_tools[num];
- build_tool.show = enable;
+ BuildTool? build_tool = build_tools.get_by_id (num);
+ return_if_fail (build_tool != null);
+
+ build_tool.enabled = enabled;
build_tools.update (num, build_tool);
});
@@ -187,10 +189,10 @@ public class BuildToolsPreferences : Grid
return;
BuildTools build_tools = BuildTools.get_default ();
- BuildTool? tool = build_tools[selected_row];
+ BuildTool? tool = build_tools.get_by_id (selected_row);
return_if_fail (tool != null);
- tool.show = false;
+ tool.enabled = false;
tool.label = _("%s [copy]").printf (tool.label);
build_tools.insert (selected_row + 1, tool);
@@ -402,7 +404,7 @@ public class BuildToolsPreferences : Grid
TreeIter iter;
_list_store.append (out iter);
_list_store.set (iter,
- BuildToolColumn.ENABLE, tool.show,
+ BuildToolColumn.ENABLED, tool.enabled,
BuildToolColumn.PIXBUF, tool.icon,
BuildToolColumn.LABEL, tool.label,
BuildToolColumn.DESCRIPTION, Markup.escape_text (tool.description)
diff --git a/src/main_window.vala b/src/main_window.vala
index 6e27c0b..43e006f 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -1178,7 +1178,7 @@ public class MainWindow : Window
int j = 0;
foreach (BuildTool build_tool in build_tools)
{
- if (! build_tool.show)
+ if (! build_tool.enabled)
{
i++;
continue;
@@ -1215,7 +1215,7 @@ public class MainWindow : Window
string[] _name = action.name.split ("_");
int tool_index = int.parse (_name[1]);
- BuildTool? tool = BuildTools.get_default ()[tool_index];
+ BuildTool? tool = BuildTools.get_default ().get_by_id (tool_index);
return_if_fail (tool != null);
if (! tool.compilation)
@@ -1223,7 +1223,7 @@ public class MainWindow : Window
build_view.show ();
- // save the document if it's a compilation (e.g. with rubber)
+ // save the document if it's a compilation
if (tool.compilation)
{
if (active_document.location == null)
@@ -1426,7 +1426,7 @@ public class MainWindow : Window
int tool_num = 0;
foreach (BuildTool tool in BuildTools.get_default ())
{
- if (! tool.show)
+ if (! tool.enabled)
{
tool_num++;
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]