New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Irrlicht file picker with new Lua dialog #13512
Conversation
Note that you need to make sure to appropriately preserve the commit author information. |
Why can't we just use the system file/folder picker? |
i think Minetest should use SAF file picker on Android, it's from Android system so we dont need to worry much about maintence |
The system file picker that you refer to might originate from GTK on Linux, comdlg32.dll on Windows and whatever else on macOS. Whereas this could be used, it would at least introduce compile-time dependencies on Linux and platform-specific implementations to handle the returned value. This is less convenient than reinventing the wheel using existing file listing functions and formspecs. |
I tested this PR on Windows 10 (10.0.19044) and found problems with path separator. Windows uses backslash ( When I entered The other problem (related but not affected by this PR) is that the problem also happens in the new setting dialog. The path is |
Co-authored-by: Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
8930e37
to
b9c1216
Compare
I assume I would add kilbith as a co-author to the commit?
Yikes, looks like it really doesn't like Windows paths. I've done some changes which makes it work for me under Wine. Please retest.
Looks like the new settings dialog value doesn't escape the value for file paths. Fixed that as well since I'm already making changes around that area anyways. |
b9c1216
to
22cfd93
Compare
I expected kilbith as commit author and you as co-author. I suppose either way is fine actually, we still have the author info the file itself. |
It is working now on Windows. I wonder if it would be easy to get the drive list on Windows (not necessary though since we can enter the path manually). |
That's just a flaw with reading default values from Exposing the default settings values to the main menu so the settings dialog can read from them too (overriding settingtypes.txt's defaults) would be the fix, I guess, but that's for another PR or an issue to be opened about this. |
This issue is (mostly) already fixed by #13489. The default values shown in the tooltips are still from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested it and it works. The concept and its implementation look good, except some code style issues in a few lines.
local dirs = get_dirs() | ||
|
||
if fields.dirs then | ||
local event, idx = fields.dirs:sub(1,3), tonumber(fields.dirs:match("%d+")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we have a helper to split events?
end | ||
end | ||
|
||
local dirs = get_dirs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't unconditionally be called
it's also prone to issues if the dir list changes between load time and click time
cache this in dialogdata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't resist ¯_(ツ)_/¯
end | ||
|
||
for _, f in ipairs(dirs) do | ||
local is_file = not core.is_dir(PATH .. DIR_DELIM .. f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename in f
is already formspec-escaped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh... yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point is escaped strings are not valid filesystem paths (anymore)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. if you have a folder called $hello$
, it's shown as a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that since the file picker doesn't really work on Android due to the touchscreen interface not supporting doubleclicking on a table, should this be disabled on Android? The if PLATFORM == "Android" then
make.filepath = make.string
make.path = make.string
end |
For Android, the option is either (1) adding a button for each row of files in the dialog or (2) showing the setting as a text input. I prefer option (2) since the player needs external tools/apps to modify Minetest's folder (the player needs to be experienced in Android's file management system) and the player can just copy the file's path. |
I support just showing a string input on Android |
-- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
local PATH = os.getenv("HOME") -- Linux & similar | ||
or os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH") -- Windows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably have to do this to fix the issue @grorp mentioned
or os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH") -- Windows | |
or (os.getenv("HOMEDRIVE") .. os.getenv("HOMEPATH")) -- Windows |
end | ||
|
||
for _, f in ipairs(dirs) do | ||
local is_file = not core.is_dir(PATH .. DIR_DELIM .. f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not fixed.
end | ||
end | ||
|
||
local dirs = get_dirs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not fixed
There should be an option to allow people to use the system file picker. Some people like their file managers more than built in ones since they are used to or love features included with their own systems. Some people even use terminal file pickers. This change may limit what users can use to program minetest games in some way. |
This change doesn't limit anything, it was never possible to use the system file picker. Allowing that would require various OS-specific integration work when time is better spent elsewhere (IMO). |
In the past, I used a small library called tinyfiledialogs to use system file dialogs, bundled in the repo. I never had many bugs reported with it, but this sort of thing is likely to have portability issues and future maintenance cost https://github.com/rollerozxa/NodeBoxEditor/blob/master/src/util/tinyfiledialogs.h |
Based on #10580, this PR replaces the current Irrlicht file/folder picker with a new one written in Lua. The code for the old Irrlicht picker dialog on the Minetest engine side of things has also been removed.
Fixes #8073
To do
This PR is a Ready for Review.
How to test
font_path
). Check so that you can only pick files, not folders.shader_path
). Check so that you can only pick folders, not folders.Platforms: