[gnumeric] Add navigator menu items to select sub menu (& for gtk 2.16+ as a pop-up menu in the selector entry)



commit e996e09ac3905acf7e6fc03b425b342fec8f13af
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Tue Jun 15 23:29:19 2010 -0600

    Add navigator menu items to select sub menu (& for gtk 2.16+ as a pop-up menu in the selector entry) [#15010]
    
    2010-06-16 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/GNOME_Gnumeric-gtk.xml.in: add new menu items
    	* src/HILDON_Gnumeric-gtk.xml.in: ditto
    	* component/Gnumeric-embed.xml.in: ditto
    	* src/sheet-utils.c (gnm_sheet_guess_data_range): new
    	* src/sheet-utils.h (gnm_sheet_guess_data_range): new
    	* src/wbc-gtk-actions.c (cb_edit_goto_*): new
    	(EditGoto*): new
    	* src/wbc-gtk.c (cb_cs_go_*): new
    	(wbc_gtk_cell_selector_popup): new
    	(wbc_gtk_create_edit_area): connect the above (for gtk 2.16+)
    	* src/workbook-control.h (wb_control_navigate_to_cell): new
    	* src/workbook-control.c (wb_control_navigate_to_cell): new

 ChangeLog                       |   15 +++++++
 component/Gnumeric-embed.xml.in |    5 ++
 src/GNOME_Gnumeric-gtk.xml.in   |    5 ++
 src/HILDON_Gnumeric-gtk.xml.in  |    4 ++
 src/sheet-utils.c               |   49 +++++++++++++++++++++-
 src/sheet-utils.h               |    1 +
 src/wbc-gtk-actions.c           |   28 ++++++++++++
 src/wbc-gtk.c                   |   88 +++++++++++++++++++++++++++++++++++++++
 src/workbook-control.c          |   51 ++++++++++++++++++++++
 src/workbook-control.h          |   10 ++++
 10 files changed, 255 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4ccb0c1..ff4de84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-06-16 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/GNOME_Gnumeric-gtk.xml.in: add new menu items
+	* src/HILDON_Gnumeric-gtk.xml.in: ditto
+	* component/Gnumeric-embed.xml.in: ditto
+	* src/sheet-utils.c (gnm_sheet_guess_data_range): new
+	* src/sheet-utils.h (gnm_sheet_guess_data_range): new
+	* src/wbc-gtk-actions.c (cb_edit_goto_*): new
+	(EditGoto*): new
+	* src/wbc-gtk.c (cb_cs_go_*): new
+	(wbc_gtk_cell_selector_popup): new
+	(wbc_gtk_create_edit_area): connect the above (for gtk 2.16+)
+	* src/workbook-control.h (wb_control_navigate_to_cell): new
+	* src/workbook-control.c (wb_control_navigate_to_cell): new
+	
 2010-06-15 Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* src/func.h (tokenized_help_*): deleted
diff --git a/component/Gnumeric-embed.xml.in b/component/Gnumeric-embed.xml.in
index fcf21ea..6d3ded7 100644
--- a/component/Gnumeric-embed.xml.in
+++ b/component/Gnumeric-embed.xml.in
@@ -71,6 +71,11 @@
         <menuitem action="EditSelectInputs"/>
         <menuitem action="EditSelectObject"/>
         <separator name="edit-sep5"/>
+	<menuitem action="EditGotoTop"/>
+	<menuitem action="EditGotoBottom"/>
+	<menuitem action="EditGotoFirst"/>
+	<menuitem action="EditGotoLast"/>
+        <separator name="edit-sep6"/>
 	<menuitem action="EditGoto"/>
       </menu>
       <menuitem action="EditRecalc"/>
diff --git a/src/GNOME_Gnumeric-gtk.xml.in b/src/GNOME_Gnumeric-gtk.xml.in
index e79f34c..0bf43cf 100644
--- a/src/GNOME_Gnumeric-gtk.xml.in
+++ b/src/GNOME_Gnumeric-gtk.xml.in
@@ -72,6 +72,11 @@
         <menuitem action="EditSelectInputs"/>
         <menuitem action="EditSelectObject"/>
         <separator name="edit-sep5"/>
+	<menuitem action="EditGotoTop"/>
+	<menuitem action="EditGotoBottom"/>
+	<menuitem action="EditGotoFirst"/>
+	<menuitem action="EditGotoLast"/>
+        <separator name="edit-sep6"/>
 	<menuitem action="EditGoto"/>
       </menu>
       <menuitem action="EditRecalc"/>
diff --git a/src/HILDON_Gnumeric-gtk.xml.in b/src/HILDON_Gnumeric-gtk.xml.in
index 61808dc..c984dde 100644
--- a/src/HILDON_Gnumeric-gtk.xml.in
+++ b/src/HILDON_Gnumeric-gtk.xml.in
@@ -63,6 +63,10 @@
       <separator name="edit-sep3"/>
       <menuitem action="EditFind"/>
       <menuitem action="EditReplace"/>
+      <menuitem action="EditGotoTop"/>
+      <menuitem action="EditGotoBottom"/>
+      <menuitem action="EditGotoFirst"/>
+      <menuitem action="EditGotoLast"/>
       <menuitem action="EditGoto"/>
       <separator name="edit-sep4"/>
       <menu name="EditSheet" action="MenuEditSheet">
diff --git a/src/sheet-utils.c b/src/sheet-utils.c
index 8871b32..52ced37 100644
--- a/src/sheet-utils.c
+++ b/src/sheet-utils.c
@@ -54,7 +54,7 @@ gnm_sheet_guess_region (Sheet *sheet, GnmRange *region)
 		for (col = start - 1; col > 0; col--)
 			if (!sheet_cell_or_one_below_is_not_empty (sheet, col, region->start.row))
 				break;
-		region->start.col = col - 1;
+		region->start.col = col + 1;
 
 		/* look for next empty column */
 		for (col = start + 1; col < gnm_sheet_get_max_cols (sheet); col++)
@@ -88,3 +88,50 @@ gnm_sheet_guess_region (Sheet *sheet, GnmRange *region)
 			region->end.row = end_row;
 	}
 }
