Skip to content

Commit

Permalink
Implement 'more' toolbar item for the explorer
Browse files Browse the repository at this point in the history
Fixes #5951

- implement the 'more' toolbar item for the explorer which
triggers a context menu which displays helpful commands.
- mainly used to limit the impact of recent developments which
removes the root node from the tree and thus the ability to
perform actions directly on the root.

Signed-off-by: Vincent Fugnitto <[email protected]>
  • Loading branch information
vince-fugnitto committed Aug 15, 2019
1 parent e8a29ca commit a591970
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/navigator/src/browser/navigator-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
OpenerService, FrontendApplicationContribution, FrontendApplication, CompositeTreeNode
} from '@theia/core/lib/browser';
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
import { CommandRegistry, MenuModelRegistry, MenuPath, isOSX, Command, DisposableCollection } from '@theia/core/lib/common';
import { CommandRegistry, MenuModelRegistry, MenuPath, isOSX, Command, DisposableCollection, Mutable } from '@theia/core/lib/common';
import { SHELL_TABBAR_CONTEXT_MENU } from '@theia/core/lib/browser';
import { WorkspaceCommands, WorkspaceService, WorkspacePreferences } from '@theia/workspace/lib/browser';
import { FILE_NAVIGATOR_ID, FileNavigatorWidget, EXPLORER_VIEW_CONTAINER_ID } from './navigator-widget';
Expand All @@ -30,7 +30,7 @@ import { NavigatorKeybindingContexts } from './navigator-keybinding-context';
import { FileNavigatorFilter } from './navigator-filter';
import { WorkspaceNode } from './navigator-tree';
import { NavigatorContextKeyService } from './navigator-context-key-service';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { TabBarToolbarContribution, TabBarToolbarRegistry, TabBarToolbarItem } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
import { NavigatorDiff, NavigatorDiffCommands } from './navigator-diff';
import { UriSelection } from '@theia/core/lib/common/selection';
Expand Down Expand Up @@ -95,6 +95,9 @@ export namespace NavigatorContextMenu {
@injectable()
export class FileNavigatorContribution extends AbstractViewContribution<FileNavigatorWidget> implements FrontendApplicationContribution, TabBarToolbarContribution {

@inject(CommandRegistry)
protected readonly commandRegistry: CommandRegistry;

@inject(NavigatorContextKeyService)
protected readonly contextKeyService: NavigatorContextKeyService;

Expand Down Expand Up @@ -340,6 +343,41 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
tooltip: 'Collapse All',
priority: 1,
});

// Register 'more' toolbar item (consists of multiple commands)
const registerItem = (item: Mutable<TabBarToolbarItem>) => {
const commandId = item.command;
const id = '__git.tabbar.toolbar.' + commandId;
const command = this.commandRegistry.getCommand(commandId);
this.commandRegistry.registerCommand({ id, iconClass: command && command.iconClass }, {
execute: (widget, ...args) => widget instanceof FileNavigatorWidget
&& this.commandRegistry.executeCommand(commandId, ...args),
isEnabled: (widget, ...args) => widget instanceof FileNavigatorWidget
&& this.commandRegistry.isEnabled(commandId, ...args),
isVisible: (widget, ...args) => widget instanceof FileNavigatorWidget
&& this.commandRegistry.isVisible(commandId, ...args),
});
item.command = id;
toolbarRegistry.registerItem(item);
};
registerItem({
id: WorkspaceCommands.NEW_FILE.id,
command: WorkspaceCommands.NEW_FILE.id,
tooltip: WorkspaceCommands.NEW_FILE.label,
group: '1_new',
});
registerItem({
id: WorkspaceCommands.NEW_FOLDER.id,
command: WorkspaceCommands.NEW_FOLDER.id,
tooltip: WorkspaceCommands.NEW_FOLDER.label,
group: '1_new',
});
registerItem({
id: WorkspaceCommands.ADD_FOLDER.id,
command: WorkspaceCommands.ADD_FOLDER.id,
tooltip: WorkspaceCommands.ADD_FOLDER.label,
group: '2_add',
});
}

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ export class WorkspaceRootUriAwareCommandHandler extends UriAwareCommandHandler<
super(selectionService, handler);
}

isEnabled(): boolean {
return true;
}

isVisible(): boolean {
return true;
}

protected getUri(): URI | undefined {
const uri = super.getUri();
if (this.workspaceService.isMultiRootWorkspaceEnabled) {
Expand Down

0 comments on commit a591970

Please sign in to comment.