Commit e3188071 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Use gnm_format_for_date_editing.

2008-01-10  Morten Welinder  <terra@gnome.org>

	* src/wbc-gtk-edit.c (wbcg_edit_start): Use
	gnm_format_for_date_editing.

	* src/wbc-gtk-actions.c (insert_date_time_common): New function to
	format numbers according to cell's format when appropriate.
	Fixes 508237.

	* src/gnm-format.c (gnm_format_for_date_editing): New function.


svn path=/trunk/; revision=16278
parent 1ad81b6e
2008-01-10 Morten Welinder <terra@gnome.org>
* src/wbc-gtk-edit.c (wbcg_edit_start): Use
gnm_format_for_date_editing.
* src/wbc-gtk-actions.c (insert_date_time_common): New function to
format numbers according to cell's format when appropriate.
Fixes 508237.
* src/gnm-format.c (gnm_format_for_date_editing): New function.
2008-01-15 Morten Welinder <terra@gnome.org>
* src/value.c (parse_database_criteria): Verify that we have a
......
......@@ -4,6 +4,7 @@ Morten:
* Fix NPV doc problem. [#506160]
* Fix python compilation problem. [#509023] [508988]
* Fix DSUM crash. [#509427]
* Fix insert-current-date locale problem. [#508237]
--------------------------------------------------------------------------
Gnumeric 1.8.0
......
......@@ -26,6 +26,7 @@
#include <gnumeric-config.h>
#include "gnm-format.h"
#include "value.h"
#include "cell.h"
#include <goffice/utils/go-font.h>
#include <goffice/utils/go-glib-extras.h>
......@@ -266,6 +267,23 @@ gnm_format_month_before_day (GOFormat const *fmt,
return mbd;
}
GOFormat *
gnm_format_for_date_editing (GnmCell const *cell)
{
int mbd = cell
? gnm_format_month_before_day (gnm_cell_get_format (cell),
cell->value)
: go_locale_month_before_day ();
switch (mbd) {
case 0: return go_format_new_from_XL ("d/m/yyyy");
default:
case 1: return go_format_new_from_XL ("m/d/yyyy");
case 2: return go_format_new_from_XL ("yyyy-m-d");
}
}
gboolean
gnm_format_has_hour (GOFormat const *fmt,
GnmValue const *value)
......
......@@ -40,6 +40,8 @@ int gnm_format_is_time_for_value (GOFormat const *fmt,
int gnm_format_month_before_day (GOFormat const *fmt,
GnmValue const *value);
GOFormat *gnm_format_for_date_editing (GnmCell const *cell);
gboolean gnm_format_has_hour (GOFormat const *fmt,
GnmValue const *value);
......
......@@ -569,45 +569,71 @@ static GNM_ACTION_DEF (cb_view_freeze_panes)
/****************************************************************************/
static GNM_ACTION_DEF (cb_insert_current_date_time)
static void
insert_date_time_common (WBCGtk *wbcg, int what)
{
if (wbcg_edit_start (wbcg, FALSE, FALSE)) {
Workbook const *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
GnmValue *v = value_new_float (
datetime_timet_to_serial_raw (time (NULL), workbook_date_conv (wb)));
char *txt = format_value (go_format_default_date_time (), v, NULL, -1,
workbook_date_conv (wb));
WorkbookControl *wbc = WORKBOOK_CONTROL (wbcg);
SheetView *sv = wb_control_cur_sheet_view (wbc);
Sheet *sheet = sv_sheet (sv);
GnmCell const *cell = sheet_cell_get (sheet,
sv->edit_pos.col,
sv->edit_pos.row);
GODateConventions const *date_conv =
workbook_date_conv (sheet->workbook);
GnmValue *v = value_new_int (
datetime_timet_to_serial (time (NULL), date_conv));
GOFormat *vfmt;
char *txt;
switch (what) {
case 1:
vfmt = go_format_default_time ();
go_format_ref (vfmt);
break;
case 2:
vfmt = gnm_format_for_date_editing (cell);
break;
case 3: {
GString *fstr;
vfmt = gnm_format_for_date_editing (cell);
fstr = g_string_new (go_format_as_XL (vfmt));
go_format_unref (vfmt);
g_string_append_c (fstr, ' ');
vfmt = go_format_default_time ();
g_string_append (fstr, go_format_as_XL (vfmt));
vfmt = go_format_new_from_XL (fstr->str);
g_string_free (fstr, TRUE);
break;
}
default:
g_assert_not_reached ();
}
txt = format_value (vfmt, v, NULL, -1, date_conv);
wb_control_edit_line_set (wbc, txt);
value_release (v);
wb_control_edit_line_set (WORKBOOK_CONTROL (wbcg), txt);
go_format_unref (vfmt);
g_free (txt);
}
}
static GNM_ACTION_DEF (cb_insert_current_date_time)
{
insert_date_time_common (wbcg, 3);
}
static GNM_ACTION_DEF (cb_insert_current_date)
{
if (wbcg_edit_start (wbcg, FALSE, FALSE)) {
Workbook const *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
GnmValue *v = value_new_int (
datetime_timet_to_serial (time (NULL), workbook_date_conv (wb)));
char *txt = format_value (go_format_default_date (), v, NULL, -1,
workbook_date_conv (wb));
value_release (v);
wb_control_edit_line_set (WORKBOOK_CONTROL (wbcg), txt);
g_free (txt);
}
insert_date_time_common (wbcg, 2);
}
static GNM_ACTION_DEF (cb_insert_current_time)
{
if (wbcg_edit_start (wbcg, FALSE, FALSE)) {
Workbook const *wb = wb_control_get_workbook (WORKBOOK_CONTROL (wbcg));
GnmValue *v = value_new_float (
datetime_timet_to_seconds (time (NULL)) / (24.0 * 60 * 60));
char *txt = format_value (go_format_default_time (), v, NULL, -1,
workbook_date_conv (wb));
value_release (v);
wb_control_edit_line_set (WORKBOOK_CONTROL (wbcg), txt);
g_free (txt);
}
insert_date_time_common (wbcg, 1);
}
static GNM_ACTION_DEF (cb_define_name)
......
......@@ -833,26 +833,19 @@ wbcg_edit_start (WBCGtk *wbcg,
}
case GO_FORMAT_DATE: {
const char *ftxt;
GString *fstr;
GOFormat *new_fmt;
int mbd = gnm_format_month_before_day
(fmt, cell->value);
switch (mbd) {
case 0: ftxt = "d/m/yyyy"; break;
default:
case 1: ftxt = "m/d/yyyy"; break;
case 2: ftxt = "yyyy-m-d"; break;
}
fstr = g_string_new (ftxt);
new_fmt = gnm_format_for_date_editing (cell);
if (!close_to_int (f, 1e-6 / (24 * 60 * 60))) {
GString *fstr = g_string_new (go_format_as_XL (new_fmt));
go_format_unref (new_fmt);
g_string_append_c (fstr, ' ');
guess_time_format (fstr, f - gnm_floor (f));
new_fmt = go_format_new_from_XL (fstr->str);
g_string_free (fstr, TRUE);
}
new_fmt = go_format_new_from_XL (fstr->str);
g_string_free (fstr, TRUE);
text = format_value (new_fmt, cell->value,
NULL, -1, date_conv);
......
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