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

implement file truncating #203

Merged
merged 13 commits into from
Nov 24, 2024
Merged

Conversation

hacknus
Copy link
Contributor

@hacknus hacknus commented Nov 21, 2024

implement file truncating in the middle to prevent filenames from bei…ng displayed over two lines.
Addresses an issue stated in #200

@hacknus
Copy link
Contributor Author

hacknus commented Nov 21, 2024

Could probably be a bit simplified by extracting the path and is_dir from the DirectoryEntry

@fluxxcode
Copy link
Owner

fluxxcode commented Nov 21, 2024

Thanks for implementing! Could you create an option in FileDialogConfig and a builder method in FileDialog so that it can be activated and deactivated from the backend? With a warning in the docs that if truncate is disabled, scolling will get an offset in large directories.

@fluxxcode fluxxcode self-requested a review November 21, 2024 19:02
@fluxxcode
Copy link
Owner

fluxxcode commented Nov 21, 2024

I've tested it now too. Works really well so far. Here are a few more points:

  • I think we can reduce the save margin from 20 pixels to around 10-15 pixels
  • We should display the full file name when we hover over a truncated element

src/file_dialog.rs Outdated Show resolved Hide resolved
@hacknus
Copy link
Contributor Author

hacknus commented Nov 21, 2024

I observed some jumping when putting the offset at 10, so I put it at 15.

The full label is now shown when hovered, but only if it is truncated, not if the full label is already shown

@hacknus
Copy link
Contributor Author

hacknus commented Nov 21, 2024

Used only the DirectoryItem and max_length as inputs.

@fluxxcode
Copy link
Owner

Hi, I made the following changes to the code:

  • Always render file and pin icons
  • Reworked truncate_filename to account for different character sizes. You first built it so that the truncate_filename works at char level. The problem is that each char has a different size that needs to be taken into account.
  • I did the truncating at the end or at the file extension. This makes the code a little cleaner and looks a little better in the UI than if it was truncated in the middle
  • General cleanup

Do you agree and could you review my changes? Thanks!

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

thanks for the improvements with the letter sizes!

I don't like truncating at the end though, mainly because now files like
long_project_name_v1.pdf
long_project_name_v2.pdf
long_project_name_v3.pdf
long_project_name_final.pdf

all look identical - which is probably the reason why macOS (and maybe other OS/explorers) split it in the middle or at like 2/3 of the name. But I personally also find the display of a_long_filena...pdf a bit odd to look at since I expect only one dot before the extension..

@fluxxcode
Copy link
Owner

mh yeah ok that's true. Then I'll try to truncate the name in the middle.

@fluxxcode
Copy link
Owner

fluxxcode commented Nov 23, 2024

Windows actually truncates right at the end, even without including the file extension.

I've now gotten the truncating in the middle to work with the char sizes, but I'm currently debating whether that justifies the performance. In terms of performance, it's much more resource heavy.

@fluxxcode
Copy link
Owner

Pushed the changes. Let me know what you think

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

Oh, okay, did not know that about windows.

Hmm, how much more resources are we talking about? I don't notice a considerable difference between the two.

I noticed a bug:

if a directory has a dot in it (like a date) it is now interpreted as the extension, thus giving:
2024.11.12_some_folder
something like this:
2...11.12_some_folder
which does not make any sense, I think we should only use the file_stem if the file is not a directory and truncate the whole filename if it is a directory

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

We could also add it as an option if one wants to split in the middle or at the end.

@fluxxcode
Copy link
Owner

Hmm, how much more resources are we talking about? I don't notice a considerable difference between the two.

We have to clone strings several times and iterate the file_stem several times, which we don't need with back truncating. In reality you won't notice much of a difference, but at the latest in large directories when all elements are updated (e.g. when you enter something in the search) it can make a difference in performance.

I noticed a bug:

if a directory has a dot in it (like a date) it is now interpreted as the extension, thus giving: 2024.11.12_some_folder something like this: 2...11.12_some_folder which does not make any sense, I think we should only use the file_stem if the file is not a directory and truncate the whole filename if it is a directory

Ahh lol. Don't think it's because of the file_stem but because of the path.extension. Will fix it.

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

shouldn't egui only update the visible items in a ScrollArea? So I think it should not use more resources in large directories or am I wrong?

But yeah, could still make sense to make it optional - especially if it is different across operating systems and people might favor one over the other out of habit

@fluxxcode
Copy link
Owner

fluxxcode commented Nov 23, 2024

shouldn't egui only update the visible items in a ScrollArea? So I think it should not use more resources in large directories or am I wrong?

Only if you use ScrollArea::show rows. However, we cannot use show_rows when the search contains something because we cannot estimate how many files or directories are relevant to the search. The same applies to the “create_directory_dialog” dialog. Currently, when the dialog is open, it is rendered as the last element in the central panel. There we are also obliged to update every item in the directory.

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

Ah, yes, I see. Thanks for the clarification!

@fluxxcode
Copy link
Owner

FYI: #181

@fluxxcode
Copy link
Owner

fluxxcode commented Nov 23, 2024

I fixed the problem with directories containing dots. The problem was both path.filestem and path.extension. This doesn't seem to be implemented correctly in the standard Rust library for directories. Could you take another look?

@fluxxcode
Copy link
Owner

I wouldn't add an option for truncating in the middle or back btw. This is actually something that the user of the file dialog should decide and not the backend app. But user settings is something much bigger that we can implement at some point in the future.

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

I wouldn't add an option for truncating in the middle or back btw. This is actually something that the user of the file dialog should decide and not the backend app. But user settings is something much bigger that we can implement at some point in the future.

yeah that makes sense.

I fixed the problem with directories containing dots. The problem was both path.filestem and path.extension. This doesn't seem to be implemented correctly in the standard Rust library for directories. Could you take another look?

Yes, I thought so too. Now it works perfectly, I like it!

@fluxxcode
Copy link
Owner

Great, thanks for testing! Will merge the PR tomorrow when I've tested on Linux.

@hacknus
Copy link
Contributor Author

hacknus commented Nov 23, 2024

Cool, thanks! I created an issue about the file_stem() function: rust-lang/rust#133399

@fluxxcode fluxxcode merged commit 4be7bfe into fluxxcode:develop Nov 24, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants