diff --git a/Default.sublime-commands b/Default.sublime-commands
new file mode 100644
index 0000000..6864255
--- /dev/null
+++ b/Default.sublime-commands
@@ -0,0 +1,12 @@
+[
+ {
+ "caption": "AutoFileName: Default Settings",
+ "command": "open_file",
+ "args": {"file": "${packages}/AutoFileName/autofilename.sublime-settings"}
+ },
+ {
+ "caption": "AutoFileName: Quick Settings",
+ "command": "afn_settings_panel"
+ }
+
+]
\ No newline at end of file
diff --git a/Default.sublime-keymap b/Default.sublime-keymap
index 6098f74..fa5e0c7 100644
--- a/Default.sublime-keymap
+++ b/Default.sublime-keymap
@@ -1,5 +1,5 @@
[
- { "keys": ["tab"], "command": "insert_dimensions",
+ { "keys": ["tab"], "command": "insert_dimensions",
"context":
[
{ "key": "setting.auto_complete_commit_on_tab" },
diff --git a/README.md b/README.md
index 138fe10..9e026e4 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,39 @@
-AutoFileName: Autocomplete Filenames in Sublime Text
-=====================================================
+AutoFileName
+============
+
+Autocomplete Filenames in Sublime Text
+--------------------------------------
Do you ever find yourself sifting through folders in the sidebar trying to remember what you named that file? Can't remember if it was a jpg or a png? Maybe you just wish you could type filenames faster. *No more.*
-Whether your making a `img` tag in html, setting a background image in css, or linking a `.js` file to your html (or whatever else people use filename paths for these days...), you can now autocomplete the filename. Plus, it uses the built-in autocomplete, so no need to learn another *pesky* shortcut.
+Whether you're making a `img` tag in html, setting a background image in css, or linking a `.js` file to your html (or whatever else people use filename paths for these days...), you can now autocomplete the filename. Plus, it uses the built-in autocomplete, so no need to learn another pesky shortcut.
+
+Features
+--------
+
+- Display filenames and folders
+- Show dimensions next to image files
+- Autoinsert dimensions in img tags (can be disabled in settings)
+- Support for both '/' and '\' for all you Windows hooligans
Usage
-=====
+-----
+**Nothing!**
+
+For example:
+
If you are looking to autocomplete an image path in an HTML `
` tag:
-
-
-Pressing control+space, will activate AutoFileName. I list of available files where be ready to select.
-
-*Looking for an even more automatic and seemless completion?* Add the following to your User Settings file:
-
- "auto_complete_triggers":
- [
- {
- "characters": "<",
- "selector": "text.html"
- },
- {
- "characters": "/",
- "selector": "string.quoted.double.html,string.quoted.single.html, source.css"
- }
- ]
-
-With this, there's no need to worry about pressing control+space, autocompletion with appear upon pressing /.
\ No newline at end of file
+ `
`
+
+AutoFileName will display a list of files without you having to do anything. As you type, the results will narrow. The list will automatically update as you enter a new directory so you don't have to do a thing.
+
+Settings
+--------
+There are some options now.
+
+Perhaps you're working on a website and all the image files are relative to the project root instead of the Computer's root directory. No worries. Just tell AutoFileName the project root. (More info in the settings file.)
+
+Additionally, if you hate awesomeness, you can turn off some of the automagicalness and use a boring keybinding to activate AutoFileName.
+
+How Can I help?
+---------------
+- **Got a feature request? Something bugging you and you're about to uninstall it?** Submit a bug report with all your fears, desires, and vulgarity. I'll heartily try to fix the plugin to your specifications... well, I'll consider it.
\ No newline at end of file
diff --git a/autofilename.py b/autofilename.py
index 004b929..952687f 100644
--- a/autofilename.py
+++ b/autofilename.py
@@ -1,14 +1,57 @@
import sublime
import sublime_plugin
import os
-from getimageinfo import getImageInfo
+from .getimageinfo import getImageInfo
+class AfnShowFilenames(sublime_plugin.TextCommand):
+ def run(self, edit):
+ FileNameComplete.is_active = True
+ self.view.run_command('auto_complete',
+ {'disable_auto_insert': True,
+ 'next_completion_if_showing': False})
+
+class AfnSettingsPanel(sublime_plugin.WindowCommand):
+ def run(self):
+ use_pr = '✗ Stop using project root' if self.get_setting('afn_use_project_root') else '✓ Use Project Root'
+ use_dim = '✗ Disable HTML Image Dimension insertion' if self.get_setting('afn_insert_dimensions') else '✓ Auto-insert Image Dimensions in HTML'
+ p_root = self.get_setting('afn_proj_root')
+
+ menu = [
+ [use_pr, p_root],
+ [use_dim, '
']
+ ]
+ self.window.show_quick_panel(menu, self.on_done)
+
+ def on_done(self, value):
+ settings = sublime.load_settings('autofilename.sublime-settings')
+ if value == 0:
+ use_pr = settings.get('afn_use_project_root')
+ settings.set('afn_use_project_root', not use_pr)
+ if value == 1:
+ use_dim = settings.get('afn_use_project_root')
+ settings.set('afn_use_project_root', not use_dim)
+
+ def get_setting(self,string,view=None):
+ if view and view.settings().get(string):
+ return view.settings().get(string)
+ else:
+ return sublime.load_settings('autofilename.sublime-settings').get(string)
+
+# Used to remove the / or \ when autocompleting a Windows drive (eg. /C:/path)
+class AfnDeletePrefixedSlash(sublime_plugin.TextCommand):
+ def run(self, edit):
+ sel = self.view.sel()[0].a
+ reg = sublime.Region(sel-4,sel-3)
+ self.view.erase(edit, reg)
+
+# inserts width and height dimensions into img tags. HTML only
class InsertDimensionsCommand(sublime_plugin.TextCommand):
this_dir = ''
def insert_dimension(self,edit,dim,name,tag_scope):
view = self.view
sel = view.sel()[0].a
+
if name in view.substr(tag_scope):
reg = view.find('(?<='+name+'\=)\s*\"\d{1,5}', tag_scope.a)
view.replace(edit, reg, '"'+str(dim))
@@ -22,32 +65,54 @@ def get_setting(self,string,view=None):
else:
return sublime.load_settings('autofilename.sublime-settings').get(string)
+
+ def insert_dimensions(self, edit, scope, w, h):
+ view = self.view
+
+ if self.get_setting('afn_insert_width_first',view):
+ self.insert_dimension(edit,h,'height', scope)
+ self.insert_dimension(edit,w,'width', scope)
+ else:
+ self.insert_dimension(edit,w,'width', scope)
+ self.insert_dimension(edit,h,'height', scope)
+
+
+ # determines if there is a template tag in a given region. supports HTML and template languages.
+ def img_tag_in_region(self, region):
+ view = self.view
+
+ # handle template languages but template languages like slim may also contain HTML so
+ # we do a check for that as well
+ return view.substr(region).strip().startswith('img') | ('
= 10) and data[:6] in ('GIF87a', 'GIF89a'):
+ if (size >= 10) and data[:6] == b'GIF89a':
# Check to see if content_type is correct
content_type = 'image/gif'
w, h = struct.unpack("= 24) and data.startswith('\211PNG\r\n\032\n')
- and (data[12:16] == 'IHDR')):
- content_type = 'image/png'
+ elif ((size >= 24) and data[:8] == b'\211PNG\r\n\032\n'
+ and (data[12:16] == b'IHDR')):
w, h = struct.unpack(">LL", data[16:24])
width = int(w)
height = int(h)
# Maybe this is for an older PNG version.
- elif (size >= 16) and data.startswith('\211PNG\r\n\032\n'):
+ elif (size >= 16) and data[:8] == b'\211PNG\r\n\032\n':
# Check to see if we have the right content type
- content_type = 'image/png'
w, h = struct.unpack(">LL", data[8:16])
width = int(w)
height = int(h)
# handle JPEGs
- elif (size >= 2) and data.startswith('\377\330'):
- content_type = 'image/jpeg'
- jpeg = StringIO.StringIO(data)
+ elif (size >= 2) and data[:2] == b'\377\330':
+ jpeg = io.BytesIO(data)
+
jpeg.read(2)
b = jpeg.read(1)
+
try:
- while (b and ord(b) != 0xDA):
- while (ord(b) != 0xFF): b = jpeg.read(1)
- while (ord(b) == 0xFF): b = jpeg.read(1)
- if (ord(b) >= 0xC0 and ord(b) <= 0xC3):
+ while (b != b''):
+ while (b != b'\xFF'): b = jpeg.read(1)
+ while (b == b'\xFF'): b = jpeg.read(1)
+ if (b >= b'\xC0' and b <= b'\xC3'):
jpeg.read(3)
h, w = struct.unpack(">HH", jpeg.read(4))
break
@@ -58,4 +59,4 @@ def getImageInfo(data):
except ValueError:
pass
- return content_type, width, height
\ No newline at end of file
+ return width, height