+
+
+/**
+ * gnm_sheet_guess_data_range :
+ * @sheet : #Sheet
+ * @range : #GnmRange
+ *
+ * Makes a guess at the logical range containing @region and returns the possibly
+ * expanded result in @region. The range is also expanded upwards.
+ **/
+void
+gnm_sheet_guess_data_range (Sheet *sheet, GnmRange *range)
+{
+	int col;
+	int row;
+	GnmRange region = *range;
+	int start = range->start.col;
+
+	/* look for previous empty column */
+	for (col = start - 1; col > 0; col--)
+		if (!sheet_cell_or_one_below_is_not_empty (sheet, col, region.start.row))
+			break;
+	region.start.col = col + 1;
+	
+	/* look for next empty column */
+	start = range->end.col;
+	for (col = start + 1; col < gnm_sheet_get_max_cols (sheet); col++)
+		if (!sheet_cell_or_one_below_is_not_empty (sheet, col, region.start.row))
+			break;
+	region.end.col = col - 1;
+
+	for (col = region.start.col; col <= region.end.col; col++) {
+		gboolean empties = FALSE;
+		for (row = region.start.row - 2; row >= 0; row--)
+			if (!sheet_cell_or_one_below_is_not_empty (sheet, col, row)) {
+				empties = TRUE;
+				break;
+			}
+		region.start.row = empties ? row + 2 : 0;
+		for (row = region.end.row + 1; row < gnm_sheet_get_max_rows (sheet); row++)
+			if (!sheet_cell_or_one_below_is_not_empty (sheet, col, row))
+				break;
+		region.end.row = row - 1;
+	}
+	*range = region;
+	return;
+}
diff --git a/src/sheet-utils.h b/src/sheet-utils.h
index a95db84..d90450a 100644
--- a/src/sheet-utils.h
+++ b/src/sheet-utils.h
@@ -7,6 +7,7 @@
 G_BEGIN_DECLS
 
 void gnm_sheet_guess_region (Sheet *sheet, GnmRange *region);
+void gnm_sheet_guess_data_range (Sheet *sheet, GnmRange *region);
 
 G_END_DECLS
 
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 1f9e170..76f898a 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -601,6 +601,22 @@ static GNM_ACTION_DEF (cb_edit_fill_series)
 	dialog_fill_series (wbcg);
 }
 
