Commit f0e4c44c authored by Maciej Stachowiak's avatar Maciej Stachowiak

New functions for subclasses to call, to implement right-click menus. Most

	* src/file-manager/fm-directory-view.c,
	src/file-manager/fm-directory-view.h
	(fm_directory_view_popup_item_context_menu,
	fm_directory_view_popup_background_context_menu): New functions
	for subclasses to call, to implement right-click menus. Most of
	the guts are here now. Machinery to merge view-specific items with
	generic ones will be added here.
	* src/file-manager/fm-directory-view-icons.c,
	src/file-manager/fm-directory-view-list.c: Use the new interface
	for right-click stuff.
parent 11b80f5d
2000-01-24 Maciej Stachowiak <mjs@eazel.com>
* src/file-manager/fm-directory-view.c,
src/file-manager/fm-directory-view.h
(fm_directory_view_popup_item_context_menu,
fm_directory_view_popup_background_context_menu): New functions
for subclasses to call, to implement right-click menus. Most of
the guts are here now. Machinery to merge view-specific items with
generic ones will be added here.
* src/file-manager/fm-directory-view-icons.c,
src/file-manager/fm-directory-view-list.c: Use the new interface
for right-click stuff.
* src/file-manager/fm-directory-view-icons.c: Corrected memory
management for background and item popup menus.
......
......@@ -39,6 +39,7 @@
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-string.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-directory.h>
#define DEFAULT_BACKGROUND_COLOR "rgb:FFFF/FFFF/FFFF"
......@@ -48,9 +49,6 @@ static void add_icon_at_free_position (FMDirectoryViewIcons *icon_view,
NautilusFile *file);
static void add_icon_if_already_positioned (FMDirectoryViewIcons *icon_view,
NautilusFile *file);
static GtkMenu *create_background_context_menu (FMDirectoryViewIcons *icon_view);
static GtkMenu *create_item_context_menu (FMDirectoryViewIcons *icon_view,
NautilusFile *file);
static GnomeIconContainer *create_icon_container (FMDirectoryViewIcons *icon_view);
static void display_icons_not_already_positioned (FMDirectoryViewIcons *icon_view);
static void fm_directory_view_icons_icon_moved_cb (GnomeIconContainer *container,
......@@ -90,7 +88,6 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (FMDirectoryViewIcons, fm_directory_view_icons
struct _FMDirectoryViewIconsDetails
{
NautilusFileList *icons_not_positioned;
GtkMenu *background_context_menu;
};
......@@ -128,10 +125,6 @@ fm_directory_view_icons_initialize (FMDirectoryViewIcons *icon_view)
icon_view->details = g_new0 (FMDirectoryViewIconsDetails, 1);
icon_view->details->background_context_menu =
create_background_context_menu (icon_view);
icon_container = create_icon_container (icon_view);
}
......@@ -145,62 +138,10 @@ fm_directory_view_icons_destroy (GtkObject *object)
g_list_free (icon_view->details->icons_not_positioned);
icon_view->details->icons_not_positioned = NULL;
gtk_object_unref(GTK_OBJECT(icon_view->details->background_context_menu));
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
static GtkMenu *
create_background_context_menu (FMDirectoryViewIcons *icon_view)
{
GtkMenu *menu;
GtkWidget *menu_item;
menu = GTK_MENU (gtk_menu_new ());
menu_item = gtk_menu_item_new_with_label ("Select all");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom in");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom out");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
gtk_object_ref(GTK_OBJECT(menu));
gtk_object_sink(GTK_OBJECT(menu));
return menu;
}
static GtkMenu *
create_item_context_menu (FMDirectoryViewIcons *icon_view,
NautilusFile *file)
{
GtkMenu *menu;
GtkWidget *menu_item;
menu = GTK_MENU (gtk_menu_new ());
menu_item = gtk_menu_item_new_with_label ("Open");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Delete");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
return menu;
}
static GnomeIconContainer *
create_icon_container (FMDirectoryViewIcons *icon_view)
{
......@@ -396,38 +337,26 @@ icon_container_selection_changed_cb (GnomeIconContainer *container,
fm_directory_view_notify_selection_changed (FM_DIRECTORY_VIEW (icon_view));
}
static void
popup_context_menu (GtkMenu *menu)
{
gtk_menu_popup (menu, NULL, NULL, NULL,
NULL, 3, GDK_CURRENT_TIME);
}
static void
icon_container_context_click_icon_cb (GnomeIconContainer *container,
NautilusFile *file,
FMDirectoryViewIcons *icon_view)
{
GtkMenu *menu;
g_assert (GNOME_IS_ICON_CONTAINER (container));
/* g_assert (NAUTILUS_IS_FILE (file)); */
g_assert (FM_IS_DIRECTORY_VIEW_ICONS (icon_view));
menu = create_item_context_menu (icon_view, file);
gtk_object_ref (GTK_OBJECT(menu));
gtk_object_sink (GTK_OBJECT(menu));
popup_context_menu (menu);
gtk_object_unref (GTK_OBJECT(menu));
fm_directory_view_popup_item_context_menu (FM_DIRECTORY_VIEW (icon_view), file);
}
static void
icon_container_context_click_background_cb (GnomeIconContainer *container,
FMDirectoryViewIcons *icon_view)
{
g_assert (GNOME_IS_ICON_CONTAINER (container));
g_assert (FM_IS_DIRECTORY_VIEW_ICONS (icon_view));
popup_context_menu (icon_view->details->background_context_menu);
fm_directory_view_popup_background_context_menu(FM_DIRECTORY_VIEW (icon_view));
}
static void
......
......@@ -30,6 +30,8 @@
#include "fm-icon-cache.h"
#include <gtk/gtkhbox.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkmenuitem.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-pixmap.h>
#include <libgnomeui/gnome-uidefs.h>
......@@ -62,6 +64,11 @@ static void add_to_flist (FMDirectoryViewList *list_view,
static void column_clicked_cb (GtkCList *clist,
gint column,
gpointer user_data);
static void context_click_row_cb (GtkCList *clist,
gint row,
FMDirectoryViewList *list_view);
static void context_click_background_cb (GtkCList *clist,
FMDirectoryViewList *list_view);
static GtkFList *create_flist (FMDirectoryViewList *list_view);
static void flist_activate_cb (GtkFList *flist,
gpointer entry_data,
......@@ -220,6 +227,32 @@ column_clicked_cb (GtkCList *clist, gint column, gpointer user_data)
list_view->details->sort_reversed);
}
static void context_click_row_cb (GtkCList *clist,
gint row,
FMDirectoryViewList *list_view)
{
NautilusFile * file;
g_assert (GTK_IS_CLIST (clist));
g_assert (FM_IS_DIRECTORY_VIEW_LIST (list_view));
file = NAUTILUS_FILE(gtk_clist_get_row_data (clist, clist->rows - 1));
fm_directory_view_popup_item_context_menu (FM_DIRECTORY_VIEW (list_view), file);
}
static void context_click_background_cb (GtkCList *clist,
FMDirectoryViewList *list_view)
{
g_assert (FM_IS_DIRECTORY_VIEW_LIST (list_view));
fm_directory_view_popup_background_context_menu (FM_DIRECTORY_VIEW (list_view));
}
static GtkFList *
create_flist (FMDirectoryViewList *list_view)
{
......@@ -303,12 +336,23 @@ create_flist (FMDirectoryViewList *list_view)
"click_column",
column_clicked_cb,
list_view);
gtk_signal_connect (GTK_OBJECT (flist),
"context_click_row",
context_click_row_cb,
list_view);
gtk_signal_connect (GTK_OBJECT (flist),
"context_click_background",
context_click_background_cb,
list_view);
gtk_signal_connect (GTK_OBJECT (nautilus_get_widget_background (GTK_WIDGET (flist))),
"changed",
GTK_SIGNAL_FUNC (fm_directory_view_list_background_changed_cb),
list_view);
gtk_container_add (GTK_CONTAINER (list_view), GTK_WIDGET (flist));
gtk_widget_show (GTK_WIDGET (flist));
......@@ -318,6 +362,11 @@ create_flist (FMDirectoryViewList *list_view)
return flist;
}
/* FIXME - this code was cut and pasted from fm-directory-view-list.c */
static void
flist_activate_cb (GtkFList *flist,
gpointer entry_data,
......@@ -545,4 +594,3 @@ show_sort_indicator (GtkFList *flist, gint column, gboolean sort_reversed)
gtk_widget_show (get_sort_indicator (flist, column, sort_reversed));
}
......@@ -30,6 +30,8 @@
#include <gtk/gtksignal.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkmenuitem.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomevfs/gnome-vfs-async-ops.h>
#include <libgnomevfs/gnome-vfs-directory-list.h>
......@@ -72,6 +74,8 @@ struct _FMDirectoryViewDetails
GnomeVFSURI *uri;
NautilusDirectory *model;
GtkMenu *background_context_menu;
};
/* forward declarations */
......@@ -80,6 +84,9 @@ static void display_selection_info (FMDirectoryView *view);
static void fm_directory_view_initialize_class (FMDirectoryViewClass *klass);
static void fm_directory_view_initialize (FMDirectoryView *view);
static void fm_directory_view_destroy (GtkObject *object);
static GtkMenu *create_item_context_menu (FMDirectoryView *view,
NautilusFile *file);
static GtkMenu *create_background_context_menu (FMDirectoryView *view);
static void stop_location_change_cb (NautilusViewFrame *view_frame,
FMDirectoryView *directory_view);
static void notify_location_change_cb (NautilusViewFrame *view_frame,
......@@ -160,6 +167,8 @@ fm_directory_view_initialize (FMDirectoryView *directory_view)
#endif
directory_view->details->background_context_menu = create_background_context_menu(directory_view);
directory_view->details->view_frame = NAUTILUS_CONTENT_VIEW_FRAME
(gtk_widget_new (nautilus_content_view_frame_get_type(), NULL));
......@@ -173,6 +182,7 @@ fm_directory_view_initialize (FMDirectoryView *directory_view)
GTK_SIGNAL_FUNC (notify_location_change_cb),
directory_view);
gtk_widget_show (GTK_WIDGET (directory_view));
gtk_container_add (GTK_CONTAINER (directory_view->details->view_frame),
......@@ -201,6 +211,9 @@ fm_directory_view_destroy (GtkObject *object)
if (view->details->model != NULL)
gtk_object_unref (GTK_OBJECT (view->details->model));
if (view->details->background_context_menu != NULL)
gtk_object_unref(GTK_OBJECT(view->details->background_context_menu));
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
......@@ -627,6 +640,123 @@ fm_directory_view_get_model (FMDirectoryView *view)
return view->details->model;
}
static void
popup_context_menu (GtkMenu *menu)
{
gtk_menu_popup (menu, NULL, NULL, NULL,
NULL, 3, GDK_CURRENT_TIME);
}
static void
popup_temporary_context_menu (GtkMenu *menu)
{
gtk_object_ref (GTK_OBJECT(menu));
gtk_object_sink (GTK_OBJECT(menu));
popup_context_menu (menu);
gtk_object_unref (GTK_OBJECT(menu));
}
/* FIXME - need better architecture for setting these. Also need to
merge per-view items. */
static GtkMenu *
create_item_context_menu (FMDirectoryView *view,
NautilusFile *file)
{
GtkMenu *menu;
GtkWidget *menu_item;
menu = GTK_MENU (gtk_menu_new ());
menu_item = gtk_menu_item_new_with_label ("Open");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Delete");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
return menu;
}
/* FIXME - need a way for specific views to add custom commands here. */
static GtkMenu *
create_background_context_menu (FMDirectoryView *view)
{
GtkMenu *menu;
GtkWidget *menu_item;
menu = GTK_MENU (gtk_menu_new ());
menu_item = gtk_menu_item_new_with_label ("Select all");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom in");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom out");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
gtk_object_ref(GTK_OBJECT(menu));
gtk_object_sink(GTK_OBJECT(menu));
return menu;
}
/**
* fm_directory_view_popup_item_context_menu
*
* Pop up a context menu appropriate to a specific view item at the last right click location.
* @view: FMDirectoryView of interest.
* @file: The model object for which a menu should be popped up.
*
* Return value: NautilusDirectory for this view.
*
**/
void
fm_directory_view_popup_item_context_menu (FMDirectoryView *view,
NautilusFile *file)
{
GtkMenu *menu;
g_assert (FM_IS_DIRECTORY_VIEW (view));
/* g_assert (NAUTILUS_IS_FILE (file)); */
menu = create_item_context_menu (view, file);
popup_temporary_context_menu (menu);
}
/**
* fm_directory_view_popup_background_context_menu
*
* Pop up a context menu appropriate to the view globally at the last right click location.
* @view: FMDirectoryView of interest.
*
* Return value: NautilusDirectory for this view.
*
**/
void
fm_directory_view_popup_background_context_menu (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
popup_context_menu (view->details->background_context_menu);
}
/**
* fm_directory_view_notify_selection_changed:
*
......
......@@ -139,5 +139,8 @@ void fm_directory_view_activate_entry (FMDirector
void fm_directory_view_notify_selection_changed (FMDirectoryView *view);
void fm_directory_view_populate (FMDirectoryView *view);
NautilusDirectory * fm_directory_view_get_model (FMDirectoryView *view);
void fm_directory_view_popup_background_context_menu (FMDirectoryView *view);
void fm_directory_view_popup_item_context_menu (FMDirectoryView *view,
NautilusFile *file);
#endif /* FM_DIRECTORY_VIEW_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment