Skip to content

Commit

Permalink
ConvertToUTF8 1.2.2 Changelog
Browse files Browse the repository at this point in the history
New Features
- Added "Reload with Encoding" menu items and command (Thanks to @ArieShout)

Enhancements
- [ST3] Perform detection for file(s) opened before plugin is ready

Fixed
- [ST3] File remains in dirty after being saved
  • Loading branch information
seanliang committed Jul 24, 2013
1 parent 5acfeb4 commit 88b7076
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
28 changes: 18 additions & 10 deletions ConvertToUTF8.py
Expand Up @@ -9,6 +9,7 @@
else:
from .chardet.universaldetector import UniversalDetector
NONE_COMMAND = ('', None, 0)
ST3 = True
import codecs
import threading
import json
Expand All @@ -24,8 +25,6 @@
ENCODINGS_NAME = []
ENCODINGS_CODE = []

PKG_PATH = None

class EncodingCache(object):
def __init__(self):
self.cache_file = os.path.join(sublime.packages_path(), 'User', 'encoding_cache.json')
Expand Down Expand Up @@ -108,20 +107,28 @@ def get_settings():
SETTINGS['convert_on_save'] = settings.get('convert_on_save', 'always')

def init_settings():
global encoding_cache, PKG_PATH
global encoding_cache
encoding_cache = EncodingCache()
PKG_PATH = os.path.join(sublime.packages_path(), 'ConvertToUTF8')
get_settings()
sublime.load_settings('ConvertToUTF8.sublime-settings').add_on_change('get_settings', get_settings)

if 'sublime_api' in dir(sublime):
def plugin_loaded():
init_settings()
if SETTINGS['convert_on_load'] == 'never':
return
# existing views should be checked
for win in sublime.windows():
for view in win.views():
if view.is_dirty() or view.settings().get('origin_encoding'):
show_encoding_status(view)
continue
threading.Thread(target=lambda: detect(view, view.file_name(), view.encoding())).start()
else:
init_settings()

def detect(view, file_name, encoding):
if not os.path.exists(file_name):
if not file_name or not os.path.exists(file_name):
return
if not encoding.endswith(' with BOM'):
encoding = encoding_cache.pop(file_name)
Expand Down Expand Up @@ -170,6 +177,8 @@ def show_encoding_status(view):
encoding = view.settings().get('force_encoding')
if not encoding:
encoding = view.settings().get('origin_encoding')
if not encoding:
return
view.set_status('origin_encoding', encoding)

def init_encoding_vars(view, encoding, run_convert=True, stamp=None, detect_on_fail=False):
Expand Down Expand Up @@ -252,10 +261,7 @@ def run(self, edit, encoding):
self.view.set_name('ConvertToUTF8 Instructions')
self.view.set_scratch(True)
self.view.settings().set("word_wrap", True)
fp = open(os.path.join(PKG_PATH, 'python26.txt'), 'r')
msg = fp.read()
fp.close()
msg += 'Version: {0}\nPlatform: {1}\nArch: {2}\nPath: {3}\nEncoding: {4}\n'.format(
msg = 'Due to the limitation of embedded Python with Sublime Text, ConvertToUTF8 might not work properly.\n\nYou have to install an extra plugin to solve this problem, please kindly send the debug information to sunlxy#yahoo.com to get it:\n====== Debug Information ======\nVersion: {0}\nPlatform: {1}\nArch: {2}\nPath: {3}\nEncoding: {4}\n'.format(
sublime.version(), sublime.platform(), sublime.arch(), sys.path, encoding
)
self.view.insert(edit, 0, msg)
Expand Down Expand Up @@ -504,10 +510,12 @@ def on_modified(self, view):
def undo_me(self, view):
view.settings().erase('prevent_detect')
view.run_command('undo')
if view.settings().get('revert_to_scratch'):
# st3 will reload file immediately
if view.settings().get('revert_to_scratch') or ST3:
view.set_scratch(True)

def on_deactivated(self, view):
# st2 will reload file when on_deactivated
if view.settings().get('prevent_detect'):
remove_reverting(view.file_name())
view.settings().set('revert_to_scratch', not view.is_dirty())
Expand Down
1 change: 1 addition & 0 deletions messages.json
@@ -1,4 +1,5 @@
{
"1.2.2": "messages/1.2.2.txt",
"1.2.1": "messages/1.2.1.txt",
"1.2.0": "messages/1.2.0.txt",
"1.1.5": "messages/1.1.5.txt",
Expand Down
10 changes: 10 additions & 0 deletions messages/1.2.2.txt
@@ -0,0 +1,10 @@
ConvertToUTF8 1.2.2 Changelog

New Features
- Added "Reload with Encoding" menu items and command (Thanks to @ArieShout)

Enhancements
- [ST3] Perform detection for file(s) opened before plugin is ready

Fixed
- [ST3] File remains in dirty after being saved
4 changes: 2 additions & 2 deletions packages.json
Expand Up @@ -6,11 +6,11 @@
"description": "For editing and saving files encoded in GBK, BIG5, EUC-KR, EUC-JP, Shift_JIS, etc.",
"author": "Sean Liang",
"homepage": "https://github.com/seanliang/ConvertToUTF8",
"last_modified": "2013-02-18 22:00:00",
"last_modified": "2013-07-24 22:30:00",
"platforms": {
"*": [
{
"version": "1.2.1",
"version": "1.2.2",
"url": "https://nodeload.github.com/seanliang/ConvertToUTF8/zipball/master"
}
]
Expand Down
4 changes: 0 additions & 4 deletions python26.txt

This file was deleted.

0 comments on commit 88b7076

Please sign in to comment.