Explorar o código

added open with... to right click

Nicole Portas hai 1 mes
pai
achega
8daf2b47da
Modificáronse 1 ficheiros con 41 adicións e 4 borrados
  1. 41 4
      src/main.cpp

+ 41 - 4
src/main.cpp

@@ -200,7 +200,17 @@ public:
         m_MenuItemSelectNone.signal_activate().connect([this](){ on_selection_change(false); });
         m_MenuPopup.append(m_MenuItemSelectNone);
 
-        m_MenuPopup.append(m_MenuSeparator);
+        m_MenuPopup.append(m_MenuSeparator1);
+
+        m_MenuItemOpenWith.set_label("Open With...");
+        auto open_img = Gtk::manage(new Gtk::Image());
+        open_img->set_from_icon_name("document-open", Gtk::ICON_SIZE_MENU);
+        m_MenuItemOpenWith.set_image(*open_img);
+        m_MenuItemOpenWith.set_always_show_image(true);
+        m_MenuItemOpenWith.signal_activate().connect(sigc::mem_fun(*this, &RenamerWindow::on_open_with_clicked));
+        m_MenuPopup.append(m_MenuItemOpenWith);
+
+        m_MenuPopup.append(m_MenuSeparator2);
 
         m_MenuItemDelete.set_label("Move to Trash");
         auto delete_img = Gtk::manage(new Gtk::Image());
@@ -225,7 +235,7 @@ public:
         this->drag_dest_set(listTargets, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_COPY);
         this->signal_drag_data_received().connect(sigc::mem_fun(*this, &RenamerWindow::on_drag_data_received));
 
-        // --- Keyboard Shortcuts (The "Hidden" Cockpit Controls) ---
+        // --- Keyboard Shortcuts ---
         this->signal_key_press_event().connect(sigc::mem_fun(*this, &RenamerWindow::on_window_key_press), false);
 
         show_all_children();
@@ -254,8 +264,8 @@ protected:
     Gtk::Menu m_MenuPopup;
     Gtk::MenuItem m_MenuItemSelectAll;
     Gtk::MenuItem m_MenuItemSelectNone;
-    Gtk::SeparatorMenuItem m_MenuSeparator;
-    Gtk::ImageMenuItem m_MenuItemDelete;
+    Gtk::SeparatorMenuItem m_MenuSeparator1, m_MenuSeparator2;
+    Gtk::ImageMenuItem m_MenuItemDelete, m_MenuItemOpenWith;
 
     struct ModelColumns : public Gtk::TreeModel::ColumnRecord {
         ModelColumns() { add(m_col_path); add(m_col_filename); add(m_col_pixbuf); add(m_col_checked); add(m_col_markup); add(m_col_time); add(m_col_info_str); }
@@ -280,6 +290,7 @@ protected:
         if ((event->state & GDK_CONTROL_MASK)) {
             if (event->keyval == GDK_KEY_o || event->keyval == GDK_KEY_O) { on_open_folder_clicked(); return true; }
             if (event->keyval == GDK_KEY_z || event->keyval == GDK_KEY_Z) { on_undo_clicked(); return true; }
+            if (event->keyval == GDK_KEY_e || event->keyval == GDK_KEY_E) { on_open_with_clicked(); return true; }
         }
         if (event->keyval == GDK_KEY_Delete) { on_delete_selected(); return true; }
         if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) { on_rename_execute(); return true; }
@@ -299,6 +310,32 @@ protected:
         }
     }
 
+    // --- Open With Handler ---
+    void on_open_with_clicked() {
+        std::string target_path;
+        for (auto row : m_RefListStore->children()) {
+            if (row[m_Columns.m_col_checked]) {
+                target_path = (std::string)row[m_Columns.m_col_path];
+                break;
+            }
+        }
+
+        if (target_path.empty()) return;
+
+        auto file = Gio::File::create_for_path(target_path);
+        // Corrected constructor: (file, parent_window)
+        Gtk::AppChooserDialog dialog(file, *this); 
+        dialog.set_title("Open With...");
+        
+        if (dialog.run() == Gtk::RESPONSE_OK) {
+            auto app_info = dialog.get_app_info();
+            if (app_info) {
+                std::vector<Glib::RefPtr<Gio::File>> files = { file };
+                app_info->launch(files);
+            }
+        }
+    }
+
     std::string format_size(uintmax_t bytes) {
         double sz = (double)bytes;
         const char* units[] = {"B", "KB", "MB", "GB"};