Skip to content

Commit

Permalink
Copy path command. Fixes #129
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjoelkemp committed Mar 19, 2015
1 parent 93ce047 commit d2ef9fd
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
16 changes: 15 additions & 1 deletion BaseCommand.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import sublime_plugin
import time

# TODO: Support Python 2 style imports
from .lib.thread_progress import ThreadProgress
from .lib.show_error import *
from .lib.command_setup import command_setup
from .lib.track import track as t

class BaseCommand():
def run(self, modifier='', edit=None):
Expand All @@ -22,4 +25,15 @@ def init_thread(self, Thread, progress_message):
thread = Thread(self)
thread.start();

ThreadProgress(thread, progress_message, '')
ThreadProgress(thread, progress_message, '')

# TODO: Move into a structure reusable with BaseThread
def start_timer(self):
self.total_start_time = time.time()

def stop_timer(self, command_name):
tracking_data = {
'etime': time.time() - self.total_start_time,
}

t(command_name, tracking_data)
3 changes: 2 additions & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{ "command": "dependents", "caption": "Open all dependents", "args": { "modifier": "OPEN_ALL"}},
{ "command": "find_driver", "caption": "Find relevant app entry points" },
{ "command": "find_driver", "caption": "Open all relevant app entry points", "args": { "modifier": "OPEN_ALL"}},
{ "command": "tree", "caption": "View this file's dependency tree" }
{ "command": "tree", "caption": "View this file's dependency tree" },
{ "command": "get_path", "caption": "Copy path to the clipboard" }
]
}
]
6 changes: 6 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
{
"keys": ["super+alt+right"],
"command": "jump_to_dependency"
},

// Copy path to clipboard
{
"keys": ["super+shift+c"],
"command": "get_path"
}
]
28 changes: 28 additions & 0 deletions GetPathCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sublime, sublime_plugin
import os

from .BaseCommand import BaseCommand
from .BaseThread import BaseThread

from .lib.normalize_trailing_slash import normalize_trailing_slash
from .lib.printer import p
from .node_dependency_tree import get_tree

class GetPathCommand(BaseCommand, sublime_plugin.WindowCommand):
def run(self):
super(GetPathCommand, self).run()
self.start_timer()

root = normalize_trailing_slash(self.window.root)
p('Root:', root)

filename_no_ext = os.path.splitext(self.view.filename)[0]
p('File w/o ext:', filename_no_ext)

path = filename_no_ext.split(root)[1]
p('Path:', path)

sublime.set_clipboard(path);

self.stop_timer('Get_Path')

8 changes: 6 additions & 2 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
"caption": "Open All Dependents",
"command": "dependents",
"args": { "modifier": "OPEN_ALL"}
}
},
{ "command": "find_driver", "caption": "Find relevant app entry points" },
{ "command": "find_driver", "caption": "Open all relevant app entry points", "args": { "modifier": "OPEN_ALL"}},
{ "command": "tree", "caption": "View this file's dependency tree" },
{ "command": "get_path", "caption": "Copy path to the clipboard" }
]
}
]
}
}
]
14 changes: 14 additions & 0 deletions changelogs/2.6.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
New Feature: Copy module path to the clipboard

`Command + Shift + C` (OSX) or

1. Within a file, right click to open the context menu
2. Click on `Dependents -> Copy path to the clipboard`

Copy the rootless path of the current module to the clipboard. (Sass and JS)

For example, if the root is `assets/js` and the filename is `path/to/assets/js/myFeature/file.js`,
then the command will copy `myFeature/file` to the clipboard.

This is useful when you want to include the current module as a dependency of another module.

3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"2.5.0": "changelogs/2.5.0.txt",
"2.5.1": "changelogs/2.5.1.txt",
"2.5.2": "changelogs/2.5.2.txt",
"2.5.3": "changelogs/2.5.3.txt"
"2.5.3": "changelogs/2.5.3.txt",
"2.6.0": "changelogs/2.6.0.txt"
}
17 changes: 16 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Currently supporting: AMD, CommonJS, ES6, and Sass codebases.
- [Find dependents](#find-the-dependents-of-the-current-module)
- [Find relevant app entry points](#find-relevant-app-entry-points)
- [View dependency tree](#view-dependency-tree)
- [Copy Path to Clipboard](#copy-path-to-clipboard)
4. [Bindings](#bindings)
- [Key Bindings](#key-bindings)
- [Mouse Bindings](#mouse-bindings)
Expand Down Expand Up @@ -195,6 +196,20 @@ View a snapshot of the current file's dependency tree (as a JSON file)
1. Within a file, right click to open the context menu
2. Click on `Dependents -> View this file's dependency tree`

#### Copy path to clipboard

Copy the rootless path of the current module to the clipboard. (JS and Sass)

For example, if the root is `assets/js` and the filename is `path/to/assets/js/myFeature/file.js`,
then the command will copy `myFeature/file` to the clipboard.

This is useful when you want to include the current module as a dependency of another module.

1. Within a file, right click to open the context menu
2. Click on `Dependents -> Copy path to the clipboard`

Or via its key binding.

### Bindings

To more swiftly and conveniently trigger the package's commands both key and mouse bindings are provided.
Expand All @@ -207,7 +222,7 @@ OSX:

* Jump to dependency: `Command + Option + Right arrow`
* Find Dependents: `Command + Option + Up arrow`

* Copy path to clipboard: `Command + Shift + C`

Windows and Linux:

Expand Down

0 comments on commit d2ef9fd

Please sign in to comment.