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:
@@ -37,6 +37,7 @@ ExternalEditorPreferences::ExternalEditorPreferences():
|
||||
list_view = Gtk::manage(new Gtk::TreeView());
|
||||
list_view->set_model(list_model);
|
||||
list_view->append_column(*Gtk::manage(makeAppColumn()));
|
||||
list_view->append_column(*Gtk::manage(makeNativeCommandColumn()));
|
||||
list_view->append_column(*Gtk::manage(makeCommandColumn()));
|
||||
|
||||
for (auto &&column : list_view->get_columns()) {
|
||||
@@ -97,12 +98,12 @@ ExternalEditorPreferences::getEditors() const
|
||||
for (auto rowIter = children.begin(); rowIter != children.end(); rowIter++) {
|
||||
const Gio::Icon *const icon = rowIter->get_value(model_columns.icon).get();
|
||||
const auto &icon_serialized = icon == nullptr ? "" : icon->serialize().print();
|
||||
editors.push_back(ExternalEditorPreferences::EditorInfo(
|
||||
rowIter->get_value(model_columns.name),
|
||||
rowIter->get_value(model_columns.command),
|
||||
icon_serialized,
|
||||
rowIter->get_value(model_columns.other_data)
|
||||
));
|
||||
editors.emplace_back(
|
||||
rowIter->get_value(model_columns.name),
|
||||
rowIter->get_value(model_columns.command),
|
||||
icon_serialized,
|
||||
rowIter->get_value(model_columns.native_command),
|
||||
rowIter->get_value(model_columns.other_data));
|
||||
}
|
||||
|
||||
return editors;
|
||||
@@ -138,6 +139,7 @@ void ExternalEditorPreferences::setEditors(
|
||||
row[model_columns.name] = editor.name;
|
||||
row[model_columns.icon] = icon;
|
||||
row[model_columns.command] = editor.command;
|
||||
row[model_columns.native_command] = editor.native_command;
|
||||
row[model_columns.other_data] = editor.other_data;
|
||||
}
|
||||
}
|
||||
@@ -194,6 +196,24 @@ Gtk::TreeViewColumn *ExternalEditorPreferences::makeCommandColumn()
|
||||
return col;
|
||||
}
|
||||
|
||||
Gtk::TreeViewColumn *ExternalEditorPreferences::makeNativeCommandColumn()
|
||||
{
|
||||
auto toggle_renderer = Gtk::manage(new Gtk::CellRendererToggle());
|
||||
auto col = Gtk::manage(new Gtk::TreeViewColumn());
|
||||
|
||||
col->set_title(M("PREFERENCES_EXTERNALEDITOR_COLUMN_NATIVE_COMMAND"));
|
||||
col->pack_start(*toggle_renderer);
|
||||
col->add_attribute(toggle_renderer->property_active(), model_columns.native_command);
|
||||
|
||||
toggle_renderer->signal_toggled().connect([this](const Glib::ustring &path) {
|
||||
const auto row_iter = list_model->get_iter(path);
|
||||
bool new_value = !row_iter->get_value(model_columns.native_command);
|
||||
row_iter->set_value(model_columns.native_command, new_value);
|
||||
});
|
||||
|
||||
return col;
|
||||
}
|
||||
|
||||
void ExternalEditorPreferences::onAppChooserDialogResponse(
|
||||
int response_id, RTAppChooserDialog *dialog)
|
||||
{
|
||||
@@ -224,6 +244,7 @@ void ExternalEditorPreferences::onFileChooserDialogResponse(
|
||||
for (const auto &selected : selection) {
|
||||
auto row = *list_model->get_iter(selected);
|
||||
row[model_columns.icon] = Glib::RefPtr<Gio::Icon>(nullptr);
|
||||
row[model_columns.native_command] = false;
|
||||
row[model_columns.command] =
|
||||
#ifdef WIN32
|
||||
'"' + dialog->get_filename() + '"';
|
||||
@@ -313,6 +334,7 @@ void ExternalEditorPreferences::setApp(const Glib::RefPtr<Gio::AppInfo> app_info
|
||||
row[model_columns.icon] = app_info->get_icon();
|
||||
row[model_columns.name] = app_info->get_name();
|
||||
row[model_columns.command] = app_info->get_commandline();
|
||||
row[model_columns.native_command] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,8 +366,8 @@ void ExternalEditorPreferences::updateToolbarSensitivity()
|
||||
}
|
||||
|
||||
ExternalEditorPreferences::EditorInfo::EditorInfo(
|
||||
Glib::ustring name, Glib::ustring command, Glib::ustring icon_serialized, void *other_data
|
||||
) : name(name), icon_serialized(icon_serialized), command(command), other_data(other_data)
|
||||
Glib::ustring name, Glib::ustring command, Glib::ustring icon_serialized, bool native_command, void *other_data
|
||||
) : name(name), icon_serialized(icon_serialized), command(command), native_command(native_command), other_data(other_data)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -354,5 +376,6 @@ ExternalEditorPreferences::ModelColumns::ModelColumns()
|
||||
add(name);
|
||||
add(icon);
|
||||
add(command);
|
||||
add(native_command);
|
||||
add(other_data);
|
||||
}
|
||||
|
Reference in New Issue
Block a user