Re: PATCH: make gnome-desktop-item-edit work



Actually there were a few more problems than that, so here's a bigger
patch that fixes some more problems and make this a little more robust.

I have also gone around and changed the window title for the launcher
properties windows to actually use the word launcher. That goes more
along with the rest of the Panel and Nautilus using "Launcher" instead
of "Menu Item". I've also capitalized the words, I hope that's ok -- I
like it better capitalized. ;)

There is a problem that I have indicated with a FIXME in the code. I
can't get the message dialog to actually show up. Anybody know how to
fix that?

If it's ok otherwise, then please commit for me. I got no CVS account.

- Frank



On Sun, 2002-04-21 at 18:39, Frank Worsley wrote:
> This small patch makes gnome-desktop-item-edit work to edit existing
> .desktop files.
> 
> - Frank
Index: gnome-desktop-item-edit.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/gnome-desktop-item-edit.c,v
retrieving revision 1.4
diff -u -r1.4 gnome-desktop-item-edit.c
--- gnome-desktop-item-edit.c	2002/03/26 04:19:39	1.4
+++ gnome-desktop-item-edit.c	2002/04/22 03:42:01
@@ -105,34 +105,31 @@
 		gnome_vfs_file_info_clear (info);
 
 		if (gnome_vfs_get_file_info
-		    (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
-			/* ok, this doesn't exist, really */
-			if (is_ext (desktops[i], ".directory")) {
+		    (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) == GNOME_VFS_OK) {
+
+			if (info->type == GNOME_VFS_FILE_TYPE_DIRECTORY && create_new) {
+				dlg = panel_new_launcher (uri);
+
+			} else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR
+				   && is_ext (desktops[i], ".directory")
+				   && !create_new) {
 				char *dirname = g_path_get_dirname (uri);
-				char *basename = g_path_get_basename (dirname);
-				dlg = panel_edit_direntry (dirname, basename);
-				g_free (basename);
+				dlg = panel_edit_direntry (dirname, NULL);
 				g_free (dirname);
-			} else {
+			
+			} else if (info->type == GNOME_VFS_FILE_TYPE_REGULAR
+				   && is_ext (desktops[i], ".desktop")
+				   && !create_new) {
 				char *dirname = g_path_get_dirname (uri);
 				dlg = panel_edit_dentry (uri, dirname);
 				g_free (dirname);
-			}
-		}
-
-		if (dlg == NULL &&
-		    info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
-			if (create_new) {
-				dlg = panel_new_launcher (uri);
+				
 			} else {
-				char *basename = g_path_get_basename (desktops[i]);
-				dlg = panel_edit_direntry (uri, basename);
-				g_free (basename);
+				fprintf (stderr, "gnome-desktop-item-edit: no file to edit\n");
+				return 0;
 			}
-		} else if (dlg == NULL) {
-			char *dirname = g_path_get_dirname (uri);
-			dlg = panel_edit_dentry (uri, dirname);
-			g_free (dirname);
+		} else {
+			fprintf (stderr, "gnome-desktop-item-edit: no file to edit\n");
 		}
 
 		if (dlg != NULL) {
Index: launcher.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/launcher.c,v
retrieving revision 1.199
diff -u -r1.199 launcher.c
--- launcher.c	2002/04/15 16:57:29	1.199
+++ launcher.c	2002/04/22 03:42:03
@@ -569,7 +569,7 @@
 
 	dialog = gtk_dialog_new ();
 
-	gtk_window_set_title (GTK_WINDOW (dialog), _("Launcher properties"));
+	gtk_window_set_title (GTK_WINDOW (dialog), _("Launcher Properties"));
 
 	help = gtk_dialog_add_button (
 			GTK_DIALOG (dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP);
@@ -758,7 +758,7 @@
 	GnomeDItemEdit *dee;
 	GnomeDesktopItem *ditem;
 
-	dialog = gtk_dialog_new_with_buttons (_("Create launcher applet"),
+	dialog = gtk_dialog_new_with_buttons (_("Create Launcher"),
 					      NULL /* parent */,
 					      0 /* flags */,
 					      GTK_STOCK_HELP,
Index: menu-ditem.c
===================================================================
RCS file: /cvs/gnome/gnome-panel/gnome-panel/menu-ditem.c,v
retrieving revision 1.7
diff -u -r1.7 menu-ditem.c
--- menu-ditem.c	2002/04/12 17:23:41	1.7
+++ menu-ditem.c	2002/04/22 03:42:03
@@ -123,8 +123,7 @@
 is_item_writable (const char *loc, const char *dir)
 {
 	if (loc != NULL) {
-		/* if old style kde link file, don't allow
-		 * editting */
+		/* if old style kde link file, don't allow editing */
 		if (is_ext (loc, ".kdelnk"))
 			return FALSE;
 		if (panel_is_uri_writable (loc))
@@ -132,9 +131,9 @@
 		else
 			return FALSE;
 	}
-
+	
 	if (dir != NULL) {
-		if (panel_is_uri_writable (loc))
+		if (panel_is_uri_writable (dir))
 			return TRUE;
 		else
 			return FALSE;
@@ -171,10 +170,10 @@
 
 	ditem = gnome_desktop_item_new_from_uri (loc,
 						 0 /* flags */,
-						 NULL /* error */);
+						 NULL /* error */);		 
 
 	/* watch the enum at the top of the file */
-	dialog = gtk_dialog_new_with_buttons (_("Desktop entry properties"),
+	dialog = gtk_dialog_new_with_buttons (_("Launcher Properties"),
 					      NULL /* parent */,
 					      0 /* flags */,
 					      GTK_STOCK_HELP,
@@ -242,15 +241,17 @@
 {
 	GtkWidget *dialog;
 	GtkWidget *dedit;
-	char *dirfile = g_build_path ("/", dir, ".directory", NULL);
 	GnomeDesktopItem *ditem;
+	char *dirfile;
+	
+	dirfile = g_strconcat (dir, "/", ".directory", NULL);
 
 	ditem = gnome_desktop_item_new_from_uri (dirfile,
 						 0 /* flags */,
 						 NULL /* error */);
 
 	/* watch the enum at the top of the file */
-	dialog = gtk_dialog_new_with_buttons (_("Desktop entry properties"),
+	dialog = gtk_dialog_new_with_buttons (_("Launcher Properties"),
 					      NULL /* parent */,
 					      0 /* flags */,
 					      GTK_STOCK_HELP,
@@ -274,8 +275,6 @@
 		g_object_set_data_full (G_OBJECT (dedit), "location",
 					g_strdup (gnome_desktop_item_get_location (ditem)),
 					(GDestroyNotify)g_free);
-		g_free (dirfile);
-		dirfile = NULL;
 	} else {
 		ditem = gnome_desktop_item_new ();
 		if (dir_name == NULL) {
@@ -294,12 +293,11 @@
 		gnome_desktop_item_set_string (ditem,
 					       GNOME_DESKTOP_ITEM_TYPE,
 					       "Directory");
-		/*we don't have to free dirfile here it will be freed as if
-		  we had strduped it here*/
+
+		/* we free dirfile below so make a copy here */
 		g_object_set_data_full (G_OBJECT (dedit),
-					"location", dirfile,
+					"location", g_strdup (dirfile),
 					(GDestroyNotify)g_free);
-		dirfile = NULL;
 		gnome_ditem_edit_set_ditem (GNOME_DITEM_EDIT (dedit), ditem);
 	}
 
@@ -333,6 +331,8 @@
 				    NULL);
 	}
 
+	g_free (dirfile);
+		
 	gtk_widget_show (dialog);
 
 	gnome_ditem_edit_grab_focus (GNOME_DITEM_EDIT (dedit));
@@ -475,8 +475,26 @@
 {
 	GtkWidget *dialog;
 	GtkWidget *dee;
+
+	if (!is_item_writable (item_loc, NULL)) {
+		dialog = gtk_message_dialog_new (NULL, /* parent */
+					 	 0,    /* flags */
+						 GTK_MESSAGE_ERROR,
+	 					 GTK_BUTTONS_OK,
+						 _("You can not create a new launcher at this location since the location is not writeable."));
+		
+		g_signal_connect (G_OBJECT (dialog), 
+				  "response", 
+				  G_CALLBACK(gtk_widget_destroy), 
+				  dialog);
+			  
+		/* FIXME: for some reason the dialog never shows up!!! */
+		gtk_widget_show_all (dialog);
+		
+		return NULL;
+	}
 
-	dialog = gtk_dialog_new_with_buttons (_("Create menu item"),
+	dialog = gtk_dialog_new_with_buttons (_("Create Launcher"),
 					      NULL /* parent */,
 					      0 /* flags */,
 					      GTK_STOCK_CANCEL,


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