From 186995acf4fbfa28d6743a74ce1683bb410f06dd Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Sun, 9 Apr 2023 13:52:09 -0700 Subject: [PATCH] Improve code quality for external editor settings --- rtgui/externaleditorpreferences.cc | 22 +++++++++++++++------- rtgui/externaleditorpreferences.h | 18 ++++++++++++------ rtgui/preferences.cc | 4 ++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/rtgui/externaleditorpreferences.cc b/rtgui/externaleditorpreferences.cc index 55c9f7956..5d9b45c5d 100644 --- a/rtgui/externaleditorpreferences.cc +++ b/rtgui/externaleditorpreferences.cc @@ -91,7 +91,7 @@ ExternalEditorPreferences::ExternalEditorPreferences(): std::vector ExternalEditorPreferences::getEditors() const { - std::vector editors; + std::vector 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 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) { } diff --git a/rtgui/externaleditorpreferences.h b/rtgui/externaleditorpreferences.h index 26903371c..a1e3c7e74 100644 --- a/rtgui/externaleditorpreferences.h +++ b/rtgui/externaleditorpreferences.h @@ -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> icon; Gtk::TreeModelColumn command; Gtk::TreeModelColumn native_command; - Gtk::TreeModelColumn other_data; + Gtk::TreeModelColumn other_data; }; ModelColumns model_columns; diff --git a/rtgui/preferences.cc b/rtgui/preferences.cc index a97cb003d..1ae01da2d 100644 --- a/rtgui/preferences.cc +++ b/rtgui/preferences.cc @@ -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);