[gnome-commander/get_rid_of_xml] Variable renaming for better code understanding
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/get_rid_of_xml] Variable renaming for better code understanding
- Date: Sun, 30 Dec 2018 17:54:22 +0000 (UTC)
commit 0c6cdc4e40a357a496e29a62576b542c7586f0f4
Author: Uwe Scholz <u scholz83 gmx de>
Date: Mon Dec 24 12:02:00 2018 +0100
Variable renaming for better code understanding
src/dialogs/gnome-cmd-search-dialog.cc | 4 +-
src/gnome-cmd-data.cc | 68 ++++++++++++++--------------
src/gnome-cmd-data.h | 26 +++++++----
src/gnome-cmd-selection-profile-component.cc | 4 +-
src/gnome-cmd-selection-profile-component.h | 6 +--
src/gnome-cmd-xml-config.cc | 4 +-
6 files changed, 61 insertions(+), 51 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-search-dialog.cc b/src/dialogs/gnome-cmd-search-dialog.cc
index a400e548..c4f0292f 100644
--- a/src/dialogs/gnome-cmd-search-dialog.cc
+++ b/src/dialogs/gnome-cmd-search-dialog.cc
@@ -197,7 +197,7 @@ inline GtkWidget *GnomeCmdSearchDialog::Private::create_placeholder_menu(GnomeCm
i->item_type = (gchar*) "<Separator>";
++i;
- for (vector<GnomeCmdData::Selection>::const_iterator p=cfg.profiles.begin(); p!=cfg.profiles.end();
++p, ++i)
+ for (vector<GnomeCmdData::SearchProfile>::const_iterator p=cfg.profiles.begin();
p!=cfg.profiles.end(); ++p, ++i)
{
i->path = g_strconcat ("/", p->name.c_str(), NULL);
i->callback = (GtkItemFactoryCallback) load_profile;
@@ -237,7 +237,7 @@ void GnomeCmdSearchDialog::Private::manage_profiles(GnomeCmdSearchDialog::Privat
if (new_profile)
priv->profile_component->copy();
- if
(GnomeCmd::ManageProfilesDialog<GnomeCmdData::SearchConfig,GnomeCmdData::Selection,GnomeCmdSelectionProfileComponent>
(*dialog,dialog->defaults,new_profile,_("Profiles"),"gnome-commander-search"))
+ if
(GnomeCmd::ManageProfilesDialog<GnomeCmdData::SearchConfig,GnomeCmdData::SearchProfile,GnomeCmdSelectionProfileComponent>
(*dialog,dialog->defaults,new_profile,_("Profiles"),"gnome-commander-search"))
{
GtkWidget *menu = widget->parent;
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 3226b2e8..477ac5d2 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -1499,7 +1499,7 @@ gboolean GnomeCmdData::Options::is_name_double(const gchar *name_to_test)
return foundstate;
}
-void GnomeCmdData::Selection::reset()
+void GnomeCmdData::SearchProfile::reset()
{
name.clear();
filename_pattern.clear();
@@ -1599,7 +1599,7 @@ void GnomeCmdData::save_search_profiles ()
GVariantBuilder* gVariantBuilder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
add_search_profile_to_gvariant_builder(gVariantBuilder, search_defaults.default_profile);
- for (auto profile : selections)
+ for (auto profile : profiles)
{
add_search_profile_to_gvariant_builder(gVariantBuilder, profile);
}
@@ -1610,19 +1610,19 @@ void GnomeCmdData::save_search_profiles ()
}
-void GnomeCmdData::add_search_profile_to_gvariant_builder(GVariantBuilder *builder, GnomeCmdData::Selection
profile)
+void GnomeCmdData::add_search_profile_to_gvariant_builder(GVariantBuilder *builder,
GnomeCmdData::SearchProfile searchProfile)
{
- gchar *nameString = g_strescape (profile.name.c_str(), NULL);
- gchar *filenamePattern = g_strescape (profile.filename_pattern.c_str(), NULL);
- gchar *textPattern = g_strescape (profile.text_pattern.c_str(), NULL);
+ gchar *nameString = g_strescape (searchProfile.name.c_str(), NULL);
+ gchar *filenamePattern = g_strescape (searchProfile.filename_pattern.c_str(), NULL);
+ gchar *textPattern = g_strescape (searchProfile.text_pattern.c_str(), NULL);
g_variant_builder_add(builder, GCMD_SETTINGS_SEARCH_PROFILE_FORMAT_STRING,
nameString,
- profile.max_depth,
- (gint) profile.syntax,
+ searchProfile.max_depth,
+ (gint) searchProfile.syntax,
filenamePattern,
- profile.content_search,
- profile.match_case,
+ searchProfile.content_search,
+ searchProfile.match_case,
textPattern
);
@@ -2213,14 +2213,14 @@ static gboolean load_devices (const gchar *fname)
*/
void GnomeCmdData::load_advrename_profiles ()
{
- GVariant *profiles = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_ADVRENAME_PROFILES);
+ GVariant *gVariantProfiles = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_ADVRENAME_PROFILES);
g_autoptr(GVariantIter) iter1 = NULL;
g_autoptr(GVariantIter) iter2 = NULL;
g_autoptr(GVariantIter) iter3 = NULL;
g_autoptr(GVariantIter) iter4 = NULL;
- g_variant_get (profiles, GCMD_SETTINGS_ADVRENAME_PROFILES_FORMAT_STRING, &iter1);
+ g_variant_get (gVariantProfiles, GCMD_SETTINGS_ADVRENAME_PROFILES_FORMAT_STRING, &iter1);
g_autofree gchar *name = NULL;
gchar *template_string = NULL;
@@ -2285,9 +2285,9 @@ void GnomeCmdData::load_advrename_profiles ()
}
if (profileNumber == 0)
- this->advrename_defaults.default_profile = p;
+ advrename_defaults.default_profile = p;
else
- this->advrename_defaults.profiles.push_back(p);
+ advrename_defaults.profiles.push_back(p);
++profileNumber;
delete(regexes_from);
@@ -2295,7 +2295,7 @@ void GnomeCmdData::load_advrename_profiles ()
delete(regexes_match_case);
}
- g_variant_unref(profiles);
+ g_variant_unref(gVariantProfiles);
// Add two sample profiles here - for new users
if (isGVariantEmpty)
@@ -2308,13 +2308,13 @@ void GnomeCmdData::load_advrename_profiles ()
p.regexes.push_back(GnomeCmd::ReplacePattern("[ _]+", " ", 0));
p.regexes.push_back(GnomeCmd::ReplacePattern("[fF]eat\\.", "fr.", 1));
p.counter_width = 1;
- this->advrename_defaults.profiles.push_back(p);
+ advrename_defaults.profiles.push_back(p);
p.reset();
p.name = "CamelCase";
p.regexes.push_back(GnomeCmd::ReplacePattern("\\s*\\b(\\w)(\\w*)\\b", "\\u\\1\\L\\2\\E", 0));
p.regexes.push_back(GnomeCmd::ReplacePattern("\\.(.+)$", ".\\L\\1", 0));
- this->advrename_defaults.profiles.push_back(p);
+ advrename_defaults.profiles.push_back(p);
}
}
@@ -2324,11 +2324,11 @@ void GnomeCmdData::load_advrename_profiles ()
*/
void GnomeCmdData::load_search_profiles ()
{
- GVariant *profiles = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_SEARCH_PROFILES);
+ GVariant *gVariantProfiles = g_settings_get_value (options.gcmd_settings->general,
GCMD_SETTINGS_SEARCH_PROFILES);
g_autoptr(GVariantIter) iter1 = nullptr;
- g_variant_get (profiles, GCMD_SETTINGS_SEARCH_PROFILES_FORMAT_STRING, &iter1);
+ g_variant_get (gVariantProfiles, GCMD_SETTINGS_SEARCH_PROFILES_FORMAT_STRING, &iter1);
g_autofree gchar *name = nullptr;
gint maxDepth = 0;
@@ -2349,25 +2349,27 @@ void GnomeCmdData::load_search_profiles ()
&matchCase,
&textPattern))
{
- Selection selection;
+ SearchProfile searchProfile;
+
+ searchProfile.reset();
- selection.name = name;
- selection.max_depth = maxDepth;
- selection.syntax = syntax == 0 ? Filter::TYPE_REGEX : Filter::TYPE_FNMATCH;
- selection.filename_pattern = filenamePattern;
- selection.content_search = contentSearch;
- selection.match_case = matchCase;
- selection.text_pattern = textPattern;
+ searchProfile.name = name;
+ searchProfile.max_depth = maxDepth;
+ searchProfile.syntax = syntax == 0 ? Filter::TYPE_REGEX : Filter::TYPE_FNMATCH;
+ searchProfile.filename_pattern = filenamePattern;
+ searchProfile.content_search = contentSearch;
+ searchProfile.match_case = matchCase;
+ searchProfile.text_pattern = textPattern;
if (profileNumber == 0)
- search_defaults.default_profile = selection;
+ search_defaults.default_profile = searchProfile;
else
- selections.push_back(selection);
+ profiles.push_back(searchProfile);
++profileNumber;
}
- g_variant_unref(profiles);
+ g_variant_unref(gVariantProfiles);
}
@@ -2675,7 +2677,7 @@ inline void GnomeCmdData::load_auto_load_plugins()
}
-GnomeCmdData::GnomeCmdData(): search_defaults(selections)
+GnomeCmdData::GnomeCmdData(): search_defaults(profiles)
{
quick_connect = NULL;
@@ -3616,7 +3618,7 @@ void GnomeCmdData::save_xml ()
xml << XML::endtag("Bookmarks");
xml << XML::tag("Selections");
- for (vector<Selection>::iterator i=selections.begin(); i!=selections.end(); ++i)
+ for (vector<SearchProfile>::iterator i=profiles.begin(); i!=profiles.end(); ++i)
xml << *i;
xml << XML::endtag("Selections");
@@ -4137,7 +4139,7 @@ const gchar *gnome_cmd_data_get_symlink_prefix ()
}
-XML::xstream &operator << (XML::xstream &xml, GnomeCmdData::Selection &cfg)
+XML::xstream &operator << (XML::xstream &xml, GnomeCmdData::SearchProfile &cfg)
{
xml << XML::tag("Profile") << XML::attr("name") << XML::escape(cfg.name);
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index f57595f0..97d67d5f 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -520,7 +520,7 @@ struct GnomeCmdData
void on_size_display_mode_changed();
};
- struct Selection
+ struct SearchProfile
{
std::string name;
std::string filename_pattern;
@@ -530,27 +530,35 @@ struct GnomeCmdData
gboolean content_search;
gboolean match_case;
- Selection(): syntax(Filter::TYPE_REGEX), max_depth(-1), content_search(FALSE), match_case(FALSE)
{}
- ~Selection() {}
+ SearchProfile(): syntax(Filter::TYPE_REGEX), max_depth(-1), content_search(FALSE), match_case(FALSE)
{}
+ ~SearchProfile() {}
const std::string &description() const { return filename_pattern; }
void reset();
- friend XML::xstream &operator << (XML::xstream &xml, Selection &cfg);
+ friend XML::xstream &operator << (XML::xstream &xml, SearchProfile &cfg);
};
struct SearchConfig
{
gint width, height;
- Selection default_profile;
+ SearchProfile default_profile;
History name_patterns;
History content_patterns;
- std::vector<Selection> &profiles;
+ std::vector<SearchProfile> &profiles;
- explicit SearchConfig(std::vector<Selection> &selections): width(600), height(400),
name_patterns(SEARCH_HISTORY_SIZE), content_patterns(SEARCH_HISTORY_SIZE), profiles(selections) {
default_profile.name = "Default"; }
+ explicit SearchConfig(std::vector<SearchProfile> &searchProfiles):
+ width(600),
+ height(400),
+ name_patterns(SEARCH_HISTORY_SIZE),
+ content_patterns(SEARCH_HISTORY_SIZE),
+ profiles(searchProfiles)
+ {
+ default_profile.name = "Default";
+ }
friend XML::xstream &operator << (XML::xstream &xml, SearchConfig &cfg);
~SearchConfig() {};
@@ -638,7 +646,7 @@ struct GnomeCmdData
void save_devices_via_gsettings();
void save_fav_apps_via_gsettings();
void add_advrename_profile_to_gvariant_builder(GVariantBuilder *builder, AdvrenameConfig::Profile
profile);
- void add_search_profile_to_gvariant_builder(GVariantBuilder *builder, Selection profile);
+ void add_search_profile_to_gvariant_builder(GVariantBuilder *builder, SearchProfile searchProfile);
inline gint get_int (const gchar *path, int def);
inline gchar* get_string (const gchar *path, const gchar *def);
inline void set_string (const gchar *path, const gchar *value);
@@ -652,7 +660,7 @@ struct GnomeCmdData
Options options;
GcmdSettings *settings;
- std::vector<Selection> selections;
+ std::vector<SearchProfile> profiles;
SearchConfig search_defaults;
AdvrenameConfig advrename_defaults;
diff --git a/src/gnome-cmd-selection-profile-component.cc b/src/gnome-cmd-selection-profile-component.cc
index 8b40f4bb..81549e9d 100644
--- a/src/gnome-cmd-selection-profile-component.cc
+++ b/src/gnome-cmd-selection-profile-component.cc
@@ -181,7 +181,7 @@ static void gnome_cmd_selection_profile_component_class_init (GnomeCmdSelectionP
}
-GnomeCmdSelectionProfileComponent::GnomeCmdSelectionProfileComponent(GnomeCmdData::Selection &p, GtkWidget
*widget, gchar *label): profile(p)
+GnomeCmdSelectionProfileComponent::GnomeCmdSelectionProfileComponent(GnomeCmdData::SearchProfile &p,
GtkWidget *widget, gchar *label): profile(p)
{
if (widget)
{
@@ -234,7 +234,7 @@ void GnomeCmdSelectionProfileComponent::copy()
}
-void GnomeCmdSelectionProfileComponent::copy(GnomeCmdData::Selection &profile_in)
+void GnomeCmdSelectionProfileComponent::copy(GnomeCmdData::SearchProfile &profile_in)
{
stringify(profile_in.filename_pattern, gtk_combo_box_get_active_text (GTK_COMBO_BOX
(priv->pattern_combo)));
profile_in.syntax = (Filter::Type) gtk_combo_box_get_active (GTK_COMBO_BOX (priv->filter_type_combo));
diff --git a/src/gnome-cmd-selection-profile-component.h b/src/gnome-cmd-selection-profile-component.h
index d7fd5df6..69190e63 100644
--- a/src/gnome-cmd-selection-profile-component.h
+++ b/src/gnome-cmd-selection-profile-component.h
@@ -46,14 +46,14 @@ struct GnomeCmdSelectionProfileComponent
void *operator new (size_t size) { return g_object_new (GNOME_CMD_TYPE_SELECTION_PROFILE_COMPONENT,
NULL); }
void operator delete (void *p) { g_object_unref (p); }
- GnomeCmdData::Selection &profile;
+ GnomeCmdData::SearchProfile &profile;
- GnomeCmdSelectionProfileComponent(GnomeCmdData::Selection &profile, GtkWidget *widget=NULL, gchar
*label=NULL);
+ GnomeCmdSelectionProfileComponent(GnomeCmdData::SearchProfile &profile, GtkWidget *widget=NULL, gchar
*label=NULL);
~GnomeCmdSelectionProfileComponent() {}
void update();
void copy(); // copies component to associated profile
- void copy(GnomeCmdData::Selection &profile); // copies component to specified profile
+ void copy(GnomeCmdData::SearchProfile &profile); // copies component to specified profile
void set_focus();
void set_name_patterns_history(GList *history);
diff --git a/src/gnome-cmd-xml-config.cc b/src/gnome-cmd-xml-config.cc
index 448ad1a9..f67ad920 100644
--- a/src/gnome-cmd-xml-config.cc
+++ b/src/gnome-cmd-xml-config.cc
@@ -88,7 +88,7 @@ static DICT<guint> xml_elem_names(XML_ELEM_NOT_FOUND);
static stack<string> xml_paths;
static GnomeCmdData::AdvrenameConfig::Profile xml_adv_profile;
-static GnomeCmdData::Selection xml_search_profile;
+static GnomeCmdData::SearchProfile xml_search_profile;
static DICT<FileSelectorID> xml_fs_names(INACTIVE);
static FileSelectorID xml_fs = INACTIVE;
@@ -462,7 +462,7 @@ static void xml_end (GMarkupParseContext *context,
case XML_GNOMECOMMANDER_SELECTIONS_PROFILE:
if (xml_search_profile.name!="Default")
- cfg->selections.push_back(xml_search_profile);
+ cfg->profiles.push_back(xml_search_profile);
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]