[Goodies-commits] r7443 - in xfce4-notes-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Fri May 29 23:38:41 CEST 2009


Author: mmassonnet
Date: 2009-05-29 21:38:41 +0000 (Fri, 29 May 2009)
New Revision: 7443

Modified:
   xfce4-notes-plugin/trunk/ChangeLog
   xfce4-notes-plugin/trunk/panel-plugin/application.vala
   xfce4-notes-plugin/trunk/panel-plugin/note.vala
   xfce4-notes-plugin/trunk/panel-plugin/window.vala
Log:
Generate an available name for a new window/note

Modified: xfce4-notes-plugin/trunk/ChangeLog
===================================================================
--- xfce4-notes-plugin/trunk/ChangeLog	2009-05-29 17:46:32 UTC (rev 7442)
+++ xfce4-notes-plugin/trunk/ChangeLog	2009-05-29 21:38:41 UTC (rev 7443)
@@ -1,3 +1,17 @@
+2009-05-29  Mike Massonnet <mmassonnet at xfce.org>
+
+Generate an available name for a new window/note
+	* panel-plugin/application.vala, panel-plugin/window.vala:
+	  - New methods window/note_name_exists to verify if a given name is
+	  already in use.
+	  - Loop n_times+1 the length of the windows/notes to generate an
+	  available name.
+	  - On window rename, if the name is already in use popup a message
+	  dialog.
+	* panel-plugin/window.vala, panel-plugin/note.vala:
+	  - New signal in Xnp.Window save-data to proxy the same signal from
+	  the note.
+
 2009-05-24  Mike Massonnet <mmassonnet at xfce.org>
 
 Use a UI to set accelerators

Modified: xfce4-notes-plugin/trunk/panel-plugin/application.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/application.vala	2009-05-29 17:46:32 UTC (rev 7442)
+++ xfce4-notes-plugin/trunk/panel-plugin/application.vala	2009-05-29 21:38:41 UTC (rev 7443)
@@ -46,20 +46,29 @@
 		 */
 		public void create_window (string? name) {
 			var window = new Xnp.Window ();
-			this.window_list.append (window);
-			foreach (var win in this.window_list) {
-				win.set_window_list (this.window_list);
-			}
 
 			if (name == null) {
-				uint len = this.window_list.length ();
-				if (len > 1)
-					window.name = "Notes %u".printf (len);
+				string window_name = "Notes";
+				int len = (int)this.window_list.length ();
+				for (int id = 1; id <= len + 1; id++) {
+					if (id > 1) {
+						window_name = "Notes %d".printf (id);
+					}
+					if (!window_name_exists (window_name)) {
+						break;
+					}
+				}
+				window.name = window_name;
 			}
 			else {
 				window.name = name;
 			}
 
+			this.window_list.append (window);
+			foreach (var win in this.window_list) {
+				win.set_window_list (this.window_list);
+			}
+
 			this.load_window_data (window);
 
 			window.action += (win, action) => {
@@ -73,6 +82,9 @@
 					create_window (null);
 				}
 			};
+			window.save_data += (win, note) => {
+				debug ("save-data on %s::%s", win.name, note.name);
+			};
 
 			window.show ();
 		}
@@ -95,7 +107,7 @@
 		 */
 		private void rename_window (Xnp.Window window) {
 			var dialog = new Gtk.Dialog.with_buttons ("Rename group", window,
-				Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
+				Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
 				Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
 			dialog.set_default_response (Gtk.ResponseType.OK);
 			dialog.resizable = false;
@@ -111,15 +123,25 @@
 
 			int res = dialog.run ();
 			dialog.hide ();
-			if (res == Gtk.ResponseType.OK)
-				window.name = entry.text;
+			if (res == Gtk.ResponseType.OK) {
+				string name = entry.text;
+				if (window_name_exists (name)) {
+					var error_dialog = new Gtk.MessageDialog (window, Gtk.DialogFlags.DESTROY_WITH_PARENT,
+						Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "The name %s is already in use", name);
+					error_dialog.run ();
+					error_dialog.destroy ();
+				}
+				else {
+					window.name = name;
+				}
+			}
 			dialog.destroy ();
 		}
 
 		/**
 		 * delete_window:
 		 *
-		 * Delte the window.
+		 * Delete the window.
 		 */
 		private void delete_window (Xnp.Window window) {
 			this.window_list.remove (window);
@@ -135,7 +157,20 @@
 			}
 		}
 
