Commit 41a7b257 authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

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
parent d45a67e2
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
......
......@@ -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]
......
......@@ -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"/>
......
......@@ -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"/>
......
......@@ -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"/>
......
......@@ -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);
......
......@@ -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,
......
......@@ -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;
}
/******************************************************************/
......
......@@ -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,
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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);
/* ------------------------------------------------------------------------- */
......
......@@ -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"),
......
......@@ -60,6 +60,18 @@ workbook_cmd_resize_selected_colrow (WorkbookControl *wbc, Sheet *sheet,
cmd_resize_colrow (wbc, sheet, is_cols, closure.selection, new_size_pixels);
}
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)
{
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment