Re: [Evolution-hackers] Re: [evolution-patches] new new button, context solution




uh, i dunno exactly why i moved this to hackers now, anyway, a partial patch attached.

the only issue is if you aren't looking at the given view, then it will act as it does not, the default.

*shrug*  not super clean, but it should work ... thoughts?


On Mon, 2004-04-19 at 15:47 +0800, Not Zed wrote:

Actually don't bother Dan, i think i worked it out.

Anyway - i've thought of a solution.  Basically what Dan said originally, and its the quickest/easiest way to do it.

In the New button, if you get a create event which matches the same component as the current new button widget owner, just emit a signal (or even a callback - it really should only have 1 ever ,and enforce that) instead of doing the create call.  Then you just have to have 1 per view (which i think everything does already).

The overhead is that you also need to connect to the signal and have two create calls implemented.

The only other alternative seems to be some nasty stuff done via the shell, i.e. the component tells the shell which view it is using currently so it can update the new button apropriately (for connector esp), and the createControls call also returns a tag used to identify the window.  That all seems more messy and error prone though.

On Mon, 2004-04-19 at 12:36 +0800, Not Zed wrote:
On Thu, 2004-04-08 at 16:50 -0400, Dan Winship wrote:
These patches redo the "New" button (and File->New submenu) to be
created and managed by each component rather than the shell. (This is
needed to get it to work correctly in Connector, and also moves us a
little bit more towards separate components with no shell.)

Can you explain a little why connector needed it to work like this?  Because it re-uses different views for the one component control, and needs to update the current 'new' button, right?

JP has asked me to look at the context issue, and i might look at something that addresses both problems in a cleaner way (if i get really keen, otherwise hack till it works).


Michael Zucchi <notzed ximian com>

Ximian Evolutionand Free Software Developer


Novell, Inc.
Michael Zucchi <notzed ximian com>

Ximian Evolutionand Free Software Developer


Novell, Inc.
Michael Zucchi <notzed ximian com>

Ximian Evolution and Free Software Developer


Novell, Inc.
Index: addressbook/gui/component/addressbook-view.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-view.c,v
retrieving revision 1.2
diff -u -3 -r1.2 addressbook-view.c
--- addressbook/gui/component/addressbook-view.c	15 Apr 2004 03:11:22 -0000	1.2
+++ addressbook/gui/component/addressbook-view.c	19 Apr 2004 13:34:23 -0000
@@ -1013,7 +1013,7 @@
 			  "changed",
 			  G_CALLBACK (source_list_changed_cb), view);
 
-	priv->creatable_items_handler = e_user_creatable_items_handler_new ("contacts");
+	priv->creatable_items_handler = e_user_creatable_items_handler_new ("contacts", NULL, NULL);
 
 	g_signal_connect (priv->folder_view_control, "activate",
 			  G_CALLBACK (control_activate_cb), view);
Index: calendar/gui/e-tasks.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-tasks.c,v
retrieving revision 1.85
diff -u -3 -r1.85 e-tasks.c
--- calendar/gui/e-tasks.c	18 Apr 2004 18:01:19 -0000	1.85
+++ calendar/gui/e-tasks.c	19 Apr 2004 13:34:24 -0000
@@ -450,7 +450,7 @@
 	if (ui_component) {
 		if (!tasks->priv->creatable_items_handler) {
 			tasks->priv->creatable_items_handler =
-				e_user_creatable_items_handler_new ("tasks");
+				e_user_creatable_items_handler_new ("tasks", NULL, NULL);
 		}
 		e_user_creatable_items_handler_activate (tasks->priv->creatable_items_handler, ui_component);
 	}
Index: calendar/gui/gnome-cal.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/gnome-cal.c,v
retrieving revision 1.319
diff -u -3 -r1.319 gnome-cal.c
--- calendar/gui/gnome-cal.c	14 Apr 2004 21:41:21 -0000	1.319
+++ calendar/gui/gnome-cal.c	19 Apr 2004 13:34:31 -0000
@@ -2007,7 +2007,7 @@
 	if (ui_component) {
 		if (!gcal->priv->creatable_items_handler) {
 			gcal->priv->creatable_items_handler =
-				e_user_creatable_items_handler_new ("calendar");
+				e_user_creatable_items_handler_new ("calendar", NULL, NULL);
 		}
 		e_user_creatable_items_handler_activate (gcal->priv->creatable_items_handler, ui_component);
 	}
Index: mail/mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.72
diff -u -3 -r1.72 mail-component.c
--- mail/mail-component.c	14 Apr 2004 09:48:36 -0000	1.72
+++ mail/mail-component.c	19 Apr 2004 13:34:37 -0000
@@ -81,6 +81,8 @@
 
 #define d(x) 
 
+static void create_local_item_cb(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data);
+
 #define MAIL_COMPONENT_DEFAULT(mc) if (mc == NULL) mc = mail_component_peek();
 
 #define PARENT_TYPE bonobo_object_get_type ()
@@ -551,8 +553,9 @@
 	*corba_statusbar_control = CORBA_Object_duplicate (BONOBO_OBJREF (statusbar_control), ev);
 
 	g_object_set_data_full((GObject *)view_widget, "e-creatable-items-handler",
-			       e_user_creatable_items_handler_new("mail"), (GDestroyNotify)g_object_unref);
-	
+			       e_user_creatable_items_handler_new("mail", create_local_item_cb, tree_widget),
+			       (GDestroyNotify)g_object_unref);
+
 	g_signal_connect (view_control, "activate", G_CALLBACK (view_control_activate_cb), view_widget);
 	g_signal_connect (tree_widget, "folder-selected", G_CALLBACK (folder_selected_cb), view_widget);
 
@@ -665,7 +668,7 @@
 }
 
 static void
-emc_new_folder_response(EMFolderSelector *emfs, int response, MailComponent *mc)
+emc_new_folder_response(EMFolderSelector *emfs, int response, void *dummy)
 {
 	const char *uri, *path;
 	
@@ -679,6 +682,30 @@
 	
 	if (em_folder_tree_create_folder(emfs->emft, path, uri))
 		gtk_widget_destroy((GtkWidget *)emfs);
+}
+
+static void
+create_local_item_cb(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data)
+{
+	EMFolderTree *tree = data;
+
+	printf("create local item '%s', data %p\n", item_type_name, data);
+
+	if (strcmp(item_type_name, "message") == 0) {
+		if (!em_utils_check_user_can_send_mail(NULL))
+			return;
+	
+		em_utils_compose_new_message ();
+	} else if (strcmp(item_type_name, "folder") == 0) {
+		EMFolderTree *folder_tree;
+		GtkWidget *dialog;
+		
+		folder_tree = (EMFolderTree *)em_folder_tree_new_with_model(em_folder_tree_get_model(tree));
+		dialog = em_folder_selector_create_new (folder_tree, 0, _("Create folder"), _("Specify where to create the folder:"));
+		em_folder_selector_set_selected ((EMFolderSelector *) dialog, em_folder_tree_get_selected_uri(tree));
+		g_signal_connect (dialog, "response", G_CALLBACK(emc_new_folder_response), NULL);
+		gtk_widget_show(dialog);
+	}
 }
 
 static void
Index: shell/e-user-creatable-items-handler.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-user-creatable-items-handler.c,v
retrieving revision 1.7
diff -u -3 -r1.7 e-user-creatable-items-handler.c
--- shell/e-user-creatable-items-handler.c	13 Apr 2004 10:37:19 -0000	1.7
+++ shell/e-user-creatable-items-handler.c	19 Apr 2004 13:34:38 -0000
@@ -79,6 +79,10 @@
 	/* This component's alias */
 	char *this_component;
 
+	/* For creating items on the view */
+	EUserCreatableItemsHandlerCreate create_local;
+	void *create_data;
+
 	/* The components that register user creatable items.  */
 	GSList *components;	/* Component */
 
@@ -373,18 +377,24 @@
 	if (component->type_list == NULL)
 		return;
 
+	/* TODO: why do we actually iterate this?  Is it just to check we have it in the menu?  The
+	   search isn't used otherwise */
 	for (i = 0; i < component->type_list->_length; i ++) {
 		if (strcmp (component->type_list->_buffer[i].id, id) == 0) {
-			CORBA_Environment ev;
-
-			CORBA_exception_init (&ev);
+			if (priv->create_local && priv->this_component && strcmp(priv->this_component, component->alias) == 0) {
+				priv->create_local(handler, id, priv->create_data);
+			} else {
+				CORBA_Environment ev;
+
+				CORBA_exception_init (&ev);
+				
+				GNOME_Evolution_Component_requestCreateItem (component->component, id, &ev);
 
-			GNOME_Evolution_Component_requestCreateItem (component->component, id, &ev);
+				if (ev._major != CORBA_NO_EXCEPTION)
+					g_warning ("Error in requestCreateItem -- %s", BONOBO_EX_REPOID (&ev));
 
-			if (ev._major != CORBA_NO_EXCEPTION)
-				g_warning ("Error in requestCreateItem -- %s", BONOBO_EX_REPOID (&ev));
-
-			CORBA_exception_free (&ev);
+				CORBA_exception_free (&ev);
+			}
 			return;
 		}
 	}
@@ -811,11 +821,18 @@
 
 
 EUserCreatableItemsHandler *
-e_user_creatable_items_handler_new (const char *component_alias)
+e_user_creatable_items_handler_new (const char *component_alias,
+				    EUserCreatableItemsHandlerCreate create_local, void *data)
 {
-	return g_object_new (e_user_creatable_items_handler_get_type (),
-			     "this_component", component_alias,
-			     NULL);
+	EUserCreatableItemsHandler *handler;
+
+	handler = g_object_new (e_user_creatable_items_handler_get_type (),
+				"this_component", component_alias,
+				NULL);
+	handler->priv->create_local = create_local;
+	handler->priv->create_data = data;
+
+	return handler;
 }
 
 
Index: shell/e-user-creatable-items-handler.h
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-user-creatable-items-handler.h,v
retrieving revision 1.2
diff -u -3 -r1.2 e-user-creatable-items-handler.h
--- shell/e-user-creatable-items-handler.h	9 Apr 2004 15:46:00 -0000	1.2
+++ shell/e-user-creatable-items-handler.h	19 Apr 2004 13:34:38 -0000
@@ -43,6 +43,7 @@
 typedef struct _EUserCreatableItemsHandlerPrivate EUserCreatableItemsHandlerPrivate;
 typedef struct _EUserCreatableItemsHandlerClass   EUserCreatableItemsHandlerClass;
 
+typedef void (*EUserCreatableItemsHandlerCreate)(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data);
 
 struct _EUserCreatableItemsHandler {
 	GObject parent;
@@ -56,7 +57,8 @@
 
 
 GType                       e_user_creatable_items_handler_get_type   (void);
-EUserCreatableItemsHandler *e_user_creatable_items_handler_new        (const char *component_alias);
+EUserCreatableItemsHandler *e_user_creatable_items_handler_new        (const char *component_alias,
+								       EUserCreatableItemsHandlerCreate create_local, void *data);
 
 void                        e_user_creatable_items_handler_activate   (EUserCreatableItemsHandler *handler,
 								       BonoboUIComponent          *ui_component);


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