[gnome-commander/gcmd-1-3] advrename: added GUI for range selections
- From: Piotr Eljasiak <epiotr src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-commander/gcmd-1-3] advrename: added GUI for range selections
- Date: Sat, 16 Jan 2010 20:00:43 +0000 (UTC)
commit dcff85586a1e714184dc9b20614562dab485af0b
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Sat Jan 16 20:56:53 2010 +0100
advrename: added GUI for range selections
src/gnome-cmd-advrename-dialog.cc | 21 ++++++
src/gnome-cmd-profile-component.cc | 135 ++++++++++++++++++++++++++++++++++++
src/gnome-cmd-profile-component.h | 1 +
3 files changed, 157 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-cmd-advrename-dialog.cc b/src/gnome-cmd-advrename-dialog.cc
index d628ec8..4f9d79e 100644
--- a/src/gnome-cmd-advrename-dialog.cc
+++ b/src/gnome-cmd-advrename-dialog.cc
@@ -81,6 +81,7 @@ struct GnomeCmdAdvrenameDialog::Private
static gboolean on_files_view_button_pressed (GtkWidget *treeview, GdkEventButton *event, GnomeCmdAdvrenameDialog *dialog);
static gboolean on_files_view_popup_menu (GtkWidget *treeview, GnomeCmdAdvrenameDialog *dialog);
static void on_files_view_row_activated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, GnomeCmdAdvrenameDialog *dialog);
+ static void on_files_view_cursor_changed (GtkTreeView *view, GnomeCmdAdvrenameDialog *dialog);
static gboolean on_dialog_delete (GtkWidget *widget, GdkEvent *event, GnomeCmdAdvrenameDialog *dialog);
static void on_dialog_size_allocate (GtkWidget *widget, GtkAllocation *allocation, GnomeCmdAdvrenameDialog *dialog);
@@ -399,6 +400,23 @@ void GnomeCmdAdvrenameDialog::Private::on_files_view_row_activated (GtkTreeView
}
+void GnomeCmdAdvrenameDialog::Private::on_files_view_cursor_changed (GtkTreeView *view, GnomeCmdAdvrenameDialog *dialog)
+{
+ GtkTreeIter iter;
+
+ if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (view), NULL, &iter))
+ {
+ GtkTreeModel *model = gtk_tree_view_get_model (view);
+ GnomeCmdFile *f;
+
+ gtk_tree_model_get (model, &iter, COL_FILE, &f, -1);
+
+ if (f)
+ dialog->priv->profile_component->set_sample_fname(gnome_cmd_file_get_name (f));
+ }
+}
+
+
gboolean GnomeCmdAdvrenameDialog::Private::on_dialog_delete (GtkWidget *widget, GdkEvent *event, GnomeCmdAdvrenameDialog *dialog)
{
return event->type==GDK_DELETE;
@@ -705,6 +723,7 @@ GnomeCmdAdvrenameDialog::GnomeCmdAdvrenameDialog(GnomeCmdData::AdvrenameConfig &
g_signal_connect (priv->files_view, "button-press-event", G_CALLBACK (Private::on_files_view_button_pressed), this);
g_signal_connect (priv->files_view, "popup-menu", G_CALLBACK (Private::on_files_view_popup_menu), this);
g_signal_connect (priv->files_view, "row-activated", G_CALLBACK (Private::on_files_view_row_activated), this);
+ g_signal_connect (priv->files_view, "cursor-changed", G_CALLBACK (Private::on_files_view_cursor_changed), this);
g_signal_connect (this, "delete-event", G_CALLBACK (Private::on_dialog_delete), this);
g_signal_connect (this, "size-allocate", G_CALLBACK (Private::on_dialog_size_allocate), this);
@@ -716,6 +735,8 @@ GnomeCmdAdvrenameDialog::GnomeCmdAdvrenameDialog(GnomeCmdData::AdvrenameConfig &
void GnomeCmdAdvrenameDialog::set(GList *file_list)
{
+ priv->profile_component->set_sample_fname(file_list ? gnome_cmd_file_get_name ((GnomeCmdFile *) file_list->data) : NULL);
+
for (GtkTreeIter iter; file_list; file_list=file_list->next)
{
GnomeCmdFile *f = (GnomeCmdFile *) file_list->data;
diff --git a/src/gnome-cmd-profile-component.cc b/src/gnome-cmd-profile-component.cc
index 21293a7..e34df99 100644
--- a/src/gnome-cmd-profile-component.cc
+++ b/src/gnome-cmd-profile-component.cc
@@ -73,6 +73,8 @@ struct GnomeCmdProfileComponent::Private
GtkWidget *case_combo;
GtkWidget *trim_combo;
+ gchar *sample_fname;
+
enum {DIR_MENU, FILE_MENU, COUNTER_MENU, DATE_MENU, METATAG_MENU, NUM_MENUS};
static GtkItemFactoryEntry dir_items[];
@@ -95,8 +97,11 @@ struct GnomeCmdProfileComponent::Private
GtkWidget *create_button_with_menu(gchar *label_text, int menu_type);
void insert_tag(const gchar *text);
+ gchar *get_selected_range (GtkWindow *parent, const gchar *title, const gchar *placeholder, const gchar *filename=NULL);
+
static void insert_text_tag(GnomeCmdProfileComponent::Private *priv, guint n, GtkWidget *widget);
static void insert_num_tag(GnomeCmdProfileComponent::Private *priv, guint tag, GtkWidget *widget);
+ static void insert_range(Private *priv, guint unused, GtkWidget *widget);
static void on_template_entry_changed(GtkEntry *entry, GnomeCmdProfileComponent *component);
@@ -122,7 +127,9 @@ GtkItemFactoryEntry GnomeCmdProfileComponent::Private::dir_items[] =
GtkItemFactoryEntry GnomeCmdProfileComponent::Private::name_items[] =
{{N_("/File name"), NULL, (GtkItemFactoryCallback) GnomeCmdProfileComponent::Private::insert_text_tag, 2},
+ {N_("/File name (range)"), NULL, (GtkItemFactoryCallback) GnomeCmdProfileComponent::Private::insert_range, 2},
{N_("/File name without extension"), NULL, (GtkItemFactoryCallback) GnomeCmdProfileComponent::Private::insert_text_tag, 3},
+ {N_("/File name without extension (range)"), NULL, (GtkItemFactoryCallback) GnomeCmdProfileComponent::Private::insert_range,3},
{N_("/File extension"), NULL, (GtkItemFactoryCallback) GnomeCmdProfileComponent::Private::insert_text_tag, 4}};
GtkItemFactoryEntry GnomeCmdProfileComponent::Private::counter_items[] =
@@ -365,6 +372,7 @@ inline GnomeCmdProfileComponent::Private::Private()
convert_case = gcmd_convert_unchanged;
trim_blanks = gcmd_convert_strip;
regex_model = NULL;
+ sample_fname = NULL;
}
@@ -375,6 +383,8 @@ inline GnomeCmdProfileComponent::Private::~Private()
clear_regex_model(regex_model);
if (regex_model) g_object_unref (regex_model);
+
+ g_free (sample_fname);
}
@@ -543,6 +553,124 @@ void GnomeCmdProfileComponent::Private::insert_num_tag(GnomeCmdProfileComponent:
}
+inline gchar *GnomeCmdProfileComponent::Private::get_selected_range (GtkWindow *parent, const gchar *title, const gchar *placeholder, const gchar *filename)
+{
+ if (!filename)
+ filename = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " \
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " \
+ "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " \
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
+
+ GtkWidget *dialog = gtk_dialog_new_with_buttons (title, parent,
+ GtkDialogFlags (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_set_size_request (dialog, 480, -1);
+ 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 *hbox, *label, *entry, *option;
+
+ hbox = gtk_hbox_new (FALSE, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
+
+ label = gtk_label_new_with_mnemonic (_("_Select range:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (entry), filename);
+ gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
+ g_object_set_data (G_OBJECT (dialog), "filename", entry);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+
+ option = gtk_check_button_new_with_mnemonic (_("_Inverse selection"));
+ g_object_set_data (G_OBJECT (dialog), "inverse", option);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), option, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (GTK_DIALOG (dialog)->vbox);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gchar *range = NULL;
+
+ if (result==GTK_RESPONSE_OK)
+ {
+ gint beg, end;
+ GtkWidget *entry = lookup_widget (GTK_WIDGET (dialog), "filename");
+
+ gboolean inversed = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (lookup_widget (GTK_WIDGET (dialog), "inverse")));
+
+ if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &beg, &end))
+ {
+#if GTK_CHECK_VERSION (2, 16, 0)
+ guint16 len = gtk_entry_get_text_length (GTK_ENTRY (entry));
+#else
+ guint16 len = (guint16) g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (entry)), -1);
+#endif
+ if (!inversed)
+ range = end==len ? g_strdup_printf ("%s(%i:)", placeholder, beg) :
+ g_strdup_printf ("%s(%i:%i)", placeholder, beg, end);
+ else
+ {
+ if (end!=len)
+ range = beg ? g_strdup_printf ("%s(:%i)%s(%i:)", placeholder, beg, placeholder, end) :
+ g_strdup_printf ("%s(%i:)", placeholder, end);
+ else
+ if (beg)
+ range = g_strdup_printf ("%s(:%i)", placeholder, beg);
+ }
+ }
+ else
+ if (inversed)
+ range = g_strdup (placeholder);
+ }
+
+ gtk_widget_destroy (dialog);
+
+ return range;
+}
+
+
+void GnomeCmdProfileComponent::Private::insert_range(GnomeCmdProfileComponent::Private *priv, guint n, GtkWidget *widget)
+{
+ static const gchar *placeholder[] = {"$g", // 0
+ "$p", // 1
+ "$N", // 2
+ "$n", // 3
+ "$e"}; // 4
+
+ gchar *fname = NULL;
+
+ if (n==3 && priv->sample_fname)
+ {
+ fname = g_strdup (priv->sample_fname);
+ gchar *ext = g_utf8_strrchr (fname, -1, '.');
+ if (ext)
+ *ext = 0;
+ }
+
+ gchar *tag = priv->get_selected_range (NULL, _("Range Selection"), placeholder[n], fname ? fname : priv->sample_fname);
+
+ if (tag)
+ priv->insert_tag(tag);
+
+ g_free (tag);
+ g_free (fname);
+}
+
+
G_DEFINE_TYPE (GnomeCmdProfileComponent, gnome_cmd_profile_component, GTK_TYPE_VBOX)
@@ -1157,6 +1285,13 @@ void GnomeCmdProfileComponent::set_template_history(GList *history)
}
+void GnomeCmdProfileComponent::set_sample_fname(const gchar *fname)
+{
+ g_free (priv->sample_fname);
+ priv->sample_fname = g_strdup (fname);
+}
+
+
GtkTreeModel *GnomeCmdProfileComponent::get_regex_model() const
{
return priv ? priv->regex_model : NULL;
diff --git a/src/gnome-cmd-profile-component.h b/src/gnome-cmd-profile-component.h
index add672f..c20e50c 100644
--- a/src/gnome-cmd-profile-component.h
+++ b/src/gnome-cmd-profile-component.h
@@ -59,6 +59,7 @@ struct GnomeCmdProfileComponent
const gchar *get_template_entry() const;
void set_template_history(GList *history);
+ void set_sample_fname(const gchar *fname);
GtkTreeModel *get_regex_model() const;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]