diff --git a/docs/index.html b/docs/index.html index c880e34..e66c53a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1801,7 +1801,7 @@

A_ThisMenuItem - # The name of the most recently selected custom menu item (blank if none). [requires v1.0.13+] + #The name of the most recently selected custom menu item (blank if none). A_ThisMenu @@ -13004,7 +13004,7 @@

Examples

#

ControlSetText


-

Changes the text of a control.

+

Changes the text of a control. Only works for user-editable fields such as text inputs - cannot be used to change button labels etc.

diff --git a/src/cmd/gtk/menu.cr b/src/cmd/gtk/menu.cr index 0aa278d..2fd2a93 100644 --- a/src/cmd/gtk/menu.cr +++ b/src/cmd/gtk/menu.cr @@ -16,7 +16,7 @@ class Cmd::Gtk::Gui::Menu < Cmd::Base label = name if label.empty? item = ::Gtk::MenuItem.new_with_label name item.activate_signal.connect do - thread.runner.add_thread label.downcase, priority + thread.runner.add_thread label.downcase, priority, menu_item_name: name end tray_menu.append item end diff --git a/src/run/runner.cr b/src/run/runner.cr index 1a0ab84..b5d3647 100644 --- a/src/run/runner.cr +++ b/src/run/runner.cr @@ -58,6 +58,7 @@ module Run "a_ostype" => "Linux", "a_iconhidden" => "0", "a_thishotkey" => "", + "a_thismenuitem" => "", "a_priorhotkey" => "", } @initial_working_dir = Dir.current @@ -120,7 +121,7 @@ module Run # add to the thread queue. Depending on priority and `@threads`, it may be picked up # by the clock fiber immediately afterwards - def add_thread(cmd : Cmd::Base, label, priority, *, hotkey : Hotkey? = nil, gui_id : String? = nil, gui_control : String? = nil) : Thread + def add_thread(cmd : Cmd::Base, label, priority, *, hotkey : Hotkey? = nil, gui_id : String? = nil, gui_control : String? = nil, menu_item_name : String? = nil) : Thread thread = Thread.new(self, cmd, label, priority, @default_thread_settings, hotkey, gui_id, gui_control) i = @threads.index { |t| t.priority > thread.priority } || @threads.size @threads.insert(i, thread) @@ -128,15 +129,18 @@ module Run set_global_built_in_static_var "A_PriorHotkey", @built_in_static_vars["a_thishotkey"] set_global_built_in_static_var "A_ThisHotkey", hotkey.key_str end + if menu_item_name + set_global_built_in_static_var "A_ThisMenuItem", menu_item_name + end @run_thread_channel.send(nil) if i == @threads.size - 1 thread end # :ditto: # TODO: cmd_str should be called label (?) - def add_thread(cmd_str : String, priority, *, hotkey : Hotkey? = nil, gui_id : String? = nil, gui_control : String? = nil) : Thread? + def add_thread(cmd_str : String, priority, *, hotkey : Hotkey? = nil, gui_id : String? = nil, gui_control : String? = nil, menu_item_name : String? = nil) : Thread? cmd = @labels[cmd_str]? return nil if ! cmd - add_thread(cmd, cmd_str, priority, hotkey: hotkey, gui_id: gui_id, gui_control: gui_control) + add_thread(cmd, cmd_str, priority, hotkey: hotkey, gui_id: gui_id, gui_control: gui_control, menu_item_name: menu_item_name) end # Forever continuously figures out the "current thread" (`@threads.last`) and