gnumeric r16279 - in branches/gnumeric-1-8: . src



Author: mortenw
Date: Wed Jan 16 02:49:42 2008
New Revision: 16279
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16279&view=rev

Log:
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.



Modified:
   branches/gnumeric-1-8/ChangeLog
   branches/gnumeric-1-8/NEWS
   branches/gnumeric-1-8/src/gnm-format.c
   branches/gnumeric-1-8/src/gnm-format.h
   branches/gnumeric-1-8/src/wbc-gtk-actions.c
   branches/gnumeric-1-8/src/wbc-gtk-edit.c

Modified: branches/gnumeric-1-8/NEWS
==============================================================================
--- branches/gnumeric-1-8/NEWS	(original)
+++ branches/gnumeric-1-8/NEWS	Wed Jan 16 02:49:42 2008
@@ -1,10 +1,10 @@
---------------------------------------------------------------------------
 Gnumeric 1.8.1
 
 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

Modified: branches/gnumeric-1-8/src/gnm-format.c
==============================================================================
--- branches/gnumeric-1-8/src/gnm-format.c	(original)
+++ branches/gnumeric-1-8/src/gnm-format.c	Wed Jan 16 02:49:42 2008
@@ -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 @@
 	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)

Modified: branches/gnumeric-1-8/src/gnm-format.h
==============================================================================
--- branches/gnumeric-1-8/src/gnm-format.h	(original)
+++ branches/gnumeric-1-8/src/gnm-format.h	Wed Jan 16 02:49:42 2008
@@ -40,6 +40,8 @@
 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);
 

Modified: branches/gnumeric-1-8/src/wbc-gtk-actions.c
==============================================================================
--- branches/gnumeric-1-8/src/wbc-gtk-actions.c	(original)
+++ branches/gnumeric-1-8/src/wbc-gtk-actions.c	Wed Jan 16 02:49:42 2008
@@ -569,45 +569,71 @@
 
 /****************************************************************************/
 
-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)

Modified: branches/gnumeric-1-8/src/wbc-gtk-edit.c
==============================================================================
--- branches/gnumeric-1-8/src/wbc-gtk-edit.c	(original)
+++ branches/gnumeric-1-8/src/wbc-gtk-edit.c	Wed Jan 16 02:49:42 2008
@@ -833,26 +833,19 @@
 			}
 
 			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);



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