-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Editor Preview as extensions of Editor classes
Signed-off-by: Colin Grant <[email protected]>
- Loading branch information
1 parent
d0aadd6
commit e8e88b7
Showing
21 changed files
with
364 additions
and
666 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/editor-preview/src/browser/editor-preview-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ApplicationShell, KeybindingContribution, KeybindingRegistry, SHELL_TABBAR_CONTEXT_MENU, Widget } from '@theia/core/lib/browser'; | ||
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common'; | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { EditorPreviewWidget } from './editor-preview-widget'; | ||
|
||
export namespace EditorPreviewCommands { | ||
export const PIN_PREVIEW_COMMAND: Command = { | ||
id: 'workbench.action.keepEditor', | ||
category: 'View', | ||
label: 'Keep Editor', | ||
}; | ||
} | ||
|
||
@injectable() | ||
export class EditorPreviewContribution implements CommandContribution, MenuContribution, KeybindingContribution { | ||
@inject(ApplicationShell) protected readonly shell: ApplicationShell; | ||
|
||
registerCommands(registry: CommandRegistry): void { | ||
registry.registerCommand(EditorPreviewCommands.PIN_PREVIEW_COMMAND, { | ||
execute: async (event?: Event) => { | ||
const widget = this.getTargetWidget(event); | ||
if (widget instanceof EditorPreviewWidget) { | ||
widget.convertToNonPreview(); | ||
await this.shell.activateWidget(widget.id); | ||
} | ||
}, | ||
isEnabled: (event?: Event) => { | ||
const widget = this.getTargetWidget(event); | ||
return widget instanceof EditorPreviewWidget && widget.isPreview; | ||
}, | ||
isVisible: (event?: Event) => { | ||
const widget = this.getTargetWidget(event); | ||
return widget instanceof EditorPreviewWidget; | ||
} | ||
}); | ||
} | ||
|
||
registerKeybindings(registry: KeybindingRegistry): void { | ||
registry.registerKeybinding({ | ||
command: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id, | ||
keybinding: 'ctrlcmd+k enter' | ||
}); | ||
} | ||
|
||
registerMenus(registry: MenuModelRegistry): void { | ||
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_MENU, { | ||
commandId: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id, | ||
label: 'Keep Open', | ||
order: '6', | ||
}); | ||
} | ||
|
||
protected getTargetWidget(event?: Event): Widget | undefined { | ||
return event ? this.shell.findTargetedWidget(event) : this.shell.activeWidget; | ||
} | ||
} |
91 changes: 0 additions & 91 deletions
91
packages/editor-preview/src/browser/editor-preview-factory.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.