2000-06-16 Jonathan Blandford <jrb@redhat.com>

* gpopup2.c (handle_empty_trash): Finished trash can.  Now I just
	need an icon.

2000-06-15  Jonathan Blandford  <jrb@redhat.com>

	* gpopup2.c: Add "Move to Trash" as an option to the popup menu.
	Also, "Empty Trash" as appropriate.

	* gscreen.c (file_list_popup): Removed New File command.  It
	wasn't working, and didn't do anything useful, anyways.  Added
	"Empty Trash" to the options for the menu.
This commit is contained in:
Jonathan Blandford 2000-06-16 18:16:44 +00:00
parent ce6e42f45a
commit 97c053032e
6 changed files with 193 additions and 4 deletions

View File

@ -1,3 +1,17 @@
2000-06-16 Jonathan Blandford <jrb@redhat.com>
* gpopup2.c (handle_empty_trash): Finished trash can. Now I just
need an icon.
2000-06-15 Jonathan Blandford <jrb@redhat.com>
* gpopup2.c: Add "Move to Trash" as an option to the popup menu.
Also, "Empty Trash" as appropriate.
* gscreen.c (file_list_popup): Removed New File command. It
wasn't working, and didn't do anything useful, anyways. Added
"Empty Trash" to the options for the menu.
2000-05-24 Arik Devens <arik@helixcode.com> and Ian Peters <itp@helixcode.com>
* gdesktop-init.c (desktop_load_init_from): don't crash on

View File

