[gnumeric] Extend the goto dialog.



commit 1f1ab9a1e4b3eee0063da8967265efddd0c7c3d2
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu May 26 00:22:34 2011 -0600

    Extend the goto dialog.
    
    2011-05-26  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* help.h (GNUMERIC_HELP_LINK_GOTO_CELL): use a valid id
    	* goto.ui: add spin buttons
    	* dialog-goto-cell.c (dialog_goto_get_val): new
    	(cb_dialog_goto_go_clicked): handle names and row/column widths
    	(cb_dialog_goto_update_sensitivity): allow names and set the correct
    	limits for rows and columns
    	(dialog_goto_load_selection): new
    	(dialog_goto_init): setup spin buttons and prelaod info
    
    2011-05-26  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/workbook-control.h (wb_control_jump): new
    	* src/workbook-control.c (wb_control_jump): make non-static

 ChangeLog                      |    5 +
 NEWS                           |    1 +
 src/dialogs/ChangeLog          |   11 ++
 src/dialogs/dialog-goto-cell.c |  127 +++++++++++++++++++++++--
 src/dialogs/goto.ui            |  203 ++++++++++++++++++++++++++++++---------
 src/dialogs/help.h             |    2 +-
 src/workbook-control.c         |    2 +-
 src/workbook-control.h         |    1 +
 8 files changed, 292 insertions(+), 60 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 71c35ae..a3c544a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-05-26  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/workbook-control.h (wb_control_jump): new
+	* src/workbook-control.c (wb_control_jump): make non-static
+
 2011-05-24  Morten Welinder  <terra gnome org>
 
 	* src/sheet.c (gnm_sheet_constructed): Don't chain up before
diff --git a/NEWS b/NEWS
index 63dbf38..b43e382 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.10.16
 Andreas
 	* Store some print range information in gnumeric files. [#649714]
 	* Hide Prefer CLIPBOARD preference under MS Windows. [#649675]
+	* Extend the goto dialog.
 
 Morten:
 	* Fix leaks in SHEET.  [#650761]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index ed6edcc..73ee43e 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,14 @@
+2011-05-26  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* help.h (GNUMERIC_HELP_LINK_GOTO_CELL): use a valid id
+	* goto.ui: add spin buttons
+	* dialog-goto-cell.c (dialog_goto_get_val): new
+	(cb_dialog_goto_go_clicked): handle names and row/column widths
+	(cb_dialog_goto_update_sensitivity): allow names and set the correct
+	limits for rows and columns
+	(dialog_goto_load_selection): new
+	(dialog_goto_init): setup spin buttons and prelaod info
+
 2011-05-23  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* dialog-preferences.c (pref_copypaste_page_initializer): hide under
diff --git a/src/dialogs/dialog-goto-cell.c b/src/dialogs/dialog-goto-cell.c
index d340058..d65afa5 100644
--- a/src/dialogs/dialog-goto-cell.c
+++ b/src/dialogs/dialog-goto-cell.c
@@ -3,9 +3,9 @@
  * dialog-goto-cell.c:  Implements the "goto cell/navigator" functionality
  *
  * Author:
- * Andreas J. Guelzow <aguelzow taliesin ca>
+ * Andreas J. Guelzow <aguelzow pyrshep ca>
  *
- * Copyright (C) Andreas J. Guelzow <aguelzow taliesin ca>
+ * Copyright (C) Andreas J. Guelzow <aguelzow pyrshep ca>
  *
  * 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
@@ -37,6 +37,10 @@
 #include <sheet.h>
 #include <workbook.h>
 #include <workbook-view.h>
+#include <workbook-control.h>
+#include <selection.h>
+#include <parse-util.h>
+#include <sheet-view.h>
 
 #include <wbc-gtk.h>
 
@@ -54,6 +58,8 @@ typedef struct {
 	GtkWidget *go_button;
 	GtkEntry *goto_text;
 
+	GtkSpinButton *spin_rows, *spin_cols;
+
 	GtkTreeStore  *model;
 	GtkTreeView   *treeview;
 	GtkTreeSelection   *selection;
@@ -98,18 +104,49 @@ cb_dialog_goto_close_clicked (G_GNUC_UNUSED GtkWidget *button,
 	gtk_widget_destroy (state->dialog);
 }
 
+static GnmValue *
+dialog_goto_get_val (GotoState *state)
+{
+	char const *text = gtk_entry_get_text (state->goto_text);
+	Sheet *sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg));
+	GnmValue *val = value_new_cellrange_str (sheet, text);
+
+	if (val == NULL) {
+		GnmParsePos pp;
+		GnmNamedExpr *nexpr = expr_name_lookup 
+			(parse_pos_init_sheet (&pp, sheet), text);
+		if (nexpr != NULL && !expr_name_is_placeholder (nexpr)) {
+			val = gnm_expr_top_get_range (nexpr->texpr);
+		} 
+	}
+	return val;
+}
+
 static void
 cb_dialog_goto_go_clicked (G_GNUC_UNUSED GtkWidget *button,
 			   GotoState *state)
 {
-	char *text = g_strdup (gtk_entry_get_text (state->goto_text));
-
-	if (wb_control_parse_and_jump (WORKBOOK_CONTROL (state->wbcg), text)) {
+	GnmEvalPos ep;
+	GnmRangeRef range;
+	gint cols = gtk_spin_button_get_value_as_int (state->spin_cols);
+	gint rows = gtk_spin_button_get_value_as_int (state->spin_rows);
+	GnmValue *val = dialog_goto_get_val (state);
+	Sheet *sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg));
+
+	if (val == NULL)
+		return;
+	
+	val->v_range.cell.b.row = val->v_range.cell.a.row + (rows - 1);
+	val->v_range.cell.b.col = val->v_range.cell.a.col + (cols - 1);
+	eval_pos_init_sheet (&ep, sheet);
+	gnm_cellref_make_abs (&range.a, &val->v_range.cell.a, &ep);
+	gnm_cellref_make_abs (&range.b, &val->v_range.cell.b, &ep);
+	value_release (val);
+
+	wb_control_jump (WORKBOOK_CONTROL (state->wbcg), sheet, &range);
 #if 0
-		gnome_entry_append_history (state->goto_text, TRUE, text);
+	gnome_entry_append_history (state->goto_text, TRUE, text);
 #endif
-	}
-	g_free (text);
 	return;
 }
 
@@ -117,10 +154,39 @@ static void
 cb_dialog_goto_update_sensitivity (G_GNUC_UNUSED GtkWidget *dummy,
 				   GotoState *state)
 {
-	GnmValue *val = value_new_cellrange_str (wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg)),
-					    gtk_entry_get_text (state->goto_text));
+	GnmValue *val = dialog_goto_get_val (state);
 	if (val != NULL) {
+		gint cols, rows;
+		Sheet *sheet = val->v_range.cell.a.sheet;
+		GnmSheetSize const *ssz;
+
+		if (sheet == NULL)
+			sheet = wb_control_cur_sheet (WORKBOOK_CONTROL (state->wbcg));
+		ssz = gnm_sheet_get_size (sheet);
+
+		cols = ssz->max_cols;
+		rows = ssz->max_rows;
+
+		if (val->v_range.cell.a.sheet != NULL && 
+		    val->v_range.cell.b.sheet != NULL &&
+		    val->v_range.cell.a.sheet != val->v_range.cell.b.sheet) {
+			ssz = gnm_sheet_get_size (sheet);
+			if (cols > ssz->max_cols)
+				cols = ssz->max_cols;
+			if (rows > ssz->max_rows)
+				cols = ssz->max_rows;
+		}
+		cols -= val->v_range.cell.a.col;
+		rows -= val->v_range.cell.a.row;
+		
+		if (cols < 1) cols = 1;
+		if (rows < 1) rows = 1;
+
+		gtk_spin_button_set_range (state->spin_cols, 1, cols);
+		gtk_spin_button_set_range (state->spin_rows, 1, rows);
+
 		gtk_widget_set_sensitive (state->go_button, TRUE);
+		
 		value_release (val);
 	} else
 		gtk_widget_set_sensitive (state->go_button, FALSE);
