Created
September 5, 2016 16:24
-
-
Save mooffie/852f3fb133a34799eefc74bf0733fe45 to your computer and use it in GitHub Desktop.
mc^2: inject a "Toggle content" button to the Find File dialog.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
This snippet adds a "Toggle content" button to the Find File dialog. This | |
restores the old behavior of that dialog (which had a similar checkbox | |
before). | |
This was requested by a user in: | |
http://www.midnight-commander.org/ticket/3680 | |
]] | |
ui.Dialog.bind('<<open>>', function(dlg) | |
if dlg.text == T'Find File' and dlg:find('Input') then -- A crude way to detect the dialog. | |
-- | |
-- Inject a "toggle" button to the dialog. | |
-- | |
local btn = ui.Button(T'Toggle conte&nt') | |
-- Put it to the right of the other buttons. | |
btn.x = dlg.cols - btn.cols - 4 | |
btn.y = dlg.rows - 3 | |
btn.on_click = function() | |
-- | |
-- Toggle the text in the content field. | |
-- | |
local content = dlg:find('Input', 4) -- The "Content:" field is the 4'th input field. | |
if content.text == "" then | |
-- Content is empty. Load the last history entry. | |
content:command "HistoryPrev" | |
else | |
-- Clear content. | |
content.text = "" | |
end | |
-- See queue()'s documentation for why we use it. | |
ui.queue(function() | |
content:focus() | |
dlg:_send_message(ui.MSG_POST_KEY) -- Update the checkboxes (enable/disable them appropriately). | |
dlg:redraw_cursor() -- After drawing the checkboxes, we put the cursor back at its correct place. | |
end) | |
end | |
dlg:map_widget(btn:fixate()) | |
dlg:find('Input', 3):focus() -- Move focus back to the "File name:" field. | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment