gnome-commander r1838 - in branches/gcmd-1-3: . doc/C src



Author: epiotr
Date: Thu Jun 12 21:54:31 2008
New Revision: 1838
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=1838&view=rev

Log:
Added support for user defined shortcuts to arbitrary programs

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/doc/C/gnome-commander.xml
   branches/gcmd-1-3/src/gnome-cmd-user-actions.cc
   branches/gcmd-1-3/src/gnome-cmd-user-actions.h

Modified: branches/gcmd-1-3/doc/C/gnome-commander.xml
==============================================================================
--- branches/gcmd-1-3/doc/C/gnome-commander.xml	(original)
+++ branches/gcmd-1-3/doc/C/gnome-commander.xml	Thu Jun 12 21:54:31 2008
@@ -4192,6 +4192,45 @@
                         <entry><para></para></entry>
                     </row>
                     <row valign="top">
+                        <entry><para>command.execute<option>|user_command</option></para></entry>
+                        <entry><para>Execute user defined command. &app; replaces found placeholders with:</para>
+                               <para></para>
+                                    <itemizedlist>
+                                        <listitem>
+                                            <para><guilabel>%f</guilabel> file name (or list for multiple selections)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%F</guilabel> quoted filename (or list for multiple selections)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%p</guilabel> full file system path (or list for multiple selections)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%P</guilabel> quoted full file system path (or list for multiple selections)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%u</guilabel> fully qualified URI for the file (or list for multiple selections)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%d</guilabel> full path to the directory containg file</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%D</guilabel> quoted full path to the directory containing file</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%s</guilabel> synonym for <guilabel>%P</guilabel> (for compatibility with previous versions of &app;)</para>
+                                        </listitem>
+                                        <listitem>
+                                            <para><guilabel>%%</guilabel> percent sign</para>
+                                        </listitem>
+                                    </itemizedlist>
+                                    <note>
+                                        <para>Unknown placeholders are copied verbatim without any substitution.</para>
+                                    </note>
+                        </entry>
+                        <entry><para></para></entry>
+                    </row>
+                    <row valign="top">
                         <entry><para>command.open_folder</para></entry>
                         <entry><para>Open the current location in Nautilus file manager</para></entry>
                         <entry><para></para></entry>

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	Thu Jun 12 21:54:31 2008
@@ -132,6 +132,7 @@
                                              {bookmarks_add_current, "bookmarks.add_current", N_("Bookmark current directory")},
                                              {bookmarks_edit, "bookmarks.edit", N_("Manage bookmarks")},
                                              {bookmarks_goto, "bookmarks.goto", N_("Go to bookmarked location")},
+                                             {command_execute, "command.execute", N_("Execute command")},
                                              {command_open_nautilus, "command.open_folder", N_("Open folder")},
                                              {command_open_terminal, "command.open_terminal", N_("Open terminal")},
                                              {command_root_mode, "command.root_mode", N_("Start GNOME Commander as root")},
@@ -927,6 +928,116 @@
 
 
 /************** Command Menu **************/
+template <typename F>
+inline void get_file_list (string &s, GList *sfl, F f)
+{
+    vector<string> a;
+
+    for (GList *i = sfl; i; i = i->next)
+        a.push_back ((*f) (GNOME_CMD_FILE (i->data)));
+
+    join (s, a.begin(), a.end());
+}
+
+
+void command_execute (GtkMenuItem *menuitem, gpointer command)
+{
+    g_return_if_fail (command != NULL);
+
+    DEBUG ('g', "invoking: %s\n", command);
+
+    string cmd;
+    string filename = "[f]";
+    string quoted_filename = "[F]";
+    string file_path = "[p]";
+    string quoted_file_path = "[P]";
+    string dir_path = "[d]";
+    string quoted_dir_path = "[D]";
+    string uri = "[U]";
+
+    GnomeCmdFileList *fl = get_fl (ACTIVE);
+    GList *sfl = gnome_cmd_file_list_get_selected_files (fl);
+    sfl = gnome_cmd_file_list_sort_selection (sfl, fl);
+
+    get_file_list (filename, sfl, gnome_cmd_file_get_name);
+    get_file_list (quoted_filename, sfl, gnome_cmd_file_get_quoted_name);
+    get_file_list (file_path, sfl, gnome_cmd_file_get_real_path);
+    get_file_list (quoted_file_path, sfl, gnome_cmd_file_get_quoted_real_path);
+    get_file_list (uri, sfl, gnome_cmd_file_get_uri_str);
+
+    g_list_free (sfl);
+
+    GnomeCmdDir *dir = gnome_cmd_file_selector_get_directory (get_fs (ACTIVE));
+
+    stringify (dir_path, gnome_cmd_file_get_real_path (GNOME_CMD_FILE (dir)));
+    stringify (quoted_dir_path, gnome_cmd_file_get_quoted_real_path (GNOME_CMD_FILE (dir)));
+
+    gboolean percent = FALSE;
+
+    cmd.reserve(2000);
+
+    for (const char *s=(const char *) command; *s; ++s)
+    {
+        if (!percent)
+        {
+            percent = *s=='%';
+
+            if (!percent)
+                cmd += *s;
+
+            continue;
+        }
+
+        switch (*s)
+        {
+            case 'f':           // %f  file name (or list for multiple selections)
+                cmd += filename;
+                break;
+
+            case 'F':           // %F  quoted filename (or list for multiple selections)
+                cmd += quoted_filename;
+                break;
+
+            case 'p':           // %p  full file system path (or list for multiple selections)
+                cmd += file_path;
+                break;
+
+            case 'P':           // %P  quoted full file system path (or list for multiple selections)
+            case 's':           // %s  synonym for %P (for compatibility with previous versions of gcmd)
+                cmd += quoted_file_path;
+                break;
+
+            case 'u':           // %u  fully qualified URI for the file (or list for multiple selections)
+                cmd += uri;
+                break;
+
+            case 'd':           // %d  full path to the directory containing file
+                cmd += dir_path;
+                break;
+
+            case 'D':           // %D  quoted full path to the directory containg file
+                cmd += quoted_dir_path;
+                break;
+
+            default:
+                cmd += '%';
+            case '%':           // %%  percent sign
+                cmd += *s;
+                break;
+        }
+
+        percent = FALSE;
+    }
+
+    if (percent)
+        cmd += '%';
+
+    DEBUG ('g', "running: %s\n", cmd.c_str());
+
+    gnome_execute_shell (gnome_cmd_dir_is_local (dir) ? dir_path.c_str() : NULL, cmd.c_str());
+}
+
+
 void command_open_terminal (GtkMenuItem *menuitem, gpointer not_used)
 {
     gchar *dpath = gnome_cmd_file_get_real_path (GNOME_CMD_FILE (gnome_cmd_file_selector_get_directory (get_fs (ACTIVE))));

Modified: branches/gcmd-1-3/src/gnome-cmd-user-actions.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-user-actions.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-user-actions.h	Thu Jun 12 21:54:31 2008
@@ -259,6 +259,7 @@
 GNOME_CMD_USER_ACTION(edit_copy_fnames);
 
 /************** Command Menu **************/
+GNOME_CMD_USER_ACTION(command_execute);
 GNOME_CMD_USER_ACTION(command_open_terminal);
 GNOME_CMD_USER_ACTION(command_open_nautilus);
 GNOME_CMD_USER_ACTION(command_open_nautilus_in_cwd);



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