View Issue Details

IDProjectCategoryView StatusLast Update
0017055ScribusUser Interfacepublic2023-11-25 20:47
Reportersfhwdt9e Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformEndeavourOSOSLinuxOS Version6.5.9-arch2-1
Product Version1.5.8 
Summary0017055: [PATCH] "Search for action" dialog too narrow
DescriptionOpening recent files via the "Search for action" dialog doesn't show the entire long pathnames. It would be good if it could resize.
Steps To Reproduce1. Open some saved .sla document in a nested path (more than 150 characters).
2. Close it.
3. Press ctrl / for the "search for action"/
4. Start typing "recent"/
5. This file will appear but the dialog is too small to see its name (it gets cut off).
Tagspatch
PatchYes

Activities

sfhwdt9e

2023-11-21 15:48

reporter  

Untitled.png (22,999 bytes)   
Untitled.png (22,999 bytes)   

ale

2023-11-21 16:50

manager   ~0050497

i'm not sure that we should make it wider.
i guess that there is no limit in how wider we can make it and still have somebody to find a path that does not fit...
(from a quick test i've made, all other actions seem to fit in the current width)

but we could try to detect if the action is a path and in that case first output the filename and then the full path in brackets.

for you information (if your OS supports it) the fastest way to get to the recent files is to press alt and F, then r and the number in front of the recent file name.

sfhwdt9e

2023-11-21 17:28

reporter   ~0050498

Maybe then an "ellipsis" (I think that's the way it's called) so that the file name is visible (e.g. `/home/user/gd/p/ea/sd/filename.sla` or just `/home/user1/gd.../filename.sla`), but the path is truncated to fit? You are right, that if that's the only action that has this problem it wouldn't make sense to go into trouble just for this.

> press alt and F, then r and the number in front of the recent file name

Sadly on my KDE this (global menu) broke some time ago and I can only access it with mouse, so this "action search" is much faster.

ale

2023-11-22 21:07

manager   ~0050499

here is a patch that:

- replaces /home/your-name/ by ~/ .
- if the action name is still longer than 50 chars, it keeps the 25 first chars, adds a ..., and then appends the last 25 chars.

i've deactivated the part of code that applies the first change only to the recent documents.
on the one side it feels more "safe" to only applies to known parts of the menues, on the other side
- there can't be an entry that contains /home/your-name/ and is not a path that can be shortened
- there are no menu entries that are longer than 50 chars (and are not a path)

personally, i'm confident that using ~/ is a good idea (and with my 3 chars username only saves a few chars) but i'm not 100% sure that keeping 25 + 25 chars is really always the best thing to do. (20 + 30 would be better? 15 + 35?)

if you can compile scribus, please test this patch.
action-search-elide.diff (1,550 bytes)   
diff --git a/scribus/actionsearch.cpp b/scribus/actionsearch.cpp
index 4eca79ba2..a173bff24 100644
--- a/scribus/actionsearch.cpp
+++ b/scribus/actionsearch.cpp
@@ -15,6 +15,7 @@
 #include <QMenuBar>
 #include <QMenu>
 #include <QStringList>
+#include <QRegularExpression>
 
 ActionSearch::ActionSearch(QMenuBar *menuBar)
 	: menuBar{menuBar}
@@ -57,6 +58,9 @@ void ActionSearch::readMenuActions(QMenu* menu)
 	}
 	QString menuName(menus.join(" > "));
 
+	// recent document tend to have a long path: we will try to shorten it a bit
+	// const bool isRecentDocument = menus.last() == QObject::tr("Open &Recent").replace("&", "");
+
 	for (auto action: menu->actions())
 	{
 		if (action->menu() != nullptr)
@@ -69,6 +73,20 @@ void ActionSearch::readMenuActions(QMenu* menu)
 		if (actionName.isEmpty() || !action->isEnabled())
 			continue;
 
+		// Currently disabled: the /home/.../ string can only happen in a unix path
+		// Paths can be long: replace /home/.../ by ~
+		// if (isRecentDocument)
+		// {
+		actionName = actionName.replace(QRegularExpression("/home/[^/]+/"), "~/");
+		// }
+		// If the actionName is longer than 40 chars remove chars from the middle
+		// and replace them with an ellipse sign.
+		// (There should be no action name that is longer than 40 chars.
+		// only paths are affected.)
+		if (actionName.length() > 50) {
+			actionName = actionName.left(25) + "…" + actionName.right(25);
+		}
+
 		// TODO: we might want to have a multilevel menuName
 		if (!menuName.isEmpty())
 			actionName += " (" + menuName +")";
action-search-elide.diff (1,550 bytes)   

ale

2023-11-22 21:10

manager   ~0050500

recent.png (71,456 bytes)   
recent.png (71,456 bytes)   

sfhwdt9e

2023-11-22 21:12

reporter   ~0050501

Amazing, thank you very much! I kept using this dialog to open documents. Now I won't have to memorise the leftmost numbers :)

ale

2023-11-23 07:27

manager   ~0050505

voilà, here are two possible solutions that actually do the same:

- one that only modifies entries that are in the two "recent" menus
- the other that relies on the fact that it can detect path even without detecting the parent menu

pick the one you're more comfortable with.

(the question is still open, what is the best length and how much to keep on the left and right side. but this can also easily be changed after having applied this patch and we have got feedback from users)
action-search-elide-2.diff (1,130 bytes)   
diff --git a/scribus/actionsearch.cpp b/scribus/actionsearch.cpp
index 4eca79ba2..a6301eac2 100644
--- a/scribus/actionsearch.cpp
+++ b/scribus/actionsearch.cpp
@@ -15,6 +15,7 @@
 #include <QMenuBar>
 #include <QMenu>
 #include <QStringList>
+#include <QRegularExpression>
 
 ActionSearch::ActionSearch(QMenuBar *menuBar)
 	: menuBar{menuBar}
@@ -69,6 +70,17 @@ void ActionSearch::readMenuActions(QMenu* menu)
 		if (actionName.isEmpty() || !action->isEnabled())
 			continue;
 
+		// Paths can be long: replace /home/.../ by ~
+		// (The /home/.../ string can only happen in a unix path)
+		actionName = actionName.replace(QRegularExpression("/home/[^/]+/"), "~/");
+		// If the actionName is still longer than 50 chars remove chars from the middle
+		// and replace them with an ellipse sign.
+		// (There should be no action name that is longer than 40 chars.
+		// only paths are affected.)
+		if (actionName.length() > 50) {
+			actionName = actionName.left(25) + "…" + actionName.right(25);
+		}
+
 		// TODO: we might want to have a multilevel menuName
 		if (!menuName.isEmpty())
 			actionName += " (" + menuName +")";
action-search-elide-2.diff (1,130 bytes)   
action-search-elide-recent.diff (1,446 bytes)   
diff --git a/scribus/actionsearch.cpp b/scribus/actionsearch.cpp
index 4eca79ba2..df46ad010 100644
--- a/scribus/actionsearch.cpp
+++ b/scribus/actionsearch.cpp
@@ -15,6 +15,7 @@
 #include <QMenuBar>
 #include <QMenu>
 #include <QStringList>
+#include <QRegularExpression>
 
 ActionSearch::ActionSearch(QMenuBar *menuBar)
 	: menuBar{menuBar}
@@ -57,6 +58,11 @@ void ActionSearch::readMenuActions(QMenu* menu)
 	}
 	QString menuName(menus.join(" > "));
 
