Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove action to update image size as it is not very useful, adds ano…

…ther file, another requirement, and another step in the installation
  • Loading branch information...
commit a02a9566c499d2ef35c014e73829bd77d39d56da 1 parent abcf4cb
@mikecrittenden authored
View
6 README.md
@@ -27,7 +27,6 @@ With this plugin, you can:
- Balance tag inward or outward with `Ctrl+Alt+I` or `Ctrl+Alt+O`
- Merge lines with `Ctrl+Alt+M`
- Go to previous or next edit point with `Alt+Left` and `Alt+Right`
-- Update tag image size with `Ctrl+Alt+S`
- Remove tag with `Ctrl+Alt+R`
- Split or join tags with `Ctrl+Alt+J`
- Toggle comment with `Ctrl+Alt+C`
@@ -39,9 +38,8 @@ Installation
1. Download [zip](http://github.com/mikecrittenden/zen-coding-gedit/zipball/master) or [tar](http://github.com/mikecrittenden/zen-coding-gedit/tarball/master) source and unpack it.
2. Move `zencoding.gedit-plugin` and the `zencoding` folder into `~/.gnome2/gedit/plugins/`
-3. In order to use "Update tag image size", install `imagemagick` if not already installed
-4. In Gedit, go to Edit → Preferences → Plugins to enable the plugin.
-5. Try it out using the shortcut keys listed above.
+3. In Gedit, go to Edit → Preferences → Plugins to enable the plugin.
+4. Try it out using the shortcut keys listed above.
Credits
-------
View
117 zencoding/image_size.py
@@ -1,117 +0,0 @@
-'''
-@author: Sergey Chikuyonok (serge.che@gmail.com)
-'''
-from subprocess import Popen, PIPE
-import urllib
-import os
-import re
-
-def replace_or_append(img_tag, attr_name, attr_value):
- """
- Replaces or adds attribute to the tag
- @type img_tag: str
- @type attr_name: str
- @type attr_value: str
- """
- if attr_name in img_tag.lower():
- # attribute exists
- re_attr = re.compile(attr_name + r'=([\'"])(.*?)\1', re.I)
- return re.sub(re_attr, lambda m: '%s=%s%s%s' % (attr_name, m.group(1), attr_value, m.group(1)), img_tag)
- else:
- return re.sub(r'\s*(\/?>)$', ' ' + attr_name + '="' + attr_value + r'" \1', img_tag)
-
-def find_image(editor):
- """
- Find image tag under caret
- @return Image tag and its indexes inside editor source
- """
- _caret = editor.get_caret_pos()
- text = editor.get_content()
- start_ix = -1
- end_ix = -1
-
- # find the beginning of the tag
- caret_pos = _caret
- while caret_pos >= 0:
- if text[caret_pos] == '<':
- if text[caret_pos:caret_pos + 4].lower() == '<img':
- # found the beginning of the image tag
- start_ix = caret_pos
- break
- else:
- # found some other tag
- return None
- caret_pos -= 1
-
- # find the end of the tag
- caret_pos = _caret
- ln = len(text)
- while caret_pos <= ln:
- if text[caret_pos] == '>':
- end_ix = caret_pos + 1
- break
- caret_pos += 1
-
-
- if start_ix != -1 and end_ix != -1:
- return {
- 'start': start_ix,
- 'end': end_ix,
- 'tag': text[start_ix:end_ix]
- }
-
- return None
-
-def get_image_size(editor, img):
- """
- Returns size of image in <img>; tag
- @param img: Image tag
- @return Dictionary with <code>width</code> and <code>height</code> attributes
- """
- m = re.search(r'src=(["\'])(.+?)\1', img, re.IGNORECASE)
- if m:
- src = get_absolute_uri(editor, m.group(2))
- if not src:
- return None
- try:
- #raw_output = Popen('sips -g pixelWidth -g pixelHeight "%s"' % src, stdout=PIPE, shell=True).communicate()[0]
- raw_output = Popen('identify "%s"' % src, stdout=PIPE, shell=True).communicate()[0]
- return {
- 'width': re.search(r'([\d]+)x[\d]+', raw_output).group(1),
- 'height': re.search(r'[\d]+x([\d]+)', raw_output).group(1)
- }
- except:
- pass
-
- return None
-
-def get_absolute_uri(editor, img_path):
- file_uri = editor.document.get_uri()
- if not file_uri: return None
- file_uri = re.sub(r'^file://', '', file_uri)
-
- if img_path[0] == '/':
- img_path = img_path[1:]
-
- while True:
- head, tail = os.path.split(file_uri)
- if not head or head == '/': break # reached the top
-
- abs_image_path = os.path.join(head, img_path)
- abs_image_path = os.path.normpath(abs_image_path)
- if os.path.exists(abs_image_path):
- return os.path.join(abs_image_path)
-
- if head == file_uri: break # infinite loop protection
- file_uri = head
-
- return None
-
-def update_image_size(editor):
- image = find_image(editor)
- if image:
- size = get_image_size(editor, image['tag'])
- if size:
- new_tag = replace_or_append(image['tag'], 'width', size['width'])
- new_tag = replace_or_append(new_tag, 'height', size['height'])
- editor.replace_content(new_tag, image['start'], image['end'])
View
6 zencoding/plugin.py
@@ -26,8 +26,6 @@
<menuitem name="ZenCodingPrev" action="ZenCodingPrevAction"/>
<menuitem name="ZenCodingNext" action="ZenCodingNextAction"/>
<separator/>
- <menuitem name="ZenCodingSize" action="ZenCodingSizeAction"/>
- <separator/>
<menuitem name="ZenCodingRemove" action="ZenCodingRemoveAction"/>
<menuitem name="ZenCodingSplit" action="ZenCodingSplitAction"/>
<menuitem name="ZenCodingComment" action="ZenCodingCommentAction"/>
@@ -52,7 +50,6 @@ def activate(self, window):
('ZenCodingMergeAction', None, '_Merge lines', '<Ctrl><Alt>M', "Merge all lines of the current selection", self.merge_lines),
('ZenCodingPrevAction', None, '_Previous edit point', '<Alt>Left', "Place the cursor at the previous edit point", self.prev_edit_point),
('ZenCodingNextAction', None, '_Next edit point', '<Alt>Right', "Place the cursor at the next edit point", self.next_edit_point),
- ('ZenCodingSizeAction', None, 'Update image _size', '<Ctrl><Alt>S', "Update image size tag from file", self.update_image_size),
('ZenCodingRemoveAction', None, '_Remove tag', '<Ctrl><Alt>R', "Remove a tag", self.remove_tag),
('ZenCodingSplitAction', None, 'Split or _join tag', '<Ctrl><Alt>J', "Toggle between single and double tag", self.split_join_tag),
('ZenCodingCommentAction', None, 'Toggle _comment', '<Ctrl><Alt>C', "Toggle an XML or HTML comment", self.toggle_comment)
@@ -112,9 +109,6 @@ def prev_edit_point(self, action, window):
def next_edit_point(self, action, window):
self.editor.next_edit_point(window)
- def update_image_size(self, action, window):
- self.editor.update_image_size(window)
-
def remove_tag(self, action, window):
self.editor.remove_tag(window)
View
7 zencoding/zen_editor.py
@@ -21,7 +21,6 @@
import zen_core, zen_actions
import os, re, locale
-from image_size import update_image_size
import zen_dialog
class ZenEditor():
@@ -304,12 +303,6 @@ def next_edit_point(self, window=None):
self.show_caret()
return result
- def update_image_size(self, window):
- self.set_context(window)
- self.buffer.begin_user_action()
- update_image_size(self)
- self.buffer.end_user_action()
-
def remove_tag(self, window):
self.set_context(window)
self.buffer.begin_user_action()
Please sign in to comment.
Something went wrong with that request. Please try again.