Allow native commands as external editors

If an editor is marked as a native command, it is launched using the
older method (native for Windows or Glib otherwise). Non-native commands
are launched with Gio. When reading preferences containing the old style
external editor settings, all commands are marked as native to avoid
breaking them.

Fix bug where the send to editor button shows the wrong editor. The bug
happens when the other editor option is selected while the user edits
the external editors in preferences. When saved, the button shows the
first option is selected instead of the other editor option (the last
entry).
This commit is contained in:
Lawrence Lee
2023-04-08 18:16:23 -07:00
parent dc1c667790
commit 19f12f3182
10 changed files with 97 additions and 32 deletions

View File

@@ -873,6 +873,7 @@ void Options::readFromFile(Glib::ustring fname)
if (keyFile.has_group("External Editor")) {
if (keyFile.has_key("External Editor", "Names")
|| keyFile.has_key("External Editor", "Commands")
|| keyFile.has_key("External Editor", "NativeCommands")
|| keyFile.has_key("External Editor", "IconsSerialized")) {
// Multiple external editors.
@@ -886,6 +887,11 @@ void Options::readFromFile(Glib::ustring fname)
std::vector<Glib::ustring>() :
static_cast<std::vector<Glib::ustring>>(
keyFile.get_string_list("External Editor", "Commands"));
const auto & native_commands =
!keyFile.has_key("External Editor", "NativeCommands") ?
std::vector<bool>() :
static_cast<std::vector<bool>>(
keyFile.get_boolean_list("External Editor", "NativeCommands"));
const auto & icons_serialized =
!keyFile.has_key("External Editor", "IconsSerialized") ?
std::vector<Glib::ustring>() :
@@ -899,6 +905,9 @@ void Options::readFromFile(Glib::ustring fname)
for (unsigned i = 0; i < commands.size(); i++) {
externalEditors[i].command = commands[i];
}
for (unsigned i = 0; i < native_commands.size(); i++) {
externalEditors[i].native_command = native_commands[i];
}
for (unsigned i = 0; i < icons_serialized.size(); i++) {
externalEditors[i].icon_serialized = icons_serialized[i];
}
@@ -938,7 +947,7 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 1) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("GIMP", "\"" + executable + "\"", getIconSerialized(executable)));
externalEditors.emplace_back("GIMP", executable, true, getIconSerialized(executable));
} else {
for (auto ver = 12; ver >= 0; --ver) {
executable = Glib::build_filename(gimpDir, "bin", Glib::ustring::compose(Glib::ustring("gimp-2.%1.exe"), ver));
@@ -946,7 +955,7 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 1) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("GIMP", "\"" + executable + "\"", getIconSerialized(executable)));
externalEditors.emplace_back("GIMP", executable, true, getIconSerialized(executable));
break;
}
}
@@ -961,7 +970,7 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 2) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("Photoshop", "\"" + executable + "\"", getIconSerialized(executable)));
externalEditors.emplace_back("Photoshop", executable, true, getIconSerialized(executable));
}
if (keyFile.has_key("External Editor", "CustomEditor")) {
@@ -970,20 +979,20 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 3) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("-", "\"" + executable + "\"", ""));
externalEditors.emplace_back("-", executable, true, "");
}
}
#elif defined __APPLE__
if (editorToSendTo == 1) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("GIMP", "open -a GIMP", "gimp"));
externalEditors.push_back(ExternalEditor("GIMP-dev", "open -a GIMP-dev", "gimp"));
externalEditors.emplace_back("GIMP", "open -a GIMP", true, "");
externalEditors.emplace_back("GIMP-dev", "open -a GIMP-dev", true, "");
if (editorToSendTo == 2) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("Photoshop", "open -a Photoshop", ""));
externalEditors.emplace_back("Photoshop", "open -a Photoshop", true, "");
if (keyFile.has_key("External Editor", "CustomEditor")) {
auto executable = keyFile.get_string("External Editor", "CustomEditor");
@@ -991,20 +1000,21 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 3) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("-", executable, ""));
externalEditors.emplace_back("-", executable, true, "");
}
}
#else
const Glib::ustring gimp_icon_serialized = "('themed', <['gimp', 'gimp-symbolic']>)";
if (Glib::find_program_in_path("gimp").compare("")) {
if (editorToSendTo == 1) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("GIMP", "gimp", "gimp"));
externalEditors.emplace_back("GIMP", "gimp", true, gimp_icon_serialized);
} else if (Glib::find_program_in_path("gimp-remote").compare("")) {
if (editorToSendTo == 1) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("GIMP", "gimp-remote", "gimp"));
externalEditors.emplace_back("GIMP", "gimp-remote", true, gimp_icon_serialized);
}
if (keyFile.has_key("External Editor", "CustomEditor")) {
@@ -1013,7 +1023,7 @@ void Options::readFromFile(Glib::ustring fname)
if (editorToSendTo == 3) {
externalEditorIndex = externalEditors.size();
}
externalEditors.push_back(ExternalEditor("-", executable, ""));
externalEditors.emplace_back("-", executable, true, "");
}
}
#endif
@@ -2328,16 +2338,19 @@ void Options::saveToFile(Glib::ustring fname)
{
std::vector<Glib::ustring> names;
std::vector<Glib::ustring> commands;
std::vector<bool> native_commands;
std::vector<Glib::ustring> icons_serialized;
for (const auto & editor : externalEditors) {
names.push_back(editor.name);
commands.push_back(editor.command);
native_commands.push_back(editor.native_command);
icons_serialized.push_back(editor.icon_serialized);
}
keyFile.set_string_list("External Editor", "Names", names);
keyFile.set_string_list("External Editor", "Commands", commands);
keyFile.set_boolean_list("External Editor", "NativeCommands", native_commands);
keyFile.set_string_list("External Editor", "IconsSerialized", icons_serialized);
keyFile.set_integer("External Editor", "EditorIndex", externalEditorIndex);
@@ -3009,15 +3022,15 @@ Glib::ustring Options::getICCProfileCopyright()
return Glib::ustring::compose("Copyright RawTherapee %1, CC0", now.get_year());
}
ExternalEditor::ExternalEditor() {}
ExternalEditor::ExternalEditor() = default;
ExternalEditor::ExternalEditor(
const Glib::ustring &name, const Glib::ustring &command, const Glib::ustring &icon_serialized
): name(name), command(command), icon_serialized(icon_serialized) {}
const Glib::ustring &name, const Glib::ustring &command, bool native_command, const Glib::ustring &icon_serialized
): name(name), command(command), native_command(native_command), icon_serialized(icon_serialized) {}
bool ExternalEditor::operator==(const ExternalEditor &other) const
{
return this->name == other.name && this->command == other.command && this->icon_serialized == other.icon_serialized;
return this->name == other.name && this->command == other.command && this->native_command == other.native_command && this->icon_serialized == other.icon_serialized;
}
bool ExternalEditor::operator!=(const ExternalEditor &other) const