Skip to content

Commit 2c5d20b

Browse files
committed
Show already installed package in the "Install Package" panel
Fixes #1569 Users tend to forget what they installed or installed and then disabled. Include in the "Install Package" panel all these packages as well. For the disabled packages, rewrite the action and just enable the package.
1 parent dc6badd commit 2c5d20b

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

package_control/commands/install_package_command.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
from ..activity_indicator import ActivityIndicator
77
from ..console_write import console_write
88
from ..package_tasks import PackageTaskRunner
9+
from ..settings import (
10+
preferences_filename,
11+
load_list_setting,
12+
)
913
from ..show_error import show_message
1014

1115

@@ -20,9 +24,16 @@ def run(self):
2024

2125
def show_quick_panel():
2226
installer = PackageTaskRunner()
27+
installed = installer.manager.installed_packages()
28+
settings = sublime.load_settings(preferences_filename())
29+
disabled = installed & load_list_setting(settings, 'ignored_packages')
2330

2431
with ActivityIndicator('Loading packages...') as progress:
25-
tasks = installer.create_package_tasks(actions=(installer.INSTALL, installer.OVERWRITE))
32+
tasks = installer.create_package_tasks(actions=(
33+
installer.INSTALL, installer.OVERWRITE, installer.REINSTALL,
34+
installer.UPGRADE, installer.DOWNGRADE
35+
)
36+
)
2637
if not tasks:
2738
message = 'There are no packages available for installation'
2839
console_write(message)
@@ -37,6 +48,11 @@ def show_quick_panel():
3748
)
3849
return
3950

51+
for task in tasks:
52+
if task.action in (installer.REINSTALL, installer.UPGRADE, installer.DOWNGRADE):
53+
if task.package_name in disabled:
54+
task.action = installer.ENABLE
55+
4056
def on_done(picked):
4157
if picked == -1:
4258
return
@@ -45,7 +61,11 @@ def worker(task):
4561
with ActivityIndicator('Installing package %s' % task.package_name) as progress:
4662
installer.run_install_tasks([task], progress)
4763

48-
threading.Thread(target=worker, args=[tasks[picked]]).start()
64+
task = tasks[picked]
65+
if task.action == installer.ENABLE:
66+
sublime.run_command("enable_packages", {"packages": [task.package_name]})
67+
else:
68+
threading.Thread(target=worker, args=[task]).start()
4969

5070
sublime.active_window().show_quick_panel(
5171
installer.render_quick_panel_items(tasks),

package_control/package_tasks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class PackageTaskRunner(PackageDisabler):
100100
Overwrite existing unmanaged packages.
101101
"""
102102

103+
ENABLE = 'enable'
104+
"""
105+
Enable existing managed packages.
106+
"""
107+
103108
PULL = 'pull'
104109
"""
105110
Upgrade unmanaged vcs packages.
@@ -638,7 +643,7 @@ def render_quick_panel_items(self, tasks):
638643

639644
for task in tasks:
640645
action = task.action
641-
if action == self.INSTALL or action == self.REINSTALL:
646+
if action in (self.INSTALL, self.REINSTALL, self.ENABLE):
642647
extra = ' v{}'.format(task.available_version)
643648
elif action == self.DOWNGRADE or action == self.UPGRADE:
644649
extra = ' to v{} from v{}'.format(task.available_version, task.package_version)
@@ -668,7 +673,7 @@ def render_quick_panel_items(self, tasks):
668673
annotation = ''
669674
if task.last_modified:
670675
try:
671-
# strip time as it is not of interrest and to be permissive with repos,
676+
# strip time as it is not of interest and to be permissive with repos,
672677
# which don't provide full timestamp.
673678
date, _ = task.last_modified.split(' ', 1)
674679
annotation = datetime.strptime(date, '%Y-%m-%d').strftime('Updated on %a %b %d, %Y')

0 commit comments

Comments
 (0)