~ubuntu-branches/ubuntu/natty/file-browser-applet/natty

« back to all changes in this revision

Viewing changes to src/context-menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2008-08-29 13:50:51 UTC
  • mfrom: (2.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080829135051-bani7mwsfjdbs9fx
Tags: 0.5.9-1
* New upstream release. (Closes: #497078)
* debian/control:
 - Remove Build-Depend on libgnomevfs2-dev and add Build-Depend
   on libglib2.0-dev as upstream has moved to GIO. (Closes: #493878)
 - Remove depreciated Depends and Build Depends on libgnome-desktop{-dev}
* Fixes Lintian warning: timewarp-standards-version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * File:                                context_menu.c
 
3
 * Created:                             April 2008
 
4
 * Created by:                  Axel von Bertoldi
 
5
 * Last Modified:               April 2008
 
6
 * Last Modified by:    Axel von Bertoldi
 
7
 * (C) 2005-2008                Axel von Bertoldi
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or modify it
 
10
 * under the terms of the GNU General Public License as published by the Free
 
11
 * Software Foundation; either version 2 of the License, or (at your option)
 
12
 * any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
16
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 
17
 * more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License along with
 
20
 * this program; if not, write to:
 
21
 * The Free Software Foundation, Inc.,
 
22
 * 51 Franklin Street, Fifth Floor
 
23
 * Boston, MA 02110-1301, USA.
 
24
 */
 
25
 
 
26
#include <glib/gprintf.h>
 
27
#include <glib.h>
 
28
 
 
29
#include "context-menu.h"
 
30
#include "vfs.h"
 
31
 
 
32
/******************************************************************************/
 
33
static void
 
34
context_menu_add_delete_item (const gchar *file_name,
 
35
                                                          GtkWidget *menu) {
 
36
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
37
                                                          
 
38
        GtkWidget *menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
 
39
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
40
        
 
41
        GtkWidget *item_label = GTK_BIN (menu_item)->child;
 
42
        gtk_label_set_text (GTK_LABEL (item_label), "Move to Trash");
 
43
        
 
44
        g_signal_connect_swapped (G_OBJECT (menu_item),
 
45
                                                          "activate",
 
46
                                                          G_CALLBACK (vfs_trash_file),
 
47
                                                          (gpointer) file_name);
 
48
}
 
49
/******************************************************************************/
 
50
static void
 
51
context_menu_add_fake_items (const gchar *file_name,
 
52
                                                         GtkWidget *menu) {
 
53
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
54
 
 
55
        GtkWidget *menu_item;
 
56
        
 
57
        menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
 
58
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
59
 
 
60
        menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_ADD, NULL);
 
61
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
62
 
 
63
        menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_APPLY, NULL);
 
64
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
65
 
 
66
        menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_BOLD, NULL);
 
67
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
68
 
 
69
        menu_item = gtk_image_menu_item_new_from_stock (GTK_STOCK_CDROM, NULL);
 
70
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
71
}
 
72
/******************************************************************************/
 
73
 
 
74
static void
 
75
context_menu_populate (const gchar *file_name,
 
76
                                           GtkWidget *menu) {
 
77
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
78
 
 
79
        context_menu_add_delete_item (file_name, menu);
 
80
        context_menu_add_fake_items (file_name, menu);
 
81
}
 
82
/******************************************************************************/
 
83
static void
 
84
context_menu_clean_up (GtkMenuShell *menu,
 
85
                                           GtkWidget *browser) {
 
86
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
87
 
 
88
        GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (browser));
 
89
        gtk_menu_shell_deactivate (GTK_MENU_SHELL (parent));
 
90
        
 
91
/*      gtk_grab_remove (GTK_WIDGET (menu));*/
 
92
/*      gdk_pointer_ungrab (GDK_CURRENT_TIME);*/
 
93
        
 
94
        gtk_widget_destroy (GTK_WIDGET (menu));
 
95
}
 
96
/******************************************************************************/
 
97
gboolean
 
98
context_menu_display (const gchar *file_name,
 
99
                                          GtkWidget *menu_item) {
 
100
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
 
101
 
 
102
        int event_button;
 
103
        int event_time;
 
104
 
 
105
        GdkEventButton *event = g_object_get_data (G_OBJECT (menu_item),
 
106
                                                                                           "button_event");
 
107
        if (event) {
 
108
                event_button = event->button;
 
109
                event_time = event->time;
 
110
        }
 
111
        else {
 
112
                event_button = 3;
 
113
                event_time = gtk_get_current_event_time();
 
114
        }
 
115
 
 
116
        GtkWidget *browser = g_object_get_data (G_OBJECT (menu_item),
 
117
                                                                                          "menu_browser");
 
118
 
 
119
/*
 
120
GtkWidget *panel_menu_bar = gtk_widget_get_parent (GTK_WIDGET (browser));
 
121
GtkWidget *parent_menu = gtk_widget_get_parent (GTK_WIDGET (menu_item));
 
122
GtkMenuShell *panel_menu_bar_shell = GTK_MENU_SHELL (panel_menu_bar);
 
123
GtkWidget *applet = gtk_widget_get_parent (GTK_WIDGET (panel_menu_bar));
 
124
GtkWidget *panel = gtk_widget_get_parent (GTK_WIDGET (applet));
 
125
*/
 
126
 
 
127
        GtkWidget *menu = gtk_menu_new ();
 
128
 
 
129
        g_signal_connect (GTK_MENU_SHELL (menu),
 
130
                                          "selection_done",
 
131
                                          G_CALLBACK (context_menu_clean_up),
 
132
                                          browser);
 
133
 
 
134
        context_menu_populate (file_name, menu);
 
135
 
 
136
        gtk_widget_show_all (menu);
 
137
 
 
138
        gtk_menu_popup (GTK_MENU (menu),
 
139
                                        NULL,
 
140
                                        NULL,
 
141
                                        NULL,
 
142
                                        NULL,
 
143
                                        event_button,
 
144
                                        event_time);
 
145
 
 
146
/*gtk_grab_add (GTK_WIDGET (menu));*/
 
147
/*gdk_pointer_grab (GTK_WIDGET (menu)->window,
 
148
                                  TRUE,
 
149
                                  0,
 
150
                                  NULL,
 
151
                                  NULL,
 
152
                                  GDK_CURRENT_TIME);*/
 
153
 
 
154
        return TRUE;
 
155
}
 
156
/******************************************************************************/