Repository navigation
Lua Scripting - Dialogs-InputListBox - Template #92
Replies: 4 comments
|
create the functions that will do all the work eg
function my_cool_funk1(param)
DC.ExecuteCommand("cm_ChangeDir", param)
end
function my_cool_funk2(param)
DC.ExecuteCommand("cm_ShellExecute", param)
end
function my_cool_funk3()
DC.ExecuteCommand("cm_RenameOnly", "extensions=no")
end
function my_cool_funk4()
local script = os.getenv("HOME") .. "/Documents/lua/create-text-file-from-clip.lua"
local param1 = DC.ExpandVar('%"0%Ds')
DC.ExecuteCommand("cm_ExecuteScript", script, param1)
end
function my_cool_funk5()
local script = os.getenv("HOME") .. "/Documents/ffmpeg.sh"
local param1 = DC.ExpandVar('%p')
SysUtils.Execute(script .. " " .. param1)
endplace the text to be displayed and the these functions into a table local stuff = {
{label = "open dir", run = my_cool_funk1, param = "$HOME"},
{label = "open file", run = my_cool_funk2, param = "/etc/os-release"},
{label = "remame", run = my_cool_funk3 },
{label = "lua", run = my_cool_funk4 },
{label = "exec", run = my_cool_funk5 },
}prepare the variables for the listbox local listbox_title = "my cool dialog title"
local listbox_message = "my cool dialog message"
local listbox_default = nil
local listbox_items = {}
for i = 1, #stuff do
listbox_items[i] = stuff[i].label
endbonus: read the last used item from a tempfile local cache_file = os.getenv("HOME") .. "/.cache/" .. debug.getinfo(1, "S").short_src:match("[^/\\]+$") .. ".sav"
local file = io.open(cache_file, "r")
if file then
listbox_default = file:read("*line")
file:close()
enddisplay the listbox and call the appropriate function if an item is selected item, index = Dialogs.InputListBox(listbox_title, listbox_message, listbox_items, listbox_default)
if item then
stuff[index].run(stuff[index].param)bonus: save item to a tempfile so that it becomes the default the next time local file = io.open(cache_file, "w")
if file then
file:write(item .. '\n')
file:close()
endENDE end |
|
About environment variables, maybe something like local sPath = "~/.config/doublecmd/ignorelist.txt"
if string.sub(sPath, 1, 2) == "~/" then
sPath = "$HOME/" .. string.sub(sPath, 3, -1)
end
sPath = SysUtils.ExpandEnv(sPath)Cross-platform (in theory). |
|
I apologize for the delayed response. @j2969719 @Skif-off Ahh usually many of my Lua "template" based requests are generally not possible, nice that this one is. |
I added a piece of code and spoke only about that code :) (I didn’t look at the rest very carefully.)
Specify any other path, this is just an example. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Eventually I would like to get into possibly being able to create some list based dialogs using
Lua Scripting-Dialogs.InputListBox.I was wondering if anyone would be willing to provide a basic "template" so that I could just be able to edit the items I would like to appear in the list.
I am trying to think of all the different "types" of actions that these lists can make use of (I am aware that many items I will mention below will be probably be similar actions because they are all commands, but will mention regardless just in case)
-Go to path location
-Open a file
-Run a DC internal command
-Run a Lua script command
-Linux based command
-Any other actions that anyone can think to add to this template that could be useful to know about
I will provide a basic example below of what this "template" list could look like
TEMPLATE
-Go to $HOME/Downloads
-Open file $HOME/Documents/apple.txt
-Run DC command
cm_RenameOnlyParameters: extension=no
Controls: Files Panel
-Run Lua script such as
Parameters: $HOME/Documents/lua/create-text-file-from-clip.lua
Parameters: %"0%Ds
-Run Linux based command
Command: cm_ExecuteScript
Parameters: $HOME/Documents/ffmpeg.sh
Parameters: %p
-Any other useful "types" of actions
Thank you to anyone who reads this and anyone willing to provide a basic template for me to be able to edit.
All reactions