[latexila/gnome-3] Clean the Latexila class



commit 7a2dbce87fbc3b0bcd11db5b872ad3ee27cddc93
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Mon Apr 2 15:38:46 2012 +0200

    Clean the Latexila class
    
    Use Gee.LinkedList instead of GLib.List. In Vala it's better.
    
    Remove Unique stuff.
    
    Move the stock icons additions in a separated file.

 src/build_tools.vala |    2 +-
 src/dialogs.vala     |    6 +-
 src/latexila.vala    |  273 ++++++++++----------------------------------------
 src/main_window.vala |   59 +++++------
 src/projects.vala    |   10 +-
 src/stock_icons.vala |  160 +++++++++++++++++++++++++++++
 6 files changed, 249 insertions(+), 261 deletions(-)
---
diff --git a/src/build_tools.vala b/src/build_tools.vala
index 34c4a7a..ecc7094 100644
--- a/src/build_tools.vala
+++ b/src/build_tools.vala
@@ -231,7 +231,7 @@ public class BuildTools
     private void update_all_menus ()
     {
         _modified = true;
-        foreach (MainWindow window in Latexila.get_default ().windows)
+        foreach (MainWindow window in Latexila.get_default ().get_windows ())
             window.update_build_tools_menu ();
     }
 
diff --git a/src/dialogs.vala b/src/dialogs.vala
index 0566428..39f6cc0 100644
--- a/src/dialogs.vala
+++ b/src/dialogs.vala
@@ -30,9 +30,9 @@ namespace Dialogs
     }
 
     public void
