[PATCH] Scaffold -- Added tooltips and file modified flag into document-manager



Hi all,


Some more things for Scaffold:

* Added tooltips to document-manager tabs that show the full filename.
* Added a simple modified flag ('*') to document-manager tab when a file
is modified.


Review my TODO and XXX comments and tell me what you think!



Regards,
Rui Lopes

# * Added tooltips to document-manager tabs that show the full filename.
# * Added a simple modified flag ('*') to document-manager tab when a file
#   is modified.
# -- Rui Lopes <rui ruilopes com>
Index: plugins/document-manager/scaffold-document-manager.c
===================================================================
RCS file: /cvs/gnome/scaffold/plugins/document-manager/scaffold-document-manager.c,v
retrieving revision 1.32
diff -u -r1.32 scaffold-document-manager.c
--- plugins/document-manager/scaffold-document-manager.c	8 Aug 2003 20:44:19 -0000	1.32
+++ plugins/document-manager/scaffold-document-manager.c	3 Sep 2003 15:43:57 -0000
@@ -61,6 +61,8 @@
 	GHashTable *verbs;
 
 	GConfClient *client;
+
+	GtkTooltips *tooltips;
 };
 
 typedef struct {
@@ -86,6 +88,8 @@
 				    const char *uri, 
 				    gpointer data);
 static void docman_doc_destroy (GtkWidget *widget, gpointer data);
+static void document_modified (GtkWidget *widget, gpointer data);
+static void document_unmodified (GtkWidget *widget, gpointer data);
 static void set_current_document (ScaffoldNotebookDocumentManager *docman,
 				  ScaffoldDocument *doc);
 static void load_new_menu (ScaffoldNotebookDocumentManager *docman);
@@ -101,7 +105,7 @@
 	ScaffoldNotebookDocumentManager *dm;
 
 	dm = g_object_new (SCAFFOLD_TYPE_NOTEBOOK_DOCUMENT_MANAGER, NULL);
-
+ 
 	dm->ui_container = ui_container;
 	dm->ui_component = ui_component;
 
@@ -141,6 +145,7 @@
 {
 	gchar *basename;
 	GdkPixbuf *pixbuf;
+	GtkWidget *tooltip;
 	GtkWidget *label;
 	GtkWidget *icon;
 
@@ -154,6 +159,11 @@
 	gtk_label_set_text (GTK_LABEL (label), basename);
 	g_free (basename);
 
+	tooltip = g_object_get_data (G_OBJECT (document), 
+				   "ScaffoldNotebookDocumentManager::tooltip"); /* XXX: Another name for this? */
+	/* TODO: Make filename absolute */
+	gtk_tooltips_set_tip (docman->priv->tooltips, tooltip, filename, NULL);
+
 	pixbuf = gdl_icons_get_uri_icon (docman->priv->icons, filename);
 	icon = g_object_get_data (G_OBJECT (document),
 				  "ScaffoldNotebookDocumentManager::icon");
@@ -177,6 +187,7 @@
 			docman->priv->untitled_count--;
 		}
 
+		/* TODO: disconnect our document_(un)modified from document here? */
 		g_signal_emit_by_name (docman, "document_removed", document);
 
 		docman->documents = 
@@ -269,6 +280,7 @@
 static void
 add_doc (ScaffoldNotebookDocumentManager *docman, ScaffoldDocument *document)
 {
+	GtkWidget *event_box;
 	GtkWidget *tab_hbox;
 	GtkWidget *label;
 	GtkWidget *button;
@@ -289,7 +301,7 @@
 	if (uri) {
 		label_str = g_path_get_basename (uri);
 	} else {
-		label_str = g_strdup_printf ("Untitled %ld", ++docman->priv->untitled_count);
+		label_str = g_strdup_printf (_("Untitled %ld"), ++docman->priv->untitled_count);
 		SCAFFOLD_BONOBO_DOCUMENT (document)->untitled = TRUE;
 	}
 
@@ -318,7 +330,12 @@
 
 	g_free (label_str);
 
-	/* Build the tab widget close button */
+	/* Build the tab widgets and tooltip */
+	event_box = gtk_event_box_new ();
+	g_object_set_data (G_OBJECT (document),
+			   "ScaffoldNotebookDocumentManager::tooltip", /* XXX: Another name for this? */
+			   event_box);
+
 	tab_hbox = gtk_hbox_new (FALSE, 2);
 	pixmap = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);;
 	button = gtk_button_new ();
@@ -335,12 +352,14 @@
 	gtk_box_pack_start (GTK_BOX (tab_hbox), label, TRUE, FALSE, 0);
 	gtk_box_pack_end (GTK_BOX (tab_hbox), button, FALSE, FALSE, 0);
 
