Skip to content

Commit

Permalink
v1.1.0 Forward compatible with Sublime Text 3 (3012 and above)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanliang committed Feb 18, 2013
1 parent 9e75cb8 commit 5c8a14f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
44 changes: 26 additions & 18 deletions JavaPropertiesEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import sublime, sublime_plugin
import os
import re
import sys

NONE_COMMAND = (None, None, 0)
if sys.version_info < (3, 0):
NONE_COMMAND = (None, None, 0)
MAP = map(unichr, range(0x7f))
else:
NONE_COMMAND = ('', None, 0)
MAP = list(map(chr, list(range(0x7f))))

class UpperTable(dict):
def __missing__(self, key):
Expand All @@ -14,34 +20,37 @@ class LowerTable(dict):
def __missing__(self, key):
return u'\\u%04x' % key

MAP = map(unichr, range(0x7f))
UPPER_TABLE = UpperTable(enumerate(MAP))
LOWER_TABLE = LowerTable(enumerate(MAP))
IS_UPPER = re.compile('\\u([A-F][A-Z0-9]{3,3}|[0-9][A-F][A-F0-9]{2,2}|[0-9]{2,2}[A-F][A-F0-9]|[0-9]{3,3}[A-F])')
IS_UPPER = re.compile('\\\\u([A-F][A-Z0-9]{3,3}|[0-9][A-F][A-F0-9]{2,2}|[0-9]{2,2}[A-F][A-F0-9]|[0-9]{3,3}[A-F])')

class JavaPropertiesEditorListener(sublime_plugin.EventListener):
def check_properties(self, view):
file_name = view.file_name()
result = file_name and file_name.endswith('.properties')
if result:
view.settings().set('is_properties', True)
return result

def replace_content(self, view, regions, contents):
class JavaPropertiesConvertCommand(sublime_plugin.TextCommand):
def run(self, edit, contents):
view = self.view
sel = view.sel()
rs = [x for x in sel]
vp = view.viewport_position()
view.set_viewport_position(tuple([0, 0]))
edit = view.begin_edit()
regions = sublime.Region(0, view.size())
view.replace(edit, regions, contents)
view.end_edit(edit)
sel.clear()
for x in rs:
sel.add(sublime.Region(x.a, x.b))
view.set_viewport_position(vp)
view.set_scratch(True)
view.settings().set('set_scratch', True)

class JavaPropertiesEditorListener(sublime_plugin.EventListener):
def check_properties(self, view):
file_name = view.file_name()
result = file_name and file_name.endswith('.properties')
if result:
view.settings().set('is_properties', True)
return result

def replace_content(self, view, contents):
view.run_command('java_properties_convert', {'contents': contents})

def on_load(self, view):
if not self.check_properties(view):
return
Expand All @@ -52,7 +61,7 @@ def on_load(self, view):
return
if IS_UPPER.search(orignal_contents) == None:
view.settings().set('use_lower', True)
self.replace_content(view, regions, contents)
self.replace_content(view, contents)

def on_modified(self, view):
if not view.settings().get('is_properties'):
Expand Down Expand Up @@ -82,7 +91,7 @@ def on_pre_save(self, view):
if contents == orignal_contents:
return
self.contents = contents
self.replace_content(view, regions, orignal_contents)
self.replace_content(view, orignal_contents)

def on_post_save(self, view):
if not view.settings().get('is_properties'):
Expand All @@ -91,5 +100,4 @@ def on_post_save(self, view):
return
contents = self.contents
del self.contents
regions = sublime.Region(0, view.size())
self.replace_content(view, regions, contents)
self.replace_content(view, contents)
1 change: 1 addition & 0 deletions messages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"1.1.0": "messages/1.1.0.txt",
"install": "messages/install.txt"
}
4 changes: 4 additions & 0 deletions messages/1.1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JavaPropertiesEditor 1.1.0 Changelog

New Features
- Forward compatible with Sublime Text 3 (3012 and above)

0 comments on commit 5c8a14f

Please sign in to comment.