-    close_several_unsaved_documents (MainWindow window, List<Document> unsaved_docs)
+    close_several_unsaved_documents (MainWindow window, Gee.List<Document> unsaved_docs)
     {
-        return_if_fail (unsaved_docs.length () >= 2);
+        return_if_fail (unsaved_docs.size >= 2);
 
         Dialog dialog = new Dialog.with_buttons (null,
             window,
@@ -64,7 +64,7 @@ namespace Dialogs
         primary_label.margin_bottom = 4;
         primary_label.set_markup ("<span weight=\"bold\" size=\"larger\">"
             + _("There are %d documents with unsaved changes. Save changes before closing?")
-            .printf (unsaved_docs.length ())
+            .printf (unsaved_docs.size)
             + "</span>");
 
         grid.attach (primary_label, 1, 0, 1, 1);
diff --git a/src/latexila.vala b/src/latexila.vala
index 22e329f..ff5a6cb 100644
--- a/src/latexila.vala
+++ b/src/latexila.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,238 +15,102 @@
  *
  * 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
  */
 
 public class Latexila : GLib.Object
 {
-    struct StockIcon
+    private static Latexila _instance = null;
+    private Gee.List<MainWindow> _windows;
+
+    public MainWindow active_window { get; private set; }
+
+    // Latexila is a singleton.
+    private Latexila ()
     {
-        public string filename;
-        public string stock_id;
+        _windows = new Gee.LinkedList<MainWindow> ();
+
+        set_application_icons ();
+        StockIcons.add_custom ();
+
+        AppSettings.get_default ();
+        create_window ();
     }
 
-    private const StockIcon[] stock_icons =
+    public static Latexila get_default ()
     {
-        { Config.DATA_DIR + "/images/icons/compile_dvi.png", "compile_dvi" },
-        { Config.DATA_DIR + "/images/icons/compile_pdf.png", "compile_pdf" },
-        { Config.DATA_DIR + "/images/icons/compile_ps.png", "compile_ps" },
-        { Config.DATA_DIR + "/images/icons/view_dvi.png", "view_dvi" },
-        { Config.DATA_DIR + "/images/icons/view_pdf.png", "view_pdf" },
-        { Config.DATA_DIR + "/images/icons/view_ps.png", "view_ps" },
-        { Config.DATA_DIR + "/images/icons/textbf.png", "bold" },
-        { Config.DATA_DIR + "/images/icons/textit.png", "italic" },
-        { Config.DATA_DIR + "/images/icons/texttt.png", "typewriter" },
-        { Config.DATA_DIR + "/images/icons/textsl.png", "slanted" },
-        { Config.DATA_DIR + "/images/icons/textsc.png", "small_caps" },
-        { Config.DATA_DIR + "/images/icons/textsf.png", "sans_serif" },
-        { Config.DATA_DIR + "/images/icons/roman.png", "roman" },
-        { Config.DATA_DIR + "/images/icons/underline.png", "underline" },
-        { Config.DATA_DIR + "/images/misc-math/set-R.png", "blackboard" },
-        { Config.DATA_DIR + "/images/icons/sectioning-part.png", "sectioning-part" },
-        { Config.DATA_DIR + "/images/icons/sectioning-chapter.png",
-            "sectioning-chapter" },
-        { Config.DATA_DIR + "/images/icons/sectioning-section.png",
-            "sectioning-section" },
-        { Config.DATA_DIR + "/images/icons/sectioning-subsection.png",
-            "sectioning-subsection" },
-        { Config.DATA_DIR + "/images/icons/sectioning-subsubsection.png",
-            "sectioning-subsubsection" },
-        { Config.DATA_DIR + "/images/icons/sectioning-paragraph.png",
-            "sectioning-paragraph" },
-        { Config.DATA_DIR + "/images/icons/character-size.png", "character-size" },
-        { Config.DATA_DIR + "/images/icons/list-itemize.png", "list-itemize" },
-        { Config.DATA_DIR + "/images/icons/list-enumerate.png", "list-enumerate" },
-        { Config.DATA_DIR + "/images/icons/list-description.png", "list-description" },
-        { Config.DATA_DIR + "/images/icons/list-item.png", "list-item" },
-        { Config.DATA_DIR + "/images/icons/references.png", "references" },
-        { Config.DATA_DIR + "/images/icons/math.png", "math" },
-        { Config.DATA_DIR + "/images/icons/math-centered.png", "math-centered" },
-        { Config.DATA_DIR + "/images/icons/math-numbered.png", "math-numbered" },
-        { Config.DATA_DIR + "/images/icons/math-array.png", "math-array" },
-        { Config.DATA_DIR + "/images/icons/math-numbered-array.png",
-            "math-numbered-array" },
-        { Config.DATA_DIR + "/images/icons/math-superscript.png", "math-superscript" },
-        { Config.DATA_DIR + "/images/icons/math-subscript.png", "math-subscript" },
-        { Config.DATA_DIR + "/images/icons/math-frac.png", "math-frac" },
-        { Config.DATA_DIR + "/images/icons/math-square-root.png", "math-square-root" },
-        { Config.DATA_DIR + "/images/icons/math-nth-root.png", "math-nth-root" },
-        { Config.DATA_DIR + "/images/icons/mathcal.png", "mathcal" },
-        { Config.DATA_DIR + "/images/icons/mathfrak.png", "mathfrak" },
-        { Config.DATA_DIR + "/images/icons/delimiters-left.png", "delimiters-left" },
-        { Config.DATA_DIR + "/images/icons/delimiters-right.png", "delimiters-right" },
-        { Config.DATA_DIR + "/images/icons/badbox.png", "badbox" },
-        { Config.DATA_DIR + "/images/icons/logviewer.png", "view_log" },
-        { Config.DATA_DIR + "/images/greek/01.png", "symbol_alpha" },
-        { Config.DATA_DIR + "/images/icons/accent0.png", "accent0" },
-        { Config.DATA_DIR + "/images/icons/accent1.png", "accent1" },
-        { Config.DATA_DIR + "/images/icons/accent2.png", "accent2" },
-        { Config.DATA_DIR + "/images/icons/accent3.png", "accent3" },
-        { Config.DATA_DIR + "/images/icons/accent4.png", "accent4" },
-        { Config.DATA_DIR + "/images/icons/accent5.png", "accent5" },
-        { Config.DATA_DIR + "/images/icons/accent6.png", "accent6" },
-        { Config.DATA_DIR + "/images/icons/accent7.png", "accent7" },
-        { Config.DATA_DIR + "/images/icons/accent8.png", "accent8" },
-        { Config.DATA_DIR + "/images/icons/accent9.png", "accent9" },
-        { Config.DATA_DIR + "/images/icons/accent10.png", "accent10" },
-        { Config.DATA_DIR + "/images/icons/accent11.png", "accent11" },
-        { Config.DATA_DIR + "/images/icons/accent12.png", "accent12" },
-        { Config.DATA_DIR + "/images/icons/accent13.png", "accent13" },
-        { Config.DATA_DIR + "/images/icons/accent14.png", "accent14" },
-        { Config.DATA_DIR + "/images/icons/accent15.png", "accent15" },
-        { Config.DATA_DIR + "/images/icons/mathaccent0.png", "mathaccent0" },
-        { Config.DATA_DIR + "/images/icons/mathaccent1.png", "mathaccent1" },
-        { Config.DATA_DIR + "/images/icons/mathaccent2.png", "mathaccent2" },
-        { Config.DATA_DIR + "/images/icons/mathaccent3.png", "mathaccent3" },
-        { Config.DATA_DIR + "/images/icons/mathaccent4.png", "mathaccent4" },
-        { Config.DATA_DIR + "/images/icons/mathaccent5.png", "mathaccent5" },
-        { Config.DATA_DIR + "/images/icons/mathaccent6.png", "mathaccent6" },
-        { Config.DATA_DIR + "/images/icons/mathaccent7.png", "mathaccent7" },
-        { Config.DATA_DIR + "/images/icons/mathaccent8.png", "mathaccent8" },
-        { Config.DATA_DIR + "/images/icons/mathaccent9.png", "mathaccent9" },
-        { Config.DATA_DIR + "/images/icons/mathaccent10.png", "mathaccent10" },
-        { Config.DATA_DIR + "/images/icons/completion_choice.png", "completion_choice" },
-        { Config.DATA_DIR + "/images/icons/completion_cmd.png", "completion_cmd" },
-        { Config.DATA_DIR + "/images/icons/tree_part.png", "tree_part" },
-        { Config.DATA_DIR + "/images/icons/tree_chapter.png", "tree_chapter" },
-        { Config.DATA_DIR + "/images/icons/tree_section.png", "tree_section" },
-        { Config.DATA_DIR + "/images/icons/tree_subsection.png", "tree_subsection" },
-        { Config.DATA_DIR + "/images/icons/tree_subsubsection.png",
-            "tree_subsubsection" },
-        { Config.DATA_DIR + "/images/icons/tree_paragraph.png", "tree_paragraph" },
-        { Config.DATA_DIR + "/images/icons/tree_todo.png", "tree_todo" },
-        { Config.DATA_DIR + "/images/icons/tree_label.png", "tree_label" },
-        { Config.DATA_DIR + "/images/icons/table.png", "table" }
-    };
+        if (_instance == null)
+            _instance = new Latexila ();
 
-    public static int NEW_WINDOW = 1;
-    private static Latexila instance = null;
-    public unowned List<MainWindow> windows { get; private set; }
-    public MainWindow active_window { get; private set; }
+        return _instance;
+    }
 
-    /* Latexila is a singleton
-     * We must use Latexila.get_default ()
-     */
-    private Latexila ()
+    private void set_application_icons ()
     {
-        windows = new List<MainWindow> ();
-
-        /* application icons */
-        string[] filenames =
-        {
-            Config.ICONS_DIR + "/16x16/apps/latexila.png",
-            Config.ICONS_DIR + "/22x22/apps/latexila.png",
-            Config.ICONS_DIR + "/24x24/apps/latexila.png",
-            Config.ICONS_DIR + "/32x32/apps/latexila.png",
-            Config.ICONS_DIR + "/48x48/apps/latexila.png"
-        };
+        string[] sizes = {"16x16", "22x22", "24x24", "32x32", "48x48"};
 
         List<Gdk.Pixbuf> list = null;
-        foreach (string filename in filenames)
+
+        foreach (string size in sizes)
         {
+            string filename = Path.build_filename (Config.ICONS_DIR, size,
+                "apps", "latexila.png");
+
             try
             {
                 list.append (new Gdk.Pixbuf.from_file (filename));
             }
             catch (Error e)
             {
-                warning ("Error with an icon: %s", e.message);
+                warning ("Application icon: %s", e.message);
             }
         }
 
         Gtk.Window.set_default_icon_list (list);
-
-        register_my_stock_icons ();
-        add_theme_icon_to_stock ("image-x-generic", "image");
-        add_theme_icon_to_stock ("x-office-presentation", "presentation");
-
-        AppSettings.get_default ();
-        create_window ();
     }
 
-    public static Latexila get_default ()
+    public Gee.List<MainWindow> get_windows ()
     {
-        if (instance == null)
-            instance = new Latexila ();
-        return instance;
+        return _windows;
     }
 
-    // get all the documents currently opened
-    public List<Document> get_documents ()
+    // Get all the documents currently opened.
+    public Gee.List<Document> get_documents ()
     {
-        List<Document> res = null;
-        foreach (MainWindow w in windows)
-            res.concat (w.get_documents ());
-        return res;
+        Gee.List<Document> all_documents = new Gee.LinkedList<Document> ();
+        foreach (MainWindow window in _windows)
+            all_documents.add_all (window.get_documents ());
+
+        return all_documents;
     }
 
-    // get all the document views
-    public List<DocumentView> get_views ()
+    // Get all the document views.
+    public Gee.List<DocumentView> get_views ()
     {
-        List<DocumentView> res = null;
-        foreach (MainWindow w in windows)
-            res.concat (w.get_views ());
-        return res;
-    }
+        Gee.List<DocumentView> all_views = new Gee.LinkedList<DocumentView> ();
+        foreach (MainWindow window in _windows)
+            all_views.add_all (window.get_views ());
 
-//    public Unique.Response message (Unique.App sender, int command,
-//                                    Unique.MessageData data, uint time)
-//    {
-//        if (command == NEW_WINDOW)
-//        {
-//            create_window ();
-//            return Unique.Response.OK;
-//        }
-//
-//        uint workspace = data.get_workspace ();
-//        Gdk.Screen screen = data.get_screen ();
-//
-//        // if active_window not on current workspace, try to find an other window on the
-//        // current workspace.
-//        if (! active_window.is_on_workspace_screen (screen, workspace))
-//        {
-//            bool found = false;
-//            foreach (MainWindow w in windows)
-//            {
-//                if (w == active_window)
-//                    continue;
-//                if (w.is_on_workspace_screen (screen, workspace))
-//                {
-//                    found = true;
-//                    active_window = w;
-//                    break;
-//                }
-//            }
-//
-//            if (! found)
-//                create_window (screen);
-//        }
-//
-//        if (command == Unique.Command.NEW)
-//            create_document ();
-//
-//        else if (command == Unique.Command.OPEN)
-//            open_documents (data.get_uris ());
-//
-//        active_window.present_with_time (time);
-//        return Unique.Response.OK;
-//    }
+        return all_views;
+    }
 
     public MainWindow create_window (Gdk.Screen? screen = null)
     {
         if (active_window != null)
-            active_window.save_state (true);
+            active_window.save_state ();
 
         MainWindow window = new MainWindow ();
+        _windows.add (window);
         active_window = window;
-        notify_property ("active-window");
 
         if (screen != null)
             window.set_screen (screen);
 
         window.destroy.connect (() =>
         {
-            windows.remove (window);
-            if (windows.length () == 0)
+            _windows.remove (window);
+            if (_windows.size == 0)
             {
                 Projects.get_default ().save ();
                 BuildTools.get_default ().save ();
@@ -254,20 +118,15 @@ public class Latexila : GLib.Object
                 Gtk.main_quit ();
             }
             else if (window == active_window)
-            {
-                active_window = (MainWindow) windows.data;
-                notify_property ("active-window");
-            }
+                active_window = _windows.first ();
         });
 
         window.focus_in_event.connect (() =>
         {
             active_window = window;
-            notify_property ("active-window");
             return false;
         });
 
-        windows.append (window);
         window.show ();
         return window;
     }
@@ -285,38 +144,10 @@ public class Latexila : GLib.Object
         {
             if (uri.length == 0)
                 continue;
+
             File location = File.new_for_uri (uri);
             active_window.open_document (location, jump_to);
             jump_to = false;
         }
     }
