diff --git a/rtgui/extprog.cc b/rtgui/extprog.cc index e4cf63733..9ec87c548 100644 --- a/rtgui/extprog.cc +++ b/rtgui/extprog.cc @@ -318,22 +318,26 @@ bool ExtProgStore::openInPhotoshop (const Glib::ustring& fileName) return spawnCommandAsync (cmdLine); } -bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName) +bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName, const Glib::ustring* command) { + if (!command) { + command = &(options.customEditorProg); + } + #if defined WIN32 - const auto cmdLine = Glib::ustring("\"") + options.customEditorProg + Glib::ustring("\""); + const auto cmdLine = Glib::ustring("\"") + *command + Glib::ustring("\""); auto success = ShellExecute( NULL, "open", cmdLine.c_str(), ('"' + fileName + '"').c_str(), NULL, SW_SHOWNORMAL ); return (uintptr_t)success > 32; #elif defined __APPLE__ - const auto cmdLine = options.customEditorProg + Glib::ustring(" \"") + fileName + Glib::ustring("\""); + const auto cmdLine = *command + Glib::ustring(" \"") + fileName + Glib::ustring("\""); return spawnCommandAsync (cmdLine); #else - const auto cmdLine = options.customEditorProg + Glib::ustring(" ") + Glib::shell_quote(fileName); + const auto cmdLine = *command + Glib::ustring(" ") + Glib::shell_quote(fileName); return spawnCommandAsync (cmdLine); #endif @@ -342,13 +346,30 @@ bool ExtProgStore::openInCustomEditor (const Glib::ustring& fileName) bool ExtProgStore::openInExternalEditor(const Glib::ustring &fileName, const Glib::RefPtr &editorInfo) { + bool success = false; + try { - return editorInfo->launch(Gio::File::create_for_path(fileName)); + success = editorInfo->launch(Gio::File::create_for_path(fileName)); } catch (const Glib::Error &e) { std::cerr << "Error launching external editor.\n" << "Error code #" << e.code() << ": " << e.what() << std::endl; - return false; + success = false; } + + if (success) { + return true; + } + + if (rtengine::settings->verbose) { + std::cout << "Unable to launch external editor with Gio. Trying custom launcher." << std::endl; + } + Glib::ustring command = editorInfo->get_commandline(); +#if defined WIN32 + if (command.length() > 2 && command[0] == '"' && command[command.length() - 1] == '"') { + command = command.substr(1, command.length() - 2); + } +#endif + return openInCustomEditor(fileName, &command); } diff --git a/rtgui/extprog.h b/rtgui/extprog.h index cdcf14e48..6547896ef 100644 --- a/rtgui/extprog.h +++ b/rtgui/extprog.h @@ -69,7 +69,7 @@ public: static bool openInGimp (const Glib::ustring& fileName); static bool openInPhotoshop (const Glib::ustring& fileName); - static bool openInCustomEditor (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); }; diff --git a/rtgui/rtwindow.h b/rtgui/rtwindow.h index f62430190..985cd3893 100755 --- a/rtgui/rtwindow.h +++ b/rtgui/rtwindow.h @@ -33,7 +33,7 @@ class BatchQueueEntry; class BatchQueuePanel; class EditorPanel; -class ExternalEditor; +struct ExternalEditor; class FilePanel; class PLDBridge; class RTWindow final :