/usr/share/gtk-sharp2-examples/Actions.cs is in gtk-sharp2-examples 2.12.10-5.
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | // Actions.cs - Gtk.Action class Test implementation (port of testactions.c)
//
// Author: Jeroen Zwartepoorte <jeroen@xs4all.nl>
//
// (c) 2004 Jeroen Zwartepoorte
namespace GtkSamples {
using Gtk;
using System;
using System.Collections;
public class Actions {
static VBox box = null;
static Statusbar statusbar = null;
static ActionGroup group = null;
static Toolbar toolbar = null;
static SpinButton spin = null;
static ActionGroup dynGroup = null;
static uint mergeId = 0;
static UIManager uim = null;
static Hashtable actions = new Hashtable ();
/* XML description of the menus for the test app. The parser understands
* a subset of the Bonobo UI XML format, and uses GMarkup for parsing */
const string ui_info =
" <menubar>\n" +
" <menu name=\"Menu _1\" action=\"Menu1Action\">\n" +
" <menuitem name=\"cut\" action=\"cut\" />\n" +
" <menuitem name=\"copy\" action=\"copy\" />\n" +
" <menuitem name=\"paste\" action=\"paste\" />\n" +
" <separator name=\"sep1\" />\n" +
" <menuitem name=\"bold1\" action=\"bold\" />\n" +
" <menuitem name=\"bold2\" action=\"bold\" />\n" +
" <separator name=\"sep2\" />\n" +
" <menuitem name=\"toggle-cnp\" action=\"toggle-cnp\" />\n" +
" <separator name=\"sep3\" />\n" +
" <menuitem name=\"quit\" action=\"quit\" />\n" +
" </menu>\n" +
" <menu name=\"Menu _2\" action=\"Menu2Action\">\n" +
" <menuitem name=\"cut\" action=\"cut\" />\n" +
" <menuitem name=\"copy\" action=\"copy\" />\n" +
" <menuitem name=\"paste\" action=\"paste\" />\n" +
" <separator name=\"sep4\"/>\n" +
" <menuitem name=\"bold\" action=\"bold\" />\n" +
" <separator name=\"sep5\"/>\n" +
" <menuitem name=\"justify-left\" action=\"justify-left\" />\n" +
" <menuitem name=\"justify-center\" action=\"justify-center\" />\n" +
" <menuitem name=\"justify-right\" action=\"justify-right\" />\n" +
" <menuitem name=\"justify-fill\" action=\"justify-fill\" />\n" +
" <separator name=\"sep6\"/>\n" +
" <menuitem name=\"customise-accels\" action=\"customise-accels\" />\n" +
" <separator name=\"sep7\"/>\n" +
" <menuitem action=\"toolbar-icons\" />\n" +
" <menuitem action=\"toolbar-text\" />\n" +
" <menuitem action=\"toolbar-both\" />\n" +
" <menuitem action=\"toolbar-both-horiz\" />\n" +
" <separator name=\"sep8\"/>\n" +
" <menuitem action=\"toolbar-small-icons\" />\n" +
" <menuitem action=\"toolbar-large-icons\" />\n" +
" </menu>\n" +
" <menu name=\"DynamicMenu\" action=\"Menu3Action\" />\n" +
" </menubar>\n" +
" <toolbar name=\"toolbar\">\n" +
" <toolitem name=\"cut\" action=\"cut\" />\n" +
" <toolitem name=\"copy\" action=\"copy\" />\n" +
" <toolitem name=\"paste\" action=\"paste\" />\n" +
" <separator name=\"sep9\" />\n" +
" <toolitem name=\"bold\" action=\"bold\" />\n" +
" <separator name=\"sep10\" />\n" +
" <toolitem name=\"justify-left\" action=\"justify-left\" />\n" +
" <toolitem name=\"justify-center\" action=\"justify-center\" />\n" +
" <toolitem name=\"justify-right\" action=\"justify-right\" />\n" +
" <toolitem name=\"justify-fill\" action=\"justify-fill\" />\n" +
" <separator name=\"sep11\"/>\n" +
" <toolitem name=\"quit\" action=\"quit\" />\n" +
" </toolbar>\n";
static ActionEntry[] entries = new ActionEntry[] {
new ActionEntry ("Menu1Action", null, "Menu _1", null, null, null),
new ActionEntry ("Menu2Action", null, "Menu _2", null, null, null),
new ActionEntry ("Menu3Action", null, "_Dynamic Menu", null, null, null),
new ActionEntry ("cut", Stock.Cut, "C_ut", "<control>X",
"Cut the selected text to the clipboard",
new EventHandler (OnActivate)),
new ActionEntry ("copy", Stock.Copy, "_Copy", "<control>C",
"Copy the selected text to the clipboard",
new EventHandler (OnActivate)),
new ActionEntry ("paste", Stock.Paste, "_Paste", "<control>V",
"Paste the text from the clipboard",
new EventHandler (OnActivate)),
new ActionEntry ("quit", Stock.Quit, null, "<control>Q",
"Quit the application", new EventHandler (OnQuit)),
new ActionEntry ("customise-accels", null, "Customise _Accels", null,
"Customize keyboard shortcuts",
new EventHandler (OnCustomizeAccels)),
new ActionEntry ("toolbar-small-icons", null, "Small Icons", null,
null, new EventHandler (OnToolbarSizeSmall)),
new ActionEntry ("toolbar-large-icons", null, "Large Icons", null,
null, new EventHandler (OnToolbarSizeLarge))
};
static ToggleActionEntry[] toggleEntries = new ToggleActionEntry[] {
new ToggleActionEntry ("bold", Stock.Bold, "_Bold", "<control>B",
"Change to bold face",
new EventHandler (OnToggle), false),
new ToggleActionEntry ("toggle-cnp", null, "Enable Cut/Copy/Paste",
null, "Change the sensitivity of the cut, copy and paste actions",
new EventHandler (OnToggleCnp), true)
};
enum Justify {
Left,
Center,
Right,
Fill
};
static RadioActionEntry[] radioEntries = new RadioActionEntry[] {
new RadioActionEntry ("justify-left", Stock.JustifyLeft, "_Left",
"<control>L", "Left justify the text",
(int)Justify.Left),
new RadioActionEntry ("justify-center", Stock.JustifyCenter, "C_enter",
"<control>E", "Center justify the text",
(int)Justify.Center),
new RadioActionEntry ("justify-right", Stock.JustifyRight, "_Right",
"<control>R", "Right justify the text",
(int)Justify.Right),
new RadioActionEntry ("justify-fill", Stock.JustifyFill, "_Fill",
"<control>J", "Fill justify the text",
(int)Justify.Fill)
};
static RadioActionEntry[] toolbarEntries = new RadioActionEntry[] {
new RadioActionEntry ("toolbar-icons", null, "Icons", null,
null, (int)ToolbarStyle.Icons),
new RadioActionEntry ("toolbar-text", null, "Text", null,
null, (int)ToolbarStyle.Text),
new RadioActionEntry ("toolbar-both", null, "Both", null,
null, (int)ToolbarStyle.Both),
new RadioActionEntry ("toolbar-both-horiz", null, "Both Horizontal",
null, null, (int)ToolbarStyle.BothHoriz)
};
public static int Main (string[] args)
{
Application.Init ();
Window win = new Window ("Action Demo");
win.DefaultSize = new Gdk.Size (200, 150);
win.DeleteEvent += new DeleteEventHandler (OnWindowDelete);
box = new VBox (false, 0);
win.Add (box);
group = new ActionGroup ("TestActions");
group.Add (entries);
group.Add (toggleEntries);
group.Add (radioEntries, (int)Justify.Left, new ChangedHandler (OnRadio));
group.Add (toolbarEntries, (int)ToolbarStyle.BothHoriz, new ChangedHandler (OnToolbarStyle));
uim = new UIManager ();
uim.AddWidget += new AddWidgetHandler (OnWidgetAdd);
uim.ConnectProxy += new ConnectProxyHandler (OnProxyConnect);
uim.InsertActionGroup (group, 0);
uim.AddUiFromString (ui_info);
statusbar = new Statusbar ();
box.PackEnd (statusbar, false, true, 0);
VBox vbox = new VBox (false, 5);
Button button = new Button ("Blah");
vbox.PackEnd (button, true, true, 0);
HBox hbox = new HBox (false, 5);
spin = new SpinButton (new Adjustment (100, 100, 10000, 1, 100, 100), 100, 0);
hbox.PackStart (spin, true, true, 0);
button = new Button ("Remove");
button.Clicked += new EventHandler (OnDynamicRemove);
hbox.PackEnd (button, false, false, 0);
button = new Button ("Add");
button.Clicked += new EventHandler (OnDynamicAdd);
hbox.PackEnd (button, false, false, 0);
vbox.PackEnd (hbox, false, false, 0);
box.PackEnd (vbox, true, true, 0);
win.ShowAll ();
Application.Run ();
return 0;
}
static void OnActivate (object obj, EventArgs args)
{
Gtk.Action action = (Gtk.Action)obj;
Console.WriteLine ("Action {0} (type={1}) activated",
action.Name, action.GetType ().FullName);
}
static void OnCustomizeAccels (object obj, EventArgs args)
{
Console.WriteLine ("Sorry, accel dialog not available");
}
static void OnToolbarSizeSmall (object obj, EventArgs args)
{
toolbar.IconSize = IconSize.SmallToolbar;
}
static void OnToolbarSizeLarge (object obj, EventArgs args)
{
toolbar.IconSize = IconSize.LargeToolbar;
}
static void OnToggle (object obj, EventArgs args)
{
ToggleAction action = (ToggleAction)obj;
Console.WriteLine ("Action {0} (type={1}) activated (active={2})",
action.Name, action.GetType ().FullName, action.Active);
}
static void OnToggleCnp (object obj, EventArgs args)
{
Gtk.Action action = (ToggleAction)obj;
bool sensitive = ((ToggleAction)action).Active;
action = group.GetAction ("cut");
action.Sensitive = sensitive;
action = group.GetAction ("copy");
action.Sensitive = sensitive;
action = group.GetAction ("paste");
action.Sensitive = sensitive;
action = group.GetAction ("toggle-cnp");
if (sensitive)
action.Label = "Disable Cut and past ops";
else
action.Label = "Enable Cut and paste ops";
}
static void OnRadio (object obj, ChangedArgs args)
{
RadioAction action = (RadioAction)obj;
Console.WriteLine ("Action {0} (type={1}) activated (active={2}) (value {3})",
action.Name, action.GetType ().FullName,
action.Active, action.CurrentValue);
}
static void OnToolbarStyle (object obj, ChangedArgs args)
{
RadioAction action = (RadioAction)obj;
ToolbarStyle style = (ToolbarStyle)action.CurrentValue;
toolbar.ToolbarStyle = style;
}
static void OnDynamicAdd (object obj, EventArgs args)
{
if (mergeId != 0 || dynGroup != null)
return;
int num = spin.ValueAsInt;
dynGroup = new ActionGroup ("DynamicActions");
uim.InsertActionGroup (dynGroup, 0);
mergeId = uim.NewMergeId ();
for (int i = 0; i < num; i++) {
string name = "DynAction" + i;
string label = "Dynamic Action " + i;
Gtk.Action action = new Gtk.Action (name, label);
dynGroup.Add (action);
uim.AddUi (mergeId, "/menubar/DynamicMenu", name,
name, UIManagerItemType.Menuitem, false);
}
uim.EnsureUpdate ();
}
static void OnDynamicRemove (object obj, EventArgs args)
{
if (mergeId == 0 || dynGroup == null)
return;
uim.RemoveUi (mergeId);
uim.EnsureUpdate ();
mergeId = 0;
uim.RemoveActionGroup (dynGroup);
dynGroup = null;
}
static void OnWindowDelete (object obj, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
static void OnWidgetAdd (object obj, AddWidgetArgs args)
{
if (args.Widget is Toolbar)
toolbar = (Toolbar)args.Widget;
args.Widget.Show ();
box.PackStart (args.Widget, false, true, 0);
}
static void OnSelect (object obj, EventArgs args)
{
Gtk.Action action = (Gtk.Action) actions[obj];
if (action.Tooltip != null)
statusbar.Push (0, action.Tooltip);
}
static void OnDeselect (object obj, EventArgs args)
{
statusbar.Pop (0);
}
static void OnProxyConnect (object obj, ConnectProxyArgs args)
{
if (args.Proxy is MenuItem) {
actions[args.Proxy] = args.Action;
((Item)args.Proxy).Selected += new EventHandler (OnSelect);
((Item)args.Proxy).Deselected += new EventHandler (OnDeselect);
}
}
static void OnQuit (object obj, EventArgs args)
{
Application.Quit ();
}
}
}
|