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

[patch] Backport protected worksheets to 1.0.x



Hi,

I've attached a patch that will backport the worksheet protection
property to the 1.0.x branch. Together with the patch for
locking cell contents earlier this should provide something
that is actually useful.

After applying this, there should be a new checkbox in format->workbook
If this box is checked, all locked cells should give error messages
when someone tries to edit them.

TODO: translations of the checkbox.
I've supplied a dutch translation of the checkbox in nl.po but
somehow can't get that to work properly. Adressing this may be
the subject of a further patch. Also, the error message does not
have any translations as far as I can tell.
(and besides, it's somewhat ugly but completely in line with
the state of the development branch so I left it alone)

Since there was a minor update to the earlier patch, I am reposting
that as well.

Regards,
Floris Kraak
-- 
        There was a long silence.  Then a slightly shorter silence.  Then
the old shaman said carefully, "You didn't just see two men go through
upside down on a broomstick, shouting and screaming at each other, did you?"
        The boy looked at him levelly.  "Certainly not," he said.
        The old man heaved a sigh of relief.  "Thank goodness for that," he
said.  "Neither did I."
                -- Terry Pratchett, "The Light Fantastic"
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/po/en_GB.po gnumeric-1.0.8-patched/po/en_GB.po
--- gnumeric-1.0.8/po/en_GB.po	Tue Jun 18 07:59:05 2002
+++ gnumeric-1.0.8-patched/po/en_GB.po	Fri Jun 21 17:12:46 2002
@@ -7113,10 +7113,14 @@
 msgstr ""
 
 #: src/dialogs/workbook-attr.glade.h:4
-msgid "_Horizontal Scrollbar"
+msgid "_Protect Workbook"
 msgstr ""
 
 #: src/dialogs/workbook-attr.glade.h:5
+msgid "_Horizontal Scrollbar"
+msgstr ""
+
+#: src/dialogs/workbook-attr.glade.h:6
 msgid "_Vertical Scrollbar"
 msgstr ""
 
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/po/nl.po gnumeric-1.0.8-patched/po/nl.po
--- gnumeric-1.0.8/po/nl.po	Tue Jun 18 07:59:53 2002
+++ gnumeric-1.0.8-patched/po/nl.po	Fri Jun 21 17:12:46 2002
@@ -7491,10 +7491,14 @@
 msgstr "_Automatisch Tekst Aanvullen"
 
 #: src/dialogs/workbook-attr.glade.h:4
+msgid "_Protect Workbook"
+msgstr "_Bescherm Werkblad"
+
+#: src/dialogs/workbook-attr.glade.h:5
 msgid "_Horizontal Scrollbar"
 msgstr "_Horizontale Schuifbalk"
 
-#: src/dialogs/workbook-attr.glade.h:5
+#: src/dialogs/workbook-attr.glade.h:6
 msgid "_Vertical Scrollbar"
 msgstr "_Verticale Schuifbalk"
 
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/src/dialogs/dialog-cell-format.c gnumeric-1.0.8-patched/src/dialogs/dialog-cell-format.c
--- gnumeric-1.0.8/src/dialogs/dialog-cell-format.c	Thu May  9 22:18:44 2002
+++ gnumeric-1.0.8-patched/src/dialogs/dialog-cell-format.c	Fri Jun 21 17:12:46 2002
@@ -34,6 +34,7 @@
 #include <validation.h>
 #include <workbook.h>
 #include <workbook-edit.h>
+#include <workbook-view.h>
 #include <commands.h>
 #include <widgets/gnumeric-expr-entry.h>
 
@@ -159,7 +160,10 @@
 		PatternPicker	 pattern;
 	} back;
 	struct {
-		GtkCheckButton *hidden, *locked;
+		GtkCheckButton *hidden, *locked, *sheet_protected;
+
+		gboolean         sheet_protected_changed;
+		gboolean         sheet_protected_value;
 	} protection;
 	struct {
 		GtkTable       *criteria_table;
@@ -1983,6 +1987,17 @@
 }
 
 static void
+cb_protection_sheet_protected_toggle (GtkToggleButton *button, FormatState *state)
+{
+	if (state->enable_edit) {
+		state->protection.sheet_protected_value =
+			gtk_toggle_button_get_active (button);
+		state->protection.sheet_protected_changed = TRUE;
+		fmt_dialog_changed (state);
+	}
+}
+
+static void
 fmt_dialog_init_protection_page (FormatState *state)
 {
 	GtkWidget *w;
@@ -2005,6 +2020,15 @@
 	gtk_signal_connect (GTK_OBJECT (w),
 		"toggled", GTK_SIGNAL_FUNC (cb_protection_hidden_toggle),
 		state);
+	
+	state->protection.sheet_protected_changed = FALSE;
+	flag = wb_control_view (WORKBOOK_CONTROL (state->wbcg))->is_protected;
+	w = glade_xml_get_widget (state->gui, "protection_sheet_protected");
+	state->protection.sheet_protected = GTK_CHECK_BUTTON (w);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), flag);
+	gtk_signal_connect (GTK_OBJECT (w),
+		"toggled",
+		GTK_SIGNAL_FUNC (cb_protection_sheet_protected_toggle), state);
 }
 
 /*****************************************************************************/
@@ -2327,6 +2351,13 @@
 	if (state->validation.changed)
 		validation_rebuild_validation (state);
 
+	if (state->protection.sheet_protected_changed) {
+		WorkbookView *wbv = wb_control_view (WORKBOOK_CONTROL (state->wbcg));
+		wbv->is_protected = state->protection.sheet_protected_value;
+		wb_view_prefs_update (wbv);
+		state->protection.sheet_protected_changed = FALSE;
+	}
+	
 	mstyle_ref (state->result);
 
 	for (i = STYLE_BORDER_TOP; i < STYLE_BORDER_EDGE_MAX; i++)
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/src/dialogs/dialog-workbook-attr.c gnumeric-1.0.8-patched/src/dialogs/dialog-workbook-attr.c
--- gnumeric-1.0.8/src/dialogs/dialog-workbook-attr.c	Thu Jan  3 08:28:51 2002
+++ gnumeric-1.0.8-patched/src/dialogs/dialog-workbook-attr.c	Fri Jun 21 17:12:46 2002
@@ -48,6 +48,7 @@
 		GtkToggleButton	*show_vsb;
 		GtkToggleButton	*show_tabs;
 		GtkToggleButton	*autocomplete;
+		GtkToggleButton *is_protected;
 	} view;
 } AttrState;
 
@@ -95,6 +96,8 @@
 		gtk_toggle_button_get_active (state->view.show_tabs);
 	state->wbv->do_auto_completion =
 		gtk_toggle_button_get_active (state->view.autocomplete);
+	state->wbv->is_protected =
+	        gtk_toggle_button_get_active (state->view.is_protected);
 
 	wb_view_prefs_update (state->wbv);
 }
@@ -148,6 +151,9 @@
 	state->view.autocomplete = attr_dialog_init_toggle (state,
 		"WorkbookView::do_auto_completion",
 		state->wbv->do_auto_completion);
+        state->view.is_protected = attr_dialog_init_toggle (state,
+		"WorkbookView::workbook_protected",
+		state->wbv->is_protected);
 }
 
 /*****************************************************************************/
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/src/dialogs/workbook-attr.glade gnumeric-1.0.8-patched/src/dialogs/workbook-attr.glade
--- gnumeric-1.0.8/src/dialogs/workbook-attr.glade	Thu Nov  1 21:43:38 2001
+++ gnumeric-1.0.8-patched/src/dialogs/workbook-attr.glade	Fri Jun 21 17:45:35 2002
@@ -49,7 +49,7 @@
       <class>GtkTable</class>
       <name>table1</name>
       <border_width>4</border_width>
-      <rows>3</rows>
+      <rows>4</rows>
       <columns>2</columns>
       <homogeneous>False</homogeneous>
       <row_spacing>0</row_spacing>
@@ -80,9 +80,9 @@
 
       <widget>
 	<class>GtkCheckButton</class>
-	<name>WorkbookView::show_notebook_tabs</name>
+	<name>WorkbookView::workbook_protected</name>
 	<can_focus>True</can_focus>
-	<label>Notebook _Tabs for Sheets</label>
+	<label>_Protect Workbook</label>
 	<active>False</active>
 	<draw_indicator>True</draw_indicator>
 	<child>
@@ -103,6 +103,29 @@
 
       <widget>
 	<class>GtkCheckButton</class>
