gnome-commander r2276 - in branches/gcmd-1-3: . po src src/dialogs



Author: epiotr
Date: Thu Nov 13 16:33:08 2008
New Revision: 2276
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2276&view=rev

Log:
advrename: move code for regex rules dlg to dialogs/gnome-cmd-advrename-regex-dialog.{cc,h} files

Added:
   branches/gcmd-1-3/src/dialogs/
   branches/gcmd-1-3/src/dialogs/Makefile.am
   branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.cc
   branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.h
Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/configure.in
   branches/gcmd-1-3/po/POTFILES.in
   branches/gcmd-1-3/src/Makefile.am
   branches/gcmd-1-3/src/gnome-cmd-advrename-dialog.cc

Modified: branches/gcmd-1-3/configure.in
==============================================================================
--- branches/gcmd-1-3/configure.in	(original)
+++ branches/gcmd-1-3/configure.in	Thu Nov 13 16:33:08 2008
@@ -387,6 +387,7 @@
 plugins/test/Makefile
 po/Makefile.in
 src/Makefile
+src/dialogs/Makefile
 src/tags/Makefile
 src/intviewer/Makefile
 tests/Makefile

Modified: branches/gcmd-1-3/po/POTFILES.in
==============================================================================
--- branches/gcmd-1-3/po/POTFILES.in	(original)
+++ branches/gcmd-1-3/po/POTFILES.in	Thu Nov 13 16:33:08 2008
@@ -7,6 +7,7 @@
 plugins/cvs/interface.c
 plugins/fileroller/file-roller-plugin.c
 plugins/test/test-plugin.c
+src/dialogs/gnome-cmd-advrename-regex-dialog.cc
 src/gnome-cmd-about-plugin.cc
 src/gnome-cmd-advrename-dialog.cc
 src/gnome-cmd-bookmark-dialog.cc

Modified: branches/gcmd-1-3/src/Makefile.am
==============================================================================
--- branches/gcmd-1-3/src/Makefile.am	(original)
+++ branches/gcmd-1-3/src/Makefile.am	Thu Nov 13 16:33:08 2008
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = tags intviewer
+SUBDIRS = dialogs tags intviewer
 
 AM_CPPFLAGS = \
 	$(CC_WARNINGS) \
@@ -105,6 +105,7 @@
 	$(PYTHON_LIBS) \
 	$(PYTHON_EXTRA_LIBS) \
 	$(top_builddir)/libgcmd/libgcmd.la \
+	dialogs/libgcmd-dialogs.a \
 	tags/libgcmd-tags.a \
 	intviewer/libgviewer.a
 

Added: branches/gcmd-1-3/src/dialogs/Makefile.am
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/dialogs/Makefile.am	Thu Nov 13 16:33:08 2008
@@ -0,0 +1,19 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libgcmd-dialogs.a
+
+AM_CPPFLAGS = \
+	$(CC_WARNINGS) \
+	-I$(top_srcdir) \
+	-I.. \
+	$(GNOMEUI_CFLAGS) \
+	$(GNOMEVFS_CFLAGS) \
+	$(EXIV2_CFLAGS) \
+	$(TAGLIB_CFLAGS) \
+	$(CHM_CFLAGS) \
+	$(GSF_CFLAGS) \
+	$(POPPLER_CFLAGS) \
+	-DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
+
+libgcmd_dialogs_a_SOURCES = \
+	gnome-cmd-advrename-regex-dialog.h gnome-cmd-advrename-regex-dialog.cc

