diff options
author | Michael Meeks <michael.meeks@novell.com> | 2010-03-03 18:36:43 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-03-14 09:53:16 +0800 |
commit | 19eea41c74154855cb68ee3a1fb41e2ec136b764 (patch) | |
tree | 4c638c63b1bdca7a2352795c1da0e30fc5b14e7e /e-util | |
parent | 3d95369f38b22dea1fc22bb3f2cf306ae82aed9d (diff) | |
download | gsoc2013-evolution-19eea41c74154855cb68ee3a1fb41e2ec136b764.tar.gz gsoc2013-evolution-19eea41c74154855cb68ee3a1fb41e2ec136b764.tar.zst gsoc2013-evolution-19eea41c74154855cb68ee3a1fb41e2ec136b764.zip |
clean up the 'express' mode hooks for UI Managers and start to
extend them to plugins - use a simple one-off boolean on the UI Manager
instead of exhaustively trying to propagate this information everywhere.
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-plugin-ui.c | 5 | ||||
-rw-r--r-- | e-util/e-util.c | 122 | ||||
-rw-r--r-- | e-util/e-util.h | 9 |
3 files changed, 96 insertions, 40 deletions
diff --git a/e-util/e-plugin-ui.c b/e-util/e-plugin-ui.c index c3b5b0df20..3ca8703d5a 100644 --- a/e-util/e-plugin-ui.c +++ b/e-util/e-plugin-ui.c @@ -16,6 +16,7 @@ */ #include "e-plugin-ui.h" +#include "e-util.h" #include <string.h> @@ -238,8 +239,8 @@ plugin_ui_hook_merge_ui (EPluginUIHook *hook, ui_definition = g_hash_table_lookup (hash_table, id); g_return_val_if_fail (ui_definition != NULL, 0); - merge_id = gtk_ui_manager_add_ui_from_string ( - ui_manager, ui_definition, -1, &error); + merge_id = e_load_ui_manager_definition_from_string ( + ui_manager, ui_definition, &error); if (error != NULL) { g_warning ("%s", error->message); diff --git a/e-util/e-util.c b/e-util/e-util.c index 16f665171b..f86ee1bff4 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -310,24 +310,103 @@ e_load_ui_builder_definition (GtkBuilder *builder, } } + +void +e_load_ui_manager_set_express (GtkUIManager *ui_manager, + gboolean express) +{ + fprintf (stderr, "set express on %p to %d\n", ui_manager, express); + g_object_set_data (G_OBJECT (ui_manager), + "e-ui-mgr-express", + GUINT_TO_POINTER (express)); +} + +static gboolean +e_load_ui_manager_get_express (GtkUIManager *ui_manager) +{ + gboolean express = GPOINTER_TO_UINT ( + g_object_get_data (G_OBJECT (ui_manager), + "e-ui-mgr-express")); + fprintf (stderr, "get express on %p to %d\n", ui_manager, express); + return express; +} + + +/** + * e_load_ui_manager_definition_from_string: + * @ui_manager: a #GtkUIManager + * @string: the UI XML in NULL terminated string form + * + * Loads a UI definition into @ui_manager from Evolution's UI directory. + * Depending on the mode signalled by the 'express' flag on the UI manager + * a simplified version of the UI may be presented. + * + * Returns: The merge ID for the merged UI. The merge ID can be used to + * unmerge the UI with gtk_ui_manager_remove_ui(). + **/ +guint +e_load_ui_manager_definition_from_string (GtkUIManager *ui_manager, + const gchar *ui_string, + GError **error) +{ + int i; + guint merge_id; + gchar *filtered, **lines; + gboolean is_express, in_conditional = FALSE; + gboolean include = TRUE; + + is_express = e_load_ui_manager_get_express (ui_manager); + + /* + * Very simple line based pre-processing based on comments: + * <!-- if [!]EXPRESS -->\n ... \n<!-- endif -->\n + */ + lines = g_strsplit (ui_string, "\n", -1); + for (i = 0; lines[i]; i++) { + char *p; + if ((p = strstr (lines[i], "<!-- if "))) { + gboolean not_express = lines[i][8] == '!'; + include = is_express ^ not_express; +/* g_warning ("not express: %d from '%s' include to %d (%d)", + not_express, lines[i], include, is_express); */ + lines[i][0] = '\0'; + in_conditional = TRUE; + } else if ((p = strstr (lines[i], "<!-- endif"))) { + lines[i][0] = '\0'; + include = TRUE; + in_conditional = FALSE; + } +/* if (in_conditional) + g_warning ("conditional: (%d): '%s'", include, lines[i]); */ + if (!include) + lines[i][0] = '\0'; + } + filtered = g_strjoinv("\n", lines); + + merge_id = gtk_ui_manager_add_ui_from_string (ui_manager, filtered, -1, error); + + g_free (filtered); + + return merge_id; +} + /** * e_load_ui_manager_definition: * @ui_manager: a #GtkUIManager * @basename: basename of the UI definition file - * @is_express: are we in 'express' mode ? * * Loads a UI definition into @ui_manager from Evolution's UI directory. * Failure here is fatal, since the application can't function without - * its UI definitions. Depending on the mode signalled by @is_express a - * simplified version of the UI may be presented. + * its UI definitions. + * Depending on the mode signalled by the 'express' flag on the UI manager + * a simplified version of the UI may be presented. * * Returns: The merge ID for the merged UI. The merge ID can be used to * unmerge the UI with gtk_ui_manager_remove_ui(). **/ guint e_load_ui_manager_definition (GtkUIManager *ui_manager, - const gchar *basename, - gboolean is_express) + const gchar *basename) { gchar *filename; guint merge_id = 0; @@ -339,37 +418,8 @@ e_load_ui_manager_definition (GtkUIManager *ui_manager, filename = g_build_filename (EVOLUTION_UIDIR, basename, NULL); - /* - * Very simple line based pre-processing based on comments: - * <!-- if [!]EXPRESS --> ... <!-- endif --> - */ - if (g_file_get_contents (filename, &buffer, NULL, &error)) { - int i; - gchar *filtered, **lines; - gboolean include = TRUE; - - lines = g_strsplit (buffer, "\n", -1); - for (i = 0; lines[i]; i++) { - char *p; - if ((p = strstr (lines[i], "<!-- if "))) { - gboolean not_express = lines[i][8] == '!'; - lines[i][0] = '\0'; - include = is_express ^ not_express; - fprintf (stderr, "not exporess: %d from '%s' include to %d\n", - not_express, lines[i], include); - } else if ((p = strstr (lines[i], "<!-- endif"))) { - lines[i][0] = '\0'; - include = TRUE; - } - if (!include) - lines[i][0] = '\0'; - } - filtered = g_strjoinv("\n", lines); - - merge_id = gtk_ui_manager_add_ui_from_string (ui_manager, filtered, -1, &error); - - g_free (filtered); - } + if (g_file_get_contents (filename, &buffer, NULL, &error)) + merge_id = e_load_ui_manager_definition_from_string (ui_manager, buffer, &error); g_free (filename); diff --git a/e-util/e-util.h b/e-util/e-util.h index 5d369595bb..34c02a2507 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -65,9 +65,14 @@ GtkActionGroup *e_lookup_action_group (GtkUIManager *ui_manager, const gchar *group_name); void e_load_ui_builder_definition (GtkBuilder *builder, const gchar *basename); +void e_load_ui_manager_set_express (GtkUIManager *ui_manager, + gboolean express); guint e_load_ui_manager_definition (GtkUIManager *ui_manager, - const gchar *basename, - gboolean express); + const gchar *basename); +guint e_load_ui_manager_definition_from_string + (GtkUIManager *ui_manager, + const gchar *ui_string, + GError **error); gint e_action_compare_by_label (GtkAction *action1, GtkAction *action2); void e_action_group_remove_all_actions |