[gnome-commander] Convert gnome_cmd_edit_profile_dialog_new() to GnomeCmd::EditProfileDialog<PROFILE, COMPONENT> templa



commit 089863a99fec59265b887b885597eaab511bd34a
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Fri Jun 17 22:30:19 2011 +0200

    Convert gnome_cmd_edit_profile_dialog_new() to GnomeCmd::EditProfileDialog<PROFILE,COMPONENT> template class

 po/POTFILES.in                                  |    2 +-
 src/dialogs/Makefile.am                         |    2 +-
 src/dialogs/gnome-cmd-edit-profile-dialog.cc    |  138 -----------------------
 src/dialogs/gnome-cmd-edit-profile-dialog.h     |  126 ++++++++++++++++++++-
 src/dialogs/gnome-cmd-manage-profiles-dialog.cc |    3 +-
 5 files changed, 129 insertions(+), 142 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3845790..6b56582 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,7 +10,7 @@ plugins/test/test-plugin.cc
 src/dialogs/gnome-cmd-advrename-dialog.cc
 src/dialogs/gnome-cmd-advrename-regex-dialog.cc
 src/dialogs/gnome-cmd-edit-bookmark-dialog.cc
-src/dialogs/gnome-cmd-edit-profile-dialog.cc
+src/dialogs/gnome-cmd-edit-profile-dialog.h
 src/dialogs/gnome-cmd-key-shortcuts-dialog.cc
 src/dialogs/gnome-cmd-manage-bookmarks-dialog.cc
 src/dialogs/gnome-cmd-manage-profiles-dialog.cc
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 7a00f3b..66c74c4 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -22,7 +22,7 @@ libgcmd_dialogs_a_SOURCES = \
 	gnome-cmd-manage-bookmarks-dialog.h gnome-cmd-manage-bookmarks-dialog.cc \
 	gnome-cmd-mkdir-dialog.h gnome-cmd-mkdir-dialog.cc \
 	gnome-cmd-key-shortcuts-dialog.h gnome-cmd-key-shortcuts-dialog.cc \
-	gnome-cmd-edit-profile-dialog.h gnome-cmd-edit-profile-dialog.cc \
+	gnome-cmd-edit-profile-dialog.h \
 	gnome-cmd-manage-profiles-dialog.h gnome-cmd-manage-profiles-dialog.cc \
 	gnome-cmd-search-dialog.h gnome-cmd-search-dialog.cc
 
diff --git a/src/dialogs/gnome-cmd-edit-profile-dialog.h b/src/dialogs/gnome-cmd-edit-profile-dialog.h
index c3d3a52..5a4c61c 100644
--- a/src/dialogs/gnome-cmd-edit-profile-dialog.h
+++ b/src/dialogs/gnome-cmd-edit-profile-dialog.h
@@ -23,6 +23,130 @@
 
 #include "gnome-cmd-data.h"
 