@ -24,6 +24,7 @@
#include "layout.h"
#include "gdesktop.h"
#include "gmain.h"
#include "file.h"
#include "../vfs/vfs.h"
static char *panelize_section = "Panelize";
@ -626,6 +627,47 @@ gnome_external_panelize (GtkWidget *widget, WPanel *panel)
g_free (data);
}
static WPanel *
create_trash_panel (void)
{
WPanel *retval;
gchar *trash_dir;
is_trash_panel = TRUE;
trash_dir = g_strconcat (gnome_user_home_dir, "/",
DESKTOP_DIR_NAME, "/",
"Trash",
NULL);
retval = new_panel_at (trash_dir);
g_free (trash_dir);
is_trash_panel = FALSE;
return retval;
}
void
gnome_empty_trash (GtkWidget *widget, WPanel *panel)
{
WPanel *trash_panel;
gint i;
trash_panel = create_trash_panel ();
for (i = 0; i < trash_panel->count; i++){
if (!strcmp (trash_panel->dir.list [i].fname, "..")) {
continue;
}
do_file_mark (trash_panel, i, 1);
}
panel_operate (trash_panel, OP_DELETE, NULL, FALSE);
gnome_close_panel (NULL, trash_panel);
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
do_refresh ();
}
void
gnome_select_all_cmd (GtkWidget *widget, WPanel *panel)
{

View File

@ -30,6 +30,7 @@ typedef enum {
sortfn *sort_get_func_from_type (SortType type);
void gnome_sort_cmd (GtkWidget *widget, WPanel *panel);
void gnome_empty_trash (GtkWidget *widget, WPanel *panel);
void gnome_select_all_cmd (GtkWidget *widget, WPanel *panel);
void gnome_start_search (GtkWidget *widget, WPanel *panel);
void gnome_filter_cmd (GtkWidget *widget, WPanel *panel);

View File

@ -15,6 +15,7 @@
#include "global.h"
#include <gnome.h>
#include "panel.h"
#include "file.h"
#include "cmd.h"
#include "dialog.h"
#include "ext.h"
@ -28,6 +29,7 @@
#include "gmount.h"
#define CLIST_FROM_SW(panel_list) GTK_CLIST (GTK_BIN (panel_list)->child)
int is_trash_panel = FALSE;
/* Flags for the popup menu entries. They specify to which kinds of files an
* entry is valid for.
@ -64,6 +66,8 @@ static void handle_view (GtkWidget *widget, WPanel *panel);
static void handle_view_unfiltered (GtkWidget *widget, WPanel *panel);
static void handle_edit (GtkWidget *widget, WPanel *panel);
static void handle_copy (GtkWidget *widget, WPanel *panel);
static void handle_trash (GtkWidget *widget, WPanel *panel);
static void handle_empty_trash (GtkWidget *widget, WPanel *panel);
static void handle_delete (GtkWidget *widget, WPanel *panel);
static void handle_move (GtkWidget *widget, WPanel *panel);
@ -79,6 +83,8 @@ static gboolean check_mount_func (WPanel *panel, DesktopIconInfo *dii);
static gboolean check_unmount_func (WPanel *panel, DesktopIconInfo *dii);
static gboolean check_eject_func (WPanel *panel, DesktopIconInfo *dii);
static gboolean check_device_func (WPanel *panel, DesktopIconInfo *dii);
static gboolean check_trash_func (WPanel *panel, DesktopIconInfo *dii);
static gboolean check_trash_icon_func (WPanel *panel, DesktopIconInfo *dii);
static gchar * get_full_filename (WPanel *panel);
@ -188,6 +194,83 @@ check_device_func (WPanel *panel, DesktopIconInfo *dii)
check_eject_func (panel, dii));
}
static gboolean
check_trash_func (WPanel *panel, DesktopIconInfo *dii)
{
gchar *trash_dir;
struct stat st;
gint i;
trash_dir = g_strconcat (gnome_user_home_dir, "/",
DESKTOP_DIR_NAME, "/",
"Trash",
NULL);
if (mc_stat (trash_dir, &st) || !S_ISDIR (st.st_mode)) {
g_free (trash_dir);
return FALSE;
}
if (strncmp (trash_dir, panel->cwd, strlen (trash_dir)) == 0) {
g_free (trash_dir);
return FALSE;
}
for (i = 0; i < panel->count; i++) {
if (panel->dir.list [i].f.marked) {
gchar *desktop_file = concat_dir_and_file (panel->cwd,
panel->dir.list [i].fname);
if (strncmp (desktop_file, trash_dir, strlen (trash_dir)) == 0) {
g_free (desktop_file);
g_free (trash_dir);
return FALSE;
}
g_free (desktop_file);
}
}
g_free (trash_dir);
return TRUE;
}
static gboolean
check_trash_icon_func (WPanel *panel, DesktopIconInfo *dii)
{
gchar *trash_dir;
gchar *file_name;
if (!is_a_desktop_panel (panel))
return FALSE;
trash_dir = g_strconcat (gnome_user_home_dir, "/",
DESKTOP_DIR_NAME, "/",
"Trash",
NULL);
file_name = get_full_filename (panel);
if (strncmp (trash_dir, file_name, strlen (trash_dir)) == 0) {
DIR *dirp;
struct dirent *dp;
gint i = 0;
dirp = mc_opendir (file_name);
g_free (trash_dir);
g_free (file_name);
for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) {
i ++;
if (i > 2) {
mc_closedir (dirp);
return TRUE;
}
}
mc_closedir (dirp);
return FALSE;
}
g_free (trash_dir);
g_free (file_name);
return FALSE;
}
/* global vars */
extern int we_can_afford_the_speed;
@ -197,6 +280,7 @@ static struct action file_actions[] = {
{ N_("Mount device"), F_ALL | F_SINGLE, handle_mount, check_mount_func },
{ N_("Unmount device"), F_ALL | F_SINGLE, handle_unmount, check_unmount_func },
{ N_("Eject device"), F_ALL | F_SINGLE, handle_eject, check_eject_func },
{ N_("Empty Trash"), F_SINGLE, handle_empty_trash, check_trash_icon_func },
/* Custom actions go here */
{ "", F_MIME_ACTIONS | F_SINGLE, NULL, check_device_func },
{ N_("Open with..."), F_REGULAR | F_SINGLE, handle_open_with, NULL },
@ -205,6 +289,7 @@ static struct action file_actions[] = {
{ N_("Edit"), F_REGULAR | F_SINGLE, handle_edit, NULL },
{ "", F_REGULAR | F_SINGLE, NULL, NULL },
{ N_("Copy..."), F_ALL, handle_copy, NULL },
{ N_("Move to Trash"), F_ALL, handle_trash, check_trash_func },
{ N_("Delete"), F_ALL, handle_delete, NULL },
{ N_("Move..."), F_ALL, handle_move, NULL },
{ N_("Hard Link..."), F_ADVANCED | F_SINGLE, handle_hard_link, NULL },
@ -711,6 +796,30 @@ handle_copy (GtkWidget *widget, WPanel *panel)
copy_cmd ();
}
/* Empties trash when in the Trash panel */
static void
handle_trash (GtkWidget *widget, WPanel *panel)
{
gchar *trash_dir;
trash_dir = g_strconcat (gnome_user_home_dir, "/",
DESKTOP_DIR_NAME, "/",
"Trash",
NULL);
if (panel_operate (cpanel, OP_MOVE, trash_dir, FALSE)) {
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
repaint_screen ();
}
}
/* Empties trash from the desktop */
static void
handle_empty_trash (GtkWidget *widget, WPanel *panel)
{
gnome_empty_trash (NULL, NULL);
}
static void
handle_delete (GtkWidget *widget, WPanel *panel)
{

View File

@ -1429,8 +1429,17 @@ static GnomeUIInfo file_list_popup_items[] = {
handle_rescan_directory),
GNOMEUIINFO_ITEM_NONE (N_("New _Directory..."), N_("Creates a new directory here"),
gnome_mkdir_cmd),
GNOMEUIINFO_ITEM_NONE (N_("New _File..."), N_("Creates a new file here"),
gnome_newfile_cmd),
GNOMEUIINFO_END
};
/* The popup menu for file panels */
static GnomeUIInfo trash_file_list_popup_items[] = {
GNOMEUIINFO_ITEM_NONE (N_("Empty _Trash"), N_("Empties the Trash"),
gnome_empty_trash),
GNOMEUIINFO_ITEM_NONE (N_("_Rescan Directory"), N_("Reloads the current directory"),
handle_rescan_directory),
GNOMEUIINFO_ITEM_NONE (N_("New _Directory..."), N_("Creates a new directory here"),
gnome_mkdir_cmd),
GNOMEUIINFO_END
};
@ -1441,8 +1450,19 @@ static void
file_list_popup (GdkEventButton *event, WPanel *panel)
{
GtkWidget *popup;
gchar *trash_dir;
GnomeUIInfo *items = file_list_popup_items;
popup = gnome_popup_menu_new (file_list_popup_items);
trash_dir = g_strconcat (gnome_user_home_dir, "/",
DESKTOP_DIR_NAME, "/",
"Trash",
NULL);
if ((strncmp (panel->cwd, trash_dir, strlen (trash_dir)) == 0) && (panel->count != 1))
items = trash_file_list_popup_items;
g_free (trash_dir);
popup = gnome_popup_menu_new (items);
gnome_popup_menu_do_popup_modal (popup, NULL, NULL, event, panel);
gtk_widget_destroy (popup);
}
@ -2489,7 +2509,7 @@ x_create_panel (Dlg_head *h, widget_data parent, WPanel *panel)
gtk_widget_show (vbox);
gtk_widget_show (panel->table);
if (!(panel->widget.options & W_PANEL_HIDDEN))
if (!(panel->widget.options & W_PANEL_HIDDEN) && !is_trash_panel)
gtk_widget_show (gtk_widget_get_toplevel (panel->table));
if (!pixmaps_ready)

View File

@ -219,6 +219,9 @@ extern int panel_scroll_pages;
#define selection(p) (&(p->dir.list [p->selected]))
#ifdef HAVE_GNOME
#define is_a_desktop_panel(p) ((p->is_a_desktop_panel))
/* Evil empty trash_hack */
extern int is_trash_panel;
#else
#define is_a_desktop_panel(p) FALSE
#endif