Skip to content

Commit

Permalink
Get phantom icon from a function
Browse files Browse the repository at this point in the history
  • Loading branch information
vicke4 committed Nov 17, 2017
1 parent c6c581e commit 9a53486
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.2.6] - 2017-11-18
### Changed
- Getting phantom icon from a function.

## [1.2.5] - 2017-11-14
### Changed
- Fix to read phantom icon.
Expand Down
10 changes: 3 additions & 7 deletions open_in_browser.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import base64, os, re, sublime, sublime_plugin, subprocess, webbrowser
from urllib.parse import urlparse
from .settings import get_setting
from .settings import get_setting, get_image

import os

PLUGIN_PATH = os.path.dirname(os.path.realpath(__file__))
PLUGIN_NAME = os.path.basename(PLUGIN_PATH).replace(".sublime-package", "")
ENCODED_IMG = base64.b64encode(sublime.load_binary_resource("Packages/" + PLUGIN_NAME +"/open-in-browser.png")).decode()
REGEX = "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?"


class OpenInBrowser(sublime_plugin.ViewEventListener):
def __init__(self, view):
self.view = view
Expand All @@ -20,7 +16,7 @@ def erase_phantom(self):
self.view.erase_phantoms('open_link_phantom')

def get_url_link(self, url):
return sublime.expand_variables("<a href='${url}'><img width='${font_size}', height='${font_size}' src='data:image/png;base64,${encoded_img}' /></a>", {"url": url, "encoded_img": ENCODED_IMG, 'font_size': str(self.font_size)})
return sublime.expand_variables("<a href='${url}'><img width='${font_size}', height='${font_size}' src='data:image/png;base64,${encoded_img}' /></a>", {"url": url, "encoded_img": get_image(), 'font_size': str(self.font_size)})

def on_activated_async(self):
if get_setting('enable'):
Expand Down
7 changes: 5 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import sublime
import base64, sublime

def get_setting(key, default=None):
settings = sublime.load_settings('OpenInBrowser.sublime-settings')
return settings.get(key, default)
return settings.get(key, default)

def get_image():
return base64.b64encode(sublime.load_binary_resource("Packages/Open In Browser/open-in-browser.png")).decode()

0 comments on commit 9a53486

Please sign in to comment.