-
-    private void register_my_stock_icons ()
-    {
-        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
-
-        foreach (StockIcon icon in stock_icons)
-        {
-            Gtk.IconSet icon_set = new Gtk.IconSet ();
-            Gtk.IconSource icon_source = new Gtk.IconSource ();
-            icon_source.set_filename (icon.filename);
-            icon_set.add_source (icon_source);
-            icon_factory.add (icon.stock_id, icon_set);
-        }
-
-        icon_factory.add_default ();
-    }
-
-    private void add_theme_icon_to_stock (string icon_name, string stock_id)
-    {
-        Gtk.IconSource icon_source = new Gtk.IconSource ();
-        icon_source.set_icon_name (icon_name);
-
-        Gtk.IconSet icon_set = new Gtk.IconSet ();
-        icon_set.add_source (icon_source);
-
-        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
-        icon_factory.add (stock_id, icon_set);
-        icon_factory.add_default ();
-    }
 }
diff --git a/src/main_window.vala b/src/main_window.vala
index bcbb0ca..ab496c8 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -503,39 +503,42 @@ public class MainWindow : Window
         show_or_hide_build_messages ();
     }
 
-    public List<Document> get_documents ()
+    public Gee.List<Document> get_documents ()
     {
-        List<Document> res = null;
-        int nb = documents_panel.get_n_pages ();
-        for (int i = 0 ; i < nb ; i++)
+        Gee.List<Document> all_documents = new Gee.LinkedList<Document> ();
+        int nb_documents = documents_panel.get_n_pages ();
+        for (int i = 0 ; i < nb_documents ; i++)
         {
-            DocumentTab tab = (DocumentTab) documents_panel.get_nth_page (i);
-            res.append (tab.document);
+            DocumentTab tab = documents_panel.get_nth_page (i) as DocumentTab;
+            all_documents.add (tab.document);
         }
-        return res;
+
+        return all_documents;
     }
 
