diff --git a/BaseCommand.py b/BaseCommand.py index b792ac3f..46665a2a 100644 --- a/BaseCommand.py +++ b/BaseCommand.py @@ -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): @@ -22,4 +25,15 @@ def init_thread(self, Thread, progress_message): thread = Thread(self) thread.start(); - ThreadProgress(thread, progress_message, '') \ No newline at end of file + 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) \ No newline at end of file diff --git a/Context.sublime-menu b/Context.sublime-menu index 924a48b8..4679163f 100644 --- a/Context.sublime-menu +++ b/Context.sublime-menu @@ -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" } ] } ] diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index e6408a69..2817bb31 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -9,5 +9,11 @@ { "keys": ["super+alt+right"], "command": "jump_to_dependency" + }, + + // Copy path to clipboard + { + "keys": ["super+shift+c"], + "command": "get_path" } ] diff --git a/GetPathCommand.py b/GetPathCommand.py new file mode 100644 index 00000000..f3d759e6 --- /dev/null +++ b/GetPathCommand.py @@ -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') + diff --git a/Main.sublime-menu b/Main.sublime-menu index 42d231b2..61e9adeb 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -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" } ] } ] - } + } ] diff --git a/changelogs/2.6.0.txt b/changelogs/2.6.0.txt new file mode 100644 index 00000000..facd7427 --- /dev/null +++ b/changelogs/2.6.0.txt @@ -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. + diff --git a/messages.json b/messages.json index 18b5d642..b6bb359c 100644 --- a/messages.json +++ b/messages.json @@ -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" } diff --git a/readme.md b/readme.md index ecf3e79d..7bd6e871 100644 --- a/readme.md +++ b/readme.md @@ -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) @@ -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. @@ -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: