Skip to content
Browse files

Whatever.

  • Loading branch information...
0 parents commit 3c6b054bc9d58f3138ddd89814c3e54eb966d0ce @xobb1t xobb1t committed Oct 28, 2011
Showing with 85 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +48 −0 AdvancedNewFile.py
  3. +4 −0 Default (Linux).sublime-keymap
  4. +4 −0 Default (OSX).sublime-keymap
  5. +4 −0 Default (Windows).sublime-keymap
  6. +24 −0 README.rst
1 .gitignore
@@ -0,0 +1 @@
+*.pyc
48 AdvancedNewFile.py
@@ -0,0 +1,48 @@
+import os
+import sublime, sublime_plugin
+
+
+class AdvancedNewFileCommand(sublime_plugin.TextCommand):
+
+ def run(self, edit, is_python=False):
+ self.count = 0
+ self.window = self.view.window()
+ self.root = self.get_root()
+ self.show_filename_input()
+ self.is_python = is_python
+
+ def get_root(self):
+ try:
+ root = self.window.folders()[0]
+ except IndexError:
+ root = os.path.abspath(os.path.dirname(self.view.file_name()))
+ return root
+
+ def show_filename_input(self, initial=''):
+ self.window.show_input_panel(
+ 'Enter a path for a new file', initial,
+ self.entered_filename, self.update_filename_input, None
+ )
+
+ def update_filename_input(self, path):
+ # TODO: Autocomplete feature
+ pass
+
+ def entered_filename(self, filename):
+ file_path = os.path.join(self.root, filename)
+ if not os.path.exists(file_path):
+ self.create(file_path)
+ self.window.run_command('open_file', {"file": file_path})
+
+ def create(self, filename):
+ base, filename = os.path.split(filename)
+ self.create_folder(base)
+
+ def create_folder(self, base):
+ if not os.path.exists(base):
+ parent = os.path.split(base)[0]
+ if not os.path.exists(parent):
+ self.create_folder(parent)
+ os.mkdir(base)
+ if self.is_python:
+ open(os.path.join(base, '__init__.py'), 'w').close()
4 Default (Linux).sublime-keymap
@@ -0,0 +1,4 @@
+[
+    { "keys": ["super+alt+n"], "command": "advanced_new_file" },
+    { "keys": ["shift+super+alt+n"], "command": "advanced_new_file", "args": {"is_python": true} }
+]
4 Default (OSX).sublime-keymap
@@ -0,0 +1,4 @@
+[
+    { "keys": ["super+alt+n"], "command": "advanced_new_file" },
+    { "keys": ["shift+super+alt+n"], "command": "advanced_new_file", "args": {"is_python": true} }
+]
4 Default (Windows).sublime-keymap
@@ -0,0 +1,4 @@
+[
+    { "keys": ["super+alt+n"], "command": "advanced_new_file" },
+    { "keys": ["shift+super+alt+n"], "command": "advanced_new_file", "args": {"is_python": true} }
+]
24 README.rst
@@ -0,0 +1,24 @@
+AdvancedNewFile -- Advanced file creation for Sublime Text 2
+============================================================
+
+
+Orverview
+---------
+
+This plugin adds features like automatic folders creation in project.
+Also it creates __init__.py files in each new folder (option).
+
+
+Installation
+------------
+1. Clone or copy this repository into:
+
+- OS X: ~/Library/Application Support/Sublime Text 2/Packages/
+- Windows: %APPDATA%/Sublime Text 2/Packages/
+- Linux: ~/.config/sublime-text-2/Packages/
+
+
+Keymaps
+-------
+super+alt+n offers input file relative path for current project (opened file)
+shift+super+alt+n also creates __init__.py in all new folders.

0 comments on commit 3c6b054

Please sign in to comment.
Something went wrong with that request. Please try again.