1998-11-25 06:48:20 +03:00
|
|
|
/* Popup menus for the Midnight Commander
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 The Free Software Foundation
|
|
|
|
*
|
|
|
|
* Authors: Federico Mena <federico@nuclecu.unam.mx>
|
|
|
|
* Miguel de Icaza <miguel@nuclecu.unam.mx>
|
|
|
|
*/
|
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
|
|
|
|
#include <config.h>
|
1999-01-27 04:14:57 +03:00
|
|
|
#include "global.h"
|
1999-02-06 03:11:39 +03:00
|
|
|
#include <gnome.h>
|
1998-12-01 09:23:50 +03:00
|
|
|
#include "panel.h"
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
#include "ext.h"
|
|
|
|
#include "gpageprop.h"
|
|
|
|
#include "gpopup.h"
|
|
|
|
#include "main.h"
|
1999-01-21 22:29:39 +03:00
|
|
|
#include "gnome-file-property-dialog.h"
|
1998-12-01 09:23:50 +03:00
|
|
|
#define CLIST_FROM_SW(panel_list) GTK_CLIST (GTK_BIN (panel_list)->child)
|
|
|
|
|
|
|
|
|
1999-01-28 08:48:02 +03:00
|
|
|
extern int we_can_afford_the_speed;
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
/* 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 symlinks */
|
|
|
|
F_SINGLE = 1 << 3, /* Applies only to a single file, not to a multiple selection */
|
|
|
|
F_NOTDIR = 1 << 4, /* Applies to non-directories */
|
|
|
|
F_DICON = 1 << 5, /* Applies to desktop icons */
|
1999-02-17 05:18:12 +03:00
|
|
|
F_PANEL = 1 << 6, /* Applies to files from a panel window */
|
|
|
|
F_MOUNTABLE = 1 << 7, /* Only if the device is mountable */
|
1999-02-17 19:32:12 +03:00
|
|
|
F_UNMOUNTABLE = 1 << 8, /* Only if the device is unmountable */
|
1999-02-26 01:03:09 +03:00
|
|
|
F_EJECTABLE = 1 << 9, /* Only if the device is ejectable */
|
|
|
|
F_LOCAL = 1 << 10 /* File must be on a local file system */
|
1998-12-02 09:33:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct action {
|
|
|
|
char *text; /* Menu item text */
|
|
|
|
int flags; /* Flags from the above enum */
|
|
|
|
GtkSignalFunc callback; /* Callback for menu item */
|
|
|
|
};
|
1998-12-01 09:23:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
panel_action_open_with (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
|
|
|
char *command;
|
|
|
|
|
|
|
|
command = input_expand_dialog (_(" Open with..."),
|
|
|
|
_("Enter extra arguments:"), panel->dir.list [panel->selected].fname);
|
|
|
|
if (!command)
|
|
|
|
return;
|
|
|
|
execute (command);
|
1999-01-27 04:14:57 +03:00
|
|
|
g_free (command);
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
panel_action_open (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
|
|
|
if (do_enter (panel))
|
|
|
|
return;
|
|
|
|
panel_action_open_with (widget, panel);
|
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-01 09:23:50 +03:00
|
|
|
panel_action_view (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
|
|
|
view_cmd (panel);
|
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-01 09:23:50 +03:00
|
|
|
panel_action_view_unfiltered (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
|
|
|
view_simple_cmd (panel);
|
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-01 09:23:50 +03:00
|
|
|
panel_action_edit (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
1999-02-12 05:42:42 +03:00
|
|
|
char *full = g_concat_dir_and_file (panel->cwd, selection (panel)->fname);
|
|
|
|
|
1999-03-11 05:40:53 +03:00
|
|
|
gmc_edit (full);
|
1999-02-12 05:42:42 +03:00
|
|
|
g_free (full);
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
/* Pops up the icon properties pages */
|
1999-01-02 21:41:59 +03:00
|
|
|
static void
|
|
|
|
dicon_properties (GtkWidget *widget, DesktopIconInfo *dii)
|
1998-12-22 02:29:46 +03:00
|
|
|
{
|
1999-01-21 22:29:39 +03:00
|
|
|
int retval = 1;
|
1998-12-30 05:51:01 +03:00
|
|
|
char *path;
|
1999-01-21 22:29:39 +03:00
|
|
|
GtkWidget *dlg;
|
1999-05-27 06:06:27 +04:00
|
|
|
int run;
|
1998-12-30 05:51:01 +03:00
|
|
|
|
1999-02-25 09:47:57 +03:00
|
|
|
path = concat_dir_and_file (desktop_directory, dii->filename);
|
1999-01-21 22:29:39 +03:00
|
|
|
/* retval = item_properties (dii->dicon, path, dii);*/
|
1999-01-28 08:48:02 +03:00
|
|
|
dlg = gnome_file_property_dialog_new (path, TRUE);
|
1999-01-21 22:29:39 +03:00
|
|
|
gtk_widget_show_all (dlg);
|
1999-05-27 06:06:27 +04:00
|
|
|
run = gnome_dialog_run (GNOME_DIALOG (dlg));
|
|
|
|
if (run == 0)
|
1999-01-21 22:29:39 +03:00
|
|
|
retval = gnome_file_property_dialog_make_changes (GNOME_FILE_PROPERTY_DIALOG (dlg));
|
1999-02-06 04:57:26 +03:00
|
|
|
|
1999-05-27 06:06:27 +04:00
|
|
|
if (run != -1)
|
|
|
|
gtk_widget_destroy (dlg);
|
1998-12-30 05:51:01 +03:00
|
|
|
g_free(path);
|
1999-02-12 05:15:17 +03:00
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
if (retval)
|
|
|
|
reread_cmd ();
|
1998-12-22 02:29:46 +03:00
|
|
|
}
|
|
|
|
|
1999-01-02 21:41:59 +03:00
|
|
|
/* Executes a desktop icon */
|
|
|
|
static void
|
|
|
|
dicon_execute (GtkWidget *widget, DesktopIconInfo *dii)
|
1998-12-22 02:29:46 +03:00
|
|
|
{
|
1999-01-02 21:41:59 +03:00
|
|
|
desktop_icon_info_open (dii);
|
1998-12-22 02:29:46 +03:00
|
|
|
}
|
|
|
|
|
1999-02-17 05:18:12 +03:00
|
|
|
static void
|
|
|
|
dicon_unmount (GtkWidget *widget, DesktopIconInfo *dii)
|
|
|
|
{
|
|
|
|
char *full = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
|
|
|
do_mount_umount (full, FALSE);
|
|
|
|
g_free (full);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dicon_mount (GtkWidget *widget, DesktopIconInfo *dii)
|
|
|
|
{
|
|
|
|
char *full = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
|
|
|
do_mount_umount (full, TRUE);
|
|
|
|
g_free (full);
|
|
|
|
}
|
|
|
|
|
1999-02-17 19:32:12 +03:00
|
|
|
static void
|
|
|
|
dicon_eject (GtkWidget *widget, DesktopIconInfo *dii)
|
|
|
|
{
|
|
|
|
char *full = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
|
|
|
|
do_mount_umount (full, FALSE);
|
|
|
|
do_eject (full);
|
|
|
|
g_free (full);
|
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-01 09:23:50 +03:00
|
|
|
panel_action_properties (GtkWidget *widget, WPanel *panel)
|
|
|
|
{
|
1999-01-21 22:29:39 +03:00
|
|
|
gint retval;
|
1998-12-01 09:23:50 +03:00
|
|
|
file_entry *fe = &panel->dir.list [panel->selected];
|
|
|
|
char *full_name = concat_dir_and_file (panel->cwd, fe->fname);
|
1999-01-21 22:29:39 +03:00
|
|
|
GtkWidget *dlg;
|
1999-05-27 06:06:27 +04:00
|
|
|
int run;
|
1999-01-21 22:29:39 +03:00
|
|
|
|
|
|
|
/* if (item_properties (GTK_WIDGET (CLIST_FROM_SW (panel->list)), full_name, NULL) != 0)
|
|
|
|
reread_cmd ();*/
|
1999-01-28 08:48:02 +03:00
|
|
|
dlg = gnome_file_property_dialog_new (full_name, we_can_afford_the_speed);
|
1999-03-11 05:40:53 +03:00
|
|
|
gnome_dialog_set_parent (GNOME_DIALOG (dlg), GTK_WINDOW (panel->xwindow));
|
1999-05-27 06:06:27 +04:00
|
|
|
|
|
|
|
run = gnome_dialog_run (GNOME_DIALOG (dlg));
|
|
|
|
|
|
|
|
if (run == 0)
|
1999-01-21 22:29:39 +03:00
|
|
|
retval = gnome_file_property_dialog_make_changes (GNOME_FILE_PROPERTY_DIALOG (dlg));
|
1999-05-27 06:06:27 +04:00
|
|
|
|
|
|
|
if (run != -1)
|
1999-01-21 22:29:39 +03:00
|
|
|
gtk_widget_destroy (dlg);
|
1999-01-27 04:14:57 +03:00
|
|
|
g_free (full_name);
|
1999-01-21 22:29:39 +03:00
|
|
|
if (retval)
|
|
|
|
reread_cmd ();
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
dicon_move (GtkWidget *widget, DesktopIconInfo *dii)
|
1998-12-02 09:33:07 +03:00
|
|
|
{
|
|
|
|
g_warning ("Implement this function!");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
dicon_copy (GtkWidget *widget, DesktopIconInfo *dii)
|
1998-12-02 09:33:07 +03:00
|
|
|
{
|
|
|
|
g_warning ("Implement this function!");
|
|
|
|
}
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
static void
|
1998-12-31 04:43:11 +03:00
|
|
|
dicon_delete (GtkWidget *widget, DesktopIconInfo *dii)
|
1998-12-02 09:33:07 +03:00
|
|
|
{
|
1999-01-02 21:41:59 +03:00
|
|
|
desktop_icon_info_delete (dii);
|
1998-12-02 09:33:07 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
/* 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
|
|
|
|
* marshaller (uiinfo->moreinfo).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
popup_connect_func (GnomeUIInfo *uiinfo, gchar *signal_name, GnomeUIBuilderData *uibdata)
|
|
|
|
{
|
|
|
|
g_assert (uibdata->is_interp);
|
|
|
|
|
|
|
|
if (uiinfo->moreinfo) {
|
|
|
|
gtk_object_set_data (GTK_OBJECT (uiinfo->widget), "popup_user_data", uiinfo->user_data);
|
|
|
|
gtk_signal_connect_full (GTK_OBJECT (uiinfo->widget), signal_name,
|
|
|
|
NULL,
|
|
|
|
uibdata->relay_func,
|
|
|
|
uiinfo->moreinfo,
|
|
|
|
uibdata->destroy_func,
|
|
|
|
FALSE,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Our custom marshaller for menu items. We need it so that it can extract the per-attachment
|
|
|
|
* user_data pointer from the parent menu shell and pass it to the callback. This overrides the
|
|
|
|
* user-specified data from the GnomeUIInfo structures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef void (* ActivateFunc) (GtkObject *object, gpointer data);
|
|
|
|
|
|
|
|
static void
|
|
|
|
popup_marshal_func (GtkObject *object, gpointer data, guint n_args, GtkArg *args)
|
|
|
|
{
|
|
|
|
ActivateFunc func;
|
|
|
|
gpointer user_data;
|
|
|
|
|
|
|
|
func = (ActivateFunc) data;
|
|
|
|
user_data = gtk_object_get_data (object, "popup_user_data");
|
|
|
|
|
|
|
|
gtk_object_set_data (GTK_OBJECT (GTK_WIDGET (object)->parent), "popup_active_item", object);
|
|
|
|
(* func) (object, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fills the menu with the specified uiinfo at the specified position, using our magic marshallers
|
|
|
|
* to be able to fetch the active item. The code is shamelessly ripped from gnome-popup-menu.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
fill_menu (GtkMenuShell *menu_shell, GnomeUIInfo *uiinfo, int pos)
|
|
|
|
{
|
|
|
|
GnomeUIBuilderData uibdata;
|
|
|
|
|
|
|
|
/* We use our own callback marshaller so that it can fetch the popup user data
|
|
|
|
* from the popup menu and pass it on to the user-defined callbacks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uibdata.connect_func = popup_connect_func;
|
|
|
|
uibdata.data = NULL;
|
|
|
|
uibdata.is_interp = TRUE;
|
|
|
|
uibdata.relay_func = popup_marshal_func;
|
|
|
|
uibdata.destroy_func = NULL;
|
|
|
|
|
|
|
|
gnome_app_fill_menu_custom (menu_shell, uiinfo, &uibdata, NULL, FALSE, pos);
|
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
/* The context menu: text displayed, condition that must be met and the routine that gets invoked
|
|
|
|
* upon activation.
|
1998-12-01 09:23:50 +03:00
|
|
|
*/
|
1998-12-02 09:33:07 +03:00
|
|
|
static struct action file_actions[] = {
|
|
|
|
{ N_("Properties"), F_SINGLE | F_PANEL, (GtkSignalFunc) panel_action_properties },
|
1999-03-10 20:54:33 +03:00
|
|
|
{ N_("Delete"), F_PANEL | F_ALL, (GtkSignalFunc) delete_cmd },
|
|
|
|
{ N_("Delete"), F_DICON | F_ALL, (GtkSignalFunc) dicon_delete },
|
1999-01-02 21:41:59 +03:00
|
|
|
{ N_("Properties"), F_SINGLE | F_DICON, (GtkSignalFunc) dicon_properties },
|
1999-02-17 05:18:12 +03:00
|
|
|
{ N_("Mount device"), F_SINGLE|F_MOUNTABLE|F_DICON, (GtkSignalFunc) dicon_mount },
|
|
|
|
{ N_("Unmount device"), F_SINGLE|F_UNMOUNTABLE|F_DICON, (GtkSignalFunc) dicon_unmount },
|
1999-02-17 19:32:12 +03:00
|
|
|
{ N_("Eject device"), F_SINGLE|F_EJECTABLE|F_DICON, (GtkSignalFunc) dicon_eject },
|
1998-12-01 09:23:50 +03:00
|
|
|
{ "", F_SINGLE, NULL },
|
1999-02-26 01:03:09 +03:00
|
|
|
{ N_("Open"), F_LOCAL| F_PANEL | F_ALL, (GtkSignalFunc) panel_action_open },
|
|
|
|
{ N_("Open"), F_LOCAL | F_DICON | F_ALL, (GtkSignalFunc) dicon_execute },
|
|
|
|
{ N_("Open with"), F_LOCAL | F_PANEL | F_ALL, (GtkSignalFunc) panel_action_open_with },
|
1998-12-02 09:33:07 +03:00
|
|
|
{ N_("View"), F_PANEL | F_NOTDIR, (GtkSignalFunc) panel_action_view },
|
|
|
|
{ N_("View unfiltered"), F_PANEL | F_NOTDIR, (GtkSignalFunc) panel_action_view_unfiltered },
|
|
|
|
{ N_("Edit"), F_PANEL | F_NOTDIR, (GtkSignalFunc) panel_action_edit },
|
1998-12-01 09:23:50 +03:00
|
|
|
{ "", 0, NULL },
|
1999-03-10 20:54:33 +03:00
|
|
|
{ N_("Move/rename..."), F_PANEL | F_ALL, (GtkSignalFunc) ren_cmd },
|
|
|
|
{ N_("Copy..."), F_PANEL | F_ALL, (GtkSignalFunc) copy_cmd },
|
|
|
|
{ "", 0, NULL },
|
1998-12-02 09:33:07 +03:00
|
|
|
{ N_("Link..."), F_PANEL | F_REGULAR | F_SINGLE, (GtkSignalFunc) link_cmd },
|
|
|
|
{ N_("Symlink..."), F_PANEL | F_SINGLE, (GtkSignalFunc) symlink_cmd },
|
|
|
|
{ N_("Edit symlink..."), F_PANEL | F_SYMLINK, (GtkSignalFunc) edit_symlink_cmd },
|
1998-12-01 09:23:50 +03:00
|
|
|
{ NULL, 0, NULL },
|
|
|
|
};
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
/* Creates the menu items for the standard actions. Returns the position at which additional menu
|
|
|
|
* items should be inserted.
|
|
|
|
*/
|
|
|
|
static int
|
1998-12-22 02:29:46 +03:00
|
|
|
create_actions (GtkWidget *menu, WPanel *panel,
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii,
|
1998-12-22 02:29:46 +03:00
|
|
|
int panel_row, char *filename)
|
1998-12-01 09:23:50 +03:00
|
|
|
{
|
1998-12-02 09:33:07 +03:00
|
|
|
gpointer closure;
|
|
|
|
struct action *action;
|
|
|
|
int pos;
|
|
|
|
GnomeUIInfo uiinfo[] = {
|
|
|
|
{ 0 },
|
|
|
|
GNOMEUIINFO_END
|
|
|
|
};
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
closure = panel ? (gpointer) panel : (gpointer) dii;
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
for (action = file_actions; action->text; action++) {
|
1998-12-01 09:23:50 +03:00
|
|
|
/* First, try F_PANEL and F_DICON flags */
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-11 22:14:55 +03:00
|
|
|
if (!panel && (action->flags & F_PANEL))
|
1998-12-01 09:23:50 +03:00
|
|
|
continue;
|
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
if (!dii && (action->flags & F_DICON))
|
1998-12-01 09:23:50 +03:00
|
|
|
continue;
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
/* Items with F_ALL bypass any other condition */
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
if (!(action->flags & F_ALL)) {
|
1998-12-01 09:23:50 +03:00
|
|
|
/* Items with F_SINGLE require that ONLY ONE marked files exist */
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
if (panel && (action->flags & F_SINGLE))
|
1998-12-01 09:23:50 +03:00
|
|
|
if (panel->marked > 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Items with F_NOTDIR requiere that the selection is not a directory */
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
if (panel && (action->flags & F_NOTDIR)) {
|
|
|
|
struct stat *s = &panel->dir.list[panel_row].buf;
|
|
|
|
|
|
|
|
if (panel->dir.list [panel_row].f.link_to_dir)
|
1998-12-01 09:23:50 +03:00
|
|
|
continue;
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
if (S_ISDIR (s->st_mode))
|
|
|
|
continue;
|
|
|
|
}
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
/* Items with F_REGULAR do not accept any strange file types */
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
if (panel && (action->flags & F_REGULAR)) {
|
|
|
|
struct stat *s = &panel->dir.list[panel_row].buf;
|
|
|
|
|
|
|
|
if (S_ISLNK (s->st_mode) && panel->dir.list[panel_row].f.link_to_dir)
|
1998-12-01 09:23:50 +03:00
|
|
|
continue;
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
if (S_ISSOCK (s->st_mode) || S_ISCHR (s->st_mode) ||
|
|
|
|
S_ISFIFO (s->st_mode) || S_ISBLK (s->st_mode))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Items with F_SYMLINK only operate on symbolic links */
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
if (panel && action->flags & F_SYMLINK) {
|
|
|
|
struct stat *s = &panel->dir.list[panel_row].buf;
|
|
|
|
|
|
|
|
if (!S_ISLNK (s->st_mode))
|
1998-12-01 09:23:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
1999-02-17 05:18:12 +03:00
|
|
|
|
|
|
|
if (action->flags & (F_MOUNTABLE|F_UNMOUNTABLE)){
|
|
|
|
char *fullname;
|
|
|
|
file_entry *fe;
|
|
|
|
int v;
|
|
|
|
int is_mounted;
|
|
|
|
|
|
|
|
fullname = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
fe = file_entry_from_file (fullname);
|
|
|
|
if (fe){
|
1999-02-23 05:53:30 +03:00
|
|
|
v = is_mountable (fullname, fe, &is_mounted, NULL);
|
1999-02-17 05:18:12 +03:00
|
|
|
file_entry_free (fe);
|
|
|
|
g_free (fullname);
|
|
|
|
|
|
|
|
if (!v)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (is_mounted && (action->flags & F_MOUNTABLE))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((!is_mounted) && (action->flags & F_UNMOUNTABLE))
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
g_free (fullname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-17 19:32:12 +03:00
|
|
|
if (action->flags & (F_EJECTABLE)){
|
|
|
|
char *fullname;
|
|
|
|
file_entry *fe;
|
|
|
|
int v;
|
|
|
|
int is_mounted;
|
|
|
|
|
|
|
|
fullname = g_concat_dir_and_file (desktop_directory, dii->filename);
|
|
|
|
fe = file_entry_from_file (fullname);
|
|
|
|
if (fe){
|
1999-02-23 05:53:30 +03:00
|
|
|
v = is_mountable (fullname, fe, &is_mounted, NULL);
|
1999-02-17 19:32:12 +03:00
|
|
|
file_entry_free (fe);
|
|
|
|
|
1999-03-09 06:56:54 +03:00
|
|
|
if (!v){
|
|
|
|
g_free (fullname);
|
1999-02-17 19:32:12 +03:00
|
|
|
continue;
|
1999-03-09 06:56:54 +03:00
|
|
|
}
|
1999-02-17 19:32:12 +03:00
|
|
|
|
1999-03-09 06:56:54 +03:00
|
|
|
if (!is_ejectable (fullname)){
|
|
|
|
g_free (fullname);
|
1999-02-17 19:32:12 +03:00
|
|
|
continue;
|
1999-03-09 06:56:54 +03:00
|
|
|
}
|
|
|
|
g_free (fullname);
|
|
|
|
|
1999-02-17 19:32:12 +03:00
|
|
|
} else {
|
|
|
|
g_free (fullname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
/* Create the appropriate GnomeUIInfo structure for the menu item */
|
|
|
|
|
|
|
|
if (action->text[0]) {
|
|
|
|
uiinfo[0].type = GNOME_APP_UI_ITEM;
|
|
|
|
uiinfo[0].label = _(action->text);
|
|
|
|
uiinfo[0].hint = NULL;
|
|
|
|
uiinfo[0].moreinfo = action->callback;
|
|
|
|
uiinfo[0].user_data = closure;
|
|
|
|
uiinfo[0].unused_data = NULL;
|
|
|
|
uiinfo[0].pixmap_type = GNOME_APP_PIXMAP_NONE;
|
|
|
|
uiinfo[0].pixmap_info = NULL;
|
|
|
|
uiinfo[0].accelerator_key = 0;
|
|
|
|
uiinfo[0].ac_mods = 0;
|
|
|
|
uiinfo[0].widget = NULL;
|
|
|
|
} else
|
|
|
|
uiinfo[0].type = GNOME_APP_UI_SEPARATOR;
|
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
fill_menu (GTK_MENU_SHELL (menu), uiinfo, pos);
|
1998-12-02 09:33:07 +03:00
|
|
|
pos++;
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
return pos;
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
/* These functions activate a menu popup action for a filename in a hackish way, as they have to
|
|
|
|
* fetch the action from the menu item's label.
|
1998-12-01 09:23:50 +03:00
|
|
|
*/
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
static char *
|
|
|
|
get_label_text (GtkMenuItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
/* THIS DEPENDS ON THE LATEST GNOME-LIBS! Keep this in sync with gnome-app-helper until we
|
|
|
|
* figure a way to do this in a non-hackish way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
label = GTK_BIN (item)->child;
|
|
|
|
g_assert (label != NULL);
|
|
|
|
|
|
|
|
return GTK_LABEL (label)->label;
|
|
|
|
}
|
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
static void
|
1998-12-17 07:51:24 +03:00
|
|
|
mime_command_from_panel (GtkMenuItem *item, WPanel *panel)
|
1998-12-01 09:23:50 +03:00
|
|
|
{
|
1998-12-02 09:33:07 +03:00
|
|
|
char *filename;
|
1998-12-01 09:23:50 +03:00
|
|
|
char *action;
|
|
|
|
int movedir;
|
1998-12-17 07:51:24 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is broken, but we dont mind. Federico
|
|
|
|
* needs to explain me what was he intending here.
|
|
|
|
* panel->selected does not mean, it was the icon
|
|
|
|
* that got clicked.
|
|
|
|
*/
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-12-17 07:51:24 +03:00
|
|
|
mime_command_from_desktop_icon (GtkMenuItem *item, char *filename)
|
1998-12-01 09:23:50 +03:00
|
|
|
{
|
1999-02-26 10:17:51 +03:00
|
|
|
char *action, *buf;
|
|
|
|
int movedir, size;
|
|
|
|
char *key, *flag_key;
|
|
|
|
const char *mime_type, *val, *flags;
|
|
|
|
int needs_terminal = 0;
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1999-02-26 10:17:51 +03:00
|
|
|
action = get_label_text (item);
|
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
key = gtk_object_get_user_data (GTK_OBJECT (item));
|
2000-01-03 Aaron Lehmann <aaronl@vitelus.com>
* gdesktop.c, gdnd.c, gaction.c, gicon.c,
gnome-file-property-dialog.c, gpopup.c, gpopup2.c, gprefs.cgmain.h,
setup.c: Add option of using GNOME "magic" routines to determine file
types. This makes MC intelligently look at the data in the file to see
what type of file it is, rather than looking at the filename extension.
This slows down MC quite a bit, so it has been made an optional
preference item. Type detection is expected to improve as mime-magic
matures.
2000-01-24 01:25:26 +03:00
|
|
|
if (use_magic)
|
|
|
|
mime_type = gnome_mime_type_or_default_of_file (filename, NULL);
|
|
|
|
else
|
|
|
|
mime_type = gnome_mime_type_or_default (filename, NULL);
|
1998-12-17 07:51:24 +03:00
|
|
|
if (!mime_type)
|
|
|
|
return;
|
1999-02-26 10:17:51 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find out if we need to run this in a terminal
|
|
|
|
*/
|
|
|
|
if (gnome_metadata_get (filename, "flags", &size, &buf) == 0){
|
|
|
|
needs_terminal = strstr (flags, "needsterminal") != 0;
|
|
|
|
g_free (buf);
|
|
|
|
} else {
|
|
|
|
flag_key = g_strconcat ("flags.", key, "flags", NULL);
|
|
|
|
flags = gnome_mime_get_value (filename, flag_key);
|
|
|
|
g_free (flag_key);
|
|
|
|
if (flags)
|
|
|
|
needs_terminal = strstr (flags, "needsterminal") != 0;
|
|
|
|
}
|
1998-12-17 07:51:24 +03:00
|
|
|
|
|
|
|
val = gnome_mime_get_value (mime_type, key);
|
1999-02-26 10:17:51 +03:00
|
|
|
exec_extension (filename, val, NULL, NULL, 0, needs_terminal);
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
/* Create the menu items common to files from panel window and desktop icons, and also the items for
|
|
|
|
* regexp_command() actions.
|
|
|
|
*/
|
1998-12-01 09:23:50 +03:00
|
|
|
static void
|
1998-12-22 02:29:46 +03:00
|
|
|
create_regexp_actions (GtkWidget *menu, WPanel *panel,
|
1998-12-31 04:43:11 +03:00
|
|
|
DesktopIconInfo *dii,
|
1998-12-22 02:29:46 +03:00
|
|
|
int panel_row, char *filename, int insert_pos)
|
1998-12-01 09:23:50 +03:00
|
|
|
{
|
1998-12-02 09:33:07 +03:00
|
|
|
gpointer closure, regex_closure;
|
|
|
|
int i;
|
|
|
|
GtkSignalFunc regex_callback;
|
1999-02-12 05:42:42 +03:00
|
|
|
const char *mime_type;
|
1998-12-17 07:51:24 +03:00
|
|
|
GList *keys, *l;
|
1998-12-02 09:33:07 +03:00
|
|
|
GnomeUIInfo uiinfo[] = {
|
|
|
|
{ 0 },
|
|
|
|
GNOMEUIINFO_END
|
|
|
|
};
|
|
|
|
|
1999-03-10 20:54:33 +03:00
|
|
|
regex_callback = mime_command_from_desktop_icon;
|
1998-12-02 09:33:07 +03:00
|
|
|
if (panel) {
|
|
|
|
closure = panel;
|
1998-12-16 05:32:31 +03:00
|
|
|
regex_closure = filename;
|
1998-12-01 09:23:50 +03:00
|
|
|
} else {
|
1998-12-22 02:29:46 +03:00
|
|
|
closure = dii;
|
1998-12-02 09:33:07 +03:00
|
|
|
regex_closure = filename;
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
1998-12-02 09:33:07 +03:00
|
|
|
|
|
|
|
/* Fill in the regex command part */
|
|
|
|
|
2000-01-03 Aaron Lehmann <aaronl@vitelus.com>
* gdesktop.c, gdnd.c, gaction.c, gicon.c,
gnome-file-property-dialog.c, gpopup.c, gpopup2.c, gprefs.cgmain.h,
setup.c: Add option of using GNOME "magic" routines to determine file
types. This makes MC intelligently look at the data in the file to see
what type of file it is, rather than looking at the filename extension.
This slows down MC quite a bit, so it has been made an optional
preference item. Type detection is expected to improve as mime-magic
matures.
2000-01-24 01:25:26 +03:00
|
|
|
if (use_magic)
|
|
|
|
mime_type = gnome_mime_type_or_default_of_file (filename, NULL);
|
|
|
|
else
|
|
|
|
mime_type = gnome_mime_type_or_default (filename, NULL);
|
1998-12-17 07:51:24 +03:00
|
|
|
if (!mime_type)
|
1998-12-01 09:23:50 +03:00
|
|
|
return;
|
1998-12-17 07:51:24 +03:00
|
|
|
|
|
|
|
keys = gnome_mime_get_keys (mime_type);
|
|
|
|
|
|
|
|
for (l = keys; l; l = l->next) {
|
|
|
|
char *key = l->data;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = key;
|
|
|
|
if (strncmp (key, "open.", 5) != 0)
|
|
|
|
continue;
|
1998-12-02 09:33:07 +03:00
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
str += 5;
|
|
|
|
while (*str && *str != '.')
|
|
|
|
str++;
|
1998-12-16 09:33:55 +03:00
|
|
|
|
1998-12-17 07:51:24 +03:00
|
|
|
if (*str)
|
|
|
|
str++;
|
|
|
|
|
|
|
|
if (!*str)
|
|
|
|
continue;
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
/* Create the item for that entry */
|
|
|
|
|
|
|
|
uiinfo[0].type = GNOME_APP_UI_ITEM;
|
1998-12-17 07:51:24 +03:00
|
|
|
uiinfo[0].label = str;
|
1998-12-02 09:33:07 +03:00
|
|
|
uiinfo[0].hint = NULL;
|
|
|
|
uiinfo[0].moreinfo = regex_callback;
|
|
|
|
uiinfo[0].user_data = regex_closure;
|
|
|
|
uiinfo[0].unused_data = NULL;
|
|
|
|
uiinfo[0].pixmap_type = GNOME_APP_PIXMAP_NONE;
|
|
|
|
uiinfo[0].pixmap_info = NULL;
|
|
|
|
uiinfo[0].accelerator_key = 0;
|
|
|
|
uiinfo[0].ac_mods = 0;
|
|
|
|
uiinfo[0].widget = NULL;
|
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
fill_menu (GTK_MENU_SHELL (menu), uiinfo, insert_pos++);
|
1998-12-17 07:51:24 +03:00
|
|
|
gtk_object_set_user_data (GTK_OBJECT (uiinfo [0].widget), key);
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
1998-12-17 07:51:24 +03:00
|
|
|
g_list_free (keys);
|
1998-12-01 09:23:50 +03:00
|
|
|
}
|
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
/* Convenience callback to exit the main loop of a modal popup menu when it is deactivated*/
|
|
|
|
static void
|
|
|
|
menu_shell_deactivated (GtkMenuShell *menu_shell, gpointer data)
|
|
|
|
{
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the index of the active item in the specified menu, or -1 if none is active */
|
|
|
|
static int
|
|
|
|
get_active_index (GtkMenu *menu)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
GtkWidget *active;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
active = gtk_object_get_data (GTK_OBJECT (menu), "popup_active_item");
|
|
|
|
|
|
|
|
for (i = 0, l = GTK_MENU_SHELL (menu)->children; l; l = l->next, i++)
|
|
|
|
if (active == l->data)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-12-01 09:23:50 +03:00
|
|
|
/*
|
|
|
|
* Create a context menu
|
|
|
|
* It can take either a WPanel or a GnomeDesktopEntry. One of them should
|
|
|
|
* be set to NULL.
|
|
|
|
*/
|
1998-12-02 09:33:07 +03:00
|
|
|
int
|
1998-12-31 04:43:11 +03:00
|
|
|
gpopup_do_popup (GdkEventButton *event, WPanel *from_panel,
|
|
|
|
DesktopIconInfo *dii,
|
|
|
|
int panel_row, char *filename)
|
1998-12-01 09:23:50 +03:00
|
|
|
{
|
1998-12-02 09:33:07 +03:00
|
|
|
GtkWidget *menu;
|
|
|
|
int pos;
|
1998-12-02 23:24:25 +03:00
|
|
|
guint id;
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 09:33:07 +03:00
|
|
|
g_return_val_if_fail (event != NULL, -1);
|
1998-12-22 02:29:46 +03:00
|
|
|
g_return_val_if_fail (from_panel != NULL || dii != NULL || filename != NULL, -1);
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
menu = gtk_menu_new ();
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
/* Connect to the deactivation signal to be able to quit our
|
|
|
|
modal main loop */
|
1998-12-02 23:24:25 +03:00
|
|
|
id = gtk_signal_connect (GTK_OBJECT (menu), "deactivate",
|
|
|
|
(GtkSignalFunc) menu_shell_deactivated,
|
|
|
|
NULL);
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
/* Fill the menu */
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-22 02:29:46 +03:00
|
|
|
pos = create_actions (menu, from_panel, dii,
|
|
|
|
panel_row, filename);
|
|
|
|
create_regexp_actions (menu, from_panel, dii,
|
|
|
|
panel_row, filename, pos);
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
/* Run it */
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-30 05:51:01 +03:00
|
|
|
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time);
|
1998-12-02 23:24:25 +03:00
|
|
|
gtk_grab_add (menu);
|
|
|
|
gtk_main ();
|
|
|
|
gtk_grab_remove (menu);
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
gtk_signal_disconnect (GTK_OBJECT (menu), id);
|
1998-12-01 09:23:50 +03:00
|
|
|
|
1998-12-02 23:24:25 +03:00
|
|
|
return get_active_index (GTK_MENU (menu));
|
1998-11-25 06:48:20 +03:00
|
|
|
}
|
1998-12-16 05:32:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|