gnome-commander r2485 - in branches/gcmd-1-3: . src
- From: epiotr svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-commander r2485 - in branches/gcmd-1-3: . src
- Date: Mon, 9 Mar 2009 22:16:40 +0000 (UTC)
Author: epiotr
Date: Mon Mar 9 22:16:40 2009
New Revision: 2485
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2485&view=rev
Log:
Moved regexes GtkTreeModel from gnome-cmd-data.h to gnome-cmd-advrename-dialog.cc
Modified:
branches/gcmd-1-3/ChangeLog
branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
branches/gcmd-1-3/src/gnome-cmd-data.cc
branches/gcmd-1-3/src/gnome-cmd-data.h
branches/gcmd-1-3/src/gnome-cmd-xml-config.cc
Modified: branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc (original)
+++ branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc Mon Mar 9 22:16:40 2009
@@ -61,6 +61,7 @@
GtkWidget *counter_step_spin;
GtkWidget *counter_digits_spin;
+ GtkTreeModel *regexes;
GtkWidget *regex_view;
GtkWidget *regex_add_button;
@@ -87,6 +88,8 @@
Private();
~Private();
+ void fill_regex_model(const GnomeCmdData::AdvrenameConfig::Profile &profile);
+
static gchar *translate_menu (const gchar *path, gpointer data);
GtkWidget *create_placeholder_menu(int menu_type, GnomeCmdData::AdvrenameConfig *cfg);
@@ -371,11 +374,13 @@
convert_case = gcmd_convert_unchanged;
trim_blanks = gcmd_convert_strip;
template_has_counters = FALSE;
+ regexes = NULL;
}
inline GnomeCmdAdvrenameDialog::Private::~Private()
{
+ if (regexes) g_object_unref (regexes);
}
@@ -386,6 +391,28 @@
return !gtk_tree_model_get_iter_first (tree_model, &iter);
}
+void GnomeCmdAdvrenameDialog::Private::fill_regex_model(const GnomeCmdData::AdvrenameConfig::Profile &profile)
+{
+ if (!regexes)
+ return;
+
+ GtkTreeIter iter;
+
+ for (vector<GnomeCmd::ReplacePattern>::const_iterator r=profile.regexes.begin(); r!=profile.regexes.end(); ++r)
+ {
+ GnomeCmd::RegexReplace *rx = new GnomeCmd::RegexReplace(r->pattern, r->replacement, r->match_case);
+
+ gtk_list_store_append (GTK_LIST_STORE (regexes), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (regexes), &iter,
+ GnomeCmdAdvrenameDialog::COL_REGEX, rx,
+ GnomeCmdAdvrenameDialog::COL_MALFORMED_REGEX, !*rx,
+ GnomeCmdAdvrenameDialog::COL_PATTERN, rx->pattern.c_str(),
+ GnomeCmdAdvrenameDialog::COL_REPLACE, rx->replacement.c_str(),
+ GnomeCmdAdvrenameDialog::COL_MATCH_CASE, rx->match_case ? _("Yes") : _("No"),
+ -1);
+ }
+}
+
gchar *GnomeCmdAdvrenameDialog::Private::translate_menu (const gchar *path, gpointer data)
{
@@ -577,6 +604,7 @@
g_return_if_fail (dialog!=NULL);
GnomeCmdData::AdvrenameConfig &cfg = GNOME_CMD_ADVRENAME_DIALOG(dialog)->defaults;
+ GtkTreeModel *regexes = GNOME_CMD_ADVRENAME_DIALOG(dialog)->priv->regexes;
if (new_profile)
{
@@ -587,11 +615,11 @@
cfg.default_profile.regexes.clear();
- for (gboolean valid_iter=gtk_tree_model_get_iter_first (cfg.regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (cfg.regexes, &i))
+ for (gboolean valid_iter=gtk_tree_model_get_iter_first (regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (regexes, &i))
{
GnomeCmd::RegexReplace *r;
- gtk_tree_model_get (cfg.regexes, &i,
+ gtk_tree_model_get (regexes, &i,
COL_REGEX, &r,
-1);
if (r) // ignore null regex patterns
@@ -628,7 +656,7 @@
gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->counter_digits_spin), p.counter_width);
on_regex_remove_all_btn_clicked (NULL, GNOME_CMD_ADVRENAME_DIALOG(dialog));
- cfg.fill_regex_model(p);
+ priv->fill_regex_model(p);
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->case_combo), p.case_conversion);
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->trim_combo), p.trim_blanks);
@@ -637,9 +665,9 @@
cfg.default_profile = p;
- gtk_widget_set_sensitive (priv->regex_edit_button, !model_is_empty(cfg.regexes));
- gtk_widget_set_sensitive (priv->regex_remove_button, !model_is_empty(cfg.regexes));
- gtk_widget_set_sensitive (priv->regex_remove_all_button, !model_is_empty(cfg.regexes));
+ gtk_widget_set_sensitive (priv->regex_edit_button, !model_is_empty(priv->regexes));
+ gtk_widget_set_sensitive (priv->regex_remove_button, !model_is_empty(priv->regexes));
+ gtk_widget_set_sensitive (priv->regex_remove_all_button, !model_is_empty(priv->regexes));
}
@@ -697,8 +725,8 @@
{
GtkTreeIter i;
- gtk_list_store_append (GTK_LIST_STORE (dialog->defaults.regexes), &i);
- gtk_list_store_set (GTK_LIST_STORE (dialog->defaults.regexes), &i,
+ gtk_list_store_append (GTK_LIST_STORE (dialog->priv->regexes), &i);
+ gtk_list_store_set (GTK_LIST_STORE (dialog->priv->regexes), &i,
COL_REGEX, rx,
COL_MALFORMED_REGEX, !*rx,
COL_PATTERN, rx->pattern.c_str(),
@@ -726,11 +754,11 @@
{
GnomeCmd::RegexReplace *rx = NULL;
- gtk_tree_model_get (dialog->defaults.regexes, &i, COL_REGEX, &rx, -1);
+ gtk_tree_model_get (dialog->priv->regexes, &i, COL_REGEX, &rx, -1);
if (gnome_cmd_advrename_regex_dialog_new (_("Edit Rule"), GTK_WINDOW (dialog), rx))
{
- gtk_list_store_set (GTK_LIST_STORE (dialog->defaults.regexes), &i,
+ gtk_list_store_set (GTK_LIST_STORE (dialog->priv->regexes), &i,
COL_REGEX, rx,
COL_MALFORMED_REGEX, !*rx,
COL_PATTERN, rx->pattern.c_str(),
@@ -753,11 +781,11 @@
{
GnomeCmd::RegexReplace *rx = NULL;
- gtk_tree_model_get (dialog->defaults.regexes, &i, COL_REGEX, &rx, -1);
- gtk_list_store_remove (GTK_LIST_STORE (dialog->defaults.regexes), &i);
+ gtk_tree_model_get (dialog->priv->regexes, &i, COL_REGEX, &rx, -1);
+ gtk_list_store_remove (GTK_LIST_STORE (dialog->priv->regexes), &i);
delete rx;
- if (model_is_empty (dialog->defaults.regexes))
+ if (model_is_empty (dialog->priv->regexes))
{
gtk_widget_set_sensitive (dialog->priv->regex_edit_button, FALSE);
gtk_widget_set_sensitive (dialog->priv->regex_remove_button, FALSE);
@@ -771,17 +799,17 @@
{
GtkTreeIter i;
- for (gboolean valid_iter=gtk_tree_model_get_iter_first (dialog->defaults.regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (dialog->defaults.regexes, &i))
+ for (gboolean valid_iter=gtk_tree_model_get_iter_first (dialog->priv->regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (dialog->priv->regexes, &i))
{
GnomeCmd::RegexReplace *rx = NULL;
- gtk_tree_model_get (dialog->defaults.regexes, &i, COL_REGEX, &rx, -1);
+ gtk_tree_model_get (dialog->priv->regexes, &i, COL_REGEX, &rx, -1);
delete rx;
}
- g_signal_handlers_block_by_func (dialog->defaults.regexes, gpointer (on_regex_model_row_deleted), dialog);
- gtk_list_store_clear (GTK_LIST_STORE (dialog->defaults.regexes));
- g_signal_handlers_unblock_by_func (dialog->defaults.regexes, gpointer (on_regex_model_row_deleted), dialog);
+ g_signal_handlers_block_by_func (dialog->priv->regexes, gpointer (on_regex_model_row_deleted), dialog);
+ gtk_list_store_clear (GTK_LIST_STORE (dialog->priv->regexes));
+ g_signal_handlers_unblock_by_func (dialog->priv->regexes, gpointer (on_regex_model_row_deleted), dialog);
dialog->update_new_filenames();
@@ -1335,6 +1363,21 @@
{
GnomeCmdAdvrenameDialog *dialog = GNOME_CMD_ADVRENAME_DIALOG (object);
+ GtkTreeIter i;
+
+ dialog->defaults.default_profile.regexes.clear();
+
+ for (gboolean valid_iter=gtk_tree_model_get_iter_first (dialog->priv->regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (dialog->priv->regexes, &i))
+ {
+ GnomeCmd::RegexReplace *rx;
+
+ gtk_tree_model_get (dialog->priv->regexes, &i,
+ GnomeCmdAdvrenameDialog::COL_REGEX, &rx,
+ -1);
+ if (rx) // ignore null regex patterns
+ dialog-> defaults.default_profile.regexes.push_back(*rx);
+ }
+
delete dialog->priv;
G_OBJECT_CLASS (gnome_cmd_advrename_dialog_parent_class)->finalize (object);
@@ -1456,11 +1499,11 @@
vector<GnomeCmd::RegexReplace *> rx;
- for (gboolean valid_iter=gtk_tree_model_get_iter_first (defaults.regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (defaults.regexes, &i))
+ for (gboolean valid_iter=gtk_tree_model_get_iter_first (priv->regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (priv->regexes, &i))
{
GnomeCmd::RegexReplace *r;
- gtk_tree_model_get (defaults.regexes, &i,
+ gtk_tree_model_get (priv->regexes, &i,
COL_REGEX, &r,
-1);
if (r && *r) // ignore regex pattern if it can't be retrieved or if it is malformed
@@ -1563,9 +1606,16 @@
g_signal_connect (priv->counter_digits_spin, "value-changed", G_CALLBACK (Private::on_counter_digits_spin_value_changed), this);
// Regex
- gtk_tree_view_set_model (GTK_TREE_VIEW (priv->regex_view), defaults.regexes);
+ priv->regexes = GTK_TREE_MODEL (gtk_list_store_new (NUM_REGEX_COLS,
+ G_TYPE_POINTER,
+ G_TYPE_BOOLEAN,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_STRING));
+ priv->fill_regex_model(cfg.default_profile);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (priv->regex_view), priv->regexes);
- g_signal_connect (defaults.regexes, "row-deleted", G_CALLBACK (Private::on_regex_model_row_deleted), this);
+ g_signal_connect (priv->regexes, "row-deleted", G_CALLBACK (Private::on_regex_model_row_deleted), this);
g_signal_connect (priv->regex_view, "row-activated", G_CALLBACK (Private::on_regex_view_row_activated), this);
g_signal_connect (priv->regex_add_button, "clicked", G_CALLBACK (Private::on_regex_add_btn_clicked), this);
g_signal_connect (priv->regex_edit_button, "clicked", G_CALLBACK (Private::on_regex_edit_btn_clicked), this);
Modified: branches/gcmd-1-3/src/gnome-cmd-data.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.cc (original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.cc Mon Mar 9 22:16:40 2009
@@ -86,29 +86,6 @@
}
-void GnomeCmdData::AdvrenameConfig::fill_regex_model(Profile &profile)
-{
- if (!regexes)
- return;
-
- GtkTreeIter iter;
-
- for (vector<GnomeCmd::ReplacePattern>::const_iterator r=profile.regexes.begin(); r!=profile.regexes.end(); ++r)
- {
- GnomeCmd::RegexReplace *rx = new GnomeCmd::RegexReplace(r->pattern, r->replacement, r->match_case);
-
- gtk_list_store_append (GTK_LIST_STORE (regexes), &iter);
- gtk_list_store_set (GTK_LIST_STORE (regexes), &iter,
- GnomeCmdAdvrenameDialog::COL_REGEX, rx,
- GnomeCmdAdvrenameDialog::COL_MALFORMED_REGEX, !*rx,
- GnomeCmdAdvrenameDialog::COL_PATTERN, rx->pattern.c_str(),
- GnomeCmdAdvrenameDialog::COL_REPLACE, rx->replacement.c_str(),
- GnomeCmdAdvrenameDialog::COL_MATCH_CASE, rx->match_case ? _("Yes") : _("No"),
- -1);
- }
-}
-
-
inline gint get_int (const gchar *path, int def)
{
gboolean b = FALSE;
@@ -994,20 +971,11 @@
GList *tmp_to = to = load_string_history ("/rename-history/to%d", size);
GList *tmp_csens = csens = load_string_history ("/rename-history/csens%d", size);
- for (GtkTreeIter iter; tmp_from && size > 0; --size)
+ for (; tmp_from && size > 0; --size)
{
- GnomeCmd::RegexReplace *rx = new GnomeCmd::RegexReplace((gchar *) tmp_from->data,
- (gchar *) tmp_to->data,
- *((gchar *) tmp_csens->data)=='T');
- gtk_list_store_append (GTK_LIST_STORE (advrename_defaults.regexes), &iter);
- gtk_list_store_set (GTK_LIST_STORE (advrename_defaults.regexes), &iter,
- GnomeCmdAdvrenameDialog::COL_REGEX, rx,
- GnomeCmdAdvrenameDialog::COL_MALFORMED_REGEX, !*rx,
- GnomeCmdAdvrenameDialog::COL_PATTERN, rx->pattern.c_str(),
- GnomeCmdAdvrenameDialog::COL_REPLACE, rx->replacement.c_str(),
- GnomeCmdAdvrenameDialog::COL_MATCH_CASE, rx->match_case ? _("Yes") : _("No"),
- -1);
-
+ advrename_defaults.default_profile.regexes.push_back(GnomeCmd::ReplacePattern((gchar *) tmp_from->data,
+ (gchar *) tmp_to->data,
+ *((gchar *) tmp_csens->data)=='T'));
tmp_from = tmp_from->next;
tmp_to = tmp_to->next;
tmp_csens = tmp_csens->next;
@@ -1398,15 +1366,6 @@
//load_dir_history ();
load_search_defaults();
- // FIXME: the regex list definitely needs to be created in GnomeCmdData::AdvrenameConfig::AdvrenameConfig() constructor
- // Unfortunately, this can't be done now, as gnome_cmd_data is global and is constructed before main() - causing gcmd crash
- // To be moved, when gnome_cmd_data is part of GnomeCmdMainWindow
- advrename_defaults.regexes = GTK_TREE_MODEL (gtk_list_store_new (GnomeCmdAdvrenameDialog::NUM_REGEX_COLS,
- G_TYPE_POINTER,
- G_TYPE_BOOLEAN,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_STRING));
if (!gnome_cmd_xml_config_load (xml_cfg_path, *this))
{
load_rename_history();
Modified: branches/gcmd-1-3/src/gnome-cmd-data.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.h (original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.h Mon Mar 9 22:16:40 2009
@@ -87,13 +87,9 @@
std::vector<Profile> profiles;
History templates;
- GtkTreeModel *regexes;
- AdvrenameConfig(): width(600), height(400),
- templates(ADVRENAME_HISTORY_SIZE), regexes(NULL) {}
- ~AdvrenameConfig() { if (regexes) g_object_unref (regexes); }
-
- void fill_regex_model(Profile &profile);
+ AdvrenameConfig(): width(600), height(400), templates(ADVRENAME_HISTORY_SIZE) {}
+ ~AdvrenameConfig() {}
};
struct IntViewerConfig
Modified: branches/gcmd-1-3/src/gnome-cmd-xml-config.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-xml-config.cc (original)
+++ branches/gcmd-1-3/src/gnome-cmd-xml-config.cc Mon Mar 9 22:16:40 2009
@@ -470,7 +470,6 @@
if (p!=cfg->advrename_defaults.profiles.end())
{
cfg->advrename_defaults.default_profile = *p;
- cfg->advrename_defaults.fill_regex_model(*p);
cfg->advrename_defaults.profiles.erase(p);
}
}
@@ -592,8 +591,6 @@
if (!f)
return;
- GtkTreeIter i;
-
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", f);
fputs("<!-- Created with GNOME Commander (http://www.nongnu.org/gcmd/) -->\n", f);
fputs("<GnomeCommander version=\"" VERSION "\">\n", f);
@@ -607,18 +604,8 @@
cfg.advrename_defaults.default_profile.counter_width);
fputs("\t\t\t<Regexes>\n", f);
- for (gboolean valid_iter=gtk_tree_model_get_iter_first (cfg.advrename_defaults.regexes, &i); valid_iter; valid_iter=gtk_tree_model_iter_next (cfg.advrename_defaults.regexes, &i))
- {
- GnomeCmd::RegexReplace *rx;
-
- gtk_tree_model_get (cfg.advrename_defaults.regexes, &i,
- GnomeCmdAdvrenameDialog::COL_REGEX, &rx,
- -1);
- if (!rx)
- continue;
-
- fprintf(f, "\t\t\t\t<Regex pattern=\"%s\" replace=\"%s\" match-case=\"%u\" />\n", rx->pattern.c_str(), rx->replacement.c_str(), rx->match_case);
- }
+ for (std::vector<GnomeCmd::ReplacePattern>::const_iterator r=cfg.advrename_defaults.default_profile.regexes.begin(); r!=cfg.advrename_defaults.default_profile.regexes.end(); ++r)
+ fprintf(f, "\t\t\t\t<Regex pattern=\"%s\" replace=\"%s\" match-case=\"%u\" />\n", r->pattern.c_str(), r->replacement.c_str(), r->match_case);
fputs("\t\t\t</Regexes>\n", f);
fprintf(f, "\t\t\t<CaseConversion use=\"%u\" />\n", cfg.advrename_defaults.default_profile.case_conversion);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]