Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

rollerozxa
Copy link
Member

@rollerozxa rollerozxa commented May 16, 2023

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

image

To do

This PR is a Ready for Review.

How to test

  • Test with a setting expecting a filepath (e.g. font_path). Check so that you can only pick files, not folders.
  • Test with a setting expecting a (folder)path (e.g. shader_path). Check so that you can only pick folders, not folders.

Platforms:

  • Linux: Works for me
  • Android: Barely functions due to it not being possible to double tap a formspec table (but does work with a keyboard, haha). Not a regression from the old Irrlicht dialog though, which straight out wouldn't function on Android.
  • Windows: Needs testing.

@Zughy Zughy added Roadmap The change matches an item on the current roadmap. UI/UX Feature ✨ PRs that add or enhance a feature labels May 16, 2023
@sfan5 sfan5 self-requested a review May 17, 2023 14:58
@sfan5
Copy link
Member

sfan5 commented May 17, 2023

Note that you need to make sure to appropriately preserve the commit author information.

@Zughy Zughy added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label May 17, 2023
@Bituvo
Copy link
Contributor

Bituvo commented May 20, 2023

Why can't we just use the system file/folder picker?

@oong819
Copy link
Contributor

oong819 commented May 21, 2023

i think Minetest should use SAF file picker on Android, it's from Android system so we dont need to worry much about maintence

@SmallJoker
Copy link
Member

SmallJoker commented May 21, 2023

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.

@srifqi
Copy link
Member

srifqi commented May 25, 2023

I tested this PR on Windows 10 (10.0.19044) and found problems with path separator. Windows uses backslash (\) as its path separator. The dialog shows no path separator. The other problem is that I can not go to root of a drive or change drive.

File picker dialog using this PR

When I entered C:\git\minetest\ in the address bar, the address bar disappeared and the file list is broken.

Broken file list in the file picker dialog

Before this PR

Irrlicht file picker dialog


The other problem (related but not affected by this PR) is that the problem also happens in the new setting dialog.

The path is C:\git\minetest\ to the root folder.

a screenshot showing inexistence of path separator on Windows machine

Co-authored-by: Jean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
@rollerozxa
Copy link
Member Author

Note that you need to make sure to appropriately preserve the commit author information.

I assume I would add kilbith as a co-author to the commit?

(testing filebrowser on windows)

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.

(new settings dialog on windows)

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.

@sfan5
Copy link
Member

sfan5 commented May 29, 2023

I assume I would add kilbith as a co-author to the commit?

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.

@srifqi
Copy link
Member

srifqi commented May 29, 2023

It is working now on Windows.

File picker dialog using this PR

I wonder if it would be easy to get the drive list on Windows (not necessary though since we can enter the path manually).


(EDIT: probably not related)

I want to ask about the default setting behaviour for path. Is it intended? The default value (when set to it) still works, though.

Reset to default behaviour

@sfan5 sfan5 removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label May 30, 2023
@rollerozxa
Copy link
Member Author

I want to ask about the default setting behaviour for path. Is it intended? The default value (when set to it) still works, though.

That's just a flaw with reading default values from settingtypes.txt, it can differ from the default values provided by the engine in defaultsettings.cpp. This can be especially noticeable for settings that have different defaults on Android, the settings menu will let you reset them to the desktop counterpart (see e.g. contentdb_flag_blacklist). The default font settings are always set to be absolute, leading them to always being considered "dirty" or changed from the generic path provided in settingtypes.txt no matter the platform.

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.

@grorp
Copy link
Member

grorp commented May 31, 2023

That's just a flaw with reading default values from settingtypes.txt, it can differ from the default values provided by the engine in defaultsettings.cpp. This can be especially noticeable for settings that have different defaults on Android, the settings menu will let you reset them to the desktop counterpart (see e.g. contentdb_flag_blacklist). The default font settings are always set to be absolute, leading them to always being considered "dirty" or changed from the generic path provided in settingtypes.txt no matter the platform.

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 settingtypes.txt, but the "detect if the setting is dirty" and the "reset the setting to its default value" code don't use the default values from settingtypes.txt anymore.

Copy link
Member

@srifqi srifqi left a 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.

builtin/mainmenu/settings/dlg_file_browser.lua Outdated Show resolved Hide resolved
builtin/mainmenu/settings/dlg_file_browser.lua Outdated Show resolved Hide resolved
builtin/mainmenu/settings/dlg_file_browser.lua Outdated Show resolved Hide resolved
builtin/mainmenu/settings/dlg_file_browser.lua Outdated Show resolved Hide resolved
local dirs = get_dirs()

if fields.dirs then
local event, idx = fields.dirs:sub(1,3), tonumber(fields.dirs:match("%d+"))
Copy link
Member

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()
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

Copy link
Member

@grorp grorp left a 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)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh... yeah?

Copy link
Member

@sfan5 sfan5 Jun 25, 2023

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)

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not fixed.

builtin/mainmenu/settings/dlg_file_browser.lua Outdated Show resolved Hide resolved
Copy link
Member

@Desour Desour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't looked through everything.


Fixes #8073, if I'm not mistaken.

LICENSE.txt Show resolved Hide resolved
@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jun 10, 2023
@rollerozxa
Copy link
Member Author

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 filepath and path setting types would be displayed as just a simple string, removing the browse button:

if PLATFORM == "Android" then
	make.filepath = make.string
	make.path = make.string
end

@Zughy Zughy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jul 10, 2023
@srifqi
Copy link
Member

srifqi commented Jul 12, 2023

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.

@rubenwardy
Copy link
Member

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
Copy link
Member

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

Suggested change
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)
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jul 30, 2023
@Nukiloco
Copy link

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.

@sfan5
Copy link
Member

sfan5 commented Aug 19, 2023

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).

@rubenwardy
Copy link
Member

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

@Zughy Zughy added the Adoption needed The pull request needs someone to adopt it. Adoption welcomed! label Sep 12, 2023
@Zughy Zughy closed this Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Action / change needed Code still needs changes (PR) / more information requested (Issues) Adoption needed The pull request needs someone to adopt it. Adoption welcomed! Feature ✨ PRs that add or enhance a feature @ Mainmenu Roadmap The change matches an item on the current roadmap. UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Buttons in directory/file selection window are untranslatable