lite-xl / lite-xl-plugins

Plugins for the Lite XL editor
MIT License
368 stars 96 forks source link

[Request] gui_filepicker: Show dialog on current file's directory #471

Open hellium6 opened 1 month ago

hellium6 commented 1 month ago

Thanks to the author(s) for the plugin.

I have zenity. Currently when I press Ctrl+O, for example, it opens a "Recent" files section. It would be great if this could be opened in the same directory as the file opened in current tab. Because often I need to check and open adjacent files from the same directory. I haven't tested other dialogs, such as save or save as, but it could be useful for them too.

With zenity, I found --filename is an option.

       File selection options

       --filename=FILENAME
              Set the file or directory to be selected by default

Running below, opens the dialog in /usr/local. / at the end shown in the command seems to be important, otherwise, it just opens /usr and selects local dir.

$ zenity --file-selection --filename=/usr/local/

Haven't tested with kdialog. But found this which says "You have to specify a starting directory, and can optionally provide a filter", then has this example:

$ kdialog --getopenfilename /usr/share/sounds/ '*.ogg'

I have a feeling / at the end shown here is also important in kdialog.

kemzops commented 1 month ago
local project_dir = core.project_dir
  if project_dir and project_dir ~= "" then
    project_dir = project_dir .. PATHSEP
  else
    project_dir = "~/"
end

this should do the trick #472

kemzops commented 1 month ago

Keep in mind core.project_dir has some limitations, when you open two projects it will return double path's //, Kdialog and Zenity deal with that perfectly fine with no need to filter the path.

/home/kemzo/Desktop//home/kemzo/.config/lite-xl/init.lua The dialog will open in /home/kemzo/Desktop/.