Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: fangnx <naxin.fang@ericsson.com>
  • Loading branch information
fangnx committed Aug 15, 2019
1 parent 3be6caf commit 0980978
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
79 changes: 70 additions & 9 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { SelectionService } from '../common/selection-service';
import { MessageService } from '../common/message-service';
import { OpenerService, open } from '../browser/opener-service';
import { ApplicationShell } from './shell/application-shell';
import { SHELL_TABBAR_CONTEXT_MENU } from './shell/tab-bars';
import { ShellTabBarContextMenu } from './shell/tab-bars';
import { AboutDialog } from './about-dialog';
import * as browser from './browser';
import URI from '../common/uri';
Expand All @@ -37,6 +37,7 @@ import { StorageService } from './storage-service';
import { Navigatable } from './navigatable';
import { QuickViewService } from './quick-view-service';
import { PrefixQuickOpenService } from './quick-open';
import { addClipboardListener } from './widgets';

export namespace CommonMenus {

Expand Down Expand Up @@ -138,6 +139,16 @@ export namespace CommonCommands {
category: VIEW_CATEGORY,
label: 'Close All Tabs'
};
export const COPY_PATH: Command = {
id: 'core.copy.path',
category: VIEW_CATEGORY,
label: 'Copy Path'
};
export const COPY_RELATIVE_PATH: Command = {
id: 'core.copy.relative.path',
category: VIEW_CATEGORY,
label: 'Copy Relative Path'
};
export const COLLAPSE_PANEL: Command = {
id: 'core.collapse.tab',
category: VIEW_CATEGORY,
Expand Down Expand Up @@ -326,36 +337,47 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
order: '1'
});

registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.CLOSE, {
commandId: CommonCommands.CLOSE_TAB.id,
label: 'Close',
order: '0'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.CLOSE, {
commandId: CommonCommands.CLOSE_OTHER_TABS.id,
label: 'Close Others',
order: '1'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.CLOSE, {
commandId: CommonCommands.CLOSE_RIGHT_TABS.id,
label: 'Close to the Right',
order: '2'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.CLOSE, {
commandId: CommonCommands.CLOSE_ALL_TABS.id,
label: 'Close All',
order: '3'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.COPY, {
commandId: CommonCommands.COPY_PATH.id,
label: 'Copy Path',
order: '0'
});
registry.registerMenuAction(ShellTabBarContextMenu.COPY, {
commandId: CommonCommands.COPY_RELATIVE_PATH.id,
label: 'Copy Relative Path',
order: '1'
});
registry.registerMenuAction(ShellTabBarContextMenu.ACTIONS, {
commandId: CommonCommands.COLLAPSE_PANEL.id,
label: 'Collapse',
order: '4'
order: '0'
});
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.ACTIONS, {
commandId: CommonCommands.TOGGLE_MAXIMIZED.id,
label: 'Toggle Maximized',
order: '5'
order: '1'
});

registry.registerMenuAction(CommonMenus.HELP, {
commandId: CommonCommands.ABOUT_COMMAND.id,
label: 'About',
Expand Down Expand Up @@ -464,6 +486,28 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
}
}
});
commandRegistry.registerCommand(CommonCommands.COPY_PATH, {
execute: (event?: Event) => {
const tabBar = this.findTabBar(event);
if (tabBar) {
const currentTitle = this.findTitle(tabBar, event);
if (currentTitle) {
this.handleCopy(currentTitle.caption);
}
}
}
});
commandRegistry.registerCommand(CommonCommands.COPY_RELATIVE_PATH, {
execute: (event?: Event) => {
const tabBar = this.findTabBar(event);
if (tabBar) {
const currentTitle = this.findTitle(tabBar, event);
if (currentTitle) {
this.handleCopy(currentTitle.caption);
}
}
}
});
commandRegistry.registerCommand(CommonCommands.COLLAPSE_PANEL, {
isEnabled: (event?: Event) => ApplicationShell.isSideArea(this.findTabArea(event)),
isVisible: (event?: Event) => ApplicationShell.isSideArea(this.findTabArea(event)),
Expand Down Expand Up @@ -543,6 +587,23 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
return tabBar.currentTitle || undefined;
}

private handleCopy(text: string): void {
if (document.documentElement) {
const toDispose = addClipboardListener(document.documentElement, 'copy', event => {
toDispose.dispose();
this.addToClipboard(event, text);
});
document.execCommand('copy');
}
}

private addToClipboard(event: ClipboardEvent, text: string): void {
if (event.clipboardData && text) {
event.clipboardData.setData('text/plain', text);
event.preventDefault();
}
}

registerKeybindings(registry: KeybindingRegistry): void {
if (supportCut) {
registry.registerKeybinding({
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const HIDDEN_CONTENT_CLASS = 'theia-TabBar-hidden-content';
/** Menu path for tab bars used throughout the application shell. */
export const SHELL_TABBAR_CONTEXT_MENU: MenuPath = ['shell-tabbar-context-menu'];

export namespace ShellTabBarContextMenu {
export const CLOSE = [...SHELL_TABBAR_CONTEXT_MENU, '1_close'];
export const COPY = [...SHELL_TABBAR_CONTEXT_MENU, '2_copy'];
export const ACTIONS = [...SHELL_TABBAR_CONTEXT_MENU, '3_toggle'];
}

export const TabBarRendererFactory = Symbol('TabBarRendererFactory');

/**
Expand Down
7 changes: 3 additions & 4 deletions packages/navigator/src/browser/navigator-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import { injectable, inject, postConstruct } from 'inversify';
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import {
Navigatable, SelectableTreeNode, Widget, KeybindingRegistry, CommonCommands,
OpenerService, FrontendApplicationContribution, FrontendApplication, CompositeTreeNode
OpenerService, FrontendApplicationContribution, FrontendApplication, CompositeTreeNode, ShellTabBarContextMenu
} 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 { 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';
import { FileNavigatorPreferences } from './navigator-preferences';
Expand Down Expand Up @@ -200,10 +199,10 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi

registerMenus(registry: MenuModelRegistry): void {
super.registerMenus(registry);
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, {
registry.registerMenuAction(ShellTabBarContextMenu.ACTIONS, {
commandId: FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id,
label: FileNavigatorCommands.REVEAL_IN_NAVIGATOR.label,
order: '5'
order: '2'
});

registry.registerMenuAction(NavigatorContextMenu.NAVIGATION, {
Expand Down

0 comments on commit 0980978

Please sign in to comment.