+static GNM_ACTION_DEF (cb_edit_goto_top)
+{
+	wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_top);
+}
+static GNM_ACTION_DEF (cb_edit_goto_bottom)
+{
+	wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_bottom);
+}
+static GNM_ACTION_DEF (cb_edit_goto_first)
+{
+	wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_first);
+}
+static GNM_ACTION_DEF (cb_edit_goto_last)
+{
+	wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_last);
+}
 static GNM_ACTION_DEF (cb_edit_goto)
 {
 	dialog_goto_cell (wbcg);
@@ -1934,6 +1950,18 @@ static GtkActionEntry const actions[] = {
 	  "<control>Tab", N_("Select the next sheet object"),
 		G_CALLBACK (cb_edit_select_object) },
 
+	{ "EditGotoTop", GTK_STOCK_GOTO_TOP, N_("Go to Top"),
+		NULL, N_("Go to the top of the data"),
+		G_CALLBACK (cb_edit_goto_top) },
+	{ "EditGotoBottom", GTK_STOCK_GOTO_BOTTOM, N_("Go to Bottom"),
+		NULL, N_("Go to the bottom of the data"),
+		G_CALLBACK (cb_edit_goto_bottom) },
+	{ "EditGotoFirst", GTK_STOCK_GOTO_FIRST, N_("Go to the First"),
+		NULL, N_("Go to the first data cell"),
+		G_CALLBACK (cb_edit_goto_first) },
+	{ "EditGotoLast", GTK_STOCK_GOTO_LAST, N_("Go to the Last"),
+		NULL, N_("Go to the last data cell"),
+		G_CALLBACK (cb_edit_goto_last) },
 	{ "EditGoto", GTK_STOCK_JUMP_TO, N_("_Goto cell..."),
 		"<control>G", N_("Jump to a specified cell"),
 		G_CALLBACK (cb_edit_goto) },
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 4b6eaef..e575283 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -2320,6 +2320,74 @@ cb_wbcg_drag_data_received (GtkWidget *widget, GdkDragContext *context,
 	g_free (target_type);
 }
 
+#ifdef HAVE_GTK_ENTRY_SET_ICON_FROM_STOCK
+
+static void cb_cs_go_up  (WBCGtk *wbcg) 
+{ wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_top); }
+static void cb_cs_go_down  (WBCGtk *wbcg)
+{ wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_bottom); }
+static void cb_cs_go_left  (WBCGtk *wbcg)
+{ wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_first); }
+static void cb_cs_go_right  (WBCGtk *wbcg)
+{ wb_control_navigate_to_cell (WORKBOOK_CONTROL (wbcg), navigator_last); }
+static void cb_cs_go_to_cell  (WBCGtk *wbcg) { dialog_goto_cell (wbcg); }
+
+static void
+wbc_gtk_cell_selector_popup (G_GNUC_UNUSED GtkEntry *entry,
+			     G_GNUC_UNUSED GtkEntryIconPosition icon_pos,
+			     G_GNUC_UNUSED GdkEvent *event,
+			     gpointer data)
+{
+	if (event->type == GDK_BUTTON_PRESS) {
+		WBCGtk *wbcg = data;
+		
+		struct CellSelectorMenu {
+			gchar const *text;
+			gchar const *stock_id;
+			void (*function) (WBCGtk *wbcg);
+		} const cell_selector_actions [] = {
+			{ N_("Go to Top"),      GTK_STOCK_GOTO_TOP,    &cb_cs_go_up      },
+			{ N_("Go to Bottom"),   GTK_STOCK_GOTO_BOTTOM, &cb_cs_go_down    },
+			{ N_("Go to First"),    GTK_STOCK_GOTO_FIRST,  &cb_cs_go_left    },
+			{ N_("Go to Last"),     GTK_STOCK_GOTO_LAST,   &cb_cs_go_right   },
+			{ NULL, NULL, NULL},
+			{ N_("Go to Cell ..."), GTK_STOCK_JUMP_TO,     &cb_cs_go_to_cell }
+		};
+		unsigned int ui;
+		GtkWidget *item, *menu = gtk_menu_new ();
+		gboolean active = (!wbcg_is_editing (wbcg) && 
+				   NULL == wbc_gtk_get_guru (wbcg));
+
+		for (ui = 0; ui < G_N_ELEMENTS (cell_selector_actions); ui++) {
+			const struct CellSelectorMenu *it =
+				cell_selector_actions + ui;
+			if (it->text) {
+				if (it->stock_id) {
+					item = gtk_image_menu_item_new_from_stock  
+						(it->stock_id, NULL);
+					gtk_menu_item_set_label 
+						(GTK_MENU_ITEM (item), _(it->text));
+				} else
+					item = gtk_image_menu_item_new_with_label 
+						(_(it->text));
+			} else
+				item = gtk_separator_menu_item_new ();
+			
+			if (it->function)
+				g_signal_connect_swapped 
+					(G_OBJECT (item), "activate",
+					 G_CALLBACK (it->function), wbcg);
+			gtk_widget_set_sensitive (item, active);
+			gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+			gtk_widget_show (item);
+		}
+		
+		gnumeric_popup_menu (GTK_MENU (menu), &event->button);
+	}
+}
+#endif
+
+
 static void
 wbc_gtk_create_edit_area (WBCGtk *wbcg)
 {
@@ -2396,6 +2464,26 @@ wbc_gtk_create_edit_area (WBCGtk *wbcg)
 		"focus-out-event",
 		G_CALLBACK (cb_statusbox_focus), wbcg);
 
