未验证 提交 5e5f6fc6 编写于 作者: R Ramya Rao 提交者: GitHub

Show recommended with popular when no extensions installed (#56186)

* Show recommended with popular when no extensions installed

* Ensure empty value results in popular extensions
上级 d4430204
......@@ -29,7 +29,7 @@ import {
} from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
import { LocalExtensionType, IExtensionManagementService, IExtensionManagementServerService, IExtensionManagementServer } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionsInput } from 'vs/workbench/parts/extensions/common/extensionsInput';
import { ExtensionsListView, InstalledExtensionsView, EnabledExtensionsView, DisabledExtensionsView, RecommendedExtensionsView, WorkspaceRecommendedExtensionsView, BuiltInExtensionsView, BuiltInThemesExtensionsView, BuiltInBasicsExtensionsView, GroupByServerExtensionsView, DefaultRecommendedExtensionsView } from './extensionsViews';
import { ExtensionsListView, EnabledExtensionsView, DisabledExtensionsView, RecommendedExtensionsView, WorkspaceRecommendedExtensionsView, BuiltInExtensionsView, BuiltInThemesExtensionsView, BuiltInBasicsExtensionsView, GroupByServerExtensionsView, DefaultRecommendedExtensionsView } from './extensionsViews';
import { OpenGlobalSettingsAction } from 'vs/workbench/parts/preferences/browser/preferencesActions';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService';
......@@ -64,7 +64,7 @@ interface SearchInputEvent extends Event {
const NonEmptyWorkspaceContext = new RawContextKey<boolean>('nonEmptyWorkspace', false);
const SearchExtensionsContext = new RawContextKey<boolean>('searchExtensions', false);
const SearchInstalledExtensionsContext = new RawContextKey<boolean>('searchInstalledExtensions', false);
const HasInstalledExtensionsContext = new RawContextKey<boolean>('hasInstalledExtensions', true);
const SearchBuiltInExtensionsContext = new RawContextKey<boolean>('searchBuiltInExtensions', false);
const RecommendedExtensionsContext = new RawContextKey<boolean>('recommendedExtensions', false);
const DefaultRecommendedExtensionsContext = new RawContextKey<boolean>('defaultRecommendedExtensions', false);
......@@ -83,7 +83,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
viewDescriptors.push(this.createMarketPlaceExtensionsListViewDescriptor());
viewDescriptors.push(this.createEnabledExtensionsListViewDescriptor());
viewDescriptors.push(this.createDisabledExtensionsListViewDescriptor());
viewDescriptors.push(this.createSearchInstalledExtensionsListViewDescriptor());
viewDescriptors.push(this.createPopularExtensionsListViewDescriptor());
viewDescriptors.push(this.createBuiltInExtensionsListViewDescriptor());
viewDescriptors.push(this.createBuiltInBasicsExtensionsListViewDescriptor());
viewDescriptors.push(this.createBuiltInThemesExtensionsListViewDescriptor());
......@@ -117,7 +117,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
name: localize('enabledExtensions', "Enabled"),
container: VIEW_CONTAINER,
ctor: EnabledExtensionsView,
when: ContextKeyExpr.not('searchExtensions'),
when: ContextKeyExpr.and(ContextKeyExpr.not('searchExtensions'), ContextKeyExpr.has('hasInstalledExtensions')),
weight: 40,
canToggleVisibility: true,
order: 1
......@@ -130,7 +130,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
name: localize('disabledExtensions', "Disabled"),
container: VIEW_CONTAINER,
ctor: DisabledExtensionsView,
when: ContextKeyExpr.not('searchExtensions'),
when: ContextKeyExpr.and(ContextKeyExpr.not('searchExtensions'), ContextKeyExpr.has('hasInstalledExtensions')),
weight: 10,
canToggleVisibility: true,
order: 3,
......@@ -138,14 +138,15 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
};
}
private createSearchInstalledExtensionsListViewDescriptor(): IViewDescriptor {
private createPopularExtensionsListViewDescriptor(): IViewDescriptor {
return {
id: 'extensions.searchInstalledList',
name: localize('searchInstalledExtensions', "Installed"),
id: 'extensions.popularExtensionsList',
name: localize('popularExtensions', "Popular"),
container: VIEW_CONTAINER,
ctor: InstalledExtensionsView,
when: ContextKeyExpr.and(ContextKeyExpr.has('searchInstalledExtensions'), ContextKeyExpr.not('groupByServersContext')),
weight: 100
ctor: ExtensionsListView,
when: ContextKeyExpr.and(ContextKeyExpr.not('searchExtensions'), ContextKeyExpr.not('hasInstalledExtensions')),
weight: 60,
order: 1
};
}
......@@ -167,7 +168,7 @@ export class ExtensionsViewletViewsContribution implements IWorkbenchContributio
container: VIEW_CONTAINER,
ctor: DefaultRecommendedExtensionsView,
when: ContextKeyExpr.and(ContextKeyExpr.not('searchExtensions'), ContextKeyExpr.has('defaultRecommendedExtensions')),
weight: 60,
weight: 40,
order: 2,
canToggleVisibility: true
};
......@@ -241,7 +242,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
private onSearchChange: EventOf<string>;
private nonEmptyWorkspaceContextKey: IContextKey<boolean>;
private searchExtensionsContextKey: IContextKey<boolean>;
private searchInstalledExtensionsContextKey: IContextKey<boolean>;
private hasInstalledExtensionsContextKey: IContextKey<boolean>;
private searchBuiltInExtensionsContextKey: IContextKey<boolean>;
private groupByServersContextKey: IContextKey<boolean>;
private recommendedExtensionsContextKey: IContextKey<boolean>;
......@@ -280,7 +281,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
this.searchDelayer = new ThrottledDelayer(500);
this.nonEmptyWorkspaceContextKey = NonEmptyWorkspaceContext.bindTo(contextKeyService);
this.searchExtensionsContextKey = SearchExtensionsContext.bindTo(contextKeyService);
this.searchInstalledExtensionsContextKey = SearchInstalledExtensionsContext.bindTo(contextKeyService);
this.hasInstalledExtensionsContextKey = HasInstalledExtensionsContext.bindTo(contextKeyService);
this.searchBuiltInExtensionsContextKey = SearchBuiltInExtensionsContext.bindTo(contextKeyService);
this.recommendedExtensionsContextKey = RecommendedExtensionsContext.bindTo(contextKeyService);
this.groupByServersContextKey = GroupByServersContext.bindTo(contextKeyService);
......@@ -288,6 +289,10 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
this.defaultRecommendedExtensionsContextKey.set(!this.configurationService.getValue<boolean>(ShowRecommendationsOnlyOnDemandKey));
this.disposables.push(this.viewletService.onDidViewletOpen(this.onViewletOpen, this, this.disposables));
this.extensionManagementService.getInstalled(LocalExtensionType.User).then(result => {
this.hasInstalledExtensionsContextKey.set(result.length > 0);
});
this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(AutoUpdateConfigurationKey)) {
this.secondaryActions = null;
......@@ -330,14 +335,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
this.searchBox.onShouldFocusResults(() => this.focusListView(), this, this.disposables);
this.extensionsBox = append(this.root, $('.extensions'));
return super.create(this.extensionsBox)
.then(() => this.extensionManagementService.getInstalled(LocalExtensionType.User))
.then(installed => {
if (installed.length === 0) {
this.searchBox.setValue('@sort:installs');
this.searchExtensionsContextKey.set(true);
}
});
return super.create(this.extensionsBox);
}
public updateStyles(): void {
......@@ -385,7 +383,7 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
if (!this.groupByServerAction) {
this.groupByServerAction = this.instantiationService.createInstance(ChangeGroupAction, 'extensions.group.servers', localize('group by servers', "Group By: Server"), this.onSearchChange, 'server');
this.disposables.push(this.onSearchChange(value => {
this.groupByServerAction.enabled = !value || InstalledExtensionsView.isInstalledExtensionsQuery(value) || ExtensionsListView.isBuiltInExtensionsQuery(value);
this.groupByServerAction.enabled = !value || ExtensionsListView.isInstalledExtensionsQuery(value) || ExtensionsListView.isBuiltInExtensionsQuery(value);
}));
}
this.secondaryActions = [
......@@ -432,7 +430,6 @@ export class ExtensionsViewlet extends ViewContainerViewlet implements IExtensio
private doSearch(): TPromise<any> {
const value = this.normalizedQuery();
this.searchExtensionsContextKey.set(!!value);
this.searchInstalledExtensionsContextKey.set(InstalledExtensionsView.isInstalledExtensionsQuery(value));
this.searchBuiltInExtensionsContextKey.set(ExtensionsListView.isBuiltInExtensionsQuery(value));
this.groupByServersContextKey.set(ExtensionsListView.isGroupByServersExtensionsQuery(value));
this.recommendedExtensionsContextKey.set(ExtensionsListView.isRecommendedExtensionsQuery(value));
......
......@@ -165,6 +165,9 @@ export class ExtensionsListView extends ViewletPanel {
case 'rating': options = assign(options, { sortBy: SortBy.WeightedRating }); break;
case 'name': options = assign(options, { sortBy: SortBy.Title }); break;
}
if (!value || !value.trim()) {
options.sortBy = SortBy.InstallCount;
}
if (/@builtin/i.test(value)) {
const showThemesOnly = /@builtin:themes/i.test(value);
......@@ -218,9 +221,9 @@ export class ExtensionsListView extends ViewletPanel {
return new PagedModel(this.sortExtensions(result, options));
}
if (!value || ExtensionsListView.isInstalledExtensionsQuery(value)) {
if (/@installed/i.test(value)) {
// Show installed extensions
value = value ? value.replace(/@installed/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase() : '';
value = value.replace(/@installed/g, '').replace(/@sort:(\w+)(-\w*)?/g, '').trim().toLowerCase();
let result = await this.extensionsWorkbenchService.queryLocal();
......@@ -623,25 +626,13 @@ export class ExtensionsListView extends ViewletPanel {
}
static isInstalledExtensionsQuery(query: string): boolean {
return /@installed/i.test(query);
return /@installed|@outdated|@enabled|@disabled/i.test(query);
}
static isGroupByServersExtensionsQuery(query: string): boolean {
return !!Query.parse(query).groupBy;
}
static isOutdatedExtensionsQuery(query: string): boolean {
return /@outdated/i.test(query);
}
static isDisabledExtensionsQuery(query: string): boolean {
return /@disabled/i.test(query);
}
static isEnabledExtensionsQuery(query: string): boolean {
return /@enabled/i.test(query);
}
static isRecommendedExtensionsQuery(query: string): boolean {
return /^@recommended$/i.test(query.trim());
}
......@@ -667,31 +658,12 @@ export class ExtensionsListView extends ViewletPanel {
}
}
export class InstalledExtensionsView extends ExtensionsListView {
public static isInstalledExtensionsQuery(query: string): boolean {
return ExtensionsListView.isInstalledExtensionsQuery(query)
|| ExtensionsListView.isOutdatedExtensionsQuery(query)
|| ExtensionsListView.isDisabledExtensionsQuery(query)
|| ExtensionsListView.isEnabledExtensionsQuery(query);
}
async show(query: string): Promise<IPagedModel<IExtension>> {
if (InstalledExtensionsView.isInstalledExtensionsQuery(query)) {
return super.show(query);
}
let searchInstalledQuery = '@installed';
searchInstalledQuery = query ? searchInstalledQuery + ' ' + query : searchInstalledQuery;
return super.show(searchInstalledQuery);
}
}
export class GroupByServerExtensionsView extends ExtensionsListView {
async show(query: string): Promise<IPagedModel<IExtension>> {
query = query.replace(/@group:server/g, '').trim();
query = query ? query : '@installed';
if (!InstalledExtensionsView.isInstalledExtensionsQuery(query) && !ExtensionsListView.isBuiltInExtensionsQuery(query)) {
if (!ExtensionsListView.isInstalledExtensionsQuery(query) && !ExtensionsListView.isBuiltInExtensionsQuery(query)) {
query = query += ' @installed';
}
return super.show(query.trim());
......@@ -744,7 +716,15 @@ export class DefaultRecommendedExtensionsView extends ExtensionsListView {
}
async show(query: string): Promise<IPagedModel<IExtension>> {
return (query && query.trim() !== this.recommendedExtensionsQuery) ? this.showEmptyModel() : super.show(this.recommendedExtensionsQuery);
if (query && query.trim() !== this.recommendedExtensionsQuery) {
return this.showEmptyModel();
}
const model = await super.show(this.recommendedExtensionsQuery);
if (!this.extensionsWorkbenchService.local.some(e => e.type === LocalExtensionType.User)) {
// This is part of popular extensions view. Collapse if no installed extensions.
this.setExpanded(model.length > 0);
}
return model;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册