[gnome-commander] XML config: load user actions bindings from XML cfg



commit b15825972b45fb8e19f7fbb756836469871317c6
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Mon Sep 7 18:01:18 2009 +0200

    XML config: load user actions bindings from XML cfg

 src/gnome-cmd-data.cc         |    5 +++
 src/gnome-cmd-user-actions.cc |    6 +++-
 src/gnome-cmd-user-actions.h  |    1 +
 src/gnome-cmd-xml-config.cc   |   60 +++++++++++++++++++++++++++++++++++++++-
 src/main.cc                   |    3 +-
 5 files changed, 70 insertions(+), 5 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 1d33066..deaed2f 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -36,6 +36,7 @@
 #include "gnome-cmd-main-win.h"
 #include "gnome-cmd-advrename-dialog.h"
 #include "gnome-cmd-bookmark-dialog.h"
+#include "gnome-cmd-user-actions.h"
 #include "filter.h"
 #include "utils.h"
 
@@ -1584,6 +1585,10 @@ void GnomeCmdData::load()
         load_search_defaults();
     }
 
+    // if number of registered user actions does not exceed 10 (nothing has been read), try to read old cfg file
+    if (gcmd_user_actions.size()<10)
+        gcmd_user_actions.load("key-bindings");
+
     load_intviewer_defaults();
     load_auto_load_plugins();
 
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index 310873c..b2c0b12 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -229,10 +229,12 @@ void GnomeCmdUserActions::init()
     register_action(GDK_F8, "file.delete");
     // register_action(GDK_F9, "edit.search");     //  do not register F9 here, as edit.search action wouldn't be checked for registration later
     // register_action(GDK_F10, "file.exit");      //  do not register F10 here, as file.exit action wouldn't be checked for registration later
+}
 
-    load("key-bindings");
 
-    if (!registered("bookmarks.edit"))
+ void GnomeCmdUserActions::set_defaults()
+ {
+   if (!registered("bookmarks.edit"))
         register_action(GDK_CONTROL_MASK, GDK_D, "bookmarks.edit");
 
     if (!registered("connections.new"))
diff --git a/src/gnome-cmd-user-actions.h b/src/gnome-cmd-user-actions.h
index 2188944..0af69f5 100644
--- a/src/gnome-cmd-user-actions.h
+++ b/src/gnome-cmd-user-actions.h
@@ -159,6 +159,7 @@ class GnomeCmdUserActions
   public:
 
     void init();
+    void set_defaults();
     void shutdown();
 
     void load(const gchar *section);
diff --git a/src/gnome-cmd-xml-config.cc b/src/gnome-cmd-xml-config.cc
index c07d066..4e5afcf 100644
--- a/src/gnome-cmd-xml-config.cc
+++ b/src/gnome-cmd-xml-config.cc
@@ -49,6 +49,7 @@
 #include "gnome-cmd-xml-config.h"
 #include "gnome-cmd-advrename-dialog.h"
 #include "gnome-cmd-regex.h"
+#include "gnome-cmd-user-actions.h"
 #include "dict.h"
 #include "utils.h"
 
@@ -356,7 +357,9 @@ enum {XML_ELEM_NOT_FOUND,
       XML_GNOMECOMMANDER_SELECTIONS_PROFILE,
       XML_GNOMECOMMANDER_SELECTIONS_PROFILE_PATTERN,
       XML_GNOMECOMMANDER_SELECTIONS_PROFILE_PATH,
-      XML_GNOMECOMMANDER_SELECTIONS_PROFILE_TEXT};
+      XML_GNOMECOMMANDER_SELECTIONS_PROFILE_TEXT,
+      XML_GNOMECOMMANDER_KEYBINDINGS,
+      XML_GNOMECOMMANDER_KEYBINDINGS_KEY};
 
 
 static DICT<guint> xml_elem_names(XML_ELEM_NOT_FOUND);
@@ -508,6 +511,57 @@ static void xml_start(GMarkupParseContext *context,
                 xml_search_profile.match_case = param4;
             break;
 
+        case XML_GNOMECOMMANDER_KEYBINDINGS_KEY:
+            {
+                gboolean shift, control, alt, super, hyper, meta;
+
+                if (g_markup_collect_attributes (element_name, attribute_names, attribute_values, error,
+                                                 G_MARKUP_COLLECT_STRING, "name", &param1,
+                                                 G_MARKUP_COLLECT_STRING, "action", &param2,
+                                                 G_MARKUP_COLLECT_STRING | G_MARKUP_COLLECT_OPTIONAL, "options", &param3,
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "shift", &shift,
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "control", &control,
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "alt", &alt,
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "super", &super,
+#if GTK_CHECK_VERSION (2, 10, 0)
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "hyper", &hyper,
+                                                 G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL, "meta", &meta,
+#endif
+                                                 G_MARKUP_COLLECT_INVALID))
+                    {
+                        if (gcmd_user_actions.has_action(param2))
+                        {
+                            guint keyval = gdk_key_names[param1];
+
+                             if (keyval==GDK_VoidSymbol)
+                                if (strlen(param1)==1 && ascii_isalnum (*param1))
+                                    keyval = *param1;
+
+                            if (keyval!=GDK_VoidSymbol)
+                            {
+                                guint accel_mask = 0;
+
+                                if (shift)  accel_mask |= GDK_SHIFT_MASK;
+                                if (control)  accel_mask |= GDK_CONTROL_MASK;
+                                if (alt)  accel_mask |= GDK_MOD1_MASK;
+#if GTK_CHECK_VERSION (2, 10, 0)
+                                if (super)  accel_mask |= GDK_SUPER_MASK;
+                                if (hyper)  accel_mask |= GDK_HYPER_MASK;
+                                if (meta)  accel_mask |= GDK_META_MASK;
+#else
+                                if (super)  accel_mask |= GDK_MOD4_MASK;
+#endif
+                                gcmd_user_actions.register_action(accel_mask, keyval, param2, param3);
+                            }
+                            else
+                                g_warning ("<KeyBindings> invalid key name: '%s' - ignored", param1);
+                        }
+                        else
+                            g_warning ("<KeyBindings> unknown user action: '%s' - ignored", param2);
+                    }
+            }
+            break;
+
         default:
             break;
     }
@@ -653,7 +707,9 @@ gboolean gnome_cmd_xml_config_parse (const gchar *xml, gsize xml_len, GnomeCmdDa
                         {XML_GNOMECOMMANDER_SELECTIONS_PROFILE, "/GnomeCommander/Selections/Profile"},
                         {XML_GNOMECOMMANDER_SELECTIONS_PROFILE_PATTERN, "/GnomeCommander/Selections/Profile/Pattern"},
                         {XML_GNOMECOMMANDER_SELECTIONS_PROFILE_PATH, "/GnomeCommander/Selections/Profile/Path"},
-                        {XML_GNOMECOMMANDER_SELECTIONS_PROFILE_TEXT, "/GnomeCommander/Selections/Profile/Text"}
+                        {XML_GNOMECOMMANDER_SELECTIONS_PROFILE_TEXT, "/GnomeCommander/Selections/Profile/Text"},
+                        {XML_GNOMECOMMANDER_KEYBINDINGS, "/GnomeCommander/KeyBindings"},
+                        {XML_GNOMECOMMANDER_KEYBINDINGS_KEY, "/GnomeCommander/KeyBindings/Key"}
                        };
 
     load_data (xml_elem_names, xml_elem_data, G_N_ELEMENTS(xml_elem_data));
diff --git a/src/main.cc b/src/main.cc
index 7967c74..d8be336 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -120,7 +120,9 @@ int main (int argc, char *argv[])
     conf_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome-commander", NULL);
     create_dir_if_needed (conf_dir);
     g_free (conf_dir);
+    gcmd_user_actions.init();
     gnome_cmd_data.load();
+    gcmd_user_actions.set_defaults();
     IMAGE_init ();
     gnome_cmd_data.load_more();
 
@@ -130,7 +132,6 @@ int main (int argc, char *argv[])
         gnome_cmd_smb_auth_init ();
 
     gnome_cmd_style_create ();
-    gcmd_user_actions.init();
 
     main_win_widget = gnome_cmd_main_win_new ();
     main_win = GNOME_CMD_MAIN_WIN (main_win_widget);



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