Permalink
Browse files

Allows to copy the URL of the selected items.

  • Loading branch information...
titoBouzout committed Mar 21, 2012
1 parent dd4688a commit 1105b2fe14dc1043de6ac289e7cb10d27702b8c8
Showing with 40 additions and 1 deletion.
  1. +4 −0 Commands.sublime-commands
  2. +3 −0 Side Bar.sublime-menu
  3. +22 −1 SideBar.py
  4. +11 −0 sidebar/SideBarSelection.py
@@ -63,6 +63,10 @@
"caption": "File: Copy as Tag style",
"command": "side_bar_copy_tag_style"
},
+ {
+ "caption": "File: Copy URL",
+ "command": "side_bar_copy_url"
+ },
{
"caption": "File: Search Files",
"command": "side_bar_find_files_path_containing"
View
@@ -63,6 +63,9 @@
{ "caption": "Name Encoded", "id": "side-bar-clip-copy-name-encoded", "command": "side_bar_copy_name_encoded", "args": {"paths": []} },
{ "caption": "-", "id": "side-bar-clip-copy-name-encoded-separator"},
+ { "caption": "URL", "id": "side-bar-clip-copy-url", "command": "side_bar_copy_url", "args": {"paths": []} },
+ { "caption": "-", "id": "side-bar-clip-copy-url-separator"},
+
{ "caption": "Tag a", "id": "side-bar-clip-copy-tag-a", "command": "side_bar_copy_tag_ahref", "args": {"paths": []} },
{ "caption": "Tag img", "id": "side-bar-clip-copy-tag-img", "command": "side_bar_copy_tag_img", "args": {"paths": []} },
{ "caption": "Tag script", "id": "side-bar-clip-copy-tag-script", "command": "side_bar_copy_tag_script", "args": {"paths": []} },
View
@@ -785,6 +785,27 @@ def run(self, paths = []):
def is_enabled(self, paths = []):
return SideBarSelection(paths).hasFiles()
+class SideBarCopyUrlCommand(sublime_plugin.WindowCommand):
+ def run(self, paths = []):
+ to_copy = []
+ project = SideBarProject()
+ url = project.getPreference('url_production')
+ if url:
+ if url[-1:] != '/':
+ url = url+'/'
+ for item in SideBarSelection(paths).getSelectedItems():
+ if item.isUnderCurrentProject():
+ to_copy.append(url + item.pathRelativeFromProjectEncoded())
+
+ sublime.set_clipboard("\n".join(to_copy));
+ if len(paths) > 1 :
+ sublime.status_message("Items URL copied")
+ else :
+ sublime.status_message("Item URL copied")
+
+ def is_enabled(self, paths = []):
+ return SideBarSelection(paths).hasItemsUnderProject()
+
class SideBarDuplicateCommand(sublime_plugin.WindowCommand):
def run(self, paths = [], new = False):
import functools
@@ -1033,4 +1054,4 @@ def run(self, paths = [], type = False):
sublime.status_message('Preference "url" was not found in project file.\n"'+project.getProjectFile()+'", opening local file')
def is_enabled(self, paths = []):
- return SideBarSelection(paths).hasFiles()
+ return SideBarSelection(paths).len() > 0
@@ -53,6 +53,17 @@ def hasProjectDirectories(self):
else:
return False
+ def hasItemsUnderProject(self):
+ project = SideBarProject()
+ url = project.getPreference('url_production')
+ if url:
+ for item in self.getSelectedItems():
+ if item.isUnderCurrentProject():
+ return True
+ return False
+ else:
+ return False
+
def hasImages(self):
return self.hasFilesWithExtension('gif|jpg|jpeg|png')

0 comments on commit 1105b2f

Please sign in to comment.