StyledPopup icon indicating copy to clipboard operation
StyledPopup copied to clipboard

Need way to add content to stylesheet

Open kbaskett248 opened this issue 10 years ago • 1 comments

I need a way to add additional selectors to the style sheet for structural formatting (margin, padding, font-size, etc.).

I've forked the repository and can add the functionality, but was wondering which would be the best approach.

  1. Add an additional keyword argument to show_popup called additional_styles that will be appended to the end of the generated stylesheet.
  2. Provide a second function called get_stylesheet that just returns the stylesheet. Other developers could then use or modify the stylesheet directly and call view.show_popup directly.

Either approach is fine for my needs, but I guess option 2 provides a bit more flexibility.

kbaskett248 avatar Sep 16 '15 13:09 kbaskett248

You could add a new style element as part of the html content that you are passing in which would override/add to the default styling. If you know the element you want to add padding to then you could do something like this. If this doesn't allow you to do what you please let me know and we can explore the option of adding additional stylesheets.

class TestPopupCommand(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()
        html = "<style> .entity.name.tag { color: #F00; padding:30px; } </style>"
        html += """<p class="entity name tag">Testing Type</p>"""

        print (html)

        styled_popup.show_popup(view, html)

The following I think would suffice for item 2, but please let me know if you need anything different:

class TestPopup2Command(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()

        manager = styled_popup.StyleSheetManager()

        stylesheet = manager.get_stylesheet(view.settings().get("color_scheme"))["content"]
        stylesheet += """
            .entity.name.tag{
                padding: 45px;
                color: #00F;
            }
            """

        html = "<style>%s</style>" % (stylesheet)
        html += """<p class="entity name tag">Testing Type</p>"""

        view.show_popup(html)

huot25 avatar Sep 19 '15 15:09 huot25