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

Icons in custom gutter theme #1125

Closed
Monokai opened this issue Mar 6, 2018 · 12 comments

Comments

6 participants
@Monokai
Copy link

commented Mar 6, 2018

I've created custom gutter themes for https://www.monokai.pro and they worked well for SL3.

In SL4, it seems custom error / warning icons are gone, while it does pick up the right colorize value from the gutter-theme file. Looking through your code, I think this is the part where custom icons are resolved:

def get_icon(f):
    def wrapper(*args):
        res = f(*args)
        key = args[1]

        if not res:
            logger.error("Styles are invalid. Please check your settings and restart Sublime Text.")
            return

        if key != "icon":
            return res
        else:
            if res in ("circle", "dot", "bookmark", "none"):  # Sublime Text has some default icons
                return res
            elif res != os.path.basename(res):
                return res
            else:
                theme = persist.settings.get('gutter_theme')
                return 'Packages/SublimeLinter/gutter-themes/{}/{}.png'.format(theme, res)

    return wrapper

I think this part 'Packages/SublimeLinter/gutter-themes/{}/{}.png'.format(theme, res) shouldn't be hardcoded, but the base folder should be the same folder as where the gutter-theme file is found (if defined via the gutter_theme setting).

@braver

This comment has been minimized.

Copy link
Member

commented Mar 6, 2018

This part should enable you to use custom icons, but I think you need to put in the path to the icons and not just the name. So, the theme in this case only tells it to colorise or not, but isn't used as a starting point to finding the icon files.

elif res != os.path.basename(res):
                return res

Let me know if putting the full path in the "icon" setting works for you.

@kaste

This comment has been minimized.

Copy link
Contributor

commented Mar 6, 2018

@braver can be really lazy. So @Monokai if you want to tackle this to make it more user friendly I would welcome the PR.

@braver

This comment has been minimized.

Copy link
Member

commented Mar 6, 2018

Very busy also. PR's very welcome indeed.

@patrickwelker

This comment has been minimized.

Copy link

commented Mar 9, 2018

In addition, some enhanced documentation for end users would be welcome. I've been spending to much time trying to get gutter icons to work and still have no clue how gutter themes in SL4 can be activated.

I tried various combinations that I thought could make sense after reading the docs and the default settings file, until I settled for the one below (– using only directly linked icons).

{
    // "gutter_theme": "$HOME/Library/Application Support/Sublime Text 3/Packages/User/gutter-themes/Blueberry Cross/Blueberry Cross.gutter-theme",
    // "gutter_theme": "Packages/User/gutter-themes/Blueberry Cross/Blueberry Cross.gutter-theme",
    // "gutter_theme": "Packages/SublimeLinter/gutter-themes/Blueberry Cross/Blueberry Cross.gutter-theme",
    // "gutter_theme": "Blueberry Cross",
    "gutter_theme": "none",
    "styles": [
        {
            "icon": "Packages/User/gutter-themes/Blueberry Cross/warning.png",
             //"icon": "warning.png"
        },
        {
            "icon": "Packages/User/gutter-themes/Blueberry Cross/error.png",
            // "icon": "error.png",
        }
    ],
}

Could you shed some light on how one is supposed to do it?

Also, Packages/SublimeLinter/ doesn't exist anymore if one does a clean install. All gutter-themes are inside Installed Packages/SublimeLinter.sublime-package… at least for me. This would also make it harder for users to find out the name of an icon since they have to unzip the file or use PackageResourceViewer.

I guess the default folder for users who create gutter themes should also be in the documentation, too. Maybe Packages/User/SublimeLinter/gutter-themes/.

@Odyseus

This comment has been minimized.

Copy link

commented Mar 9, 2018

Hello, everybody.

What follows is slightly off-topic to what this issue is all about, but it should be taken into account if the code mentioned in the first message is modified so the gutter themes might work in a different way.

@pattulus: The default SublimeLinter settings file explains exactly how the gutter themes work:

// - icon can be:
//   one of the default icons: "circle", "dot" or "bookmark"
//   or a path to an icon file like (e.g. "Packages/icons/warning.png")
//   or "none" to remove the icon
//   or one provided by a gutter theme (e.g. "warning" or "error")
//      in theme Default: "warning", "error", "cog", "x",
//      and "diamond", "heart", "pointer", "square", "star", "triangle" all
//      also have an -outline variant.

Example:

{
    "gutter_theme": "Default",
    "styles": [{
        "mark_style": "outline",
        "priority": 1,
        "scope": "sublimelinter.mark.warning",
        "icon": "triangle",
        "types": [
            "warning"
        ]
    }, {
        "mark_style": "outline",
        "priority": 1,
        "scope": "sublimelinter.mark.error",
        "icon": "x",
        "types": [
            "error"
        ]
    }]
}

gutter_theme should be just the name of the theme for themes provided by SublimeLinter. Or the path to were you placed your custom gutter theme.

If the gutter theme used has the colorize setting set to false (Knob, Knob Symbol, Hands, Blueberry Round, ProjectIcons, Blueberry Cross, Danish Royalty, and Koloria), and you are using a Sublime Text version that doesn't implement the color(ish) scopes yet, then the color scheme used in Sublime Text should have a color defined for the region.whitish scope set to white (region.whitish scope is hard-coded in SublimeLinter). Without the region.whitish scope defined, the icons on the gutter will be displayed in black.

@newhouse

This comment has been minimized.

Copy link

commented Mar 10, 2018

Still having trouble understanding all this stuff, but @Odyseus settings got me back to where I want to be. Thank you! Hopefully will help others...

@patrickwelker

This comment has been minimized.

Copy link

commented Mar 10, 2018

@Odyseus The explanations in the default SublimeLinter settings file worked for me, too, in the end.

Although, they are "exact" like you said, I would wish them to be a tad more elaborate.

Obviously, I tried to hard yesterday because I had something alike your example, but added the file extension to the icon name (and yes, this is exactly like the settings tell you to do it). Maybe I was confused because even the relative and absolute paths I tried failed. I don't know. Just glad it works now and knowing how to do it properly. Thanks.

@braver

This comment has been minimized.

Copy link
Member

commented Mar 19, 2018

See, I’m not that lazy 😎

@Monokai

This comment has been minimized.

Copy link
Author

commented Mar 20, 2018

@braver Thanks, I've tested your code. It could be even simpler and user-friendly. What do you think of this?

elif persist.settings.get('gutter_theme').endswith('.gutter-theme'):
    theme_path = 'Packages/SublimeLinter/gutter-themes/Default'
    files = sublime.find_resources(persist.settings.get('gutter_theme'))
    if files:
        theme_path = os.path.dirname(files[0])
    if not res.endswith('.png'):
        res += '.png'
    return '{}/{}'.format(theme_path, res)

So If you have a gutter_theme setting that ends with .gutter-theme, it finds all resources in all packages and resolves the first one. So you can have MyTheme.gutter-theme in the settings instead of something like Packages/MyTheme/MySubFolder/MyTheme.gutter-theme. In SL3 you would also save the filename only.

If you have a gutter_theme setting that doesn't end with '.gutter-theme', it follows the folders inside SublimeLinter/gutter-themes as per your existing code.

@braver

This comment has been minimized.

Copy link
Member

commented Mar 20, 2018

@Monokai using find_resources results in a guessing game instead of giving the user control. It doesn't work with paths, so you cannot be more specific than say MyTheme.gutter-theme and you can't know what other packages also deliver gutter themes that may have the same name.

At some point the user will have to know what to put in the gutter-theme setting. Either he put something in Packages himself and is therefore able to set the path correctly, or a plugin provides something and explains what to put in that setting. I don't see a need to make the implementation guess here, because the user can be explicit.

Also, minor other point, you're proving a fallback to the Default theme if the user mucks up his setting by entering something that doesn't exist. My approach here is for it to visually fail instead, again to take out the guesswork.
screen shot 2018-03-20 at 13 23 18

So, yeah, it can perhaps be more friendly with even more effort, but I think the PR covers the feature request well enough?

@Monokai

This comment has been minimized.

Copy link
Author

commented Mar 20, 2018

@braver Yes, it's a guessing game, maybe you're right. I thought you could work with paths, but if not, then it's indeed not a better solution. I would say just do your original thing!

@braver

This comment has been minimized.

Copy link
Member

commented Mar 20, 2018

I thought you could work with paths

Yeah, I kinda hoped for that too, but alas. Thanks for thinking along with us though!

@braver braver closed this in #1247 Mar 20, 2018

braver added a commit that referenced this issue Mar 20, 2018

Merge pull request #1247 from SublimeLinter/friendly-icons
fix #1125 Friendly configuration for icons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.