+	<name>WorkbookView::show_notebook_tabs</name>
+	<can_focus>True</can_focus>
+	<label>Notebook _Tabs for Sheets</label>
+	<active>False</active>
+	<draw_indicator>True</draw_indicator>
+	<child>
+	  <left_attach>0</left_attach>
+	  <right_attach>2</right_attach>
+	  <top_attach>2</top_attach>
+	  <bottom_attach>3</bottom_attach>
+	  <xpad>0</xpad>
+	  <ypad>0</ypad>
+	  <xexpand>False</xexpand>
+	  <yexpand>False</yexpand>
+	  <xshrink>False</xshrink>
+	  <yshrink>False</yshrink>
+	  <xfill>True</xfill>
+	  <yfill>False</yfill>
+	</child>
+      </widget>
+
+      <widget>
+	<class>GtkCheckButton</class>
 	<name>WorkbookView::show_horizontal_scrollbar</name>
 	<can_focus>True</can_focus>
 	<has_focus>True</has_focus>
@@ -112,8 +135,8 @@
 	<child>
 	  <left_attach>0</left_attach>
 	  <right_attach>1</right_attach>
-	  <top_attach>2</top_attach>
-	  <bottom_attach>3</bottom_attach>
+	  <top_attach>3</top_attach>
+	  <bottom_attach>4</bottom_attach>
 	  <xpad>0</xpad>
 	  <ypad>0</ypad>
 	  <xexpand>True</xexpand>
@@ -135,8 +158,8 @@
 	<child>
 	  <left_attach>1</left_attach>
 	  <right_attach>2</right_attach>
-	  <top_attach>2</top_attach>
-	  <bottom_attach>3</bottom_attach>
+	  <top_attach>3</top_attach>
+	  <bottom_attach>4</bottom_attach>
 	  <xpad>0</xpad>
 	  <ypad>0</ypad>
 	  <xexpand>True</xexpand>
diff -urN --minimal --ignore-space-change gnumeric-1.0.8/src/workbook-view.c gnumeric-1.0.8-patched/src/workbook-view.c
--- gnumeric-1.0.8/src/workbook-view.c	Fri Jun 21 17:47:12 2002
+++ gnumeric-1.0.8-patched/src/workbook-view.c	Fri Jun 21 17:12:46 2002
@@ -522,6 +522,7 @@
 	wbv->show_vertical_scrollbar = TRUE;
 	wbv->show_notebook_tabs = TRUE;
 	wbv->do_auto_completion = application_use_auto_complete ();
+	wbv->is_protected = FALSE;
 
 	/* Set the default operation to be performed over selections */
 	wbv->auto_expr      = NULL;
diff -urN --ignore-space-change gnumeric-1.0.8/src/gnumeric-canvas.c gnumeric-1.0.8-patched/src/gnumeric-canvas.c
--- gnumeric-1.0.8/src/gnumeric-canvas.c	Sat Dec 29 20:08:53 2001
+++ gnumeric-1.0.8-patched/src/gnumeric-canvas.c	Thu Jun 20 14:35:07 2002
@@ -283,7 +283,8 @@
 		return TRUE;
 
 	case GDK_F2:
-		wbcg_edit_start (wbcg, FALSE, FALSE);
+		if (!wbcg_edit_start (wbcg, FALSE, FALSE))
+			return FALSE; /* attempt to edit failed */
 		/* fall down */
 
 	case GDK_BackSpace:
@@ -303,7 +304,8 @@
 			if (event->length == 0)
 				return FALSE;
 
-			wbcg_edit_start (wbcg, TRUE, TRUE);
+			if (!wbcg_edit_start (wbcg, TRUE, TRUE))
+				return FALSE; /* attempt to edit failed */
 		}
 		scg_rangesel_stop (gcanvas->simple.scg, FALSE);
 
diff -urN --ignore-space-change gnumeric-1.0.8/src/sheet.c gnumeric-1.0.8-patched/src/sheet.c
--- gnumeric-1.0.8/src/sheet.c	Sat May  4 19:23:33 2002
+++ gnumeric-1.0.8-patched/src/sheet.c	Thu Jun 20 14:35:37 2002
@@ -257,6 +257,7 @@
 	sheet->hide_grid = FALSE;
 	sheet->hide_col_header = FALSE;
 	sheet->hide_row_header = FALSE;
+	sheet->is_protected = FALSE;
 	sheet->display_outlines = TRUE;
 	sheet->outline_symbols_below = TRUE;
 	sheet->outline_symbols_right = TRUE;
diff -urN --ignore-space-change gnumeric-1.0.8/src/sheet.h gnumeric-1.0.8-patched/src/sheet.h
--- gnumeric-1.0.8/src/sheet.h	Sat May  4 19:23:33 2002
+++ gnumeric-1.0.8-patched/src/sheet.h	Thu Jun 20 14:30:54 2002
@@ -63,6 +63,7 @@
 	gboolean    hide_grid;
 	gboolean    hide_col_header;
 	gboolean    hide_row_header;
