/usr/share/gtk-doc/html/libpanel-applet/getting-started.context-menu.setup.html is in libpanel-applet-doc 3.20.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Setting Up the Menu: Panel Applet Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Panel Applet Reference Manual">
<link rel="up" href="getting-started.context-menu.html" title="Using a Context Menu">
<link rel="prev" href="getting-started.context-menu.html" title="Using a Context Menu">
<link rel="next" href="getting-started.settings.html" title="Settings">
<meta name="generator" content="GTK-Doc V1.25 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="getting-started.context-menu.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="getting-started.context-menu.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="getting-started.settings.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="getting-started.context-menu.setup"></a>Setting Up the Menu</h2></div></div></div>
<p>
The only part of dealing with a context menu that is specific to applets is how to setup the context menu. Once it is setup, this is really just a matter of using <span class="type">GtkAction</span>.
</p>
<p>
To setup the context menu of the applet, the <a class="link" href="libpanel-applet-Panel-Applet.html#panel-applet-setup-menu-from-file" title="panel_applet_setup_menu_from_file ()"><code class="function">panel_applet_setup_menu_from_file()</code></a> function should be used, with a path to a <a class="link" href="getting-started.context-menu.html#getting-started.context-menu.xml-file" title="Menu XML File">menu XML file</a> and a <span class="type">GtkActionGroup</span> object containing all actions that are used in the menu XML file. The example below shows how to achieve this:
</p>
<div class="example">
<a name="id-1.3.5.4.4"></a><p class="title"><b>Example 3. Hello World applet, with a context menu</b></p>
<div class="example-contents">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc ppc">#include <glib/gi18n.h></span>
<span class="gtkdoc ppc">#include <gtk/gtk.h></span>
<span class="gtkdoc ppc">#include <panel-applet.h></span>
<span class="comment">/* This would usually be defined in config.h */</span>
<span class="gtkdoc ppc">#define GETTEXT_PACKAGE</span> <span class="gtkdoc pps">"hello-world"</span><span class="gtkdoc ppc"></span>
<span class="comment">/* This would usually be defined in Makefile.am */</span>
<span class="gtkdoc ppc">#define HELLO_WORLD_UI_DIR</span> <span class="gtkdoc pps">"/usr/share/hello-world"</span><span class="gtkdoc ppc"></span>
<span class="gtkdoc kwb">static void</span> <span class="function">hello_world_applet_prefs</span> <span class="gtkdoc opt">(</span>GtkAction <span class="gtkdoc opt">*</span>action<span class="gtkdoc opt">,</span>
PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">);</span>
<span class="gtkdoc kwb">static void</span> <span class="function">hello_world_applet_say</span> <span class="gtkdoc opt">(</span>GtkAction <span class="gtkdoc opt">*</span>action<span class="gtkdoc opt">,</span>
PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">);</span>
<span class="gtkdoc kwb">static const</span> GtkActionEntry hello_world_menu_actions <span class="gtkdoc opt">[] = {</span>
<span class="gtkdoc opt">{</span> <span class="string">"HelloWorldPrefs"</span><span class="gtkdoc opt">,</span> GTK_STOCK_HELP<span class="gtkdoc opt">,</span> <span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-I18N.html#N-:CAPS">N_</a></span><span class="gtkdoc opt">(</span><span class="string">"_Preferences"</span><span class="gtkdoc opt">),</span>
NULL<span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">,</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span> <span class="gtkdoc opt">(</span>hello_world_applet_prefs<span class="gtkdoc opt">) },</span>
<span class="gtkdoc opt">{</span> <span class="string">"HelloWorldSay"</span><span class="gtkdoc opt">,</span> GTK_STOCK_ABOUT<span class="gtkdoc opt">,</span> <span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-I18N.html#N-:CAPS">N_</a></span><span class="gtkdoc opt">(</span><span class="string">"_Say Hello"</span><span class="gtkdoc opt">),</span>
NULL<span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">,</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span> <span class="gtkdoc opt">(</span>hello_world_applet_say<span class="gtkdoc opt">) }</span>
<span class="gtkdoc opt">};</span>
<span class="gtkdoc kwb">static void</span>
<span class="function">hello_world_applet_prefs</span> <span class="gtkdoc opt">(</span>GtkAction <span class="gtkdoc opt">*</span>action<span class="gtkdoc opt">,</span>
PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
GtkWidget <span class="gtkdoc opt">*</span>dialog<span class="gtkdoc opt">;</span>
dialog <span class="gtkdoc opt">=</span> <span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkMessageDialog.html#gtk-message-dialog-new">gtk_message_dialog_new</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">,</span> <span class="number">0</span><span class="gtkdoc opt">,</span>
GTK_MESSAGE_INFO<span class="gtkdoc opt">,</span> GTK_BUTTONS_CLOSE<span class="gtkdoc opt">,</span>
<span class="string">"Preferences"</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span> <span class="gtkdoc opt">(</span>dialog<span class="gtkdoc opt">,</span> <span class="string">"response"</span><span class="gtkdoc opt">,</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span> <span class="gtkdoc opt">(</span>gtk_widget_destroy<span class="gtkdoc opt">),</span> NULL<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-show">gtk_widget_show</a></span> <span class="gtkdoc opt">(</span>dialog<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span>
<span class="gtkdoc kwb">static void</span>
<span class="function">hello_world_applet_say</span> <span class="gtkdoc opt">(</span>GtkAction <span class="gtkdoc opt">*</span>action<span class="gtkdoc opt">,</span>
PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
GtkWidget <span class="gtkdoc opt">*</span>dialog<span class="gtkdoc opt">;</span>
dialog <span class="gtkdoc opt">=</span> <span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkMessageDialog.html#gtk-message-dialog-new">gtk_message_dialog_new</a></span> <span class="gtkdoc opt">(</span>NULL<span class="gtkdoc opt">,</span> <span class="number">0</span><span class="gtkdoc opt">,</span>
GTK_MESSAGE_INFO<span class="gtkdoc opt">,</span> GTK_BUTTONS_CLOSE<span class="gtkdoc opt">,</span>
<span class="string">"Hello World!"</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Signals.html#g-signal-connect">g_signal_connect</a></span> <span class="gtkdoc opt">(</span>dialog<span class="gtkdoc opt">,</span> <span class="string">"response"</span><span class="gtkdoc opt">,</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-Closures.html#G-CALLBACK:CAPS">G_CALLBACK</a></span> <span class="gtkdoc opt">(</span>gtk_widget_destroy<span class="gtkdoc opt">),</span> NULL<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-show">gtk_widget_show</a></span> <span class="gtkdoc opt">(</span>dialog<span class="gtkdoc opt">);</span>
<span class="gtkdoc opt">}</span>
<span class="gtkdoc kwb">static</span> gboolean
<span class="function">hello_world_applet_start</span> <span class="gtkdoc opt">(</span>PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
GtkWidget <span class="gtkdoc opt">*</span>label<span class="gtkdoc opt">;</span>
GtkActionGroup <span class="gtkdoc opt">*</span>action_group<span class="gtkdoc opt">;</span>
gchar <span class="gtkdoc opt">*</span>ui_path<span class="gtkdoc opt">;</span>
label <span class="gtkdoc opt">=</span> <span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkLabel.html#gtk-label-new">gtk_label_new</a></span> <span class="gtkdoc opt">(</span><span class="string">"Hello World"</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkContainer.html#gtk-container-add">gtk_container_add</a></span> <span class="gtkdoc opt">(</span><span class="function">GTK_CONTAINER</span> <span class="gtkdoc opt">(</span>applet<span class="gtkdoc opt">),</span> label<span class="gtkdoc opt">);</span>
action_group <span class="gtkdoc opt">=</span> <span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkActionGroup.html#gtk-action-group-new">gtk_action_group_new</a></span> <span class="gtkdoc opt">(</span><span class="string">"Hello World Applet Actions"</span><span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkActionGroup.html#gtk-action-group-set-translation-domain">gtk_action_group_set_translation_domain</a></span> <span class="gtkdoc opt">(</span>action_group<span class="gtkdoc opt">,</span> GETTEXT_PACKAGE<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkActionGroup.html#gtk-action-group-add-actions">gtk_action_group_add_actions</a></span> <span class="gtkdoc opt">(</span>action_group<span class="gtkdoc opt">,</span>
hello_world_menu_actions<span class="gtkdoc opt">,</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#G-N-ELEMENTS:CAPS">G_N_ELEMENTS</a></span> <span class="gtkdoc opt">(</span>hello_world_menu_actions<span class="gtkdoc opt">),</span>
applet<span class="gtkdoc opt">);</span>
ui_path <span class="gtkdoc opt">=</span> <span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Miscellaneous-Utility-Functions.html#g-build-filename">g_build_filename</a></span> <span class="gtkdoc opt">(</span>HELLO_WORLD_UI_DIR<span class="gtkdoc opt">,</span> <span class="string">"hello-world-menu.xml"</span><span class="gtkdoc opt">,</span> NULL<span class="gtkdoc opt">);</span>
<span class="function"><a href="libpanel-applet-Panel-Applet.html#panel-applet-setup-menu-from-file">panel_applet_setup_menu_from_file</a></span> <span class="gtkdoc opt">(</span>applet<span class="gtkdoc opt">,</span> ui_path<span class="gtkdoc opt">,</span> action_group<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-Memory-Allocation.html#g-free">g_free</a></span> <span class="gtkdoc opt">(</span>ui_path<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span> <span class="gtkdoc opt">(</span>action_group<span class="gtkdoc opt">);</span>
<span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-show-all">gtk_widget_show_all</a></span> <span class="gtkdoc opt">(</span><span class="function">GTK_WIDGET</span> <span class="gtkdoc opt">(</span>applet<span class="gtkdoc opt">));</span>
<span class="keyword">return</span> TRUE<span class="gtkdoc opt">;</span>
<span class="gtkdoc opt">}</span>
<span class="gtkdoc kwb">static</span> gboolean
<span class="function">hello_world_factory_callback</span> <span class="gtkdoc opt">(</span>PanelApplet <span class="gtkdoc opt">*</span>applet<span class="gtkdoc opt">,</span>
<span class="gtkdoc kwb">const</span> gchar <span class="gtkdoc opt">*</span>iid<span class="gtkdoc opt">,</span>
gpointer data<span class="gtkdoc opt">)</span>
<span class="gtkdoc opt">{</span>
gboolean retval <span class="gtkdoc opt">=</span> FALSE<span class="gtkdoc opt">;</span>
<span class="keyword">if</span> <span class="gtkdoc opt">(</span><span class="function"><a href="/usr/share/gtk-doc/html/glib/glib-String-Utility-Functions.html#g-strcmp0">g_strcmp0</a></span> <span class="gtkdoc opt">(</span>iid<span class="gtkdoc opt">,</span> <span class="string">"HelloWorldApplet"</span><span class="gtkdoc opt">) ==</span> <span class="number">0</span><span class="gtkdoc opt">)</span>
retval <span class="gtkdoc opt">=</span> <span class="function">hello_world_applet_start</span> <span class="gtkdoc opt">(</span>applet<span class="gtkdoc opt">);</span>
<span class="keyword">return</span> retval<span class="gtkdoc opt">;</span>
<span class="gtkdoc opt">}</span>
<span class="function"><a href="libpanel-applet-Panel-Applet-Factory.html#PANEL-APPLET-OUT-PROCESS-FACTORY:CAPS">PANEL_APPLET_OUT_PROCESS_FACTORY</a></span> <span class="gtkdoc opt">(</span><span class="string">"HelloWorldFactory"</span><span class="gtkdoc opt">,</span>
PANEL_TYPE_APPLET<span class="gtkdoc opt">,</span>
hello_world_factory_callback<span class="gtkdoc opt">,</span>
NULL<span class="gtkdoc opt">)</span></pre></td>
</tr>
</tbody>
</table>
</div>
</div>
<br class="example-break"><p>
Here are the changes compared to the <a class="link" href="getting-started.example.html#getting-started.example.simple" title="Example 1. Hello World applet">simple example</a> with no context menu:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
We define a list of <span class="type">GtkActionEntry</span> entries: <code class="constant">hello_world_menu_actions</code>. This will be used later on to build <span class="type">GtkAction</span> objects, with their label and callback. We obviously implement the callbacks.
</p></li>
<li class="listitem"><p>
We change <code class="function">hello_world_applet_start()</code> to define a <span class="type">GtkActionGroup</span> object, to which we add, with <code class="function">gtk_action_group_add_actions()</code>, <span class="type">GtkAction</span> objects based on the <span class="type">GtkActionEntry</span> entries. Note that the the last argument to <code class="function">gtk_action_group_add_actions()</code> will be passed as user data to the callbacks.
</p></li>
<li class="listitem"><p>
We also change <code class="function">hello_world_applet_start()</code> to add this <span class="type">GtkActionGroup</span> object to the context menu of the applet, by calling <a class="link" href="libpanel-applet-Panel-Applet.html#panel-applet-setup-menu-from-file" title="panel_applet_setup_menu_from_file ()"><code class="function">panel_applet_setup_menu_from_file()</code></a>. This function takes as argument a path to the <a class="link" href="getting-started.context-menu.html#getting-started.context-menu.xml-file" title="Menu XML File">menu XML file</a> that will define how to display the <span class="type">GtkAction</span> objects in the context menu.
</p></li>
</ul></div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.25</div>
</body>
</html>
|