diff --git a/JavaPropertiesEditor.py b/JavaPropertiesEditor.py index 5cd5c51..01133f5 100644 --- a/JavaPropertiesEditor.py +++ b/JavaPropertiesEditor.py @@ -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): @@ -14,27 +20,19 @@ 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)) @@ -42,6 +40,17 @@ def replace_content(self, view, regions, contents): 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 @@ -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'): @@ -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'): @@ -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) diff --git a/messages.json b/messages.json index a917a4f..b20cb5f 100644 --- a/messages.json +++ b/messages.json @@ -1,3 +1,4 @@ { + "1.1.0": "messages/1.1.0.txt", "install": "messages/install.txt" } diff --git a/messages/1.1.0.txt b/messages/1.1.0.txt new file mode 100644 index 0000000..95ca185 --- /dev/null +++ b/messages/1.1.0.txt @@ -0,0 +1,4 @@ +JavaPropertiesEditor 1.1.0 Changelog + +New Features +- Forward compatible with Sublime Text 3 (3012 and above)