+	gboolean    is_protected;
 
 	gboolean    display_outlines;
 	gboolean    outline_symbols_below;
diff -urN --ignore-space-change gnumeric-1.0.8/src/workbook-control-gui.c gnumeric-1.0.8-patched/src/workbook-control-gui.c
--- gnumeric-1.0.8/src/workbook-control-gui.c	Sun Jun  2 02:08:32 2002
+++ gnumeric-1.0.8-patched/src/workbook-control-gui.c	Thu Jun 20 14:38:08 2002
@@ -2452,11 +2452,13 @@
 	entry = GTK_ENTRY (wbcg_get_entry (wbcg));
 	txt = gtk_entry_get_text (entry);
 	if (strncmp (txt, "=sum(", 5)) {
-		wbcg_edit_start (wbcg, TRUE, TRUE);
+		if (!wbcg_edit_start (wbcg, TRUE, TRUE))
+			return; /* attempt to edit failed */
 		gtk_entry_set_text (entry, "=sum()");
 		gtk_entry_set_position (entry, 5);
 	} else {
-		wbcg_edit_start (wbcg, FALSE, TRUE);
+		if (!wbcg_edit_start (wbcg, FALSE, TRUE))
+			return; /* attempt to edit failed */
 
 		/*
 		 * FIXME : This is crap!
@@ -3470,7 +3472,8 @@
 		      WorkbookControlGUI *wbcg)
 {
 	if (!wbcg->editing)
-		wbcg_edit_start (wbcg, FALSE, TRUE);
+		if (!wbcg_edit_start (wbcg, FALSE, TRUE))
+			wb_control_gui_focus_cur_sheet (wbcg);
 
 	return TRUE;
 }
@@ -3509,11 +3512,13 @@
 	entry = GTK_ENTRY (wbcg_get_entry (wbcg));
 	txt = gtk_entry_get_text (entry);
 	if (strncmp (txt, "=", 1)) {
-		wbcg_edit_start (wbcg, TRUE, TRUE);
+		if (!wbcg_edit_start (wbcg, TRUE, TRUE))
+			return; /* attempt to edit failed */
 		gtk_entry_set_text (entry, "=");
 		gtk_entry_set_position (entry, 1);
 	} else {
-		wbcg_edit_start (wbcg, FALSE, TRUE);
+		if (!wbcg_edit_start (wbcg, FALSE, TRUE))
+			return; /* attempt to edit failed */
 
 		/* FIXME : This is crap!
 		 * When the function druid is more complete use that.
diff -urN --ignore-space-change gnumeric-1.0.8/src/workbook-edit.c gnumeric-1.0.8-patched/src/workbook-edit.c
--- gnumeric-1.0.8/src/workbook-edit.c	Tue Feb 19 16:05:43 2002
+++ gnumeric-1.0.8-patched/src/workbook-edit.c	Thu Jun 20 14:49:45 2002
@@ -322,8 +322,12 @@
  * editing:
  *  1) in-cell editing when you just start typing, and
  *  2) above sheet editing when you hit F2.
+ *
+ * Returns TRUE if we did indeed start editing.  Returns FALSE if the
+ * cell-to-be-edited was locked.
+ *
  */
-void
+gboolean
 wbcg_edit_start (WorkbookControlGUI *wbcg,
 		 gboolean blankp, gboolean cursorp)
 {
@@ -335,14 +339,14 @@
 	int col, row;
 	WorkbookView *wbv;
 
-	g_return_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg));
+	g_return_val_if_fail (IS_WORKBOOK_CONTROL_GUI (wbcg), FALSE);
 
 	if (wbcg->editing)
-		return;
+		return TRUE;
 
 	/* Avoid recursion, and do not begin editing if a guru is up */
 	if (inside_editing || wbcg_edit_has_guru (wbcg))
-		return;
+		return TRUE;
 
 	inside_editing = TRUE;
 
@@ -353,6 +357,24 @@
 	col = sheet->edit_pos.col;
 	row = sheet->edit_pos.row;
 
+        /* don't edit a locked cell */
+        /* TODO : extend this to disable edits that can not succeed
+         * like editing a single cell of an array.  I think we have enough
+         * information if we look at the selection.
+         */
+        if (wb_view_is_protected (wbv, TRUE) &&
+            mstyle_get_content_locked (sheet_style_get (sheet, col, row))) {
+                char *pos =  g_strdup_printf ( _("%s!%s is locked"),
+		        sheet->name_quoted, cell_coord_name (col, row));
+                gnumeric_error_invalid (COMMAND_CONTEXT (wbcg), pos,
+			wb_view_is_protected (wbv, FALSE)
+			 ? _("Unprotect the workbook to enable editing.")
+			 : _("Unprotect the sheet to enable editing."));
+                inside_editing = FALSE;
+                g_free (pos);
+                return FALSE;
+        }
+
 	application_clipboard_unant ();
 	workbook_edit_set_sensitive (wbcg, TRUE, FALSE);
 
@@ -407,7 +429,7 @@
 	 * If this assert fails, it means editing was not shut down
 	 * properly before
 	 */
-	g_assert (wbcg->edit_line.signal_changed == -1);
+	g_return_val_if_fail (wbcg->edit_line.signal_changed == -1, TRUE);
 	wbcg->edit_line.signal_changed = gtk_signal_connect (
 		GTK_OBJECT (wbcg_get_entry (wbcg)), "changed",
 		GTK_SIGNAL_FUNC (entry_changed), wbcg);
@@ -416,6 +438,7 @@
 		g_free (text);
 
 	inside_editing = FALSE;
+	return TRUE;
 }
 
 GnumericExprEntry *
diff -urN --ignore-space-change gnumeric-1.0.8/src/workbook-edit.h gnumeric-1.0.8-patched/src/workbook-edit.h
--- gnumeric-1.0.8/src/workbook-edit.h	Sun Nov 11 01:18:57 2001
+++ gnumeric-1.0.8-patched/src/workbook-edit.h	Thu Jun 20 14:30:54 2002
@@ -8,7 +8,7 @@
 void	 wbcg_edit_ctor	  (WorkbookControlGUI *wbcg);
 void	 wbcg_edit_dtor	  (WorkbookControlGUI *wbcg);
 gboolean wbcg_edit_finish (WorkbookControlGUI *wbcg, gboolean accept);
-void     wbcg_edit_start  (WorkbookControlGUI *wbcg,
+gboolean wbcg_edit_start  (WorkbookControlGUI *wbcg,
 			   gboolean blankp, gboolean cursorp);
 
 void	    wbcg_edit_attach_guru	(WorkbookControlGUI *wbcg, GtkWidget *guru);
diff -urN --ignore-space-change gnumeric-1.0.8/src/workbook-view.c gnumeric-1.0.8-patched/src/workbook-view.c
--- gnumeric-1.0.8/src/workbook-view.c	Sun Jun  2 02:08:33 2002
+++ gnumeric-1.0.8-patched/src/workbook-view.c	Thu Jun 20 14:42:32 2002
@@ -117,6 +117,15 @@
 		wb_control_sheet_add (control, new_sheet););
 }
 
+gboolean
+wb_view_is_protected (WorkbookView *wbv, gboolean check_sheet)
+{
+	g_return_val_if_fail (IS_WORKBOOK_VIEW (wbv), FALSE);
+
+	return wbv->is_protected || (check_sheet &&
+			wbv->current_sheet != NULL && wbv->current_sheet->is_protected);
+}
+
 void
 wb_view_set_attribute_list (WorkbookView *wbv, GList *list)
 {
diff -urN --ignore-space-change gnumeric-1.0.8/src/workbook-view.h gnumeric-1.0.8-patched/src/workbook-view.h
--- gnumeric-1.0.8/src/workbook-view.h	Thu Jan 31 04:11:27 2002
+++ gnumeric-1.0.8-patched/src/workbook-view.h	Thu Jun 20 14:44:21 2002
@@ -18,6 +18,7 @@
 	gboolean   show_vertical_scrollbar;
 	gboolean   show_notebook_tabs;
 	gboolean   do_auto_completion;
+	gboolean   is_protected;
 
 	/* Non-normative size information */
 	int preferred_width, preferred_height;
@@ -57,6 +58,7 @@
 Sheet		*wb_view_cur_sheet	  (WorkbookView *wbv);
 void		 wb_view_sheet_focus	  (WorkbookView *wbv, Sheet *sheet);
 void		 wb_view_sheet_add	  (WorkbookView *wbv, Sheet *new_sheet);
+gboolean	 wb_view_is_protected	  (WorkbookView *wbv, gboolean check_sheet);
 
 /* Manipulation */
 GtkArg		*wb_view_get_attributev	  (WorkbookView *wbv, guint *n_args);


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