diff --git a/rtgui/editorpanel.cc b/rtgui/editorpanel.cc index 420717b7e..d91e2d7e3 100644 --- a/rtgui/editorpanel.cc +++ b/rtgui/editorpanel.cc @@ -2249,8 +2249,10 @@ void EditorPanel::sendToExternalPressed() dialog->show(); } else { struct ExternalEditor editor = options.externalEditors.at(options.externalEditorIndex); - external_editor_info = Gio::AppInfo::create_from_commandline(editor.command, editor.name, Gio::APP_INFO_CREATE_NONE); - external_editor_native_command = editor.native_command; + external_editor_info = { + editor.name, + editor.command, + editor.native_command}; sendToExternal(); } } @@ -2416,7 +2418,7 @@ bool EditorPanel::idle_sentToGimp (ProgressConnector *pc, rtengine::IImagef setUserOnlyPermission(Gio::File::create_for_path(filename), false); - success = ExtProgStore::openInExternalEditor(filename, external_editor_info, external_editor_native_command); + success = ExtProgStore::openInExternalEditor(filename, external_editor_info); if (!success) { Gtk::MessageDialog msgd (*parent, M ("MAIN_MSG_CANNOTSTARTEDITOR"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); @@ -2445,12 +2447,16 @@ RTAppChooserDialog *EditorPanel::getAppChooserDialog() void EditorPanel::onAppChooserDialogResponse(int responseId) { switch (responseId) { - case Gtk::RESPONSE_OK: + case Gtk::RESPONSE_OK: { getAppChooserDialog()->close(); - external_editor_info = getAppChooserDialog()->get_app_info(); - external_editor_native_command = false; + const auto app_info = getAppChooserDialog()->get_app_info(); + external_editor_info = { + app_info->get_name(), + app_info->get_commandline(), + false}; sendToExternal(); break; + } case Gtk::RESPONSE_CANCEL: case Gtk::RESPONSE_CLOSE: getAppChooserDialog()->close(); @@ -2781,7 +2787,9 @@ void EditorPanel::updateExternalEditorWidget(int selectedIndex, const std::vecto send_to_external->insertEntry(i, "palette-brush.png", name, &send_to_external_radio_group); } } +#ifndef __APPLE__ send_to_external->addEntry("palette-brush.png", M("GENERAL_OTHER"), &send_to_external_radio_group); +#endif send_to_external->setSelected(selectedIndex); send_to_external->show(); } diff --git a/rtgui/editorpanel.h b/rtgui/editorpanel.h index 309f14e8c..b895585ad 100644 --- a/rtgui/editorpanel.h +++ b/rtgui/editorpanel.h @@ -21,6 +21,7 @@ #include +#include "extprog.h" #include "histogrampanel.h" #include "history.h" #include "imageareapanel.h" @@ -252,8 +253,7 @@ private: Gtk::Button* navSync; Gtk::Button* navNext; Gtk::Button* navPrev; - Glib::RefPtr external_editor_info; - bool external_editor_native_command; + EditorInfo external_editor_info; std::unique_ptr app_chooser_dialog; ExternalEditorChangedSignal *externalEditorChangedSignal; sigc::connection externalEditorChangedSignalConnection; diff --git a/rtgui/externaleditorpreferences.cc b/rtgui/externaleditorpreferences.cc index 5d9b45c5d..df48d1466 100644 --- a/rtgui/externaleditorpreferences.cc +++ b/rtgui/externaleditorpreferences.cc @@ -37,7 +37,9 @@ ExternalEditorPreferences::ExternalEditorPreferences(): list_view = Gtk::manage(new Gtk::TreeView()); list_view->set_model(list_model); list_view->append_column(*Gtk::manage(makeAppColumn())); +#ifndef __APPLE__ list_view->append_column(*Gtk::manage(makeNativeCommandColumn())); +#endif list_view->append_column(*Gtk::manage(makeCommandColumn())); for (auto &&column : list_view->get_columns()) { @@ -59,11 +61,18 @@ ExternalEditorPreferences::ExternalEditorPreferences(): button_remove = Gtk::manage(new Gtk::Button()); button_add->set_image(*add_image); button_remove->set_image(*remove_image); - button_app_chooser = Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE"))); + button_app_chooser = +#ifdef __APPLE__ + nullptr; +#else + Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE"))); +#endif button_file_chooser = Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE_FILE"))); - button_app_chooser->signal_pressed().connect(sigc::mem_fun( - *this, &ExternalEditorPreferences::openAppChooserDialog)); + if (button_app_chooser) { + button_app_chooser->signal_pressed().connect(sigc::mem_fun( + *this, &ExternalEditorPreferences::openAppChooserDialog)); + } button_add->signal_pressed().connect(sigc::mem_fun( *this, &ExternalEditorPreferences::addEditor)); button_file_chooser->signal_pressed().connect(sigc::mem_fun( @@ -77,7 +86,9 @@ ExternalEditorPreferences::ExternalEditorPreferences(): // Toolbar. toolbar.set_halign(Gtk::Align::ALIGN_END); - toolbar.add(*button_app_chooser); + if (button_app_chooser) { + toolbar.add(*button_app_chooser); + } toolbar.add(*button_file_chooser); toolbar.add(*button_add); toolbar.add(*button_remove); @@ -156,6 +167,9 @@ void ExternalEditorPreferences::addEditor() } row[model_columns.name] = "-"; +#ifdef __APPLE__ + row[model_columns.native_command] = true; +#endif list_view->get_selection()->select(row); } @@ -244,7 +258,12 @@ void ExternalEditorPreferences::onFileChooserDialogResponse( for (const auto &selected : selection) { auto row = *list_model->get_iter(selected); row[model_columns.icon] = Glib::RefPtr(nullptr); - row[model_columns.native_command] = false; + row[model_columns.native_command] = +#ifdef __APPLE__ + true; +#else + false; +#endif row[model_columns.command] = #ifdef WIN32 '"' + dialog->get_filename() + '"'; @@ -360,7 +379,9 @@ void ExternalEditorPreferences::setAppName( void ExternalEditorPreferences::updateToolbarSensitivity() { bool selected = list_view->get_selection()->count_selected_rows(); - button_app_chooser->set_sensitive(selected); + if (button_app_chooser) { + button_app_chooser->set_sensitive(selected); + } button_file_chooser->set_sensitive(selected); button_remove->set_sensitive(selected); } diff --git a/rtgui/extprog.cc b/rtgui/extprog.cc index ea1800638..4af8ceeed 100644 --- a/rtgui/extprog.cc +++ b/rtgui/extprog.cc @@ -344,13 +344,13 @@ bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName, const Glib } -bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Glib::RefPtr &editorInfo, bool nativeCommand) +bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const EditorInfo &editorInfo) { - if (nativeCommand) { + if (editorInfo.isNativeCommand) { if (rtengine::settings->verbose) { std::cout << "Launching external editor as native command." << std::endl; } - const Glib::ustring command = editorInfo->get_commandline(); + const Glib::ustring command = editorInfo.commandline; return openInCustomEditor(fileName, &command); } @@ -361,7 +361,10 @@ bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Gli bool success = false; try { - success = editorInfo->launch(Gio::File::create_for_path(fileName)); + Glib::RefPtr appInfo = + Gio::AppInfo::create_from_commandline( + editorInfo.commandline, editorInfo.name, Gio::APP_INFO_CREATE_NONE); + success = appInfo->launch(Gio::File::create_for_path(fileName)); } catch (const Glib::Error &e) { std::cerr << "Error launching external editor.\n" @@ -377,7 +380,7 @@ bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Gli if (rtengine::settings->verbose) { std::cout << "Unable to launch external editor with Gio. Trying custom launcher." << std::endl; } - Glib::ustring command = editorInfo->get_commandline(); + Glib::ustring command = editorInfo.commandline; #if defined WIN32 if (command.length() > 2 && command[0] == '"' && command[command.length() - 1] == '"') { command = command.substr(1, command.length() - 2); diff --git a/rtgui/extprog.h b/rtgui/extprog.h index 5336c4703..df54f8cc5 100644 --- a/rtgui/extprog.h +++ b/rtgui/extprog.h @@ -42,6 +42,13 @@ struct ExtProgAction bool execute (const std::vector& fileNames) const; }; +struct EditorInfo +{ + Glib::ustring name; + Glib::ustring commandline; + bool isNativeCommand; +}; + // Stores all external programs that could be called by the user class ExtProgStore { @@ -70,7 +77,7 @@ public: static bool openInGimp (const Glib::ustring& fileName); static bool openInPhotoshop (const Glib::ustring& fileName); static bool openInCustomEditor (const Glib::ustring& fileName, const Glib::ustring* command = nullptr); - static bool openInExternalEditor(const Glib::ustring &fileName, const Glib::RefPtr &editorInfo, bool nativeCommand); + static bool openInExternalEditor(const Glib::ustring &fileName, const EditorInfo &editorInfo); }; #define extProgStore ExtProgStore::getInstance()