Skip to content

Commit

Permalink
Add A_ThisMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Aug 12, 2023
1 parent 62da8af commit ac1ba97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ <h4 class="calibre25"><a id="Variables.htm__h" href="#Variables.htm__h" class="p
<tbody class="calibre2">
<tr class="calibre3">
<td class="calibre4">A_ThisMenuItem</td>
<td class="calibre4"><a id="Variables.htm__ThisMenuItem" href="#Variables.htm__ThisMenuItem" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="tbd"> The name of the most recently selected <a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">custom menu item</a> (blank if none). [requires v1.0.13+]</span></td>
<td class="calibre4"><a id="Variables.htm__ThisMenuItem" href="#Variables.htm__ThisMenuItem" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a>The name of the most recently selected <a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">custom menu item</a> (blank if none).</span></td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_ThisMenu</td>
Expand Down Expand Up @@ -13004,7 +13004,7 @@ <h2 id="Examples">Examples</h2>
<div class="calibreEbookContent">
<a id="ControlSetText.htm" href="#ControlSetText.htm">#</a> <h2 class="calibre17">ControlSetText</h2>
<hr size="2" class="calibre24" />
<p class="calibre8">Changes the text of a control. </p>
<p class="calibre8">Changes the text of a control. <span class="x11">Only works for user-editable fields such as text inputs - cannot be used to change button labels etc.</span> </p>
<table cellspacing="5" width="100%" class="calibre28">
<tbody class="calibre2">
<tr class="calibre3">
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/gtk/menu.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/run/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module Run
"a_ostype" => "Linux",
"a_iconhidden" => "0",
"a_thishotkey" => "",
"a_thismenuitem" => "",
"a_priorhotkey" => "",
}
@initial_working_dir = Dir.current
Expand Down Expand Up @@ -120,23 +121,26 @@ 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)
if hotkey
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
Expand Down

0 comments on commit ac1ba97

Please sign in to comment.