+	// recent document tend to have a long path: we will try to shorten it a bit
+	const bool isRecentDocument =
+		menus.last() == QObject::tr("Open &Recent").replace("&", "") ||
+		menus.last() == QObject::tr("&Recent Scripts").replace("&", "");
+
 	for (auto action: menu->actions())
 	{
 		if (action->menu() != nullptr)
@@ -69,6 +75,17 @@ void ActionSearch::readMenuActions(QMenu* menu)
 		if (actionName.isEmpty() || !action->isEnabled())
 			continue;
 
+		if (isRecentDocument)
+		{
+			// Paths can be long: replace /home/.../ by ~
+			actionName = actionName.replace(QRegularExpression("/home/[^/]+/"), "~/");
+			// If the actionName is still longer than 50 chars remove chars from the middle
+			// and replace them with an ellipse sign.
+			if (actionName.length() > 50) {
+				actionName = actionName.left(25) + "…" + actionName.right(25);
+			}
+		}
+
 		// TODO: we might want to have a multilevel menuName
 		if (!menuName.isEmpty())
 			actionName += " (" + menuName +")";

sfhwdt9e

2023-11-23 14:24

reporter   ~0050509

Thank you, it works me (image).

> 25 + 25 chars is really always the best thing to do. (20 + 30 would be better? 15 + 35?)

I suppose that for each path/file it might be different? Sometimes the relevant part may be at the beginning/end of some folder name (`~/path-version1/file.jpg`, `~/path-version2/file.jpg`), sometimes at the beginning/end of the filename (`~/path/file-version1.jpg`), so I don't think there's a one-size-fits-all solution?

I am okay 25+25.

I liked what p10k shell prompt did - if path is too long it abbreviates path parts (e.g. `~/path-version1/1subpath-optionA/file.jpg` --> `~/pa1/1sub-A/file.jpg`), but that's probably more complicated to implement.
image.png (41,528 bytes)   
image.png (41,528 bytes)   

cbradney

2023-11-25 12:49

administrator   ~0050510

I am not sure ~ always represents /home/username. Needs to be checked for security measures - eg logged on user vs the application being run as another user.
mac OS and Windows are also not considered by this patch.

ale

2023-11-25 15:05

manager   ~0050511

thanks craig for your feedback.

the part about /home/ -> ~ should not affect os x or windows users.
this is not by accident. as far as i know those platforms do not have a similar convention for the user home.

the part about the "..." might or not be better for os x or windows users. nobody gave feedback until now (and i don't have access to windows or macs).
it would have been interesting to hear your own experience on mac.

anyway, it would be easy to do the same for /Users/User-name/ -> ~ for mac
but i'm not sure that mac user will understand the ~.

for windows, i don't really know what do.
i'm pretty sure that windows users do not have a short shortcut for their home. (the only one i've found is %UserProfile% and is not really short)
(https://superuser.com/a/217506)

concerning the security measures: what you see on the screen is not what will be triggered by scribus (... that 4 at the beginning and the new ... in the middle would not work well).
the only thing that could happen is that one loses the information that the information about a document being in somebody else home.
but i don't think it's a common case, and the user has to have access to that directory before the document can show up in the list of recent files.

but, if you prefer, i can for sure use QStandardPaths::HomeLocation when converting to ~.
(for linux and/or mac)

personally, i agree with sfhwdt9e that the paths in this dialog are too long.
but, as i already wrote, above, there is a better way to open the recent files or launch recent scripts.
so, not a big issue for me.

my proposal:

if you would be happy with the same patch, but using QStandardPaths::HomeLocation for linux and mabye os x i can upload a new patch.

if you have specific suggestions i should implement, i can do that.

but i don't think that, in this case, we should aim for perfection.
it's not a critical feature and we can change the behavior at any time.
so having a first implementation might let other users tell us what we can do to improve real use cases.
and we can improve it step by step.

ale

2023-11-25 16:29

manager   ~0050512

here a version of the patch that uses home dir... and only on linux.

two users have confirmed that this patch has a positive effect on linux.

you're welcome to put both tweaks inside of the "if linux",, if unsure about the result on other os.
action-search-elide-homedir.diff (1,084 bytes)   
diff --git a/scribus/actionsearch.cpp b/scribus/actionsearch.cpp
index 4eca79ba2..cde2b0d0d 100644
--- a/scribus/actionsearch.cpp
+++ b/scribus/actionsearch.cpp
@@ -15,6 +15,7 @@
 #include <QMenuBar>
 #include <QMenu>
 #include <QStringList>
+#include <QDir>
 
 ActionSearch::ActionSearch(QMenuBar *menuBar)
 	: menuBar{menuBar}
@@ -69,6 +70,18 @@ void ActionSearch::readMenuActions(QMenu* menu)
 		if (actionName.isEmpty() || !action->isEnabled())
 			continue;
 
+#ifdef Q_OS_LINUX
+		// Paths can be long: replace /home/.../ by ~
+		actionName = actionName.replace(QDir::homePath() + QDir::separator(), "~/");
+#endif
+		// If the actionName is still longer than 50 chars remove chars from the middle
+		// and replace them with an ellipse sign.
+		// (There should be no action name that is longer than 40 chars.
+		// only paths are affected.)
+		if (actionName.length() > 50) {
+			actionName = actionName.left(25) + "…" + actionName.right(25);
+		}
+
 		// TODO: we might want to have a multilevel menuName
 		if (!menuName.isEmpty())
 			actionName += " (" + menuName +")";

cbradney

2023-11-25 16:48

administrator   ~0050513

Last edited: 2023-11-25 16:51

mac OS uses ~ like any other *nix. Windows uses ~ in PowerShell.
Always best to use the QStandardPaths or QDir::homePath().

Have you tried setting the textElideMode on the QListView for the action search dialog instead of trying to do it manually? You might need to consider a different way to construct the text in there if it does not work.

ale

2023-11-25 20:47

manager   ~0050516

concerning the ~, i'm not really sure that the typical mac or windows users will understand it (i'm pretty sure that this is not a thing in windows; and the typical mac user around me does not use the shell and probably have never seen a ~)

can you check if on mac any common UI software shortens the paths to ~?

i've now tried to set textElideMode in the .ui file, but i could not get it to elide anything.
... i now managed to remove the scrollbar (horizontal size policy to preferred instead of expanding) but even then i get no elision

(but i'm not sure that i'd prefer the ellision on the whole row... i fear that then the path might be shorten too much and the elision could even occur inside of the file name)

Issue History

Date Modified Username Field Change
2023-11-21 15:48 sfhwdt9e New Issue
2023-11-21 15:48 sfhwdt9e File Added: Untitled.png
2023-11-21 16:50 ale Note Added: 0050497
2023-11-21 17:28 sfhwdt9e Note Added: 0050498
2023-11-22 21:07 ale Note Added: 0050499
2023-11-22 21:07 ale File Added: action-search-elide.diff
2023-11-22 21:10 ale Note Added: 0050500
2023-11-22 21:10 ale File Added: recent.png
2023-11-22 21:12 sfhwdt9e Note Added: 0050501
2023-11-22 21:16 ale Summary "Search for action" dialog too narrow => [PATCH] "Search for action" dialog too narrow
2023-11-22 21:16 ale Patch No => Yes
2023-11-22 21:16 ale Tag Attached: patch
2023-11-23 07:27 ale Note Added: 0050505
2023-11-23 07:27 ale File Added: action-search-elide-2.diff
2023-11-23 07:27 ale File Added: action-search-elide-recent.diff
2023-11-23 14:24 sfhwdt9e Note Added: 0050509
2023-11-23 14:24 sfhwdt9e File Added: image.png
2023-11-25 12:49 cbradney Note Added: 0050510
2023-11-25 15:05 ale Note Added: 0050511
2023-11-25 16:29 ale Note Added: 0050512
2023-11-25 16:29 ale File Added: action-search-elide-homedir.diff
2023-11-25 16:48 cbradney Note Added: 0050513
2023-11-25 16:49 cbradney Note Edited: 0050513
2023-11-25 16:51 cbradney Note Edited: 0050513
2023-11-25 20:47 ale Note Added: 0050516