From 5cd0eeb455d1a1dc28ab5623e542d0b60f1ca15c Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 12 Feb 1999 02:15:17 +0000 Subject: [PATCH] 1999-02-11 Federico Mena Quintero * gdesktop-icon.c (set_icon): Do not destroy the image if it is the same as the old one. Sigh, imlib really needs proper refcounting. * gscreen.c: Use gpopup_do_popup() until the new version is finished. * gpopup2.c (create_actions): Made the action selection logic simpler. (gpopup_do_popup2): Now can only operate on panels. (file_actions): Sanitized the actions a bit. * gutil.c (my_system_get_child_pid): sa_handler must be gnome_sigchld_handler, not gnome_sigchld_installed. * gpopup.c (dicon_properties): Do not call reread_cmd(). This is a hack until the menus for panels/desktop are finished. * gscreen.c (panel_file_list_press_row): Use gpopup_do_popup2(). --- gnome/ChangeLog | 23 +++++- gnome/gdesktop-icon.c | 2 +- gnome/gpopup.c | 1 + gnome/gpopup.h | 5 +- gnome/gpopup2.c | 173 ++++++++++++++++-------------------------- gnome/gscreen.c | 11 ++- gnome/gutil.c | 2 +- 7 files changed, 101 insertions(+), 116 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index ae2146176..c2a1ed531 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,25 @@ +1999-02-11 Federico Mena Quintero + + * gdesktop-icon.c (set_icon): Do not destroy the image if it is + the same as the old one. Sigh, imlib really needs proper + refcounting. + + * gscreen.c: Use gpopup_do_popup() until the new version is + finished. + + * gpopup2.c (create_actions): Made the action selection logic + simpler. + (gpopup_do_popup2): Now can only operate on panels. + (file_actions): Sanitized the actions a bit. + + * gutil.c (my_system_get_child_pid): sa_handler must be + gnome_sigchld_handler, not gnome_sigchld_installed. + + * gpopup.c (dicon_properties): Do not call reread_cmd(). This is + a hack until the menus for panels/desktop are finished. + + * gscreen.c (panel_file_list_press_row): Use gpopup_do_popup2(). + 1999-02-11 Miguel de Icaza * gutil.c (my_system_get_child_pid): Implement a erase-temp-file @@ -88,7 +110,6 @@ scan_begin and scan_end signals of the tree -- these will set the cursor to a watch while the tree is being scanned. ->>>>>>> 1.321 1999-02-08 Miguel de Icaza * gdesktop.c (desktop_icon_info_destroy): Delete the metadata diff --git a/gnome/gdesktop-icon.c b/gnome/gdesktop-icon.c index 3dc12f937..33dcd05ac 100644 --- a/gnome/gdesktop-icon.c +++ b/gnome/gdesktop-icon.c @@ -201,7 +201,7 @@ set_icon (DesktopIcon *dicon, GdkImlibImage *im) "height", (double) im->rgb_height, NULL); - if (old_im) + if (old_im != im) gdk_imlib_destroy_image (old_im); } diff --git a/gnome/gpopup.c b/gnome/gpopup.c index c2ea663d6..4a4de8bc9 100644 --- a/gnome/gpopup.c +++ b/gnome/gpopup.c @@ -103,6 +103,7 @@ dicon_properties (GtkWidget *widget, DesktopIconInfo *dii) gtk_widget_destroy (dlg); g_free(path); + if (retval) reread_cmd (); } diff --git a/gnome/gpopup.h b/gnome/gpopup.h index 6f91d7a7b..acf391939 100644 --- a/gnome/gpopup.h +++ b/gnome/gpopup.h @@ -13,9 +13,8 @@ #include #include "panel.h" #include "gdesktop.h" -int gpopup_do_popup2 (GdkEventButton *event, - WPanel *panel, GList *file_list, - gboolean on_selected); + +int gpopup_do_popup2 (GdkEventButton *event, WPanel *panel); int gpopup_do_popup (GdkEventButton *event, WPanel *from_panel, DesktopIconInfo *dii, diff --git a/gnome/gpopup2.c b/gnome/gpopup2.c index cd807de9a..6e7295b65 100644 --- a/gnome/gpopup2.c +++ b/gnome/gpopup2.c @@ -25,28 +25,29 @@ #include "gnome-file-property-dialog.h" #define CLIST_FROM_SW(panel_list) GTK_CLIST (GTK_BIN (panel_list)->child) -/* Flags for the popup menu entries. They specify to which kinds of files an entry is valid for. */ +/* Flags for the popup menu entries. They specify to which kinds of files an + * entry is valid for. + */ enum { F_ALL = 1 << 0, /* Applies to all files */ F_REGULAR = 1 << 1, /* Applies only to regular files */ - F_SYMLINK = 1 << 2, /* Applies only to symlink */ - F_SINGLE = 1 << 3, /* Applies only to a single file, not to a multiple selection */ + F_SYMLINK = 1 << 2, /* Applies only to symlinks */ + F_SINGLE = 1 << 3, /* Applies only to a single file, not to multiple files */ F_NOTDIR = 1 << 4, /* Applies to non-directories */ F_DICON = 1 << 5, /* Applies only to desktop icons */ - F_NOTDEV = 1 << 6, /* Applies to non-devices only (ie. reg, lnk, dir) */ - F_ADVANCED = 1 << 7 /* Only appears in (non-existent) Advanced mode */ + F_NOTDEV = 1 << 6, /* Applies to non-devices only (ie. reg, lnk, dir) */ + F_ADVANCED = 1 << 7 /* Only appears in advanced mode */ }; /* typedefs */ -typedef struct action { +struct action { char *text; /* Menu item text */ int flags; /* Flags from the above enum */ gpointer callback; /* Callback for menu item */ -} action; +}; -/* Prototypes */ /* Multiple File commands */ -static void panel_action_with (GtkWidget *widget, WPanel *panel); +static void panel_action_open_with (GtkWidget *widget, WPanel *panel); static void handle_open (GtkWidget *widget, WPanel *panel); static void handle_view (GtkWidget *widget, WPanel *panel); static void handle_view_unfiltered (GtkWidget *widget, WPanel *panel); @@ -71,11 +72,9 @@ static void handle_logout (GtkWidget *widget, WPanel *panel); /* global vars */ extern int we_can_afford_the_speed; -static action file_actions[] = { - { N_("Properties"), F_SINGLE | F_ALL, handle_properties }, - { "", F_SINGLE | F_ALL, NULL }, - { N_("Open"), F_NOTDEV, handle_open }, - { "", F_NOTDEV, NULL }, +static struct action file_actions[] = { + { N_("Open"), F_NOTDEV, handle_open }, + { "", F_NOTDEV, NULL }, { N_("Open with..."), F_REGULAR | F_SINGLE, handle_open_with }, { N_("View"), F_REGULAR | F_SINGLE, handle_view }, { N_("View Unfiltered"), F_REGULAR | F_ADVANCED | F_SINGLE, handle_view_unfiltered }, @@ -84,13 +83,15 @@ static action file_actions[] = { { N_("Copy..."), F_ALL, handle_copy }, { N_("Delete"), F_ALL, handle_delete }, { N_("Move..."), F_ALL, handle_move }, - { "", F_SINGLE, NULL }, { N_("Hard Link..."), F_ADVANCED | F_SINGLE, handle_hard_link }, - { N_("Link..."), F_SINGLE, handle_symlink }, + { N_("Symlink..."), F_SINGLE, handle_symlink }, { N_("Edit Symlink..."), F_SYMLINK | F_SINGLE, handle_edit_symlink }, + { "", F_SINGLE | F_ALL, NULL }, + { N_("Properties..."), F_SINGLE | F_ALL, handle_properties }, { NULL, 0, NULL } }; +#if 0 static action generic_actions[] = { { N_("NEW(FIXME)"), F_ALL, NULL }, { "", F_ALL, NULL }, @@ -101,7 +102,7 @@ static action generic_actions[] = { { N_("Logout"), F_DICON, handle_logout }, { NULL, 0, NULL } }; - +#endif /* This is our custom signal connection function for popup menu items -- see below for the * marshaller information. We pass the original callback function as the data pointer for the @@ -178,42 +179,20 @@ fill_menu (GtkMenuShell *menu_shell, GnomeUIInfo *uiinfo, int pos) /* Creates the menu items for the standard actions. Returns the position at * which additional menu items should be inserted. */ -static int -create_actions (GtkWidget *menu, gint flags, gboolean on_selected, WPanel *panel) +static void +create_actions (GtkWidget *menu, gint flags, WPanel *panel) { struct action *action; - gint pos = 0; - gint error_correction; + int pos; GnomeUIInfo uiinfo[] = { { 0 }, GNOMEUIINFO_END }; - if (on_selected) - action = file_actions; - else - action = generic_actions; + pos = 0; - - for (;action->text; action++) { - error_correction = 0; - /* Let's see if we want this particular entry */ - /* we need to special-case F_SINGLE */ - if (action->flags & F_SINGLE) { - if (!(flags & F_SINGLE)) - continue; - else if (action->flags != F_SINGLE) - error_correction |= F_SINGLE; - } - /* same with advanced */ - if (action->flags & F_ADVANCED) { - if (!(flags & F_ADVANCED)) - continue; - else - error_correction |= F_ADVANCED; - } - - if ((flags & (action->flags - error_correction)) == 0) + for (action = file_actions; action->text; action++) { + if ((action->flags & flags) != action->flags) continue; if (action->text[0]) { @@ -231,11 +210,8 @@ create_actions (GtkWidget *menu, gint flags, gboolean on_selected, WPanel *panel } else uiinfo[0].type = GNOME_APP_UI_SEPARATOR; - fill_menu (GTK_MENU_SHELL (menu), uiinfo, pos); - pos++; + fill_menu (GTK_MENU_SHELL (menu), uiinfo, pos++); } - - return pos; } /* Convenience callback to exit the main loop of a modal popup menu when it is deactivated*/ @@ -262,81 +238,62 @@ get_active_index (GtkMenu *menu) return -1; } -/* Create a context menu. It can take either a WPanel or a GnomeDesktopEntry. - * One of them should be set to NULL. - */ #define REMOVE(x,f) x &= ~f int -gpopup_do_popup2 (GdkEventButton *event, - WPanel *panel, GList *file_list, - gboolean on_selected) +gpopup_do_popup2 (GdkEventButton *event, WPanel *panel) { GtkWidget *menu; - GList *list; gint flags = F_ALL | F_REGULAR | F_SYMLINK | F_SINGLE | F_NOTDEV | F_NOTDIR; struct stat s; guint id; - gint i; - gint count = 0; + int i; + int marked; g_return_val_if_fail (event != NULL, -1); + g_return_val_if_fail (panel != NULL, -1); menu = gtk_menu_new (); - /* Connect to the deactivation signal to be able to quit our - modal main loop */ + /* Connect to the deactivation signal to be able to quit our modal main + * loop. + */ id = gtk_signal_connect (GTK_OBJECT (menu), "deactivate", (GtkSignalFunc) menu_shell_deactivated, NULL); - if (file_list == NULL) { - /* make the file list */ - for (i = 0; i < panel->count; i++) { - if (!strcmp (panel->dir.list [i].fname, "..")) { - continue; - } - if (panel->dir.list [i].f.marked) { - s.st_mode = panel->dir.list[i].buf.st_mode; - /* do flag stuff */ - if (S_ISLNK (s.st_mode)) - mc_stat (panel->dir.list [i].fname, &s); - else - REMOVE (flags, F_SYMLINK); - if (S_ISDIR (s.st_mode)) - REMOVE (flags, F_NOTDIR); - if (!S_ISREG (s.st_mode)) - REMOVE (flags, F_REGULAR); - if (count == 1) - REMOVE (flags, F_SINGLE); - if (!S_ISREG (s.st_mode) && !S_ISDIR (s.st_mode)) - REMOVE (flags, F_NOTDEV); - count++; - } - } - } else { - /* we already have the file list, but we need to create the flags */ - for (list = file_list; list; list = list->next) { - mc_lstat (list->data, &s); - if (S_ISLNK (s.st_mode)) - mc_stat (list->data, &s); - else - REMOVE (flags, F_SYMLINK); - - if (S_ISDIR (s.st_mode)) - REMOVE (flags, F_NOTDIR); - if (!S_ISREG (s.st_mode)) - REMOVE (flags, F_REGULAR); - if (count == 1) - REMOVE (flags, F_SINGLE); - if (!S_ISREG (s.st_mode) && !S_ISDIR (s.st_mode)) - REMOVE (flags, F_NOTDEV); - count++; - } + marked = 0; + + for (i = 0; i < panel->count; i++) { + if (!strcmp (panel->dir.list [i].fname, "..") || !panel->dir.list[i].f.marked) + continue; + + marked++; + + s = panel->dir.list[i].buf; + + if (S_ISLNK (s.st_mode)) + mc_stat (panel->dir.list [i].fname, &s); + else + REMOVE (flags, F_SYMLINK); + + if (S_ISDIR (s.st_mode)) + REMOVE (flags, F_NOTDIR); + + if (!S_ISREG (s.st_mode)) + REMOVE (flags, F_REGULAR); + + if (S_ISCHR (s.st_mode) || S_ISBLK (s.st_mode)) + REMOVE (flags, F_NOTDEV); } + g_assert (marked > 0); + + if (marked > 1) + REMOVE (flags, F_SINGLE); + /* Fill the menu */ - create_actions (menu, flags, on_selected, panel); + create_actions (menu, flags, panel); /* Run it */ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); @@ -345,8 +302,10 @@ gpopup_do_popup2 (GdkEventButton *event, gtk_grab_remove (menu); gtk_signal_disconnect (GTK_OBJECT (menu), id); - /* FIXME: FIXME: FIXME: free the stoopid memory */ - return get_active_index (GTK_MENU (menu)); + + i = get_active_index (GTK_MENU (menu)); + gtk_widget_destroy (menu); + return i; } static void @@ -439,7 +398,7 @@ static void handle_open_with (GtkWidget *widget, WPanel *panel) { char *command; - + command = input_expand_dialog (_(" Open with..."), _("Enter extra arguments:"), panel->dir.list [panel->selected].fname); diff --git a/gnome/gscreen.c b/gnome/gscreen.c index 887cfc834..54a842d5a 100644 --- a/gnome/gscreen.c +++ b/gnome/gscreen.c @@ -470,7 +470,8 @@ panel_file_list_press_row (GtkWidget *file_list, GdkEvent *event, WPanel *panel) event->button.x, event->button.y, &row, &column); gtk_clist_select_row (GTK_CLIST (file_list), row, 0); - gpopup_do_popup ((GdkEventButton *) event, panel, NULL, row, panel->dir.list[row].fname); + gpopup_do_popup ((GdkEventButton *) event, panel, NULL, + row, panel->dir.list[row].fname); } return TRUE; } @@ -1365,7 +1366,8 @@ panel_icon_list_select_icon (GtkWidget *widget, int index, GdkEvent *event, WPan switch (event->type){ case GDK_BUTTON_PRESS: if (event->button.button == 3) - gpopup_do_popup2 ((GdkEventButton *) event, panel, NULL, TRUE); + gpopup_do_popup ((GdkEventButton *) event, panel, NULL, + index, panel->dir.list[index].fname); break; case GDK_BUTTON_RELEASE: @@ -1433,7 +1435,10 @@ panel_icon_list_button_press (GtkWidget *widget, GdkEventButton *event, WPanel * if (icon == -1) { if (event->button == 3) { - gpopup_do_popup2 ((GdkEventButton *) event, panel, NULL, FALSE); +#if 0 + g_warning ("FIXME: icon_list_button_press menu"); + gpopup_do_popup ((GdkEventButton *) event, panel, NULL, FALSE); +#endif return TRUE; } } else if (event->button != 3) diff --git a/gnome/gutil.c b/gnome/gutil.c index 6edd5fab6..d504e882d 100644 --- a/gnome/gutil.c +++ b/gnome/gutil.c @@ -123,7 +123,7 @@ int my_system_get_child_pid (int flags, const char *shell, const char *command, pipe (monitors); sigemptyset (&newsig.sa_mask); newsig.sa_flags = 0; - newsig.sa_handler = gnome_sigchld_installed; + newsig.sa_handler = gnome_sigchld_handler; sigaction (SIGCHLD, &newsig, &previous_sigchld); gnome_sigchld_installed = 1;