Fix external editor on macOS

Avoid using Gio::AppInfo.
This commit is contained in:
Lawrence Lee
2023-07-31 22:57:57 -07:00
parent b68a6e9581
commit a626bdae3e
5 changed files with 59 additions and 20 deletions

View File

@@ -2249,8 +2249,10 @@ void EditorPanel::sendToExternalPressed()
dialog->show(); dialog->show();
} else { } else {
struct ExternalEditor editor = options.externalEditors.at(options.externalEditorIndex); 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_info = {
external_editor_native_command = editor.native_command; editor.name,
editor.command,
editor.native_command};
sendToExternal(); sendToExternal();
} }
} }
@@ -2416,7 +2418,7 @@ bool EditorPanel::idle_sentToGimp (ProgressConnector<int> *pc, rtengine::IImagef
setUserOnlyPermission(Gio::File::create_for_path(filename), false); 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) { if (!success) {
Gtk::MessageDialog msgd (*parent, M ("MAIN_MSG_CANNOTSTARTEDITOR"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); 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) void EditorPanel::onAppChooserDialogResponse(int responseId)
{ {
switch (responseId) { switch (responseId) {
case Gtk::RESPONSE_OK: case Gtk::RESPONSE_OK: {
getAppChooserDialog()->close(); getAppChooserDialog()->close();
external_editor_info = getAppChooserDialog()->get_app_info(); const auto app_info = getAppChooserDialog()->get_app_info();
external_editor_native_command = false; external_editor_info = {
app_info->get_name(),
app_info->get_commandline(),
false};
sendToExternal(); sendToExternal();
break; break;
}
case Gtk::RESPONSE_CANCEL: case Gtk::RESPONSE_CANCEL:
case Gtk::RESPONSE_CLOSE: case Gtk::RESPONSE_CLOSE:
getAppChooserDialog()->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); 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); send_to_external->addEntry("palette-brush.png", M("GENERAL_OTHER"), &send_to_external_radio_group);
#endif
send_to_external->setSelected(selectedIndex); send_to_external->setSelected(selectedIndex);
send_to_external->show(); send_to_external->show();
} }

View File

@@ -21,6 +21,7 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "extprog.h"
#include "histogrampanel.h" #include "histogrampanel.h"
#include "history.h" #include "history.h"
#include "imageareapanel.h" #include "imageareapanel.h"
@@ -252,8 +253,7 @@ private:
Gtk::Button* navSync; Gtk::Button* navSync;
Gtk::Button* navNext; Gtk::Button* navNext;
Gtk::Button* navPrev; Gtk::Button* navPrev;
Glib::RefPtr<Gio::AppInfo> external_editor_info; EditorInfo external_editor_info;
bool external_editor_native_command;
std::unique_ptr<RTAppChooserDialog> app_chooser_dialog; std::unique_ptr<RTAppChooserDialog> app_chooser_dialog;
ExternalEditorChangedSignal *externalEditorChangedSignal; ExternalEditorChangedSignal *externalEditorChangedSignal;
sigc::connection externalEditorChangedSignalConnection; sigc::connection externalEditorChangedSignalConnection;

View File

@@ -37,7 +37,9 @@ ExternalEditorPreferences::ExternalEditorPreferences():
list_view = Gtk::manage(new Gtk::TreeView()); list_view = Gtk::manage(new Gtk::TreeView());
list_view->set_model(list_model); list_view->set_model(list_model);
list_view->append_column(*Gtk::manage(makeAppColumn())); list_view->append_column(*Gtk::manage(makeAppColumn()));
#ifndef __APPLE__
list_view->append_column(*Gtk::manage(makeNativeCommandColumn())); list_view->append_column(*Gtk::manage(makeNativeCommandColumn()));
#endif
list_view->append_column(*Gtk::manage(makeCommandColumn())); list_view->append_column(*Gtk::manage(makeCommandColumn()));
for (auto &&column : list_view->get_columns()) { for (auto &&column : list_view->get_columns()) {
@@ -59,11 +61,18 @@ ExternalEditorPreferences::ExternalEditorPreferences():
button_remove = Gtk::manage(new Gtk::Button()); button_remove = Gtk::manage(new Gtk::Button());
button_add->set_image(*add_image); button_add->set_image(*add_image);
button_remove->set_image(*remove_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_file_chooser = Gtk::manage(new Gtk::Button(M("PREFERENCES_EXTERNALEDITOR_CHANGE_FILE")));
if (button_app_chooser) {
button_app_chooser->signal_pressed().connect(sigc::mem_fun( button_app_chooser->signal_pressed().connect(sigc::mem_fun(
*this, &ExternalEditorPreferences::openAppChooserDialog)); *this, &ExternalEditorPreferences::openAppChooserDialog));
}
button_add->signal_pressed().connect(sigc::mem_fun( button_add->signal_pressed().connect(sigc::mem_fun(
*this, &ExternalEditorPreferences::addEditor)); *this, &ExternalEditorPreferences::addEditor));
button_file_chooser->signal_pressed().connect(sigc::mem_fun( button_file_chooser->signal_pressed().connect(sigc::mem_fun(
@@ -77,7 +86,9 @@ ExternalEditorPreferences::ExternalEditorPreferences():
// Toolbar. // Toolbar.
toolbar.set_halign(Gtk::Align::ALIGN_END); toolbar.set_halign(Gtk::Align::ALIGN_END);
if (button_app_chooser) {
toolbar.add(*button_app_chooser); toolbar.add(*button_app_chooser);
}
toolbar.add(*button_file_chooser); toolbar.add(*button_file_chooser);
toolbar.add(*button_add); toolbar.add(*button_add);
toolbar.add(*button_remove); toolbar.add(*button_remove);
@@ -156,6 +167,9 @@ void ExternalEditorPreferences::addEditor()
} }
row[model_columns.name] = "-"; row[model_columns.name] = "-";
#ifdef __APPLE__
row[model_columns.native_command] = true;
#endif
list_view->get_selection()->select(row); list_view->get_selection()->select(row);
} }
@@ -244,7 +258,12 @@ void ExternalEditorPreferences::onFileChooserDialogResponse(
for (const auto &selected : selection) { for (const auto &selected : selection) {
auto row = *list_model->get_iter(selected); auto row = *list_model->get_iter(selected);
row[model_columns.icon] = Glib::RefPtr<Gio::Icon>(nullptr); row[model_columns.icon] = Glib::RefPtr<Gio::Icon>(nullptr);
row[model_columns.native_command] = false; row[model_columns.native_command] =
#ifdef __APPLE__
true;
#else
false;
#endif
row[model_columns.command] = row[model_columns.command] =
#ifdef WIN32 #ifdef WIN32
'"' + dialog->get_filename() + '"'; '"' + dialog->get_filename() + '"';
@@ -360,7 +379,9 @@ void ExternalEditorPreferences::setAppName(
void ExternalEditorPreferences::updateToolbarSensitivity() void ExternalEditorPreferences::updateToolbarSensitivity()
{ {
bool selected = list_view->get_selection()->count_selected_rows(); bool selected = list_view->get_selection()->count_selected_rows();
if (button_app_chooser) {
button_app_chooser->set_sensitive(selected); button_app_chooser->set_sensitive(selected);
}
button_file_chooser->set_sensitive(selected); button_file_chooser->set_sensitive(selected);
button_remove->set_sensitive(selected); button_remove->set_sensitive(selected);
} }

View File

@@ -344,13 +344,13 @@ bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName, const Glib
} }
bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Glib::RefPtr<Gio::AppInfo> &editorInfo, bool nativeCommand) bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const EditorInfo &editorInfo)
{ {
if (nativeCommand) { if (editorInfo.isNativeCommand) {
if (rtengine::settings->verbose) { if (rtengine::settings->verbose) {
std::cout << "Launching external editor as native command." << std::endl; 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); return openInCustomEditor(fileName, &command);
} }
@@ -361,7 +361,10 @@ bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Gli
bool success = false; bool success = false;
try { try {
success = editorInfo->launch(Gio::File::create_for_path(fileName)); Glib::RefPtr<Gio::AppInfo> 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) { } catch (const Glib::Error &e) {
std::cerr std::cerr
<< "Error launching external editor.\n" << "Error launching external editor.\n"
@@ -377,7 +380,7 @@ bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Gli
if (rtengine::settings->verbose) { if (rtengine::settings->verbose) {
std::cout << "Unable to launch external editor with Gio. Trying custom launcher." << std::endl; 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 defined WIN32
if (command.length() > 2 && command[0] == '"' && command[command.length() - 1] == '"') { if (command.length() > 2 && command[0] == '"' && command[command.length() - 1] == '"') {
command = command.substr(1, command.length() - 2); command = command.substr(1, command.length() - 2);

View File

@@ -42,6 +42,13 @@ struct ExtProgAction
bool execute (const std::vector<Glib::ustring>& fileNames) const; bool execute (const std::vector<Glib::ustring>& fileNames) const;
}; };
struct EditorInfo
{
Glib::ustring name;
Glib::ustring commandline;
bool isNativeCommand;
};
// Stores all external programs that could be called by the user // Stores all external programs that could be called by the user
class ExtProgStore class ExtProgStore
{ {
@@ -70,7 +77,7 @@ public:
static bool openInGimp (const Glib::ustring& fileName); static bool openInGimp (const Glib::ustring& fileName);
static bool openInPhotoshop (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 openInCustomEditor (const Glib::ustring& fileName, const Glib::ustring* command = nullptr);
static bool openInExternalEditor(const Glib::ustring &fileName, const Glib::RefPtr<Gio::AppInfo> &editorInfo, bool nativeCommand); static bool openInExternalEditor(const Glib::ustring &fileName, const EditorInfo &editorInfo);
}; };
#define extProgStore ExtProgStore::getInstance() #define extProgStore ExtProgStore::getInstance()