1
namespace ElementaryWidgets {
5
public abstract class ToolButtonWithMenu : ToggleToolButton
8
private PositionType _menu_orientation;
9
protected PositionType menu_orientation{
11
if(value == PositionType.TOP || value == PositionType.BOTTOM){
12
value = PositionType.LEFT;
15
_menu_orientation = value;
18
return _menu_orientation;
22
public ToolButtonWithMenu (Image image, string label, Menu _menu, PositionType menu_orientation = PositionType.LEFT)
24
this.menu_orientation = menu_orientation;
27
label_widget = new Label (label);
28
((Label) label_widget).use_underline = true;
30
set_tooltip_text ("Menu");
32
menu.attach_to_widget (this, null);
33
menu.deactivate.connect(() => {
37
mnemonic_activate.connect(on_mnemonic_activate);
38
menu.deactivate.connect(popdown_menu);
39
clicked.connect(on_clicked);
42
private bool on_mnemonic_activate (bool group_cycling)
44
// ToggleButton always grabs focus away from the editor,
45
// so reimplement Widget's version, which only grabs the
46
// focus if we are group cycling.
49
} else if (can_focus) {
56
protected new void popup_menu(Gdk.EventButton? ev)
62
(ev == null) ? 0 : ev.button,
63
(ev == null) ? get_current_event_time() : ev.time);
65
// Highlight the parent
66
if (menu.attach_widget != null)
67
menu.attach_widget.set_state(StateType.SELECTED);
71
protected void popdown_menu ()
75
// Unhighlight the parent
76
if (menu.attach_widget != null)
77
menu.attach_widget.set_state(Gtk.StateType.NORMAL);
80
public override void show_all(){
85
private void on_clicked ()
87
menu.select_first (true);
91
private void get_menu_position (Menu menu, out int x, out int y, out bool push_in)
93
if (menu.attach_widget == null ||
94
menu.attach_widget.get_window() == null) {
95
// Prevent null exception in weird cases
102
menu.attach_widget.get_window().get_origin (out x, out y);
103
Allocation allocation;
104
menu.attach_widget.get_allocation(out allocation);
111
menu.get_size_request(out width, out height);
113
if (y + height >= menu.attach_widget.get_screen().get_height())
116
y += allocation.height;
122
public class AppMenu : ToolButtonWithMenu
126
string LAUNCHPAD_NAME;
134
public AppMenu (Window window, Menu menu,
136
string launchpad_name,
143
Image image = new Image.from_stock(Stock.PROPERTIES, IconSize.MENU);
144
MenuItem help_item = new MenuItem.with_label ("Get Help Online...");
145
MenuItem translate_item = new MenuItem.with_label ("Translate This Application...");
146
MenuItem report_item = new MenuItem.with_label ("Report a Problem...");
147
MenuItem about_item = new MenuItem.with_label ("About");
148
menu.append (help_item);
149
menu.append (translate_item);
150
menu.append (report_item);
151
menu.append(new SeparatorMenuItem());
152
menu.append (about_item);
153
base(image, "Menu", menu);
155
LAUNCHPAD_NAME = launchpad_name;
160
COPYRIGHT = copyright;
161
ICON_NAME = icon_name;
162
help_item.activate.connect(() => launch_launchpad("answers"));
163
translate_item.activate.connect(() => launch_launchpad("translations"));
164
report_item.activate.connect(() => launch_launchpad("bugs"));
165
about_item.activate.connect(about_dialog);
168
private void launch_launchpad (string service) {
170
GLib.Process.spawn_async ("/usr/bin/",
172
"https://"+service+".launchpad.net/"+LAUNCHPAD_NAME},
173
null, GLib.SpawnFlags.STDERR_TO_DEV_NULL, null, null);
177
private void about_dialog () {
178
Gtk.show_about_dialog (WINDOW,
179
"program-name", APP_NAME,
182
"copyright", COPYRIGHT,
184
"logo-icon-name", ICON_NAME,