[gnome-latex: 51/205] Cleaning of the code



commit 653e4611bd1bdf4f3e5d3671d6e808362305a991
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Thu Sep 10 00:34:39 2009 +0200

    Cleaning of the code
    
    The extern variable "latexile" became too big, so some variables are
    grouped together in the same structure. It's the case for the action
    log and the symbols.
    Rename run_compilation () to compile_document ().
    Maybe other little things...

 TODO            | 40 ++++++++++++++++++++++------------------
 src/actions.c   | 25 ++++++++++++++-----------
 src/actions.h   |  2 +-
 src/callbacks.c | 24 +++++++++++++-----------
 src/main.c      | 22 +++++++++++++---------
 src/main.h      | 28 ++++++++++++++++++++--------
 src/symbols.c   | 38 +++++++++++++++++++-------------------
 7 files changed, 102 insertions(+), 77 deletions(-)
---
diff --git a/TODO b/TODO
index d9aa4ef..35f7d52 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,22 @@
 TODO LaTeXila
 
-Thu Sep 3, 2009 to Thu Sep 10, 2009
+Wed Sep 9, 2009 to Wed Sep 16, 2009
+
+[-] undo/redo and the "saved" document property
+       - detect when the buffer is the same as in the file currently saved
+
+[-] execution of the actions
+       - verify that the method used for compile_document () is correct
+       - optimisations?
+       - same behavior than compile_document () for:
+               * convert_document ()
+               * view_document ()
+
+[-] save and load
+       - show/hide symbol tables
+       - size of the window
+       - position of the panes
+       - sceen position (center by default)
 
 [-] new toolbar
        - structure: part, chapter, section, subsection, subsubsection, paragraph, subparagraph
@@ -12,25 +28,13 @@ Thu Sep 3, 2009 to Thu Sep 10, 2009
        - various: label, ref, pageref, cite, footnote, index
 
 [-] symbol tables
-       x show/hide symbol tables
-       x Greek alphabet
-       x arrows
-       x relation
-       x delimiters
-       x operators
-       x miscellaneous math
-       x miscellaneous text
+       - the categories must take the minimum place but the presentation must be nice
+               * homogeneous icons
+               * text under or to the right of the icons?
 
-[-] save and load
-       - show/hide symbol tables
-       - size of the window
-       - position of the panes
-       - sceen position (center by default)
+[-] document tabs
+       - arrows to navigate between tabs if there are a lot of documents opened
 
 [x] bugs correction
-       x sometimes command output is not UTF-8:
-         Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed
-       x open files from the command line:
-         can not open relative path, only absolute
 
 [-] update French translation
diff --git a/src/actions.c b/src/actions.c
index fb3061e..79e5f38 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -84,9 +84,10 @@ command_running_finished (void)
        
        // store the string to the action list store
        GtkTreeIter iter;
-       if (gtk_tree_selection_get_selected (latexila.list_selection, NULL, &iter))
+       if (gtk_tree_selection_get_selected (latexila.action_log->list_selection,
+                               NULL, &iter))
        {
-               gtk_list_store_set (latexila.list_store, &iter,
+               gtk_list_store_set (latexila.action_log->list_store, &iter,
                                COLUMN_ACTION_COMMAND_OUTPUT, command_output_string,
                                -1);
        }
@@ -94,7 +95,7 @@ command_running_finished (void)
                print_warning ("no action selected in the list => the output command is not saved");
 
        // unlock the action list
-       gtk_widget_set_sensitive (GTK_WIDGET (latexila.list_view), TRUE);
+       gtk_widget_set_sensitive (GTK_WIDGET (latexila.action_log->list_view), TRUE);
 
        // pop the message from the statusbar
        guint context_id = gtk_statusbar_get_context_id (latexila.statusbar,
@@ -130,7 +131,7 @@ cb_watch_output_command (GIOChannel *channel, GIOCondition condition,
        }
 
        // print the command output line to the log zone
-       print_log_add (latexila.log_view, line, FALSE);
+       print_log_add (latexila.action_log->text_view, line, FALSE);
 
        // store temporarily the line to the GList
        // We insert the line at the beginning of the list, so we avoid to traverse
@@ -145,7 +146,7 @@ cb_watch_output_command (GIOChannel *channel, GIOCondition condition,
 }
 
 void
-run_compilation (gchar *title, gchar **command)
+compile_document (gchar *title, gchar **command)
 {
        if (latexila.active_doc == NULL)
                return;
@@ -224,7 +225,8 @@ run_compilation (gchar *title, gchar **command)
        // Lock the action list so the user can not view an other action while the
        // compilation is running.
        // It will be unlock when the compilation is finished.
-       gtk_widget_set_sensitive (GTK_WIDGET (latexila.list_view), FALSE);
+       gtk_widget_set_sensitive (GTK_WIDGET (latexila.action_log->list_view),
+                       FALSE);
 
        add_action (title, command_line, "", is_error);
 
@@ -399,8 +401,8 @@ add_action (gchar *title, gchar *command, gchar *command_output, gboolean error)
 
        // append an new entry to the action list
        GtkTreeIter iter;
-       gtk_list_store_append (latexila.list_store, &iter);
-       gtk_list_store_set (latexila.list_store, &iter,
+       gtk_list_store_append (latexila.action_log->list_store, &iter);
+       gtk_list_store_set (latexila.action_log->list_store, &iter,
                        COLUMN_ACTION_TITLE, title2,
                        COLUMN_ACTION_COMMAND, command,
                        COLUMN_ACTION_COMMAND_OUTPUT, command_output,
@@ -409,12 +411,13 @@ add_action (gchar *title, gchar *command, gchar *command_output, gboolean error)
 
        // the new entry is selected
        // cb_action_list_changed () is called, so the details are showed
-       gtk_tree_selection_select_iter (latexila.list_selection, &iter);
+       gtk_tree_selection_select_iter (latexila.action_log->list_selection, &iter);
 
        // scroll to the end
        GtkTreePath *path = gtk_tree_model_get_path (
-                       GTK_TREE_MODEL (latexila.list_store), &iter);
-       gtk_tree_view_scroll_to_cell (latexila.list_view, path, NULL, FALSE, 0, 0);
+                       GTK_TREE_MODEL (latexila.action_log->list_store), &iter);
+       gtk_tree_view_scroll_to_cell (latexila.action_log->list_view, path, NULL,
+                       FALSE, 0, 0);
 
        num++;
        g_free (title2);
diff --git a/src/actions.h b/src/actions.h
index 41a9768..f7e2a29 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -1,7 +1,7 @@
 #ifndef ACTIONS_H
 #define ACTIONS_H
 
-void run_compilation (gchar *title, gchar **command);
+void compile_document (gchar *title, gchar **command);
 void view_document (gchar *title, gchar *doc_extension);
 void convert_document (gchar *title, gchar *doc_extension, gchar *command);
 
diff --git a/src/callbacks.c b/src/callbacks.c
index 8c3afdf..03c36af 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -158,7 +158,8 @@ cb_close_tab (GtkWidget *widget, GtkWidget *child)
                close_document (page_to_close);
 
                if (gtk_notebook_get_n_pages (latexila.notebook) > 0)
-                       latexila.active_doc = g_list_nth_data (latexila.all_docs, 
gtk_notebook_get_current_page (latexila.notebook));
+                       latexila.active_doc = g_list_nth_data (latexila.all_docs,
+                                       gtk_notebook_get_current_page (latexila.notebook));
                else
                        latexila.active_doc = NULL;
 
@@ -548,7 +549,7 @@ cb_latex (void)
                NULL
        };
 
-       run_compilation (title, command);
+       compile_document (title, command);
 }
 
 void
@@ -565,7 +566,7 @@ cb_pdflatex (void)
                NULL
        };
 
-       run_compilation (title, command);
+       compile_document (title, command);
 }
 
 void
@@ -628,7 +629,8 @@ cb_action_list_changed (GtkTreeSelection *selection, gpointer user_data)
                                COLUMN_ACTION_COMMAND_OUTPUT, &command_output,
                                COLUMN_ACTION_ERROR, &error,
                                -1);
-               print_log (latexila.log_buffer, title, command, command_output, error);
+               print_log (latexila.action_log->text_buffer, title, command,
+                               command_output, error);
        }
 }
 
@@ -789,16 +791,16 @@ cb_category_symbols_selected (GtkIconView *icon_view, gpointer user_data)
                gtk_tree_model_get (model, &iter, COLUMN_CAT_NUM, &num, -1);
 
                // change the model
-               gtk_icon_view_set_model (latexila.symbol_view,
-                               GTK_TREE_MODEL (latexila.symbol_stores[num]));
+               gtk_icon_view_set_model (latexila.symbols->icon_view,
+                               GTK_TREE_MODEL (latexila.symbols->list_stores[num]));
 
                // TODO scroll to the start
                /* this doesn't work...
                GtkTreePath *first_path = gtk_icon_view_get_path_at_pos (
-                               latexila.symbol_view, 0, 0);
+                               latexila.symbols->icon_view, 0, 0);
                if (first_path != NULL)
                {
-                       gtk_icon_view_scroll_to_path (latexila.symbol_view, first_path,
+                       gtk_icon_view_scroll_to_path (latexila.symbols->icon_view, first_path,
                                        TRUE, 0.0, 0.0);
                }
                */
@@ -852,13 +854,13 @@ cb_symbol_selected (GtkIconView *icon_view, gpointer user_data)
 void
 cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data)
 {
-       if (latexila.symbol_tables == NULL)
+       if (latexila.symbols == NULL || latexila.symbols->vbox == NULL)
                return;
 
        if (gtk_toggle_action_get_active (toggle_action))
-               gtk_widget_show_all (latexila.symbol_tables);
+               gtk_widget_show_all (latexila.symbols->vbox);
        else
-               gtk_widget_hide (latexila.symbol_tables);
+               gtk_widget_hide (latexila.symbols->vbox);
 }
 
 void
diff --git a/src/main.c b/src/main.c
index e41bb8a..cff98fb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,7 +37,7 @@ static gboolean option_version (const gchar *option_name, const gchar *value,
                gpointer data, GError **error);
 
 latexila_t latexila = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-       NULL, NULL, NULL, NULL, NULL, NULL}; 
+       NULL, NULL, NULL, NULL}; 
 
 static struct {
        gchar *filename;
@@ -319,8 +319,9 @@ main (int argc, char *argv[])
        gtk_box_pack_start (GTK_BOX (main_vbox), main_hpaned, TRUE, TRUE, 0);
 
        /* symbol tables */
+       latexila.symbols = g_malloc (sizeof (symbols_t));
        GtkWidget *vbox_symbols = gtk_vbox_new (FALSE, 0);
-       latexila.symbol_tables = vbox_symbols;
+       latexila.symbols->vbox = vbox_symbols;
        gtk_paned_pack1 (GTK_PANED (main_hpaned), vbox_symbols, TRUE, TRUE);
 
        init_symbols ();
@@ -341,6 +342,8 @@ main (int argc, char *argv[])
        gtk_paned_pack1 (GTK_PANED (vpaned), notebook, TRUE, TRUE);
 
        /* log zone */
+       latexila.action_log = g_malloc (sizeof (action_log_t));
+
        // horizontal pane:
        // left: action history
        // right: details
@@ -351,21 +354,22 @@ main (int argc, char *argv[])
        // action history
        GtkListStore *list_store = gtk_list_store_new (N_COLUMNS_ACTION,
                        G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
-       latexila.list_store = list_store;
+       latexila.action_log->list_store = list_store;
        
        GtkWidget *list_view = gtk_tree_view_new_with_model (
                        GTK_TREE_MODEL (list_store));
-       latexila.list_view = GTK_TREE_VIEW (list_view);
+       latexila.action_log->list_view = GTK_TREE_VIEW (list_view);
        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes (
                        _("Action history"), renderer, "text", COLUMN_ACTION_TITLE, NULL);      
-       gtk_tree_view_append_column (latexila.list_view, column);
+       gtk_tree_view_append_column (latexila.action_log->list_view, column);
        
        // hide "Action history"
        //gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list_view), FALSE);
 
-       GtkTreeSelection *select = gtk_tree_view_get_selection (latexila.list_view);
-       latexila.list_selection = select;
+       GtkTreeSelection *select =
+               gtk_tree_view_get_selection (latexila.action_log->list_view);
+       latexila.action_log->list_selection = select;
        gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
        g_signal_connect (G_OBJECT (select), "changed",
                        G_CALLBACK (cb_action_list_changed), NULL);
@@ -382,8 +386,8 @@ main (int argc, char *argv[])
        GtkTextBuffer *log_buffer = gtk_text_view_get_buffer (
                        GTK_TEXT_VIEW (log_view));
 
-       latexila.log_view = GTK_TEXT_VIEW (log_view);
-       latexila.log_buffer = log_buffer;
+       latexila.action_log->text_view = GTK_TEXT_VIEW (log_view);
+       latexila.action_log->text_buffer = log_buffer;
 
        gtk_text_buffer_set_text (log_buffer, _("Welcome to LaTeXila!"), -1);
        gtk_text_view_set_editable (GTK_TEXT_VIEW (log_view), FALSE);
diff --git a/src/main.h b/src/main.h
index d07cdd1..adf6c0c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -53,17 +53,32 @@ typedef struct
        GtkWidget               *title;
 } document_t;
 
+// the log zone
+typedef struct
+{
+       GtkListStore            *list_store;
+       GtkTreeView                     *list_view;
+       GtkTreeSelection        *list_selection;
+       GtkTextView                     *text_view;
+       GtkTextBuffer           *text_buffer;
+} action_log_t;
+
+// symbols tables
+typedef struct
+{
+       GtkWidget                       *vbox;
+       GtkListStore            *list_stores[7];
+       GtkIconView                     *icon_view;
+} symbols_t;
+
 typedef struct
 {
        GList                           *all_docs;
        document_t                      *active_doc;
+       action_log_t            *action_log;
+       symbols_t                       *symbols;
        GtkWindow                       *main_window;
        GtkNotebook                     *notebook;
-       GtkListStore            *list_store;
-       GtkTreeView                     *list_view;
-       GtkTreeSelection        *list_selection;
-       GtkTextView                     *log_view;
-       GtkTextBuffer           *log_buffer;
        GtkStatusbar            *statusbar;
        GtkStatusbar            *cursor_position;
        GtkAction                       *undo;
@@ -72,9 +87,6 @@ typedef struct
        gchar                           *pref_file;
        PangoFontDescription *font_desc;
        gint                            font_size;
-       GtkWidget                       *symbol_tables;
-       GtkListStore            *symbol_stores[7];
-       GtkIconView                     *symbol_view;
 } latexila_t;
 
 // all the documents are accessible by the "latexila" variable
diff --git a/src/symbols.c b/src/symbols.c
index 0e4ddcc..87b7885 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -846,32 +846,32 @@ init_symbols (void)
        g_signal_connect (G_OBJECT (categories_view), "selection-changed",
                        G_CALLBACK (cb_category_symbols_selected), NULL);
 
-       gtk_box_pack_start (GTK_BOX (latexila.symbol_tables), categories_view, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (latexila.symbols->vbox), categories_view, FALSE, FALSE, 0);
 
        // store all the symbols
-       // Attention, we must save the GtkListStore in latexila.symbol_stores in
-       // the same order than the structure "categories" above
-       latexila.symbol_stores[0] = get_symbol_store (symbols_greek);
-       latexila.symbol_stores[1] = get_symbol_store (symbols_arrows);
-       latexila.symbol_stores[2] = get_symbol_store (symbols_relations);
-       latexila.symbol_stores[3] = get_symbol_store (symbols_operators);
-       latexila.symbol_stores[4] = get_symbol_store (symbols_delimiters);
-       latexila.symbol_stores[5] = get_symbol_store (symbols_misc_math);
-       latexila.symbol_stores[6] = get_symbol_store (symbols_misc_text);
+       // Attention, we must save the GtkListStore in latexila.symbols->list_stores
+       // in the same order than the structure "categories" above
+       latexila.symbols->list_stores[0] = get_symbol_store (symbols_greek);
+       latexila.symbols->list_stores[1] = get_symbol_store (symbols_arrows);
+       latexila.symbols->list_stores[2] = get_symbol_store (symbols_relations);
+       latexila.symbols->list_stores[3] = get_symbol_store (symbols_operators);
+       latexila.symbols->list_stores[4] = get_symbol_store (symbols_delimiters);
+       latexila.symbols->list_stores[5] = get_symbol_store (symbols_misc_math);
+       latexila.symbols->list_stores[6] = get_symbol_store (symbols_misc_text);
 
        // show the symbols
        GtkWidget *symbol_view = gtk_icon_view_new_with_model (
-                       GTK_TREE_MODEL (latexila.symbol_stores[0]));
-       latexila.symbol_view = GTK_ICON_VIEW (symbol_view);
-       gtk_icon_view_set_pixbuf_column (latexila.symbol_view,
+                       GTK_TREE_MODEL (latexila.symbols->list_stores[0]));
+       latexila.symbols->icon_view = GTK_ICON_VIEW (symbol_view);
+       gtk_icon_view_set_pixbuf_column (latexila.symbols->icon_view,
                        COLUMN_SYMBOL_PIXBUF);
-       gtk_icon_view_set_tooltip_column (latexila.symbol_view,
+       gtk_icon_view_set_tooltip_column (latexila.symbols->icon_view,
                        COLUMN_SYMBOL_TOOLTIP);
-       gtk_icon_view_set_selection_mode (latexila.symbol_view,
+       gtk_icon_view_set_selection_mode (latexila.symbols->icon_view,
                        GTK_SELECTION_SINGLE);
-       gtk_icon_view_set_spacing (latexila.symbol_view, 0);
-       gtk_icon_view_set_row_spacing (latexila.symbol_view, 0);
-       gtk_icon_view_set_column_spacing (latexila.symbol_view, 0);
+       gtk_icon_view_set_spacing (latexila.symbols->icon_view, 0);
+       gtk_icon_view_set_row_spacing (latexila.symbols->icon_view, 0);
+       gtk_icon_view_set_column_spacing (latexila.symbols->icon_view, 0);
 
        g_signal_connect (G_OBJECT (symbol_view), "selection-changed",
                        G_CALLBACK (cb_symbol_selected), NULL);
@@ -881,5 +881,5 @@ init_symbols (void)
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollbar),
                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
        gtk_container_add (GTK_CONTAINER (scrollbar), symbol_view);
-       gtk_box_pack_start (GTK_BOX (latexila.symbol_tables), scrollbar, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (latexila.symbols->vbox), scrollbar, TRUE, TRUE, 0);
 }


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