-	gtk_widget_show_all (tab_hbox);
+	gtk_container_add (GTK_CONTAINER (event_box), tab_hbox);
+	gtk_widget_show_all (event_box);
 
 	gtk_notebook_append_page (GTK_NOTEBOOK (docman),
-				  GTK_WIDGET (document), tab_hbox);
+				  GTK_WIDGET (document), event_box);
 	
 	/* Listen for changes */
+	/* XXX: Why connect'ing to "(un)modifed" signals here? if we are (de)connecting on set_current_document? */
 	g_signal_connect (document, "modified", 
 			  G_CALLBACK (docman_doc_modified), 
 			  docman);
@@ -350,7 +369,14 @@
 	g_signal_connect (document, "uri_changed",
 			  G_CALLBACK (docman_doc_uri_changed),
 			  docman);
-	
+
+	/* Make necessary document connections for changing tab appearance when the file is (un)modified. */
+	g_signal_connect (document, "modified", 
+			  G_CALLBACK (document_modified), 
+			  document);
+	g_signal_connect (document, "unmodified",
+			  G_CALLBACK (document_unmodified),
+			  document);
 
 	g_signal_connect (G_OBJECT(document), "destroy",
 			  G_CALLBACK (docman_doc_destroy),
@@ -410,6 +436,11 @@
 		g_list_free (docman->documents);
 		docman->documents = NULL;
 	}
+
+	if (docman->priv->tooltips) {
+		g_object_unref (docman->priv->tooltips);
+		docman->priv->tooltips = NULL; /* XXX: Why is this needed? */
+	}
 }
 
 static void
@@ -552,6 +583,10 @@
 			  "activate",
 			  G_CALLBACK (docman_recent_files),
 			  dm);
+
+	dm->priv->tooltips = gtk_tooltips_new ();
+	g_object_ref (G_OBJECT (dm->priv->tooltips)); /* XXX: maybe just add the tooltips widget to the notebook? */
+	gtk_object_sink (GTK_OBJECT (dm->priv->tooltips)); /* don't forget to remove the unref from docman_dispose! */
 }
 
 static void
@@ -571,7 +606,7 @@
 		(SCAFFOLD_DOCUMENT_MANAGER (docman), page_num);
 	
 	if (!document) {
-		g_warning ("Couldn't find document\n");
+		g_warning ("Couldn't find document\n"); /* XXX: gettext it? */
 		return;
 	}
 	
@@ -693,6 +728,50 @@
 }
 
 static void
+document_modified (GtkWidget *widget, gpointer data)
+{
+	ScaffoldDocument *document;
+	GtkWidget *label;
+	const gchar *str;
+	const gchar *new_str;
+
+	g_assert (SCAFFOLD_IS_DOCUMENT (data));
+
+	document = SCAFFOLD_DOCUMENT (data);
+	label = g_object_get_data (G_OBJECT (document), 
+				    "ScaffoldNotebookDocumentManager::label");
+	str = gtk_label_get_label (GTK_LABEL (label));
+
+	new_str = g_strdup_printf ("%s*", str);
+	gtk_label_set_label (GTK_LABEL (label), new_str);
+	g_free ((void*) new_str);
+}
+
+static void
+document_unmodified (GtkWidget *widget, gpointer data)
+{
+	ScaffoldDocument *document;
+	GtkWidget *label;
+	const gchar *str;
+	const gchar *new_str;
+	int length;
+
+	g_assert (SCAFFOLD_IS_DOCUMENT (data));
+
+	document = SCAFFOLD_DOCUMENT (data);
+	label = g_object_get_data (G_OBJECT (document), 
+				    "ScaffoldNotebookDocumentManager::label");
+	str = gtk_label_get_label (GTK_LABEL (label));
+
+	length = strlen (str);
+	if (length > 1 && str[length-1] == '*') {
+		new_str = g_strndup (str, length-1);
+		gtk_label_set_label (GTK_LABEL (label), new_str);
+		g_free ((void*) new_str);
+	}
+}
+
+static void
 set_current_document (ScaffoldNotebookDocumentManager *docman, 
 		      ScaffoldDocument *doc)
 {
@@ -955,7 +1034,7 @@
 			     "document-preferences", NULL);
 
 	if (!gui) {
-		g_warning ("Could not load scaffold-document-manager.glade, reinstall scaffold");
+		g_warning ("Could not load scaffold-document-manager.glade, reinstall scaffold"); /* XXX: gettext it? */
 		return NULL;
 	}
 


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