Code polish
This commit is contained in:
parent
8d564675f8
commit
7509d7c960
@ -22,8 +22,8 @@ interface SystemTrayMenuAction {
|
||||
* (GtkStatusIcon/AppIndicator based).
|
||||
*
|
||||
* @param systemTray this is the parent, system tray object
|
||||
* @param parentMenu this is the parent menu of this menu entry
|
||||
* @param menuEntry this is the menu entry that was clicked
|
||||
* @param parent this is the parent menu of this menu entry
|
||||
* @param entry this is the menu entry that was clicked
|
||||
*/
|
||||
void onClick(SystemTray systemTray, Menu parentMenu, final MenuEntry menuEntry);
|
||||
void onClick(SystemTray systemTray, Menu parent, final MenuEntry entry);
|
||||
}
|
||||
|
@ -27,12 +27,12 @@ import dorkbox.systemTray.linux.jna.Gobject;
|
||||
import dorkbox.systemTray.linux.jna.Gtk;
|
||||
|
||||
class GtkMenu extends Menu {
|
||||
// must ONLY be created at the end of delete!
|
||||
volatile Pointer _native;
|
||||
|
||||
// called on dispatch
|
||||
GtkMenu(SystemTray systemTray, GtkMenu parentMenu) {
|
||||
super(systemTray, parentMenu);
|
||||
// this._native = Gtk.gtk_menu_new();
|
||||
GtkMenu(SystemTray systemTray, GtkMenu parent) {
|
||||
super(systemTray, parent);
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ abstract
|
||||
class GtkMenuEntry implements MenuEntry {
|
||||
private final int id = Menu.MENU_ID_COUNTER.getAndIncrement();
|
||||
|
||||
private final GtkMenu parentMenu;
|
||||
private final GtkMenu parent;
|
||||
final Pointer _native;
|
||||
|
||||
// this have to be volatile, because they can be changed from any thread
|
||||
@ -40,14 +40,14 @@ class GtkMenuEntry implements MenuEntry {
|
||||
* called from inside dispatch thread. ONLY creates the menu item, but DOES NOT attach it!
|
||||
* this is a FLOATING reference. See: https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#floating-ref
|
||||
*/
|
||||
GtkMenuEntry(final GtkMenu parentMenu, final Pointer menuItem) {
|
||||
this.parentMenu = parentMenu;
|
||||
GtkMenuEntry(final GtkMenu parent, final Pointer menuItem) {
|
||||
this.parent = parent;
|
||||
this._native = menuItem;
|
||||
}
|
||||
|
||||
public
|
||||
Menu getParent() {
|
||||
return parentMenu;
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,16 +148,16 @@ class GtkMenuEntry implements MenuEntry {
|
||||
*/
|
||||
public final
|
||||
void remove() {
|
||||
Gtk.gtk_container_remove(parentMenu._native, _native);
|
||||
Gtk.gtk_menu_shell_deactivate(parentMenu._native, _native);
|
||||
Gtk.gtk_container_remove(parent._native, _native);
|
||||
Gtk.gtk_menu_shell_deactivate(parent._native, _native);
|
||||
|
||||
removePrivate();
|
||||
|
||||
Gtk.gtk_widget_destroy(_native);
|
||||
|
||||
// have to rebuild the menu now...
|
||||
parentMenu.deleteMenu();
|
||||
parentMenu.createMenu();
|
||||
parent.deleteMenu();
|
||||
parent.createMenu();
|
||||
}
|
||||
|
||||
// called when this item is removed. Necessary to cleanup/remove itself
|
||||
|
@ -43,8 +43,8 @@ class GtkMenuEntryItem extends GtkMenuEntry implements GCallback {
|
||||
* called from inside dispatch thread. ONLY creates the menu item, but DOES NOT attach it!
|
||||
* this is a FLOATING reference. See: https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#floating-ref
|
||||
*/
|
||||
GtkMenuEntryItem(final GtkMenu parentMenu, final SystemTrayMenuAction callback) {
|
||||
super(parentMenu, Gtk.gtk_image_menu_item_new_with_label(""));
|
||||
GtkMenuEntryItem(final GtkMenu parent, final SystemTrayMenuAction callback) {
|
||||
super(parent, Gtk.gtk_image_menu_item_new_with_label(""));
|
||||
this.callback = callback;
|
||||
|
||||
|
||||
|
@ -29,8 +29,8 @@ class GtkMenuEntryStatus extends GtkMenuEntryItem {
|
||||
* called from inside dispatch thread. ONLY creates the menu item, but DOES NOT attach it!
|
||||
* this is a FLOATING reference. See: https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#floating-ref
|
||||
*/
|
||||
GtkMenuEntryStatus(final GtkMenu parentMenu, final String text) {
|
||||
super(parentMenu, null);
|
||||
GtkMenuEntryStatus(final GtkMenu parent, final String text) {
|
||||
super(parent, null);
|
||||
setText(text);
|
||||
}
|
||||
|
||||
|
@ -383,11 +383,11 @@ class Gtk {
|
||||
* @param callback will never be null.
|
||||
*/
|
||||
public static
|
||||
void proxyClick(final Menu parentMenu, final MenuEntry menuEntry, final SystemTrayMenuAction callback) {
|
||||
void proxyClick(final Menu parent, final MenuEntry menuEntry, final SystemTrayMenuAction callback) {
|
||||
Gtk.isDispatch = true;
|
||||
|
||||
try {
|
||||
callback.onClick(parentMenu.getSystemTray(), parentMenu, menuEntry);
|
||||
callback.onClick(parent.getSystemTray(), parent, menuEntry);
|
||||
} catch (Throwable throwable) {
|
||||
SystemTray.logger.error("Error calling menu entry {} click event.", menuEntry.getText(), throwable);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user