! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
"New From Template" in localized environment
Status:
RESOLVED: FIXED
Product:
Mousepad
Component:
General

Comments

Description Sergey 2014-07-27 13:17:15 CEST
If ~/Templates dir is localized with xdg-user-dir, then "New From Template" menu in Mousepad is not shown.
Comment 1 Andre Miranda editbugs 2014-11-20 03:17:16 CET
Created attachment 5762 
Quick 'n' dirt patch

I guess this patch handles this problem, but a review wouldn't hurt =)
Comment 2 Andre Miranda editbugs 2014-11-20 03:17:39 CET
Related: Bug 10486
Comment 3 Steve Dodier-Lazaro editbugs 2014-11-20 08:34:53 CET
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.
Comment 4 Andre Miranda editbugs 2014-11-21 01:41:54 CET
(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.
Comment 5 Theo Linkspfeifer editbugs 2019-11-14 16:28:07 CET
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.
Comment 6 Andre Miranda editbugs 2019-12-06 04:56:19 CET
(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.
Comment 7 Theo Linkspfeifer editbugs 2019-12-06 16:09:10 CET
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.
Comment 8 Matthew Brush editbugs 2019-12-06 21:31:44 CET
Isn't it redundant to use `g_getenv("HOME")` since `g_get_home_dir()` already does that?
Comment 9 Andre Miranda editbugs 2019-12-08 22:19:09 CET
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.
Comment 10 Theo Linkspfeifer editbugs 2019-12-09 14:24:40 CET
Patch works.
Comment 11 Git Bot editbugs 2019-12-10 17:07:34 CET
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

Bug #11048

Reported by:
Sergey
Reported on: 2014-07-27
Last modified on: 2019-12-10

People

Assignee:
Matthew Brush
CC List:
5 users

Version

Version:
Unspecified
Target Milestone:
Mousepad 0.4.x

Attachments

Quick 'n' dirt patch (1.56 KB, patch)
2014-11-20 03:17 CET , Andre Miranda
no flags
diff (1.04 KB, patch)
2019-12-06 16:09 CET , Theo Linkspfeifer
no flags
patch (1.35 KB, patch)
2019-12-08 22:19 CET , Andre Miranda
no flags

Additional information