New feature, new plugin. Makes use of the new show_quick_panel() API!
Description:
Displays a list of web colors in the quick panel API along with the corresponding hex code (indigo => #4B0082). Simply select the color from the quick panel and the hex code will be inserted into the current cursor or cursors positions.
Code:
[code]import sublime, sublime_plugin
import webcolors
class WebColorsCommand(sublime_plugin.WindowCommand):
colorList = ]
def init(self, *args, **kwargs):
super(WebColorsCommand, self).init(*args, **kwargs)
self.generateColorDialog()
def run(self):
self.window.show_quick_panel(self.colorList , self.callback)
def callback(self, index):
if (index > -1):
colorValue = self.colorList[index][1]
self.window.active_view().run_command(“insert_web_colors”, {“value”: colorValue})
def generateColorDialog(self):
for name, color in webcolors.css3_names_to_hex.iteritems():
self.colorList.append([name, color.upper()])
class InsertWebColorsCommand(sublime_plugin.TextCommand):
def run(self, edit, value):
for region in self.view.sel():
self.view.replace(edit, region, value)
[/code]
Thanks to bizoo for the tweaks and Python tuitions!
** Dependencies:**
This plugin relies on webcolors.py, you’ll need a copy and can grab it from webcolors.py, copy it in to your User directory.
I set the binding to:
{ "keys": "ctrl+shift+u"], "command": "web_colors" }
Have fun.