-/**/
+		/**
+		 * window_name_exists:
+		 *
+		 * Verify if the given name already exists in the window list.
+		 */
+		private bool window_name_exists (string name) {
+			foreach (var win in this.window_list) {
+				if (win.name == name) {
+					return true;
+				}
+			}
+			return false;
+		}
+
 	}
 
 }

Modified: xfce4-notes-plugin/trunk/panel-plugin/note.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/note.vala	2009-05-29 17:46:32 UTC (rev 7442)
+++ xfce4-notes-plugin/trunk/panel-plugin/note.vala	2009-05-29 21:38:41 UTC (rev 7443)
@@ -25,11 +25,11 @@
 	public class Note : Gtk.Bin {
 
 		public new string name { get; set; }
-		private uint timeout;
+		private uint save_timeout;
 		public Gtk.ScrolledWindow scrolled_window;
 		public Xnp.HypertextView text_view;
 
-		public signal void save_data (string name);
+		public signal void save_data ();
 
 		public Note (string name) {
 			this.name = name;
@@ -53,8 +53,8 @@
 		}
 
 		~Note () {
-			if (this.timeout != 0)
-				Source.remove (this.timeout);
+			if (this.save_timeout != 0)
+				Source.remove (this.save_timeout);
 		}
 
 		public override void size_request (ref Gtk.Requisition requisition) {
@@ -83,16 +83,16 @@
 		/**
 		 * buffer_changed_cb:
 		 *
-		 * Reset the timeout as long as the buffer is under constant
+		 * Reset the save_timeout as long as the buffer is under constant
 		 * changes and send the save-data signal.
 		 */
 		private void buffer_changed_cb () {
-			if (this.timeout > 0) {
-				Source.remove (this.timeout);
+			if (this.save_timeout > 0) {
+				Source.remove (this.save_timeout);
 			}
-			this.timeout = Timeout.add_seconds (60, () => {
-				save_data (name);
-				timeout = 0;
+			this.save_timeout = Timeout.add_seconds (60, () => {
+				save_data ();
+				this.save_timeout = 0;
 				return false;
 			});
 		}

Modified: xfce4-notes-plugin/trunk/panel-plugin/window.vala
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/window.vala	2009-05-29 17:46:32 UTC (rev 7442)
+++ xfce4-notes-plugin/trunk/panel-plugin/window.vala	2009-05-29 21:38:41 UTC (rev 7443)
@@ -107,6 +107,7 @@
 		}
 
 		public signal void action (string action);
+		public signal void save_data (Xnp.Note note);
 
 		construct {
 			base.name = "xfce4-notes-plugin";
@@ -819,12 +820,22 @@
 		 * the current position.
 		 */
 		public Xnp.Note insert_note () {
+			int len = this.notebook.get_n_pages ();
+			string name = "Notes";
+			for (int id = 1; id <= len + 1; id++) {
+				if (id > 1) {
+					name = "Notes %d".printf (id);
+				}
+				if (!note_name_exists (name)) {
+					break;
+				}
+			}
+
 			int page = this.notebook.get_current_page () + 1;
-			string name = "Notes";
 			var note = new Xnp.Note (name);
 
 			note.notify += note_notify;
-			note.save_data += (o, n) => { print ("note `%s' save-data\n", n); };
+			note.save_data += (note) => { save_data (note); };
 
 			note.show ();
 			this.notebook.insert_page (note, null, page);
@@ -875,7 +886,7 @@
 			var note = (Xnp.Note)(this.notebook.get_nth_page (page));
 
 			var dialog = new Gtk.Dialog.with_buttons ("Rename note", (Gtk.Window)get_toplevel (),
-				Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT,
+				Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT|Gtk.DialogFlags.NO_SEPARATOR,
 				Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK);
 			dialog.set_default_response (Gtk.ResponseType.OK);
 			dialog.resizable = false;
@@ -917,6 +928,22 @@
 			dialog.destroy ();
 		}
 
+		/**
+		 * note_name_exists:
+		 *
+		 * Verify if the given name already exists in the notebook.
+		 */
+		private bool note_name_exists (string name) {
+			int n_pages = this.notebook.get_n_pages ();
+			for (int p = 0; p < n_pages; p++) {
+				var note = (Xnp.Note)this.notebook.get_nth_page (p);
+				if (note.name == name) {
+					return true;
+				}
+			}
+			return false;
+		}
+
 /*
 		static int main (string[] args) {
 			Gtk.init (ref args);




More information about the Goodies-commits mailing list