-    public List<Document> get_unsaved_documents ()
+    public Gee.List<Document> get_unsaved_documents ()
     {
-        List<Document> list = null;
+        Gee.List<Document> unsaved_documents = new Gee.LinkedList<Document> ();
         foreach (Document doc in get_documents ())
         {
             if (doc.get_modified ())
-                list.append (doc);
+                unsaved_documents.add (doc);
         }
-        return list;
+
+        return unsaved_documents;
     }
 
-    public List<DocumentView> get_views ()
+    public Gee.List<DocumentView> get_views ()
     {
-        List<DocumentView> res = null;
-        int nb = documents_panel.get_n_pages ();
-        for (int i = 0 ; i < nb ; i++)
+        Gee.List<DocumentView> all_views = new Gee.LinkedList<Document> ();
+        int nb_documents = documents_panel.get_n_pages ();
+        for (int i = 0 ; i < nb_documents ; i++)
         {
-            DocumentTab tab = (DocumentTab) documents_panel.get_nth_page (i);
-            res.append (tab.view);
+            DocumentTab tab = documents_panel.get_nth_page (i) as DocumentTab;
+            all_views.add (tab.view);
         }
-        return res;
+
+        return all_views;
     }
 
     private void initialize_menubar_and_toolbar ()
@@ -693,7 +696,7 @@ public class MainWindow : Window
     public DocumentTab? open_document (File location, bool jump_to = true)
     {
         /* check if the document is already opened */
-        foreach (MainWindow w in Latexila.get_default ().windows)
+        foreach (MainWindow w in Latexila.get_default ().get_windows ())
         {
             foreach (Document doc in w.get_documents ())
             {
@@ -1028,19 +1031,19 @@ public class MainWindow : Window
     // return true if all the documents are closed
     private bool close_all_documents ()
     {
-        List<Document> unsaved_documents = get_unsaved_documents ();
+        Gee.List<Document> unsaved_documents = get_unsaved_documents ();
 
         /* no unsaved document */
-        if (unsaved_documents == null)
+        if (unsaved_documents.size == 0)
         {
             documents_panel.remove_all_tabs ();
             return true;
         }
 
         /* only one unsaved document */
-        else if (unsaved_documents.next == null)
+        else if (unsaved_documents.size == 1)
         {
-            Document doc = unsaved_documents.data;
+            Document doc = unsaved_documents.first ();
             active_tab = doc.tab;
             if (close_tab (doc.tab))
             {
@@ -1107,7 +1110,7 @@ public class MainWindow : Window
         });
     }
 
-    public void save_state (bool sync = false)
+    public void save_state ()
     {
         /* state of the window */
         GLib.Settings settings_window =
@@ -1158,12 +1161,6 @@ public class MainWindow : Window
 
         action = (ToggleAction) action_group.get_action ("BuildShowBadBoxes");
         settings_ui.set_boolean ("show-build-badboxes", action.active);
-
-        if (sync)
-        {
-            settings_window.sync ();
-            settings_ui.sync ();
-        }
     }
 
     private void move_tab_to_new_window (DocumentTab tab)
@@ -1260,7 +1257,7 @@ public class MainWindow : Window
             // save all the documents belonging to the project
             else
             {
-                List<Document> docs = Latexila.get_default ().get_documents ();
+                Gee.List<Document> docs = Latexila.get_default ().get_documents ();
                 foreach (Document doc in docs)
                 {
                     if (doc.project_id == project_id)
diff --git a/src/projects.vala b/src/projects.vala
index 4f74682..e6895a0 100644
--- a/src/projects.vala
+++ b/src/projects.vala
@@ -80,7 +80,7 @@ public class Projects
 
     private void update_all_menus ()
     {
-        foreach (MainWindow window in Latexila.get_default ().windows)
+        foreach (MainWindow window in Latexila.get_default ().get_windows ())
             window.update_config_project_sensitivity ();
     }
 
@@ -102,7 +102,7 @@ public class Projects
         modified = true;
 
         // find if some opened documents are belonging to the new project
-        GLib.List<Document> docs = Latexila.get_default ().get_documents ();
+        Gee.List<Document> docs = Latexila.get_default ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id != -1 || doc.location == null)
@@ -133,7 +133,7 @@ public class Projects
         modified = true;
 
         // refresh docs
-        GLib.List<Document> docs = Latexila.get_default ().get_documents ();
+        Gee.List<Document> docs = Latexila.get_default ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id == num)
@@ -150,7 +150,7 @@ public class Projects
         modified = true;
 
         // refresh docs
-        GLib.List<Document> docs = Latexila.get_default ().get_documents ();
+        Gee.List<Document> docs = Latexila.get_default ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id == num)
@@ -172,7 +172,7 @@ public class Projects
 
     private void update_all_documents ()
     {
-        GLib.List<Document> docs = Latexila.get_default ().get_documents ();
+        Gee.List<Document> docs = Latexila.get_default ().get_documents ();
         foreach (Document doc in docs)
         {
             doc.project_id = -1;
diff --git a/src/stock_icons.vala b/src/stock_icons.vala
new file mode 100644
index 0000000..b54217a
--- /dev/null
+++ b/src/stock_icons.vala
@@ -0,0 +1,160 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright  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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ */
+
+namespace StockIcons
+{
+    // Add some icons to the stock icons, so it can be used e.g. in menus.
+    public void add_custom ()
+    {
+        register_my_stock_icons ();
+        add_theme_icon_to_stock ("image-x-generic", "image");
+        add_theme_icon_to_stock ("x-office-presentation", "presentation");
+    }
+
+    private struct StockIcon
+    {
+        string filename;
+        string stock_id;
+    }
+
+    // TODO: use GResource
+    private const StockIcon[] stock_icons =
+    {
+        { Config.DATA_DIR + "/images/icons/compile_dvi.png", "compile_dvi" },
+        { Config.DATA_DIR + "/images/icons/compile_pdf.png", "compile_pdf" },
+        { Config.DATA_DIR + "/images/icons/compile_ps.png", "compile_ps" },
+        { Config.DATA_DIR + "/images/icons/view_dvi.png", "view_dvi" },
+        { Config.DATA_DIR + "/images/icons/view_pdf.png", "view_pdf" },
+        { Config.DATA_DIR + "/images/icons/view_ps.png", "view_ps" },
+        { Config.DATA_DIR + "/images/icons/textbf.png", "bold" },
+        { Config.DATA_DIR + "/images/icons/textit.png", "italic" },
+        { Config.DATA_DIR + "/images/icons/texttt.png", "typewriter" },
+        { Config.DATA_DIR + "/images/icons/textsl.png", "slanted" },
+        { Config.DATA_DIR + "/images/icons/textsc.png", "small_caps" },
+        { Config.DATA_DIR + "/images/icons/textsf.png", "sans_serif" },
+        { Config.DATA_DIR + "/images/icons/roman.png", "roman" },
+        { Config.DATA_DIR + "/images/icons/underline.png", "underline" },
+        { Config.DATA_DIR + "/images/misc-math/set-R.png", "blackboard" },
+        { Config.DATA_DIR + "/images/icons/sectioning-part.png", "sectioning-part" },
+        { Config.DATA_DIR + "/images/icons/sectioning-chapter.png",
+            "sectioning-chapter" },
+        { Config.DATA_DIR + "/images/icons/sectioning-section.png",
+            "sectioning-section" },
+        { Config.DATA_DIR + "/images/icons/sectioning-subsection.png",
+            "sectioning-subsection" },
+        { Config.DATA_DIR + "/images/icons/sectioning-subsubsection.png",
+            "sectioning-subsubsection" },
+        { Config.DATA_DIR + "/images/icons/sectioning-paragraph.png",
+            "sectioning-paragraph" },
+        { Config.DATA_DIR + "/images/icons/character-size.png", "character-size" },
+        { Config.DATA_DIR + "/images/icons/list-itemize.png", "list-itemize" },
+        { Config.DATA_DIR + "/images/icons/list-enumerate.png", "list-enumerate" },
+        { Config.DATA_DIR + "/images/icons/list-description.png", "list-description" },
+        { Config.DATA_DIR + "/images/icons/list-item.png", "list-item" },
+        { Config.DATA_DIR + "/images/icons/references.png", "references" },
+        { Config.DATA_DIR + "/images/icons/math.png", "math" },
+        { Config.DATA_DIR + "/images/icons/math-centered.png", "math-centered" },
+        { Config.DATA_DIR + "/images/icons/math-numbered.png", "math-numbered" },
+        { Config.DATA_DIR + "/images/icons/math-array.png", "math-array" },
+        { Config.DATA_DIR + "/images/icons/math-numbered-array.png",
+            "math-numbered-array" },
+        { Config.DATA_DIR + "/images/icons/math-superscript.png", "math-superscript" },
+        { Config.DATA_DIR + "/images/icons/math-subscript.png", "math-subscript" },
+        { Config.DATA_DIR + "/images/icons/math-frac.png", "math-frac" },
+        { Config.DATA_DIR + "/images/icons/math-square-root.png", "math-square-root" },
+        { Config.DATA_DIR + "/images/icons/math-nth-root.png", "math-nth-root" },
+        { Config.DATA_DIR + "/images/icons/mathcal.png", "mathcal" },
+        { Config.DATA_DIR + "/images/icons/mathfrak.png", "mathfrak" },
+        { Config.DATA_DIR + "/images/icons/delimiters-left.png", "delimiters-left" },
+        { Config.DATA_DIR + "/images/icons/delimiters-right.png", "delimiters-right" },
+        { Config.DATA_DIR + "/images/icons/badbox.png", "badbox" },
+        { Config.DATA_DIR + "/images/icons/logviewer.png", "view_log" },
+        { Config.DATA_DIR + "/images/greek/01.png", "symbol_alpha" },
+        { Config.DATA_DIR + "/images/icons/accent0.png", "accent0" },
+        { Config.DATA_DIR + "/images/icons/accent1.png", "accent1" },
+        { Config.DATA_DIR + "/images/icons/accent2.png", "accent2" },
+        { Config.DATA_DIR + "/images/icons/accent3.png", "accent3" },
+        { Config.DATA_DIR + "/images/icons/accent4.png", "accent4" },
+        { Config.DATA_DIR + "/images/icons/accent5.png", "accent5" },
+        { Config.DATA_DIR + "/images/icons/accent6.png", "accent6" },
+        { Config.DATA_DIR + "/images/icons/accent7.png", "accent7" },
+        { Config.DATA_DIR + "/images/icons/accent8.png", "accent8" },
+        { Config.DATA_DIR + "/images/icons/accent9.png", "accent9" },
+        { Config.DATA_DIR + "/images/icons/accent10.png", "accent10" },
+        { Config.DATA_DIR + "/images/icons/accent11.png", "accent11" },
+        { Config.DATA_DIR + "/images/icons/accent12.png", "accent12" },
+        { Config.DATA_DIR + "/images/icons/accent13.png", "accent13" },
+        { Config.DATA_DIR + "/images/icons/accent14.png", "accent14" },
+        { Config.DATA_DIR + "/images/icons/accent15.png", "accent15" },
+        { Config.DATA_DIR + "/images/icons/mathaccent0.png", "mathaccent0" },
+        { Config.DATA_DIR + "/images/icons/mathaccent1.png", "mathaccent1" },
+        { Config.DATA_DIR + "/images/icons/mathaccent2.png", "mathaccent2" },
+        { Config.DATA_DIR + "/images/icons/mathaccent3.png", "mathaccent3" },
+        { Config.DATA_DIR + "/images/icons/mathaccent4.png", "mathaccent4" },
+        { Config.DATA_DIR + "/images/icons/mathaccent5.png", "mathaccent5" },
+        { Config.DATA_DIR + "/images/icons/mathaccent6.png", "mathaccent6" },
+        { Config.DATA_DIR + "/images/icons/mathaccent7.png", "mathaccent7" },
+        { Config.DATA_DIR + "/images/icons/mathaccent8.png", "mathaccent8" },
+        { Config.DATA_DIR + "/images/icons/mathaccent9.png", "mathaccent9" },
+        { Config.DATA_DIR + "/images/icons/mathaccent10.png", "mathaccent10" },
+        { Config.DATA_DIR + "/images/icons/completion_choice.png", "completion_choice" },
+        { Config.DATA_DIR + "/images/icons/completion_cmd.png", "completion_cmd" },
+        { Config.DATA_DIR + "/images/icons/tree_part.png", "tree_part" },
+        { Config.DATA_DIR + "/images/icons/tree_chapter.png", "tree_chapter" },
+        { Config.DATA_DIR + "/images/icons/tree_section.png", "tree_section" },
+        { Config.DATA_DIR + "/images/icons/tree_subsection.png", "tree_subsection" },
+        { Config.DATA_DIR + "/images/icons/tree_subsubsection.png",
+            "tree_subsubsection" },
+        { Config.DATA_DIR + "/images/icons/tree_paragraph.png", "tree_paragraph" },
+        { Config.DATA_DIR + "/images/icons/tree_todo.png", "tree_todo" },
+        { Config.DATA_DIR + "/images/icons/tree_label.png", "tree_label" },
+        { Config.DATA_DIR + "/images/icons/table.png", "table" }
+    };
+
+    private void register_my_stock_icons ()
+    {
+        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
+
+        foreach (StockIcon icon in stock_icons)
+        {
+            Gtk.IconSet icon_set = new Gtk.IconSet ();
+            Gtk.IconSource icon_source = new Gtk.IconSource ();
+            icon_source.set_filename (icon.filename);
+            icon_set.add_source (icon_source);
+            icon_factory.add (icon.stock_id, icon_set);
+        }
+
+        icon_factory.add_default ();
+    }
+
+    private void add_theme_icon_to_stock (string icon_name, string stock_id)
+    {
+        Gtk.IconSource icon_source = new Gtk.IconSource ();
+        icon_source.set_icon_name (icon_name);
+
+        Gtk.IconSet icon_set = new Gtk.IconSet ();
+        icon_set.add_source (icon_source);
+
+        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
+        icon_factory.add (stock_id, icon_set);
+        icon_factory.add_default ();
+    }
+}



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