Skip to content

Commit

Permalink
[navigator] Added command and toolbar menu item to disable auto sync
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Efftinge <sven.efftinge@typefox.io>
  • Loading branch information
svenefftinge committed Aug 31, 2019
1 parent 85b7576 commit 41ef406
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/browser/shell/tab-bar-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class TabBarToolbar extends ReactWidget {
}
}
const command = this.commands.getCommand(item.command);
const iconClass = item.icon || (command && command.iconClass);
const iconClass = (typeof item.icon === 'function' && item.icon()) || item.icon || (command && command.iconClass);
if (iconClass) {
classNames.push(iconClass);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ export interface TabBarToolbarItem {
/**
* Optional icon for the item.
*/
readonly icon?: string;
readonly icon?: string | (() => string);

/**
* https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/browser/style/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@
cursor: pointer;
}

.p-TabBar-toolbar .item .inActiveToggle {
color: var(--theia-ui-font-color3);
}

.p-TabBar-toolbar .item > div {
height: 18px;
width: 18px;
Expand Down
32 changes: 29 additions & 3 deletions packages/navigator/src/browser/navigator-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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, PreferenceScope
} from '@theia/core/lib/browser';
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
import { CommandRegistry, MenuModelRegistry, MenuPath, isOSX, Command, DisposableCollection, Mutable } from '@theia/core/lib/common';
Expand All @@ -34,6 +34,7 @@ import { TabBarToolbarContribution, TabBarToolbarRegistry, TabBarToolbarItem } f
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
import { NavigatorDiff, NavigatorDiffCommands } from './navigator-diff';
import { UriSelection } from '@theia/core/lib/common/selection';
import { PreferenceService } from '@theia/core/lib/browser';

export namespace FileNavigatorCommands {
export const REVEAL_IN_NAVIGATOR: Command = {
Expand All @@ -44,6 +45,11 @@ export namespace FileNavigatorCommands {
id: 'navigator.toggle.hidden.files',
label: 'Toggle Hidden Files'
};
export const TOGGLE_AUTO_REVEAL: Command = {
id: 'navigator.toggle.autoReveal',
category: 'File',
label: 'Auto Reveal'
};
export const REFRESH_NAVIGATOR: Command = {
id: 'navigator.refresh',
category: 'File',
Expand All @@ -67,7 +73,8 @@ export namespace FileNavigatorCommands {
*/
export namespace NavigatorMoreToolbarGroups {
export const NEW_OPEN = '1_navigator_new_open';
export const WORKSPACE = '2_navigator_workspace';
export const TOOLS = '2_navigator_tools';
export const WORKSPACE = '3_navigator_workspace';
}

export const NAVIGATOR_CONTEXT_MENU: MenuPath = ['navigator-context-menu'];
Expand Down Expand Up @@ -119,6 +126,9 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
@inject(NavigatorDiff)
protected readonly navigatorDiff: NavigatorDiff;

@inject(PreferenceService)
protected readonly preferenceService: PreferenceService;

constructor(
@inject(FileNavigatorPreferences) protected readonly fileNavigatorPreferences: FileNavigatorPreferences,
@inject(OpenerService) protected readonly openerService: OpenerService,
Expand Down Expand Up @@ -177,6 +187,16 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
isEnabled: () => true,
isVisible: () => true
});
registry.registerCommand(FileNavigatorCommands.TOGGLE_AUTO_REVEAL, {
execute: () => {
const autoReveal = !this.fileNavigatorPreferences['explorer.autoReveal'];
this.preferenceService.set('explorer.autoReveal', autoReveal, PreferenceScope.User);
if (autoReveal) {
this.selectWidgetFileNode(this.shell.currentWidget);
}
},
isToggled: () => this.fileNavigatorPreferences['explorer.autoReveal']
});
registry.registerCommand(FileNavigatorCommands.COLLAPSE_ALL, {
execute: widget => this.withWidget(widget, () => this.collapseFileNavigatorTree()),
isEnabled: widget => this.withWidget(widget, () => this.workspaceService.opened),
Expand Down Expand Up @@ -367,6 +387,12 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
tooltip: WorkspaceCommands.NEW_FOLDER.label,
group: NavigatorMoreToolbarGroups.NEW_OPEN,
});
this.registerMoreToolbarItem({
id: FileNavigatorCommands.TOGGLE_AUTO_REVEAL.id,
command: FileNavigatorCommands.TOGGLE_AUTO_REVEAL.id,
tooltip: FileNavigatorCommands.TOGGLE_AUTO_REVEAL.label,
group: NavigatorMoreToolbarGroups.TOOLS,
});
this.registerMoreToolbarItem({
id: WorkspaceCommands.ADD_FOLDER.id,
command: WorkspaceCommands.ADD_FOLDER.id,
Expand Down Expand Up @@ -416,7 +442,7 @@ export class FileNavigatorContribution extends AbstractViewContribution<FileNavi
}

protected onCurrentWidgetChangedHandler(): void {
if (this.fileNavigatorPreferences['navigator.autoReveal']) {
if (this.fileNavigatorPreferences['explorer.autoReveal']) {
this.selectWidgetFileNode(this.shell.currentWidget);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/navigator/src/browser/navigator-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceCo
export const FileNavigatorConfigSchema: PreferenceSchema = {
'type': 'object',
properties: {
'navigator.autoReveal': {
'explorer.autoReveal': {
type: 'boolean',
description: 'Selects file under editing in the navigator.',
description: 'Selects file under editing in the explorer.',
default: true
}
}
};

export interface FileNavigatorConfiguration {
'navigator.autoReveal': boolean;
'explorer.autoReveal': boolean;
}

export const FileNavigatorPreferences = Symbol('NavigatorPreferences');
Expand Down

0 comments on commit 41ef406

Please sign in to comment.