Improve code quality for external editor settings
This commit is contained in:
parent
19f12f3182
commit
186995acf4
@ -91,7 +91,7 @@ ExternalEditorPreferences::ExternalEditorPreferences():
|
||||
std::vector<ExternalEditorPreferences::EditorInfo>
|
||||
ExternalEditorPreferences::getEditors() const
|
||||
{
|
||||
std::vector<ExternalEditorPreferences::EditorInfo> editors;
|
||||
std::vector<EditorInfo> editors;
|
||||
|
||||
auto children = list_model->children();
|
||||
|
||||
@ -114,7 +114,7 @@ void ExternalEditorPreferences::setEditors(
|
||||
{
|
||||
list_model->clear();
|
||||
|
||||
for (const ExternalEditorPreferences::EditorInfo & editor : editors) {
|
||||
for (const EditorInfo & editor : editors) {
|
||||
auto row = *list_model->append();
|
||||
Glib::RefPtr<Gio::Icon> icon;
|
||||
|
||||
@ -169,8 +169,8 @@ Gtk::TreeViewColumn *ExternalEditorPreferences::makeAppColumn()
|
||||
col->set_resizable();
|
||||
col->pack_start(*icon_renderer, false);
|
||||
col->pack_start(*name_renderer);
|
||||
col->add_attribute(*icon_renderer, "gicon", model_columns.icon);
|
||||
col->add_attribute(*name_renderer, "text", model_columns.name);
|
||||
col->add_attribute(icon_renderer->property_gicon(), model_columns.icon);
|
||||
col->add_attribute(name_renderer->property_text(), model_columns.name);
|
||||
col->set_min_width(20);
|
||||
|
||||
name_renderer->property_editable() = true;
|
||||
@ -187,7 +187,7 @@ Gtk::TreeViewColumn *ExternalEditorPreferences::makeCommandColumn()
|
||||
|
||||
col->set_title(M("PREFERENCES_EXTERNALEDITOR_COLUMN_COMMAND"));
|
||||
col->pack_start(*command_renderer);
|
||||
col->add_attribute(*command_renderer, "text", model_columns.command);
|
||||
col->add_attribute(command_renderer->property_text(), model_columns.command);
|
||||
|
||||
command_renderer->property_editable() = true;
|
||||
command_renderer->signal_edited().connect(
|
||||
@ -366,8 +366,16 @@ void ExternalEditorPreferences::updateToolbarSensitivity()
|
||||
}
|
||||
|
||||
ExternalEditorPreferences::EditorInfo::EditorInfo(
|
||||
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)
|
||||
const Glib::ustring &name,
|
||||
const Glib::ustring &command,
|
||||
const Glib::ustring &icon_serialized,
|
||||
bool native_command,
|
||||
EditorTag other_data) :
|
||||
name(name),
|
||||
icon_serialized(icon_serialized),
|
||||
command(command),
|
||||
native_command(native_command),
|
||||
other_data(other_data)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -42,16 +42,22 @@ class FileChooserDialog;
|
||||
class ExternalEditorPreferences : public Gtk::Box
|
||||
{
|
||||
public:
|
||||
struct EditorTag {
|
||||
bool selected;
|
||||
EditorTag(): selected(false) {}
|
||||
explicit EditorTag(bool selected): selected(selected) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Data struct containing information about an external editor.
|
||||
*/
|
||||
struct EditorInfo {
|
||||
explicit EditorInfo(
|
||||
Glib::ustring name = Glib::ustring(),
|
||||
Glib::ustring command = Glib::ustring(),
|
||||
Glib::ustring icon_serialized = Glib::ustring(),
|
||||
const Glib::ustring &name = Glib::ustring(),
|
||||
const Glib::ustring &command = Glib::ustring(),
|
||||
const Glib::ustring &icon_serialized = Glib::ustring(),
|
||||
bool native_command = false,
|
||||
void *other_data = nullptr
|
||||
EditorTag other_data = EditorTag()
|
||||
);
|
||||
/**
|
||||
* Name of the external editor.
|
||||
@ -74,7 +80,7 @@ public:
|
||||
* Holds any other data associated with the editor. For example, it can
|
||||
* be used as a tag to uniquely identify the editor.
|
||||
*/
|
||||
void *other_data;
|
||||
EditorTag other_data;
|
||||
};
|
||||
|
||||
ExternalEditorPreferences();
|
||||
@ -102,7 +108,7 @@ private:
|
||||
Gtk::TreeModelColumn<Glib::RefPtr<Gio::Icon>> icon;
|
||||
Gtk::TreeModelColumn<Glib::ustring> command;
|
||||
Gtk::TreeModelColumn<bool> native_command;
|
||||
Gtk::TreeModelColumn<void *> other_data;
|
||||
Gtk::TreeModelColumn<EditorTag> other_data;
|
||||
};
|
||||
|
||||
ModelColumns model_columns;
|
||||
|
@ -1753,7 +1753,7 @@ void Preferences::storePreferences()
|
||||
for (unsigned i = 0; i < editors.size(); i++) {
|
||||
moptions.externalEditors[i] = (ExternalEditor(
|
||||
editors[i].name, editors[i].command, editors[i].native_command, editors[i].icon_serialized));
|
||||
if (editors[i].other_data) {
|
||||
if (editors[i].other_data.selected) {
|
||||
// The current editor was marked before the list was edited. We
|
||||
// found the mark, so this is the editor that was active.
|
||||
moptions.externalEditorIndex = i;
|
||||
@ -2038,7 +2038,7 @@ void Preferences::fillPreferences()
|
||||
}
|
||||
if (moptions.externalEditorIndex >= 0) {
|
||||
// Mark the current editor so we can track it.
|
||||
editorInfos[moptions.externalEditorIndex].other_data = (void *)1;
|
||||
editorInfos[moptions.externalEditorIndex].other_data.selected = true;
|
||||
}
|
||||
externalEditors->setEditors(editorInfos);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user