If ~/Templates dir is localized with xdg-user-dir, then "New From Template" menu in Mousepad is not shown.
Created attachment 5762 Quick 'n' dirt patch I guess this patch handles this problem, but a review wouldn't hurt =)
Related: Bug 10486
g_get_user_dir seems the correct approach for finding the Templates dir. Good job Andre! Two suggestions: 1. if the XDG special dir environment variable is unset, then you can fallback on ~/Templates. However if it is set then it means the user *has* a Template dir. If you can't read inside that directory then you should log an error (because there was indeed an I/O error in that case) rather than fallback to another directory. The reason is that this might confuse users who see the "New from template" feature is "working" but their templates don't appear (or even worse, older versions of the templates). Catch and treat the early error instead of risking more complicated usability issues later. 2. the feature should always be visible, but only disabled when it cannot be used (I can see you attached a patch doing this to 10486). Ideally, you would add a tooltip on disabled widgets so that users get a slim chance at being informed of the actions they can take (without UI clutter): 2.a When disabling, add gtk_widget_set_tooltip(...) with either of: "An error occurred when loading the Templates: %s", strerror(...) "You don't have any template in '%s'.", path_to_templates 2.b When re-enabling, unset the tooltip.
(In reply to Steve Dodier-Lazaro from comment #3) > g_get_user_dir seems the correct approach for finding the Templates dir. > Good job Andre! Thanks =) > Two suggestions: > 1. if the XDG special dir environment variable is unset, then you can > fallback on ~/Templates. However if it is set then it means the user *has* a > Template dir. I guess the patch already handles this. > If you can't read inside that directory then you should log an > error (because there was indeed an I/O error in that case) rather than > fallback to another directory. The reason is that this might confuse users > who see the "New from template" feature is "working" but their templates > don't appear (or even worse, older versions of the templates). Catch and > treat the early error instead of risking more complicated usability issues > later. To where would this error be logged? A file? A dialog with a "don't bother me again" check? > 2. the feature should always be visible, but only disabled when it cannot be > used (I can see you attached a patch doing this to 10486). Ideally, you > would add a tooltip on disabled widgets so that users get a slim chance at > being informed of the actions they can take (without UI clutter): I guess this is the more sensible and unobstructive solution > 2.a When disabling, add gtk_widget_set_tooltip(...) with either of: > "An error occurred when loading the Templates: %s", strerror(...) > "You don't have any template in '%s'.", path_to_templates I guess the second message is more "user-friendly" > 2.b When re-enabling, unset the tooltip. Another way to solve this (and bug 10486), would be: Always show the "New from Template" menu item. If the Templates folder is missing, display something like: "Missing templates folder(~/Templates)" But this message would be a subitem as the current message for empty Templates folder.
I tested the patch from comment #2 and noticed that g_get_user_special_dir() falls back to /home/user, so it does not return NULL.
(In reply to Theo Linkspfeifer from comment #5) > I tested the patch from comment #2 and noticed that g_get_user_special_dir() > falls back to /home/user, so it does not return NULL. Would kindly update the patch? (you can make yourself as the commit author) By the way, the fallback code uses g_build_filename and the result is not freed.
Created attachment 9293 diff I tested this slightly modified diff and it seemed to worked fine. Not sure if the observation in my previous comment was due to some strange test case.
Isn't it redundant to use `g_getenv("HOME")` since `g_get_home_dir()` already does that?
Created attachment 9299 patch (In reply to Theo Linkspfeifer from comment #7) > Created attachment 9293 > diff > > I tested this slightly modified diff and it seemed to worked fine. Not sure > if the observation in my previous comment was due to some strange test case. Can you please test this simplified patch? I had to add a check if the templates directory is not $HOME because Mousepad freezes for couple of seconds in that case. (In reply to Matthew Brush from comment #8) > Isn't it redundant to use `g_getenv("HOME")` since `g_get_home_dir()` > already does that? You're right, thanks for the heads-up.
Patch works.
Andre Miranda referenced this bugreport in commit ea1f76b7afb3592c5eb5fa2c5c9ea0d64c8d2e55 Use g_get_user_dir to get Templates directory (Bug #11048) https://git.xfce.org/apps/mousepad/commit?id=ea1f76b7afb3592c5eb5fa2c5c9ea0d64c8d2e55