gnome-commander r1711 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Tue Apr 22 21:38:48 2008
New Revision: 1711
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1711&view=rev

Log:
Write modified shortcuts to config file

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/src/gnome-cmd-key-shortcuts-dialog.cc
   branches/gcmd-1-3/src/gnome-cmd-user-actions.cc

Modified: branches/gcmd-1-3/src/gnome-cmd-key-shortcuts-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-key-shortcuts-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-key-shortcuts-dialog.cc	Tue Apr 22 21:38:48 2008
@@ -42,10 +42,6 @@
 
 struct GnomeCmdKeyShortcutsDialogPrivate
 {
-    GnomeCmdUserActions actions;            // local copy of user actions
-
-  public:
-
     GnomeCmdKeyShortcutsDialogPrivate();
 };
 
@@ -68,8 +64,6 @@
 
 inline GnomeCmdKeyShortcutsDialogPrivate::GnomeCmdKeyShortcutsDialogPrivate()
 {
-    if (_GnomeCmdKeyShortcutsDialog::user_actions)
-        actions = *_GnomeCmdKeyShortcutsDialog::user_actions;
 }
 
 
@@ -89,13 +83,71 @@
 }
 
 
-static void response_callback (GnomeCmdKeyShortcutsDialog *dialog, int response_id, gpointer data)
+enum
+{
+    COL_ACCEL_KEY,
+    COL_ACCEL_MASK,
+    COL_ACTION,
+    COL_NAME,
+    COL_OPTION,
+    NUM_COLUMNS
+} ;
+
+
+static void response_callback (GnomeCmdKeyShortcutsDialog *dialog, int response_id, GtkWidget *view)
 {
     switch (response_id)
     {
         case GTK_RESPONSE_OK:
             if (dialog->user_actions)
-                *dialog->user_actions = dialog->priv->actions;
+            {
+                dialog->user_actions->clear();
+
+                GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+                GtkTreeIter i;
+
+                // copy model -> dialog->user_actions
+
+                for (gboolean valid_iter=gtk_tree_model_get_iter_first (model, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (model, &i))
+                {
+                    guint accel_key  = 0;
+                    guint accel_mask = 0;
+                    gchar *name = NULL;
+                    gchar *options = NULL;
+
+                    gtk_tree_model_get (model, &i,
+                                        COL_ACCEL_KEY, &accel_key,
+                                        COL_ACCEL_MASK, &accel_mask,
+                                        COL_NAME, &name,
+                                        COL_OPTION, &options,
+                                        -1);
+
+                    if (accel_key)
+                        dialog->user_actions->register_action(accel_mask, accel_key, name, g_strstrip (options));
+
+                    g_free (name);
+                    g_free (options);
+                }
+
+                dialog->user_actions->unregister(GDK_F3);
+                dialog->user_actions->unregister(GDK_F4);
+                dialog->user_actions->unregister(GDK_F5);
+                dialog->user_actions->unregister(GDK_F6);
+                dialog->user_actions->unregister(GDK_F7);
+                dialog->user_actions->unregister(GDK_F8);
+                dialog->user_actions->unregister(GDK_F9);
+                dialog->user_actions->unregister(GDK_F10);
+
+                dialog->user_actions->register_action(GDK_F3, "file.view");
+                dialog->user_actions->register_action(GDK_F4, "file.edit");
+                dialog->user_actions->register_action(GDK_F5, "file.copy");
+                dialog->user_actions->register_action(GDK_F6, "file.rename");
+                dialog->user_actions->register_action(GDK_F7, "file.mkdir");
+                dialog->user_actions->register_action(GDK_F8, "file.delete");
+                dialog->user_actions->register_action(GDK_F9, "edit.search");
+                dialog->user_actions->register_action(GDK_F10, "file.exit");
+            }
+
             break;
 
         case GTK_RESPONSE_NONE:
@@ -191,7 +243,7 @@
 
     gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-    g_signal_connect (dialog, "response", G_CALLBACK (response_callback), dialog);
+    g_signal_connect (dialog, "response", G_CALLBACK (response_callback), view);
 
     gtk_widget_grab_focus (view);
 }
@@ -298,17 +350,6 @@
 
 enum
 {
-    COL_ACCEL_KEY,
-    COL_ACCEL_MASK,
-    COL_ACTION,
-    COL_NAME,
-    COL_OPTION,
-    NUM_COLUMNS
-} ;
-
-
-enum
-{
     SORTID_ACCEL,
     SORTID_ACTION,
     SORTID_OPTION

Modified: branches/gcmd-1-3/src/gnome-cmd-user-actions.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-user-actions.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-user-actions.cc	Tue Apr 22 21:38:48 2008
@@ -403,31 +403,16 @@
 
 void GnomeCmdUserActions::write(const gchar *section)
 {
-    string section_path = G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S;
+    string section_path  = G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S;
            section_path += section;
-           section_path += G_DIR_SEPARATOR;
 
-    char *key = NULL;
-    char *action_name = NULL;
-
-    for (gpointer i=gnome_config_init_iterator (section_path.c_str()); (i=gnome_config_iterator_next (i, &key, &action_name)); )
-    {
-        string curr_key = key;
-        string norm_key = key2str(str2key(key));        // <ALT><Ctrl>F3 -> <ctrl><alt>f3
-
-        if (!norm_key.empty() && curr_key!=norm_key)    // if (norm_key is valid && not 'canonical')
-        {
-            gnome_config_clean_key ((section_path+curr_key).c_str());
-            gnome_config_set_string ((section_path+norm_key).c_str(), action_name);
-        }
-
-        g_free (key);
-        g_free (action_name);
-    }
+    gnome_config_clean_section (section_path.c_str());
 
     for (ACTIONS_COLL::const_iterator i=action.begin(); i!=action.end(); ++i)
     {
-        string path = section_path + key2str(i->first);
+        string path  = section_path;
+               path += G_DIR_SEPARATOR;
+               path += key2str(i->first);
 
         string action_name = action_func[i->second.func];
 



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