@@ -240,6 +306,40 @@ cb_sheet_added (Workbook *wb, GotoState *state)
 	cb_dialog_goto_update_sensitivity (NULL, state);
 }
 
+static void
+dialog_goto_load_selection (GotoState *state)
+{
+	SheetView *sv = wb_control_cur_sheet_view 
+		(WORKBOOK_CONTROL (state->wbcg));
+	GnmRange const *first = selection_first_range (sv, NULL, NULL);
+
+	if (first != NULL) {
+		gint rows = range_height (first);
+		gint cols = range_width (first);
+		GnmConventionsOut out;
+		GString *str = g_string_new (NULL);
+		GnmParsePos pp;
+		GnmRangeRef rr;
+		
+		out.accum = str;
+		out.pp = parse_pos_init_sheet (&pp, sv->sheet);
+		out.convs = sheet_get_conventions (sv->sheet);
+		gnm_cellref_init (&rr.a, NULL, first->start.col, 
+				  first->start.row, TRUE);
+		gnm_cellref_init (&rr.b, NULL, first->start.col, 
+				  first->start.row, TRUE);
+		rangeref_as_string (&out, &rr);
+		gtk_entry_set_text (state->goto_text, str->str);
+		gtk_editable_select_region (GTK_EDITABLE (state->goto_text),
+					    0, -1);
+		g_string_free (str, TRUE);
+		cb_dialog_goto_update_sensitivity (NULL, state);
+		gtk_spin_button_set_value (state->spin_rows, rows);
+		gtk_spin_button_set_value (state->spin_cols, cols);
+	} else
+		cb_dialog_goto_update_sensitivity (NULL, state);
+
+}
 
 /**
  * dialog_init:
@@ -265,6 +365,11 @@ dialog_goto_init (GotoState *state)
 		"changed",
 		G_CALLBACK (cb_dialog_goto_update_sensitivity), state);
 
+	state->spin_rows = GTK_SPIN_BUTTON 
+		(go_gtk_builder_get_widget (state->gui, "spin-rows"));
+	state->spin_cols = GTK_SPIN_BUTTON 
+		(go_gtk_builder_get_widget (state->gui, "spin-columns"));
+
 	/* Set-up treeview */
 	scrolled = go_gtk_builder_get_widget (state->gui, "scrolled");
 	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
@@ -323,7 +428,7 @@ dialog_goto_init (GotoState *state)
 		go_gtk_builder_get_widget (state->gui, "help_button"),
 		GNUMERIC_HELP_LINK_GOTO_CELL);
 
-	cb_dialog_goto_update_sensitivity (NULL, state);
+	dialog_goto_load_selection (state);
 
 	wbc_gtk_attach_guru (state->wbcg, state->dialog);
 	g_object_set_data_full (G_OBJECT (state->dialog),
diff --git a/src/dialogs/goto.ui b/src/dialogs/goto.ui
index a348a59..47e4cc6 100644
--- a/src/dialogs/goto.ui
+++ b/src/dialogs/goto.ui
@@ -1,22 +1,82 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 2.12 -->
   <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="lower">1</property>
+    <property name="upper">100000</property>
+    <property name="value">1</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustment2">
+    <property name="lower">1</property>
+    <property name="upper">100000</property>
+    <property name="value">1</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkDialog" id="goto_dialog">
+    <property name="can_focus">False</property>
     <property name="title" translatable="yes">Go To...</property>
     <property name="window_position">center</property>
     <property name="type_hint">normal</property>
-    <property name="has_separator">False</property>
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
+        <property name="can_focus">False</property>
         <property name="spacing">5</property>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="help_button">
+                <property name="label">gtk-help</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="close_button">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkTable" id="names">
             <property name="visible">True</property>
+            <property name="can_focus">False</property>
             <property name="border_width">5</property>
-            <property name="n_rows">3</property>
+            <property name="n_rows">5</property>
             <property name="n_columns">2</property>
             <property name="column_spacing">5</property>
             <property name="row_spacing">5</property>
@@ -30,8 +90,8 @@
               </object>
               <packing>
                 <property name="right_attach">2</property>
-                <property name="top_attach">3</property>
-                <property name="bottom_attach">4</property>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
               </packing>
             </child>
             <child>
@@ -41,6 +101,7 @@
                 <property name="can_focus">True</property>
                 <property name="can_default">True</property>
                 <property name="receives_default">False</property>
+                <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
               <packing>
@@ -53,7 +114,91 @@
               </packing>
             </child>
             <child>
-              <placeholder/>
+              <object class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Rows:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="spin-rows">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">â??</property>
+                    <property name="primary_icon_activatable">False</property>
+                    <property name="secondary_icon_activatable">False</property>
+                    <property name="primary_icon_sensitive">True</property>
+                    <property name="secondary_icon_sensitive">True</property>
+                    <property name="adjustment">adjustment1</property>
+                    <property name="numeric">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xpad">1</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">Columns:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="spin-columns">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">â??</property>
+                    <property name="primary_icon_activatable">False</property>
+                    <property name="secondary_icon_activatable">False</property>
+                    <property name="primary_icon_sensitive">True</property>
+                    <property name="secondary_icon_sensitive">True</property>
+                    <property name="adjustment">adjustment2</property>
+                    <property name="numeric">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="right_attach">2</property>
+                <property name="top_attach">3</property>
+                <property name="bottom_attach">4</property>
+              </packing>
             </child>
             <child>
               <placeholder/>
@@ -67,50 +212,14 @@
             <child>
               <placeholder/>
             </child>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child internal-child="action_area">
-          <object class="GtkHButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="help_button">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="close_button">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
+              <placeholder/>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
           </packing>
         </child>
       </object>
diff --git a/src/dialogs/help.h b/src/dialogs/help.h
index b63db31..06f5845 100644
--- a/src/dialogs/help.h
+++ b/src/dialogs/help.h
@@ -73,7 +73,7 @@
 #define GNUMERIC_HELP_LINK_GOAL_SEEK "sect-advanced-analysis-goalseek"
 
 /* dialog-goto-cell.c  */
-#define GNUMERIC_HELP_LINK_GOTO_CELL "sect-worksheets-viewing"
+#define GNUMERIC_HELP_LINK_GOTO_CELL "menu-edit-select.png"
 
 /* dialog-hyperlink.c  */
 #define GNUMERIC_HELP_LINK_HYPERLINK "sect-data-link"
diff --git a/src/workbook-control.c b/src/workbook-control.c
index 47a8451..65b3d19 100644
--- a/src/workbook-control.c
+++ b/src/workbook-control.c
@@ -227,7 +227,7 @@ wb_create_name (WorkbookControl *wbc, char const *text, GnmParsePos *pp)
 /*
  * Select the given range and make the it visible.
  */
-static gboolean
+gboolean
 wb_control_jump (WorkbookControl *wbc, Sheet *sheet, const GnmRangeRef *r)
 {
 	SheetView *sv;
diff --git a/src/workbook-control.h b/src/workbook-control.h
index 71226c4..b904b1d 100644
--- a/src/workbook-control.h
+++ b/src/workbook-control.h
@@ -85,6 +85,7 @@ Sheet        *wb_control_cur_sheet	(WorkbookControl const *wbc);
 SheetView    *wb_control_cur_sheet_view	(WorkbookControl const *wbc);
 
 gboolean      wb_control_parse_and_jump (WorkbookControl *wbc, char const *text);
+gboolean      wb_control_jump (WorkbookControl *wbc, Sheet *sheet, const GnmRangeRef *r);
 
 typedef enum {
 	navigator_top,



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