[gnome-commander] search: support for profile management
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] search: support for profile management
- Date: Sat, 2 Jul 2011 09:53:11 +0000 (UTC)
commit 86090fa0fbbfcde2509ad00f40b301ec0687c4be
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Sat Jul 2 11:50:20 2011 +0200
search: support for profile management
src/dialogs/gnome-cmd-search-dialog.cc | 117 ++++++++++++++++++++++++++++++++
src/dialogs/gnome-cmd-search-dialog.h | 2 +-
2 files changed, 118 insertions(+), 1 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-search-dialog.cc b/src/dialogs/gnome-cmd-search-dialog.cc
index a8c0ac4..e8b94b1 100755
--- a/src/dialogs/gnome-cmd-search-dialog.cc
+++ b/src/dialogs/gnome-cmd-search-dialog.cc
@@ -56,6 +56,7 @@
#include "gnome-cmd-main-win.h"
#include "gnome-cmd-con-list.h"
#include "gnome-cmd-selection-profile-component.h"
+#include "gnome-cmd-manage-profiles-dialog.h"
#include "filter.h"
#include "utils.h"
@@ -146,10 +147,19 @@ struct GnomeCmdSearchDialog::Private
GnomeCmdFileList *result_list;
GtkWidget *statusbar;
GtkWidget *pbar;
+ GtkWidget *profile_menu_button;
Private(GnomeCmdSearchDialog *dlg);
~Private();
+ static gchar *translate_menu(const gchar *path, gpointer data);
+
+ GtkWidget *create_placeholder_menu(GnomeCmdData::SearchConfig &cfg);
+ GtkWidget *create_button_with_menu(gchar *label_text, GnomeCmdData::SearchConfig &cfg);
+
+ static void manage_profiles(GnomeCmdSearchDialog::Private *priv, guint unused, GtkWidget *menu);
+ static void load_profile(GnomeCmdSearchDialog::Private *priv, guint profile_idx, GtkWidget *menu);
+
static gboolean on_list_keypressed (GtkWidget *result_list, GdkEventKey *event, gpointer unused);
static void on_dialog_show (GtkWidget *widget, GnomeCmdSearchDialog *dialog);
@@ -176,6 +186,105 @@ inline GnomeCmdSearchDialog::Private::~Private()
}
+gchar *GnomeCmdSearchDialog::Private::translate_menu(const gchar *path, gpointer data)
+{
+ return _(path);
+}
+
+
+inline GtkWidget *GnomeCmdSearchDialog::Private::create_placeholder_menu(GnomeCmdData::SearchConfig &cfg)
+{
+ guint items_size = cfg.profiles.empty() ? 1 : cfg.profiles.size()+3;
+ GtkItemFactoryEntry *items = g_try_new0 (GtkItemFactoryEntry, items_size);
+ GtkItemFactoryEntry *i = items;
+
+ g_return_val_if_fail (items!=NULL, NULL);
+
+ i->path = g_strdup (_("/_Save Profile As..."));
+ i->callback = (GtkItemFactoryCallback) manage_profiles;
+ i->callback_action = TRUE;
+ i->item_type = "<StockItem>";
+ i->extra_data = GTK_STOCK_SAVE_AS;
+ ++i;
+
+ if (!cfg.profiles.empty())
+ {
+ i->path = g_strdup (_("/_Manage Profiles..."));
+ i->callback = (GtkItemFactoryCallback) manage_profiles;
+ i->item_type = "<StockItem>";
+ i->extra_data = GTK_STOCK_EDIT;
+ ++i;
+
+ i->path = g_strdup ("/");
+ i->item_type = "<Separator>";
+ ++i;
+
+ for (vector<GnomeCmdData::Selection>::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;
+ i->callback_action = (i-items)-3;
+ i->item_type = "<StockItem>";
+ i->extra_data = GTK_STOCK_REVERT_TO_SAVED;
+ }
+ }
+
+ GtkItemFactory *ifac = gtk_item_factory_new (GTK_TYPE_MENU, "<main>", NULL);
+
+ gtk_item_factory_create_items (ifac, items_size, items, this);
+
+ for (guint i=0; i<items_size; ++i)
+ g_free (items[i].path);
+
+ g_free (items);
+
+ return gtk_item_factory_get_widget (ifac, "<main>");
+}
+
+
+inline GtkWidget *GnomeCmdSearchDialog::Private::create_button_with_menu(gchar *label_text, GnomeCmdData::SearchConfig &cfg)
+{
+ profile_menu_button = gnome_cmd_button_menu_new (label_text, create_placeholder_menu(cfg));
+
+ return profile_menu_button;
+}
+
+
+void GnomeCmdSearchDialog::Private::manage_profiles(GnomeCmdSearchDialog::Private *priv, guint new_profile, GtkWidget *widget)
+{
+ GnomeCmdSearchDialog *dialog = (GnomeCmdSearchDialog *) gtk_widget_get_ancestor (priv->profile_menu_button, GNOME_CMD_TYPE_SEARCH_DIALOG);
+
+ g_return_if_fail (dialog!=NULL);
+
+ if (new_profile)
+ priv->profile_component->copy();
+
+ if (GnomeCmd::ManageProfilesDialog<GnomeCmdData::SearchConfig,GnomeCmdData::Selection,GnomeCmdSelectionProfileComponent> (*dialog,dialog->defaults,new_profile,_("Profiles"),"helpid..."))
+ {
+ GtkWidget *menu = widget->parent;
+
+ gnome_cmd_button_menu_disconnect_handler (priv->profile_menu_button, menu);
+ g_object_unref (gtk_item_factory_from_widget (menu));
+ gnome_cmd_button_menu_connect_handler (priv->profile_menu_button, priv->create_placeholder_menu(dialog->defaults));
+ }
+}
+
+
+void GnomeCmdSearchDialog::Private::load_profile(GnomeCmdSearchDialog::Private *priv, guint profile_idx, GtkWidget *widget)
+{
+ GtkWidget *dialog = gtk_widget_get_ancestor (priv->profile_menu_button, GNOME_CMD_TYPE_SEARCH_DIALOG);
+
+ g_return_if_fail (dialog!=NULL);
+
+ GnomeCmdData::SearchConfig &cfg = GNOME_CMD_SEARCH_DIALOG(dialog)->defaults;
+
+ g_return_if_fail (profile_idx<cfg.profiles.size());
+
+ cfg.default_profile = cfg.profiles[profile_idx];
+ priv->profile_component->update();
+}
+
+
inline SearchData::SearchData(GnomeCmdSearchDialog *dlg): dialog(dlg)
{
start_dir = NULL;
@@ -920,6 +1029,9 @@ void GnomeCmdSearchDialog::Private::on_dialog_response(GtkDialog *window, int re
g_signal_stop_emission_by_name (dialog, "response");
break;
+ case GCMD_RESPONSE_PROFILES:
+ break;
+
default :
g_assert_not_reached ();
}
@@ -1019,6 +1131,10 @@ GnomeCmdSearchDialog::GnomeCmdSearchDialog(GnomeCmdData::SearchConfig &cfg): def
{
gtk_window_set_default_size (*this, defaults.width, defaults.height);
+ GtkWidget *button = priv->create_button_with_menu(_("Profiles..."), cfg);
+
+ gtk_dialog_add_action_widget (*this, button, GCMD_RESPONSE_PROFILES);
+
gtk_dialog_add_buttons (*this,
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
@@ -1046,6 +1162,7 @@ GnomeCmdSearchDialog::GnomeCmdSearchDialog(GnomeCmdData::SearchConfig &cfg): def
priv->profile_component->set_content_patterns_history(defaults.content_patterns.ents);
+ gtk_widget_show_all (button);
gtk_widget_show (*priv->profile_component);
g_signal_connect (priv->result_list, "key-press-event", G_CALLBACK (Private::on_list_keypressed), this);
diff --git a/src/dialogs/gnome-cmd-search-dialog.h b/src/dialogs/gnome-cmd-search-dialog.h
index 06f09f3..62b020e 100755
--- a/src/dialogs/gnome-cmd-search-dialog.h
+++ b/src/dialogs/gnome-cmd-search-dialog.h
@@ -50,7 +50,7 @@ struct GnomeCmdSearchDialog
void *operator new (size_t size) { return g_object_new (GNOME_CMD_TYPE_SEARCH_DIALOG, NULL); }
void operator delete (void *p) { g_object_unref (p); }
- enum {GCMD_RESPONSE_GOTO=123, GCMD_RESPONSE_STOP, GCMD_RESPONSE_FIND};
+ enum {GCMD_RESPONSE_PROFILES=123, GCMD_RESPONSE_GOTO, GCMD_RESPONSE_STOP, GCMD_RESPONSE_FIND};
GnomeCmdData::SearchConfig &defaults;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]