+#ifdef HAVE_GTK_ENTRY_SET_ICON_FROM_STOCK
+
+	gtk_entry_set_icon_from_stock 
+		(GTK_ENTRY (wbcg->selection_descriptor),
+		 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_JUMP_TO);
+	gtk_entry_set_icon_sensitive
+		(GTK_ENTRY (wbcg->selection_descriptor),
+		 GTK_ENTRY_ICON_SECONDARY, TRUE);
+	gtk_entry_set_icon_activatable
+		(GTK_ENTRY (wbcg->selection_descriptor),
+		 GTK_ENTRY_ICON_SECONDARY, TRUE);
+
+	g_signal_connect (G_OBJECT (wbcg->selection_descriptor),
+			  "icon-press",
+			  G_CALLBACK
+			  (wbc_gtk_cell_selector_popup),
+			  wbcg);
+#endif
+
+
 	gtk_widget_show_all (GTK_WIDGET (tb));
 }
 
diff --git a/src/workbook-control.c b/src/workbook-control.c
index 356cef6..fa95d99 100644
--- a/src/workbook-control.c
+++ b/src/workbook-control.c
@@ -29,6 +29,7 @@
 #include "workbook-priv.h"
 #include "sheet.h"
 #include "sheet-view.h"
+#include "sheet-utils.h"
 #include "selection.h"
 #include "commands.h"
 #include "value.h"
@@ -306,6 +307,56 @@ wb_control_parse_and_jump (WorkbookControl *wbc, char const *text)
 	return wb_control_jump (wbc, sheet, &range);
 }
 
+void 
+wb_control_navigate_to_cell (WorkbookControl *wbc, wb_control_navigator_t to)
+{
+	Sheet *sheet = wb_control_cur_sheet (wbc);
+	SheetView *sv = wb_control_cur_sheet_view (wbc);
+	GnmRange region;
+	GnmRange const *first = selection_first_range (sv, NULL, NULL);
+	GnmRangeRef rangeref;
+
+	region = *first;
+	gnm_sheet_guess_data_range (sheet, &region);
+	range_ensure_sanity (&region, sheet);
+	
+	switch (to) {
+	case navigator_top:
+		region.end.row = region.start.row;
+		region.start.col = first->start.col;
+		region.end.col = first->end.col;
+		break;
+	case navigator_bottom:
+		region.start.row = region.end.row;
+		region.start.col = first->start.col;
+		region.end.col = first->end.col;
+		break;
+	case navigator_first:
+		region.end.col = region.start.col;
+		region.start.row = first->start.row;
+		region.end.row = first->end.row;
+		break;
+	case navigator_last:
+		region.start.col = region.end.col;
+		region.start.row = first->start.row;
+		region.end.row = first->end.row;
+		break;
+	default:
+		break;
+	}
+	gnm_cellref_init (&rangeref.a, sheet,
+			  region.start.col, region.start.row, FALSE);
+	gnm_cellref_init (&rangeref.b, sheet,
+			  region.end.col, region.end.row, FALSE);
+
+	wb_control_jump (wbc, sheet, &rangeref);
+
+	return;
+}
+
+
+
+
 static void
 cb_wbc_clipboard_modified (GnmApp *app, WorkbookControl *wbc)
 {
diff --git a/src/workbook-control.h b/src/workbook-control.h
index 908a672..5bef8a2 100644
--- a/src/workbook-control.h
+++ b/src/workbook-control.h
@@ -83,6 +83,16 @@ SheetView    *wb_control_cur_sheet_view	(WorkbookControl const *wbc);
 
 gboolean      wb_control_parse_and_jump (WorkbookControl *wbc, char const *text);
 
+typedef enum {
+	navigator_top,
+	navigator_bottom,
+	navigator_last,
+	navigator_first	
+} wb_control_navigator_t;
+
+void wb_control_navigate_to_cell (WorkbookControl *wbc, wb_control_navigator_t to);
+
+
 G_END_DECLS
 
 #endif /* _GNM_WORKBOOK_CONTROL_H_ */



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