-gboolean gnome_cmd_edit_profile_dialog_new (GtkWindow *parent, GnomeCmdData::AdvrenameConfig::Profile &profile);
+namespace GnomeCmd
+{
+    template <typename PROFILE, typename COMPONENT>
+    class EditProfileDialog
+    {
+        COMPONENT *component;
+        const char *help_id;
+        gint result;
+
+        enum {GCMD_RESPONSE_RESET=123};
+
+        static void response_callback(GtkDialog *dialog, int response_id, EditProfileDialog<PROFILE,COMPONENT> *dlg);
+
+      public:
+
+        EditProfileDialog(GtkWindow *parent, PROFILE &profile, const char *id);
+
+        operator gboolean () const       {  return result==GTK_RESPONSE_OK;  }
+    };
+
+    template <typename PROFILE, typename COMPONENT>
+    void EditProfileDialog<PROFILE,COMPONENT>::response_callback(GtkDialog *dialog, int response_id, EditProfileDialog<PROFILE,COMPONENT> *dlg)
+    {
+        switch (response_id)
+        {
+            case GTK_RESPONSE_HELP:
+                gnome_cmd_help_display ("gnome-commander.xml", dlg->help_id);
+                g_signal_stop_emission_by_name (dialog, "response");
+                break;
+
+            case GCMD_RESPONSE_RESET:
+                dlg->component->profile.reset();
+                dlg->component->update();
+                g_signal_stop_emission_by_name (dialog, "response");
+                break;
+
+            case GTK_RESPONSE_OK:
+                dlg->component->profile.name = gtk_entry_get_text (GTK_ENTRY (lookup_widget (GTK_WIDGET (dialog), "name")));
+                dlg->component->copy();
+                break;
+
+            case GTK_RESPONSE_NONE:
+            case GTK_RESPONSE_DELETE_EVENT:
+            case GTK_RESPONSE_CANCEL:
+                break;
+
+            default :
+                g_assert_not_reached ();
+        }
+    }
+
+    template <typename PROFILE, typename COMPONENT>
+    inline EditProfileDialog<PROFILE,COMPONENT>::EditProfileDialog(GtkWindow *parent, PROFILE &profile, const char *id):  help_id(id)
+    {
+        GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Edit Profile"), parent,
+                                                         GtkDialogFlags (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+                                                         GTK_STOCK_HELP, GTK_RESPONSE_HELP,
+                                                         _("Reset"), GCMD_RESPONSE_RESET,
+                                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
+                                                         NULL);
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+        GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+#endif
+
+        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);
+#if GTK_CHECK_VERSION (2, 14, 0)
+        gtk_box_set_spacing (GTK_BOX (content_area), 2);
+        gtk_container_set_border_width (GTK_CONTAINER (content_area), 5);
+        gtk_box_set_spacing (GTK_BOX (content_area),6);
+#else
+        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);
+#endif
+
+        GtkWidget *vbox = gtk_vbox_new (FALSE, 6);
+        gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
+#if GTK_CHECK_VERSION (2, 14, 0)
+        gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
+#else
+        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0);
+#endif
+
+        gchar *str = g_strdup_printf ("<b>%s</b>", _("_Name"));
+        GtkWidget *label = gtk_label_new_with_mnemonic (str);
+        g_free (str);
+
+        gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+
+        GtkWidget *align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+        gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 6, 12, 0);
+        gtk_container_add (GTK_CONTAINER (vbox), align);
+
+        GtkWidget *entry = gtk_entry_new ();
+        g_object_set_data (G_OBJECT (dialog), "name", entry);
+        gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+        gtk_entry_set_text (GTK_ENTRY (entry), profile.name.c_str());
+        gtk_container_add (GTK_CONTAINER (align), entry);
+
+        component = new COMPONENT(profile);
+        gtk_container_add (GTK_CONTAINER (vbox), *component);
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+        gtk_widget_show_all (content_area);
+#else
+        gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+#endif
+
+        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+        g_signal_connect (dialog, "response", G_CALLBACK (response_callback), this);
+
+        result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+        gtk_widget_destroy (dialog);
+    }
+}
 
 #endif // __GNOME_CMD_EDIT_PROFILE_DIALOG_H__
diff --git a/src/dialogs/gnome-cmd-manage-profiles-dialog.cc b/src/dialogs/gnome-cmd-manage-profiles-dialog.cc
index 577e998..d9e3c19 100644
--- a/src/dialogs/gnome-cmd-manage-profiles-dialog.cc
+++ b/src/dialogs/gnome-cmd-manage-profiles-dialog.cc
@@ -23,6 +23,7 @@
 #include "gnome-cmd-includes.h"
 #include "gnome-cmd-data.h"
 #include "gnome-cmd-manage-profiles-dialog.h"
+#include "gnome-cmd-advrename-profile-component.h"
 #include "gnome-cmd-edit-profile-dialog.h"
 #include "gnome-cmd-treeview.h"
 #include "gnome-cmd-menu-button.h"
@@ -348,7 +349,7 @@ static void edit_clicked_callback (GtkButton *button, GtkWidget *view)
 
         GnomeCmdData::AdvrenameConfig::Profile p = profiles[idx];
 
-        if (gnome_cmd_edit_profile_dialog_new (GTK_WINDOW (dialog), p))
+        if (GnomeCmd::EditProfileDialog<GnomeCmdData::AdvrenameConfig::Profile,GnomeCmdAdvrenameProfileComponent>(GTK_WINDOW (dialog), p, "gnome-commander-advanced-rename"))
         {
             profiles[idx] = p;
 



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