Added: branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.cc
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.cc	Thu Nov 13 16:33:08 2008
@@ -0,0 +1,122 @@
+/*
+    GNOME Commander - A GNOME based file manager
+    Copyright (C) 2001-2006 Marcus Bjurman
+    Copyright (C) 2007-2008 Piotr Eljasiak
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <config.h>
+#include <regex.h>
+#include "gnome-cmd-includes.h"
+#include "gnome-cmd-advrename-dialog.h"
+#include "gnome-cmd-advrename-regex-dialog.h"
+#include "utils.h"
+
+using namespace std;
+
+
+static void response_callback (GtkDialog *dialog, int response_id, PatternEntry *rx)
+{
+    switch (response_id)
+    {
+        case GTK_RESPONSE_OK:
+            g_free (rx->from);
+            g_free (rx->to);
+            rx->from = gtk_editable_get_chars (GTK_EDITABLE (lookup_widget (GTK_WIDGET (dialog), "pattern")), 0, -1);
+            rx->to = gtk_editable_get_chars (GTK_EDITABLE (lookup_widget (GTK_WIDGET (dialog), "replace")), 0, -1);
+            rx->case_sens = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (lookup_widget (GTK_WIDGET (dialog), "match_case")));
+            break;
+
+        case GTK_RESPONSE_NONE:
+        case GTK_RESPONSE_DELETE_EVENT:
+        case GTK_RESPONSE_CANCEL:
+            break;
+
+        default :
+            g_assert_not_reached ();
+    }
+}
+
+
+gboolean gnome_cmd_advrename_regex_dialog_new (const gchar *title, GtkWindow *parent, PatternEntry *rx)
+{
+    GtkWidget *dialog = gtk_dialog_new_with_buttons (title, parent,
+                                                     GtkDialogFlags (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+                                                     // GTK_STOCK_HELP, GTK_RESPONSE_HELP,             //  FIXME: ???
+                                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                                     NULL);
+
+    gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+    gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+
+    // HIG defaults
+    gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+    gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
+    gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
+    gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area),6);
+
+    GtkWidget *table, *align, *label, *entry, *check;
+
+    table = gtk_table_new (3, 2, FALSE);
+    gtk_container_set_border_width (GTK_CONTAINER (table), 5);
+    gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+    gtk_table_set_col_spacings (GTK_TABLE (table), 12);
+    gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), table);
+
+    label = gtk_label_new_with_mnemonic (_("_Search for:"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+    gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
+
+    entry = gtk_entry_new ();
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+    if (rx->from)
+        gtk_entry_set_text (GTK_ENTRY (entry), rx->from);
+    g_object_set_data (G_OBJECT (dialog), "pattern", entry);
+    gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, 0, 1);
+
+    label = gtk_label_new_with_mnemonic (_("_Replace with:"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+    gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
+
+    entry = gtk_entry_new ();
+    gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+    if (rx->to)
+        gtk_entry_set_text (GTK_ENTRY (entry), rx->to);
+    g_object_set_data (G_OBJECT (dialog), "replace", entry);
+    gtk_table_attach_defaults (GTK_TABLE (table), entry, 1, 2, 1, 2);
+
+    align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+    gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 12, 0);
+    gtk_table_attach_defaults (GTK_TABLE (table), align, 0, 2, 2, 3);
+
+    check = gtk_check_button_new_with_mnemonic (_("_Match case"));
+    g_object_set_data (G_OBJECT (dialog), "match_case", check);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), rx ? rx->case_sens : FALSE);
+    gtk_container_add (GTK_CONTAINER (align), check);
+
+    gtk_widget_show_all (table);
+
+    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+    g_signal_connect (dialog, "response", G_CALLBACK (response_callback), rx);
+
+    gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+    gtk_widget_destroy (dialog);
+
+    return result==GTK_RESPONSE_OK;
+}

Added: branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.h
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/dialogs/gnome-cmd-advrename-regex-dialog.h	Thu Nov 13 16:33:08 2008
@@ -0,0 +1,28 @@
+/*
+    GNOME Commander - A GNOME based file manager
+    Copyright (C) 2001-2006 Marcus Bjurman
+    Copyright (C) 2007-2008 Piotr Eljasiak
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __GNOME_CMD_ADVRENAME_REGEX_DIALOG_H__
+#define __GNOME_CMD_ADVRENAME_REGEX_DIALOG_H__
+
+#include "gnome-cmd-advrename-dialog.h"
+
+gboolean gnome_cmd_advrename_regex_dialog_new (const gchar *title, GtkWindow *parent, PatternEntry *rx);
+
+#endif // __GNOME_CMD_ADVRENAME_REGEX_DIALOG_H__

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	Thu Nov 13 16:33:08 2008
@@ -26,6 +26,7 @@
 #include "gnome-cmd-includes.h"
 #include "gnome-cmd-convert.h"
 #include "gnome-cmd-advrename-dialog.h"
+#include "dialogs/gnome-cmd-advrename-regex-dialog.h"
 #include "gnome-cmd-advrename-lexer.h"
 #include "gnome-cmd-file.h"
 #include "gnome-cmd-clist.h"
@@ -596,78 +597,6 @@
 }
 
 
-static gboolean on_add_rule_dialog_ok (GnomeCmdStringDialog *string_dialog, const gchar **values, GnomeCmdAdvrenameDialog *dialog)
-{
-    PatternEntry *entry = g_new0 (PatternEntry, 1);
-
-    gchar *error_desc = update_entry (entry, string_dialog, values);
-
-    if (error_desc != NULL)
-    {
-        gnome_cmd_string_dialog_set_error_desc (string_dialog, error_desc);
-        return FALSE;
-    }
-
-    add_pattern_entry (dialog, entry);
-    dialog->priv->defaults->patterns = g_list_append (dialog->priv->defaults->patterns, entry);
-    update_remove_all_button (dialog);
-    do_test (dialog);
-
-    return TRUE;
-}
-
-
-static gboolean on_edit_rule_dialog_ok (GnomeCmdStringDialog *string_dialog, const gchar **values, GnomeCmdAdvrenameDialog *dialog)
-{
-    GtkWidget *pat_list = dialog->priv->pat_list;
-    gint row = GTK_CLIST (pat_list)->focus_row;
-    PatternEntry *entry = (PatternEntry *) g_list_nth_data (dialog->priv->defaults->patterns, row);
-
-    g_return_val_if_fail (entry != NULL, TRUE);
-
-    gchar *error_desc = update_entry (entry, string_dialog, values);
-    if (error_desc != NULL)
-    {
-        gnome_cmd_string_dialog_set_error_desc (string_dialog, error_desc);
-        return FALSE;
-    }
-
-    gchar *text[4];
-
-    format_entry (entry, text);
-    //gtk_clist_set_foreground (GTK_CLIST (pat_list), row, entry->malformed_pattern ? &red : &black);
-    gtk_clist_set_text (GTK_CLIST (pat_list), row, 0, text[0]);
-    gtk_clist_set_text (GTK_CLIST (pat_list), row, 1, text[1]);
-    gtk_clist_set_text (GTK_CLIST (pat_list), row, 2, text[2]);
-    gtk_clist_set_text (GTK_CLIST (pat_list), row, 3, text[3]);
-    update_remove_all_button (dialog);
-    do_test (dialog);
-
-    return TRUE;
-}
-
-
-static GtkWidget *create_rule_dialog (GnomeCmdAdvrenameDialog *parent_dialog, const gchar *title, GnomeCmdStringDialogCallback on_ok_func, PatternEntry *entry)
-{
-    // Translators: this is a part of dialog for replacing text 'Replace this:' -> 'With this:'
-    const gchar *labels[] = {_("Replace this:"), _("With this:")};
-
-    GtkWidget *dialog = gnome_cmd_string_dialog_new (title, labels, 2, on_ok_func, parent_dialog);
-    gtk_widget_ref (dialog);
-    gtk_object_set_data_full (GTK_OBJECT (parent_dialog), "rule-dialog", dialog, (GtkDestroyNotify) gtk_widget_unref);
-    gnome_cmd_string_dialog_set_value (GNOME_CMD_STRING_DIALOG (dialog), 0, entry?entry->from:"");
-    gnome_cmd_string_dialog_set_value (GNOME_CMD_STRING_DIALOG (dialog), 1, entry?entry->to:"");
-
-    GtkWidget *case_check = create_check (dialog, _("Case sensitive matching"), "case_check");
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (case_check), entry?entry->case_sens:FALSE);
-    gnome_cmd_dialog_add_category (GNOME_CMD_DIALOG (dialog), case_check);
-
-    gtk_widget_show (dialog);
-
-    return dialog;
-}
-
-
 static gchar *apply_one_pattern (gchar *in, PatternEntry *entry, int eflags)
 {
     regex_t re_exp;
@@ -783,13 +712,41 @@
 
 static void on_rule_add (GtkButton *button, GnomeCmdAdvrenameDialog *dialog)
 {
-    create_rule_dialog (dialog, _("New Rule"), (GnomeCmdStringDialogCallback) on_add_rule_dialog_ok, NULL);
+    PatternEntry *entry = g_new0 (PatternEntry, 1);
+
+    if (gnome_cmd_advrename_regex_dialog_new (_("New Rule"), GTK_WINDOW (dialog), entry))
+    {
+        add_pattern_entry (dialog, entry);
+        dialog->priv->defaults->patterns = g_list_append (dialog->priv->defaults->patterns, entry);
+        update_remove_all_button (dialog);
+        do_test (dialog);
+    }
+    else
+        g_free (entry);
 }
 
 
 static void on_rule_edit (GtkButton *button, GnomeCmdAdvrenameDialog *dialog)
 {
-    create_rule_dialog (dialog, _("Edit Rule"), (GnomeCmdStringDialogCallback) on_edit_rule_dialog_ok, dialog->priv->sel_entry);
+    GtkWidget *pat_list = dialog->priv->pat_list;
+    gint row = GTK_CLIST (pat_list)->focus_row;
+    PatternEntry *entry = (PatternEntry *) g_list_nth_data (dialog->priv->defaults->patterns, row);
+
+    g_return_if_fail (entry != NULL);
+
+    if (gnome_cmd_advrename_regex_dialog_new (_("Edit Rule"), GTK_WINDOW (dialog), entry))
+    {
+        gchar *text[4];
+
+        format_entry (entry, text);
+        //gtk_clist_set_foreground (GTK_CLIST (pat_list), row, entry->malformed_pattern ? &red : &black);
+        gtk_clist_set_text (GTK_CLIST (pat_list), row, 0, text[0]);
+        gtk_clist_set_text (GTK_CLIST (pat_list), row, 1, text[1]);
+        gtk_clist_set_text (GTK_CLIST (pat_list), row, 2, text[2]);
+        gtk_clist_set_text (GTK_CLIST (pat_list), row, 3, text[3]);
+        update_remove_all_button (dialog);
+        do_test (dialog);
+    }
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]