Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"caption": "Package Control: List Packages",
"command": "list_packages"
},
{
"caption": "Package Control: List Packages on View",
"command": "list_packages_on_view"
},
{
"caption": "Package Control: Remove Channel",
"command": "remove_channel"
Expand Down
2 changes: 2 additions & 0 deletions package_control/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .install_local_dependency_command import InstallLocalDependencyCommand
from .install_package_command import InstallPackageCommand
from .list_packages_command import ListPackagesCommand
from .list_packages_command import ListPackagesOnViewCommand
from .list_unmanaged_packages_command import ListUnmanagedPackagesCommand
from .remove_package_command import RemovePackageCommand
from .upgrade_all_packages_command import UpgradeAllPackagesCommand
Expand All @@ -30,6 +31,7 @@
'InstallLocalDependencyCommand',
'InstallPackageCommand',
'ListPackagesCommand',
'ListPackagesOnViewCommand',
'ListUnmanagedPackagesCommand',
'RemovePackageCommand',
'UpgradeAllPackagesCommand',
Expand Down
72 changes: 63 additions & 9 deletions package_control/commands/list_packages_command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
import threading
import os

Expand All @@ -10,6 +11,8 @@
from .existing_packages_command import ExistingPackagesCommand


# print( "Reloading `Package Control\package_control\commands\list_packages_command.py`" )

class ListPackagesCommand(sublime_plugin.WindowCommand):

"""
Expand All @@ -20,13 +23,23 @@ def run(self):
ListPackagesThread(self.window).start()


class ListPackagesOnViewCommand(sublime_plugin.WindowCommand):

"""
A command that shows a list of all installed packages in a new view
"""

def run(self):
ListPackagesThread(self.window, on_view=True).start()


class ListPackagesThread(threading.Thread, ExistingPackagesCommand):

"""
A thread to prevent the listing of existing packages from freezing the UI
"""

def __init__(self, window, filter_function=None):
def __init__(self, window, filter_function=None, on_view=False):
"""
:param window:
An instance of :class:`sublime.Window` that represents the Sublime
Expand All @@ -44,6 +57,7 @@ def __init__(self, window, filter_function=None):
"""

self.window = window
self.on_view = on_view
self.filter_function = filter_function
self.manager = PackageManager()
threading.Thread.__init__(self)
Expand All @@ -53,18 +67,57 @@ def run(self):
if self.filter_function:
self.package_list = list(filter(self.filter_function, self.package_list))

def show_no_packages():
sublime.message_dialog(text.format(
u'''
Package Control

There are no packages to list
'''
))

def show_panel():
if not self.package_list:
sublime.message_dialog(text.format(
u'''
Package Control

There are no packages to list
'''
))
show_no_packages()
return
show_quick_panel(self.window, self.package_list, self.on_done)
sublime.set_timeout(show_panel, 10)

def show_view():
if not self.package_list:
show_no_packages()
return

new_view = sublime.active_window().new_file()
package_count = 0
prefix_indent = " "
package_string_list = []

new_view.set_scratch(True)
new_view.set_name("Packages List")
new_view.set_syntax_file("Packages/Text/Plain text.tmLanguage")
new_view.settings().set('tab_size', 8)

for package in self.package_list:
package_count += 1;
wrapper = textwrap.TextWrapper(initial_indent=prefix_indent, width=80, subsequent_indent=prefix_indent)

# Efficient String Concatenation in Python - https://waymoot.org/home/python_string/
package_string_list.append( "%3d: <%s>\n" % ( package_count, package[0] ) )
package_string_list.append( wrapper.fill(package[1]) + "\n" + prefix_indent + "[" + package[2] + "]\n\n" )

# https://forum.sublimetext.com/t/how-to-insert-text-on-view-with-no-indentation/28496
new_view.run_command("append", {"characters": "Packages list within %d entries:\n\n" % (len(self.package_list))})
new_view.run_command("append", {"characters": "".join( package_string_list )})

new_view.sel().clear()
initial_region = sublime.Region(0,0)
new_view.sel().add(initial_region)
new_view.show_at_center(initial_region)

if self.on_view:
sublime.set_timeout(show_view, 10)
else:
sublime.set_timeout(show_panel, 10)

def on_done(self, picked):
"""
Expand Down Expand Up @@ -95,3 +148,4 @@ def open_dir():

self.window.run_command('open_dir', open_dir_file)
sublime.set_timeout(open_dir, 10)