[gnumeric] Add menu item to autofit column width or row height based on the selection only. [#125595]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Add menu item to autofit column width or row height based on the selection only. [#125595]
- Date: Thu, 8 Jul 2010 20:27:46 +0000 (UTC)
commit 41a7b257904ffcd54c68cfe231cd0c222058ad8c
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Thu Jul 8 14:28:43 2010 -0600
Add menu item to autofit column width or row height based on the selection only. [#125595]
2010-07-08 Andreas J. Guelzow <aguelzow pyrshep ca>
* component/Gnumeric-embed.xml.in: add menu items to Format->Cells
* src/GNOME_Gnumeric-gtk.xml.in: ditto
* src/HILDON_Gnumeric-gtk.xml.in: ditto
* src/colrow.c (colrow_set_sizes): add arguments to restrict the
range of autofitting.
* src/colrow.h (colrow_set_sizes): add arguments
* src/commands.c (cmd_autofit_selection): new
(cmd_resize_colrow): adjust call of colrow_set_sizes
* src/commands.h (cmd_autofit_selection): new
* src/stf-parse.c (stf_parse_sheet): adjust call of colrow_set_sizes
* src/undo.c (gnm_undo_colrow_set_sizes_new): ditto
(gnm_undo_colrow_set_sizes_undo): adjust call of colrow_set_sizes
* src/undo.h (_GNMUndoColrowSetSizesClass): add from/to specifiers
(gnm_undo_colrow_set_sizes_new): ditto
* src/wbc-gtk-actions.c (cb_format_cells_auto_fit_height): new
(cb_format_cells_auto_fit_width): new
(FormatCellsFitHeight): new action
(FormatCellsFitWidth): new action
* src/workbook-cmd-format.c (workbook_cmd_autofit_selection): new
* src/workbook-cmd-format.h (workbook_cmd_autofit_selection): new
ChangeLog | 23 +++++++++++++++++++++++
NEWS | 2 ++
component/Gnumeric-embed.xml.in | 2 ++
src/GNOME_Gnumeric-gtk.xml.in | 2 ++
src/HILDON_Gnumeric-gtk.xml.in | 2 ++
src/colrow.c | 22 ++++++++++++++++------
src/colrow.h | 3 ++-
src/commands.c | 32 +++++++++++++++++++++++++++++++-
src/commands.h | 3 +++
src/stf-parse.c | 2 +-
src/undo.c | 35 +++++++++++++++++++++++++++++++----
src/undo.h | 4 ++--
src/wbc-gtk-actions.c | 37 ++++++++++++++++++++++++++++++-------
src/workbook-cmd-format.c | 12 ++++++++++++
src/workbook-cmd-format.h | 5 ++++-
15 files changed, 163 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 25a68fa..e895191 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2010-07-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * component/Gnumeric-embed.xml.in: add menu items to Format->Cells
+ * src/GNOME_Gnumeric-gtk.xml.in: ditto
+ * src/HILDON_Gnumeric-gtk.xml.in: ditto
+ * src/colrow.c (colrow_set_sizes): add arguments to restrict the
+ range of autofitting.
+ * src/colrow.h (colrow_set_sizes): add arguments
+ * src/commands.c (cmd_autofit_selection): new
+ (cmd_resize_colrow): adjust call of colrow_set_sizes
+ * src/commands.h (cmd_autofit_selection): new
+ * src/stf-parse.c (stf_parse_sheet): adjust call of colrow_set_sizes
+ * src/undo.c (gnm_undo_colrow_set_sizes_new): ditto
+ (gnm_undo_colrow_set_sizes_undo): adjust call of colrow_set_sizes
+ * src/undo.h (_GNMUndoColrowSetSizesClass): add from/to specifiers
+ (gnm_undo_colrow_set_sizes_new): ditto
+ * src/wbc-gtk-actions.c (cb_format_cells_auto_fit_height): new
+ (cb_format_cells_auto_fit_width): new
+ (FormatCellsFitHeight): new action
+ (FormatCellsFitWidth): new action
+ * src/workbook-cmd-format.c (workbook_cmd_autofit_selection): new
+ * src/workbook-cmd-format.h (workbook_cmd_autofit_selection): new
+
2010-07-08 Morten Welinder <terra gnome org>
* src/wbc-gtk-actions.c (cb_format_as_currency): Use
diff --git a/NEWS b/NEWS
index b65c34a..fe3f97b 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,8 @@ Andreas:
* Add hyperlink and comment removal menu items.
* Fix undoing of Clear->All. [#623803]
* Add merge and unmerge menu items.
+ * Add menu item to autofit column width or row height based on the
+ selection only. [#125595]
Jean:
* Fix strong/weak cursor display. [#623241]
diff --git a/component/Gnumeric-embed.xml.in b/component/Gnumeric-embed.xml.in
index 8f21618..e26288a 100644
--- a/component/Gnumeric-embed.xml.in
+++ b/component/Gnumeric-embed.xml.in
@@ -131,6 +131,8 @@
<menuitem action="FormatCells"/>
<menuitem action="FormatMergeCells"/>
<menuitem action="FormatUnmergeCells"/>
+ <menuitem action="FormatCellsFitHeight"/>
+ <menuitem action="FormatCellsFitWidth"/>
</menu>
<menu name="FormatColumn" action="MenuFormatColumn">
<menuitem action="ColumnSize"/>
diff --git a/src/GNOME_Gnumeric-gtk.xml.in b/src/GNOME_Gnumeric-gtk.xml.in
index 7a6723a..028d849 100644
--- a/src/GNOME_Gnumeric-gtk.xml.in
+++ b/src/GNOME_Gnumeric-gtk.xml.in
@@ -132,6 +132,8 @@
<menuitem action="FormatCells"/>
<menuitem action="FormatMergeCells"/>
<menuitem action="FormatUnmergeCells"/>
+ <menuitem action="FormatCellsFitHeight"/>
+ <menuitem action="FormatCellsFitWidth"/>
</menu>
<menu name="FormatColumn" action="MenuFormatColumn">
<menuitem action="ColumnSize"/>
diff --git a/src/HILDON_Gnumeric-gtk.xml.in b/src/HILDON_Gnumeric-gtk.xml.in
index 2a768ce..ca87fa7 100644
--- a/src/HILDON_Gnumeric-gtk.xml.in
+++ b/src/HILDON_Gnumeric-gtk.xml.in
@@ -141,6 +141,8 @@
<menuitem action="FormatCells"/>
<menuitem action="FormatMergeCells"/>
<menuitem action="FormatUnmergeCells"/>
+ <menuitem action="FormatCellsFitHeight"/>
+ <menuitem action="FormatCellsFitWidth"/>
</menu>
<menu name="FormatColumn" action="MenuFormatColumn">
<menuitem action="ColumnSize"/>
diff --git a/src/colrow.c b/src/colrow.c
index af31d16..259d2db 100644
--- a/src/colrow.c
+++ b/src/colrow.c
@@ -449,7 +449,9 @@ colrow_get_sizes (Sheet *sheet, gboolean is_cols,
ColRowStateGroup *
colrow_set_sizes (Sheet *sheet, gboolean is_cols,
- ColRowIndexList *src, int new_size)
+ ColRowIndexList *src, int new_size, int from, int to)
+/* from & to are used to restrict fitting to that range. Pass 0, -1 if you want to use the */
+/*whole row/column */
{
int i;
ColRowStateGroup *res = NULL;
@@ -516,12 +518,20 @@ colrow_set_sizes (Sheet *sheet, gboolean is_cols,
for (i = index->first ; i <= index->last ; ++i) {
int tmp = new_size;
- if (tmp < 0)
- /* Fall back to assigning the defaul if it is empty */
+ if (tmp < 0) {
+ int max = is_cols ? gnm_sheet_get_last_row (sheet)
+ : gnm_sheet_get_last_col (sheet);
+ if (from < 0)
+ from = 0;
+ if (to < 0 || to > max)
+ to = max;
+ if (from > max)
+ from = to;
+ /* Fall back to assigning the default if it is empty */
tmp = (is_cols)
- ? sheet_col_size_fit_pixels (sheet, i, 0, gnm_sheet_get_last_row (sheet), FALSE)
- : sheet_row_size_fit_pixels (sheet, i, 0, gnm_sheet_get_last_col (sheet), FALSE);
-
+ ? sheet_col_size_fit_pixels (sheet, i, from, to, FALSE)
+ : sheet_row_size_fit_pixels (sheet, i, from, to, FALSE);
+ }
if (tmp > 0) {
if (is_cols)
sheet_col_set_size_pixels (sheet, i, tmp, new_size > 0);
diff --git a/src/colrow.h b/src/colrow.h
index 6f15ccd..1bff94b 100644
--- a/src/colrow.h
+++ b/src/colrow.h
@@ -111,7 +111,8 @@ void colrow_set_states (Sheet *sheet, gboolean is_cols,
ColRowStateGroup *colrow_state_group_destroy (ColRowStateGroup *set);
ColRowStateGroup *colrow_set_sizes (Sheet *sheet, gboolean is_cols,
- ColRowIndexList *src, int new_size);
+ ColRowIndexList *src, int new_size,
+ int from, int to);
ColRowStateGroup *colrow_get_sizes (Sheet *sheet, gboolean is_cols,
ColRowIndexList *src, int new_size);
void colrow_restore_state_group (Sheet *sheet, gboolean is_cols,
diff --git a/src/commands.c b/src/commands.c
index 5f5c535..aa59960 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -1888,7 +1888,7 @@ cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
undo = gnm_undo_colrow_restore_state_group_new
(sheet, is_cols, colrow_index_list_copy (selection), saved_state);
- redo = gnm_undo_colrow_set_sizes_new (sheet, is_cols, selection, new_size);
+ redo = gnm_undo_colrow_set_sizes_new (sheet, is_cols, selection, new_size, NULL);
result = cmd_generic_with_size (wbc, text, size, undo, redo);
g_free (text);
@@ -1896,6 +1896,36 @@ cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
return result;
}
+gboolean
+cmd_autofit_selection (WorkbookControl *wbc, SheetView *sv, Sheet *sheet, gboolean fit_width,
+ ColRowIndexList *selectionlist)
+{
+ GOUndo *undo = NULL;
+ GOUndo *redo = NULL;
+ gboolean result;
+ ColRowStateGroup *saved_state;
+ GSList *l, *selection = selection_get_ranges (sv, TRUE);
+ gchar *names = undo_range_list_name (sheet, selection);
+ gchar const *format = fit_width ?
+ N_("Autofitting width of %s") : N_("Autofitting height of %s");
+ gchar *text = g_strdup_printf (_(format), names);
+
+ g_free (names);
+
+ saved_state = colrow_get_sizes (sheet, fit_width, selectionlist, -1);;
+ undo = gnm_undo_colrow_restore_state_group_new
+ (sheet, fit_width, colrow_index_list_copy (selectionlist), saved_state);
+
+ for (l = selection; l != NULL; l = l->next)
+ redo = go_undo_combine
+ (redo, gnm_undo_colrow_set_sizes_new
+ (sheet, fit_width, NULL, -1, l->data));
+
+ result = cmd_generic (wbc, text, undo, redo);
+ g_free (text);
+ return result;
+}
+
/******************************************************************/
diff --git a/src/commands.h b/src/commands.h
index 205209f..d28937a 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -57,6 +57,9 @@ gboolean cmd_delete_rows (WorkbookControl *wbc, Sheet *sheet,
gboolean cmd_resize_colrow (WorkbookControl *wbc, Sheet *sheet,
gboolean is_col, ColRowIndexList *selection,
int new_size);
+gboolean cmd_autofit_selection (WorkbookControl *wbc, SheetView *sv, Sheet *sheet,
+ gboolean fit_width,
+ ColRowIndexList *selectionlist);
gboolean cmd_paste_cut (WorkbookControl *wbc,
GnmExprRelocateInfo const *info,
diff --git a/src/stf-parse.c b/src/stf-parse.c
index 3483287..9df2796 100644
--- a/src/stf-parse.c
+++ b/src/stf-parse.c
@@ -1323,7 +1323,7 @@ stf_parse_sheet (StfParseOptions_t *parseoptions,
if (parseoptions->col_autofit_array == NULL ||
parseoptions->col_autofit_array[lcol]) {
ColRowIndexList *list = colrow_get_index_list (col, col, NULL);
- ColRowStateGroup *state = colrow_set_sizes (sheet, TRUE, list, -1);
+ ColRowStateGroup *state = colrow_set_sizes (sheet, TRUE, list, -1, 0, -1);
colrow_index_list_destroy (list);
g_slist_free (state);
}
diff --git a/src/undo.c b/src/undo.c
index 9228fd5..3582259 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -102,7 +102,8 @@ gnm_undo_colrow_set_sizes_undo (GOUndo *u, gpointer data)
{
GNMUndoColrowSetSizes *ua = (GNMUndoColrowSetSizes *)u;
- colrow_set_sizes (ua->sheet, ua->is_cols, ua->selection, ua->new_size);
+ colrow_set_sizes (ua->sheet, ua->is_cols, ua->selection, ua->new_size,
+ ua->from, ua->to);
}
static void
@@ -123,20 +124,46 @@ GSF_CLASS (GNMUndoColrowSetSizes, gnm_undo_colrow_set_sizes,
/**
* gnm_undo_colrow_set_sizes_new:
*
+ * If r is non-null and new_size == -1, selection is ignored.
+ *
* Returns: a new undo object.
**/
GOUndo *
gnm_undo_colrow_set_sizes_new (Sheet *sheet, gboolean is_cols,
ColRowIndexList *selection,
- int new_size)
+ int new_size, GnmRange const *r)
{
- GNMUndoColrowSetSizes *ua = g_object_new (GNM_TYPE_UNDO_COLROW_SET_SIZES, NULL);
+ GNMUndoColrowSetSizes *ua;
+
+ g_return_val_if_fail (selection != NULL || (r != NULL && new_size == -1), NULL);
+
+ ua = g_object_new (GNM_TYPE_UNDO_COLROW_SET_SIZES, NULL);
ua->sheet = sheet;
ua->is_cols = is_cols;
- ua->selection = selection;
ua->new_size = new_size;
+
+ if (r == NULL || new_size != -1) {
+ ua->selection = selection;
+ ua->from = 0;
+ ua->to = -1;
+ } else {
+ int first, last;
+
+ if (is_cols) {
+ first = r->start.col;
+ last = r->end.col;
+ ua->from = r->start.row;
+ ua->to = r->end.row;
+ } else {
+ first = r->start.row;
+ last = r->end.row;
+ ua->from = r->start.col;
+ ua->to = r->end.col;
+ }
+ ua->selection = colrow_get_index_list (first, last, NULL);
+ }
return (GOUndo *)ua;
}
diff --git a/src/undo.h b/src/undo.h
index 90aca8b..ef8d134 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -53,7 +53,7 @@ struct _GNMUndoColrowSetSizes {
Sheet *sheet;
gboolean is_cols;
ColRowIndexList *selection;
- int new_size;
+ int new_size, from, to;
};
struct _GNMUndoColrowSetSizesClass {
@@ -62,7 +62,7 @@ struct _GNMUndoColrowSetSizesClass {
GOUndo *gnm_undo_colrow_set_sizes_new (Sheet *sheet, gboolean is_cols,
ColRowIndexList *selection,
- int new_size);
+ int new_size, GnmRange const *r);
/* ------------------------------------------------------------------------- */
diff --git a/src/wbc-gtk-actions.c b/src/wbc-gtk-actions.c
index 8fee648..4219492 100644
--- a/src/wbc-gtk-actions.c
+++ b/src/wbc-gtk-actions.c
@@ -1708,6 +1708,20 @@ static GNM_ACTION_DEF (cb_copyright)
cmd_copyrel (wbc, -1, 0, _("Copy right"));
}
+static GNM_ACTION_DEF (cb_format_cells_auto_fit_height)
+{
+ WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
+ workbook_cmd_autofit_selection
+ (wbc, wb_control_cur_sheet (wbc), FALSE);
+}
+
+static GNM_ACTION_DEF (cb_format_cells_auto_fit_width)
+{
+ WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
+ workbook_cmd_autofit_selection
+ (wbc, wb_control_cur_sheet (wbc), TRUE);
+}
+
static GNM_ACTION_DEF (cb_format_column_auto_fit)
{
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
@@ -2122,9 +2136,6 @@ static GtkActionEntry const actions[] = {
G_CALLBACK (cb_define_name) },
/* Format */
- { "FormatCells", NULL, N_("_Format..."),
- "<control>1", N_("Modify the formatting of the selected cells"),
- G_CALLBACK (cb_format_cells) },
{ "FormatWorkbook", NULL, N_("View _Properties..."),
NULL, N_("Modify the view properties"),
G_CALLBACK (cb_workbook_attr) },
@@ -2135,12 +2146,24 @@ static GtkActionEntry const actions[] = {
NULL, N_("Toggle sheet direction, left-to-right vs right-to-left"),
G_CALLBACK (cb_direction) },
+/* Format -> Cells */
+ { "FormatCells", NULL, N_("_Format..."),
+ "<control>1", N_("Modify the formatting of the selected cells"),
+ G_CALLBACK (cb_format_cells) },
+ { "FormatCellsFitHeight", NULL, N_("Auto Fit _Height"), NULL,
+ N_("Ensure rows are just tall enough to display content of selection"),
+ G_CALLBACK (cb_format_cells_auto_fit_height) },
+ { "FormatCellsFitWidth", NULL, N_("Auto Fit _Width"), NULL,
+ N_("Ensure columns are just wide enough to display content of selection"),
+ G_CALLBACK (cb_format_cells_auto_fit_width) },
+
+
/* Format -> Col */
{ "ColumnSize", "Gnumeric_ColumnSize", N_("_Width..."),
NULL, N_("Change width of the selected columns"),
G_CALLBACK (cb_set_column_width) },
- { "ColumnAutoSize", NULL, N_("_Auto fit selection"),
- NULL, N_("Ensure columns are just wide enough to display content"),
+ { "ColumnAutoSize", NULL, N_("_Auto Fit Width"),
+ NULL, N_("Ensure columns are just wide enough to display their content"),
G_CALLBACK (cb_format_column_auto_fit) },
{ "ColumnHide", "Gnumeric_ColumnHide", N_("_Hide"),
"<control>0", N_("Hide the selected columns"),
@@ -2156,8 +2179,8 @@ static GtkActionEntry const actions[] = {
{ "RowSize", "Gnumeric_RowSize", N_("H_eight..."),
NULL, N_("Change height of the selected rows"),
G_CALLBACK (cb_set_row_height) },
- { "RowAutoSize", NULL, N_("_Auto fit selection"),
- NULL, N_("Ensure rows are just tall enough to display content"),
+ { "RowAutoSize", NULL, N_("_Auto Fit Height"),
+ NULL, N_("Ensure rows are just tall enough to display their content"),
G_CALLBACK (cb_format_row_auto_fit) },
{ "RowHide", "Gnumeric_RowHide", N_("_Hide"),
"<control>9", N_("Hide the selected rows"),
diff --git a/src/workbook-cmd-format.c b/src/workbook-cmd-format.c
index b4e46b6..898c0cd 100644
--- a/src/workbook-cmd-format.c
+++ b/src/workbook-cmd-format.c
@@ -61,6 +61,18 @@ workbook_cmd_resize_selected_colrow (WorkbookControl *wbc, Sheet *sheet,
}
void
+workbook_cmd_autofit_selection (WorkbookControl *wbc, Sheet *sheet,
+ gboolean is_cols)
+{
+ SheetView *sv = sheet_get_view (sheet, wb_control_view (wbc));
+ struct closure_colrow_resize closure;
+ closure.is_cols = is_cols;
+ closure.selection = NULL;
+ sv_selection_foreach (sv, &cb_colrow_collect, &closure);
+ cmd_autofit_selection (wbc, sv, sheet, is_cols, closure.selection);
+}
+
+void
workbook_cmd_inc_indent (WorkbookControl *wbc)
{
WorkbookView const *wbv = wb_control_view (wbc);
diff --git a/src/workbook-cmd-format.h b/src/workbook-cmd-format.h
index 80ad094..afd95fe 100644
--- a/src/workbook-cmd-format.h
+++ b/src/workbook-cmd-format.h
@@ -7,7 +7,10 @@
G_BEGIN_DECLS
void workbook_cmd_resize_selected_colrow (WorkbookControl *wbc, Sheet *sheet,
- gboolean is_cols, int new_size_pixels);
+ gboolean is_cols,
+ int new_size_pixels);
+void workbook_cmd_autofit_selection (WorkbookControl *wbc, Sheet *sheet,
+ gboolean is_cols);
void workbook_cmd_inc_indent (WorkbookControl *wbc);
void workbook_cmd_dec_indent (WorkbookControl *wbc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]