Skip to content

Commit

Permalink
UPDATE: v0.1.1 view image from selected text
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaksim committed Jan 26, 2012
1 parent 9198cd7 commit 93b7cef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Default (Windows).sublime-keymap

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Image-Viewer

**v0.1.0**
**v0.1.1**

---
## View image from CSS declaration, HTML <img> tag, and may be from something else :)
Expand Down
26 changes: 12 additions & 14 deletions image_viewer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Image-Viewer v0.1.0
Image-Viewer v0.1.1
[
{"keys": ["super+i"], "command": "image_viewer"}
Expand Down Expand Up @@ -44,27 +44,25 @@ def is_image(file_name):
self.view_image(file_name)

else:
cur_pos = view.sel()[0].a
scope_reg = view.extract_scope(cur_pos)
for reg in self.view.sel():

file_string = view.substr(scope_reg)
with_quotes = re.match('^[\"\']{1}(.*)[\"\']{1}$', file_string)
file_string = with_quotes.group(1) if with_quotes else file_string
scope_reg = view.extract_scope(reg.a) if reg.a == reg.b else reg
file_string = view.substr(scope_reg)
with_quotes = re.match('^[\"\']{1}(.*)[\"\']{1}$', file_string)
file_string = with_quotes.group(1) if with_quotes else file_string

if is_image(file_string):
dir_name = re.match('(.*)(\/.*)$', view.file_name())
dir_name = dir_name.group(1) + "/" if dir_name else ""
full_name = dir_name + file_string
self.view_image(dir_name, file_string)
if is_image(file_string):
dir_name = os.path.dirname(view.file_name())
self.view_image(dir_name, file_string)

else:
sublime.error_message("Image-Viewer\n\nERROR: Image type is not recognized:\n\n" + file_string)
else:
sublime.error_message("Image-Viewer\n\nERROR: Image type is not recognized:\n\n" + file_string)


def view_image(self, dir_name, file_name = ""):
'''View image with default OS viewer'''

full_name = dir_name + file_name
full_name = dir_name + "/" + file_name

if (os.path.isfile(full_name)):
desktop.open(full_name)
Expand Down

0 comments on commit 93b7cef

Please sign in to comment.