deploy: current vibn theia state
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
||||
import { ScmAvatarService } from '@theia/scm/lib/browser/scm-avatar-service';
|
||||
import { GitCommitDetailWidgetOptions } from './git-commit-detail-widget-options';
|
||||
import { ReactWidget, KeybindingRegistry, codicon } from '@theia/core/lib/browser';
|
||||
import { Git } from '../../common';
|
||||
import * as React from '@theia/core/shared/react';
|
||||
|
||||
@injectable()
|
||||
export class GitCommitDetailHeaderWidget extends ReactWidget {
|
||||
|
||||
@inject(KeybindingRegistry) protected readonly keybindings: KeybindingRegistry;
|
||||
@inject(ScmAvatarService) protected readonly avatarService: ScmAvatarService;
|
||||
|
||||
protected options: Git.Options.Diff;
|
||||
|
||||
protected authorAvatar: string;
|
||||
|
||||
constructor(
|
||||
@inject(GitCommitDetailWidgetOptions) protected readonly commitDetailOptions: GitCommitDetailWidgetOptions
|
||||
) {
|
||||
super();
|
||||
this.id = 'commit-header' + commitDetailOptions.commitSha;
|
||||
this.title.label = commitDetailOptions.commitSha.substring(0, 8);
|
||||
this.options = {
|
||||
range: {
|
||||
fromRevision: commitDetailOptions.commitSha + '~1',
|
||||
toRevision: commitDetailOptions.commitSha
|
||||
}
|
||||
};
|
||||
this.title.closable = true;
|
||||
this.title.iconClass = codicon('git-commit');
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
protected init(): void {
|
||||
this.doInit();
|
||||
}
|
||||
|
||||
protected async doInit(): Promise<void> {
|
||||
this.authorAvatar = await this.avatarService.getAvatar(this.commitDetailOptions.authorEmail);
|
||||
}
|
||||
|
||||
protected render(): React.ReactNode {
|
||||
return React.createElement('div', this.createContainerAttributes(), this.renderDiffListHeader());
|
||||
}
|
||||
|
||||
protected createContainerAttributes(): React.HTMLAttributes<HTMLElement> {
|
||||
return {
|
||||
style: { flexGrow: 0 }
|
||||
};
|
||||
}
|
||||
|
||||
protected renderDiffListHeader(): React.ReactNode {
|
||||
const authorEMail = this.commitDetailOptions.authorEmail;
|
||||
const subject = <div className='subject'>{this.commitDetailOptions.commitMessage}</div>;
|
||||
const body = <div className='body'>{this.commitDetailOptions.messageBody || ''}</div>;
|
||||
const subjectRow = <div className='header-row'><div className='subjectContainer'>{subject}{body}</div></div>;
|
||||
const author = <div className='author header-value noWrapInfo'>{this.commitDetailOptions.authorName}</div>;
|
||||
const mail = <div className='mail header-value noWrapInfo'>{`<${authorEMail}>`}</div>;
|
||||
const authorRow = <div className='header-row noWrapInfo'><div className='theia-header'>author: </div>{author}</div>;
|
||||
const mailRow = <div className='header-row noWrapInfo'><div className='theia-header'>e-mail: </div>{mail}</div>;
|
||||
const authorDate = new Date(this.commitDetailOptions.authorDate);
|
||||
const dateStr = authorDate.toLocaleDateString('en', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour12: true,
|
||||
hour: 'numeric',
|
||||
minute: 'numeric'
|
||||
});
|
||||
const date = <div className='date header-value noWrapInfo'>{dateStr}</div>;
|
||||
const dateRow = <div className='header-row noWrapInfo'><div className='theia-header'>date: </div>{date}</div>;
|
||||
const revisionRow = <div className='header-row noWrapInfo'>
|
||||
<div className='theia-header'>revision: </div>
|
||||
<div className='header-value noWrapInfo'>{this.commitDetailOptions.commitSha}</div>
|
||||
</div>;
|
||||
const gravatar = <div className='image-container'>
|
||||
<img className='gravatar' src={this.authorAvatar}></img></div>;
|
||||
const commitInfo = <div className='header-row commit-info-row'>{gravatar}<div className='commit-info'>{authorRow}{mailRow}{dateRow}{revisionRow}</div></div>;
|
||||
|
||||
return <div className='diff-header'>{subjectRow}{commitInfo}</div>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
import { WidgetOpenHandler, WidgetOpenerOptions } from '@theia/core/lib/browser';
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
import { GitCommitDetailWidgetOptions } from './git-commit-detail-widget-options';
|
||||
import { GitCommitDetailWidget } from './git-commit-detail-widget';
|
||||
import { GitScmProvider } from '../git-scm-provider';
|
||||
|
||||
export namespace GitCommitDetailUri {
|
||||
export const scheme = GitScmProvider.GIT_COMMIT_DETAIL;
|
||||
export function toCommitSha(uri: URI): string {
|
||||
if (uri.scheme === scheme) {
|
||||
return uri.fragment;
|
||||
}
|
||||
throw new Error('The given uri is not an commit detail URI, uri: ' + uri);
|
||||
}
|
||||
}
|
||||
|
||||
export type GitCommitDetailOpenerOptions = WidgetOpenerOptions & GitCommitDetailWidgetOptions;
|
||||
|
||||
@injectable()
|
||||
export class GitCommitDetailOpenHandler extends WidgetOpenHandler<GitCommitDetailWidget> {
|
||||
readonly id = GitScmProvider.GIT_COMMIT_DETAIL;
|
||||
|
||||
canHandle(uri: URI): number {
|
||||
try {
|
||||
GitCommitDetailUri.toCommitSha(uri);
|
||||
return 200;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected createWidgetOptions(uri: URI, commit: GitCommitDetailOpenerOptions): GitCommitDetailWidgetOptions {
|
||||
return commit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2020 Arm 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
export const GitCommitDetailWidgetOptions = Symbol('GitCommitDetailWidgetOptions');
|
||||
export interface GitCommitDetailWidgetOptions {
|
||||
rootUri: string;
|
||||
commitSha: string;
|
||||
commitMessage: string;
|
||||
messageBody?: string;
|
||||
authorName: string;
|
||||
authorEmail: string;
|
||||
authorDate: string;
|
||||
authorDateRelative: string;
|
||||
}
|
||||
136
packages/git/src/browser/history/git-commit-detail-widget.tsx
Normal file
136
packages/git/src/browser/history/git-commit-detail-widget.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2020 Arm 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
import { Message } from '@theia/core/shared/@lumino/messaging';
|
||||
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
|
||||
import {
|
||||
BaseWidget, Widget, StatefulWidget, Panel, PanelLayout, MessageLoop, codicon
|
||||
} from '@theia/core/lib/browser';
|
||||
import { GitCommitDetailWidgetOptions } from './git-commit-detail-widget-options';
|
||||
import { GitCommitDetailHeaderWidget } from './git-commit-detail-header-widget';
|
||||
import { ScmService } from '@theia/scm/lib/browser/scm-service';
|
||||
import { GitDiffTreeModel } from '../diff/git-diff-tree-model';
|
||||
import { ScmTreeWidget } from '@theia/scm/lib/browser/scm-tree-widget';
|
||||
import { ScmPreferences } from '@theia/scm/lib/common/scm-preferences';
|
||||
|
||||
@injectable()
|
||||
export class GitCommitDetailWidget extends BaseWidget implements StatefulWidget {
|
||||
|
||||
protected panel: Panel;
|
||||
|
||||
@inject(ScmService) protected readonly scmService: ScmService;
|
||||
@inject(GitCommitDetailHeaderWidget) protected readonly commitDetailHeaderWidget: GitCommitDetailHeaderWidget;
|
||||
@inject(ScmTreeWidget) protected readonly resourceWidget: ScmTreeWidget;
|
||||
@inject(GitDiffTreeModel) protected readonly model: GitDiffTreeModel;
|
||||
@inject(ScmPreferences) protected readonly scmPreferences: ScmPreferences;
|
||||
|
||||
set viewMode(mode: 'tree' | 'list') {
|
||||
this.resourceWidget.viewMode = mode;
|
||||
}
|
||||
get viewMode(): 'tree' | 'list' {
|
||||
return this.resourceWidget.viewMode;
|
||||
}
|
||||
|
||||
constructor(
|
||||
@inject(GitCommitDetailWidgetOptions) protected readonly options: GitCommitDetailWidgetOptions
|
||||
) {
|
||||
super();
|
||||
this.id = 'commit' + options.commitSha;
|
||||
this.title.label = options.commitSha.substring(0, 8);
|
||||
this.title.closable = true;
|
||||
this.title.iconClass = codicon('git-commit');
|
||||
|
||||
this.addClass('theia-scm');
|
||||
this.addClass('theia-git');
|
||||
this.addClass('git-diff-container');
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
protected init(): void {
|
||||
const layout = new PanelLayout();
|
||||
this.layout = layout;
|
||||
this.panel = new Panel({
|
||||
layout: new PanelLayout({
|
||||
})
|
||||
});
|
||||
this.panel.node.tabIndex = -1;
|
||||
this.panel.node.setAttribute('class', 'theia-scm-panel');
|
||||
layout.addWidget(this.panel);
|
||||
|
||||
this.containerLayout.addWidget(this.commitDetailHeaderWidget);
|
||||
this.containerLayout.addWidget(this.resourceWidget);
|
||||
|
||||
this.updateViewMode(this.scmPreferences.get('scm.defaultViewMode'));
|
||||
this.toDispose.push(this.scmPreferences.onPreferenceChanged(e => {
|
||||
if (e.preferenceName === 'scm.defaultViewMode') {
|
||||
this.updateViewMode(this.scmPreferences.get('scm.defaultViewMode'));
|
||||
}
|
||||
}));
|
||||
|
||||
const diffOptions = {
|
||||
range: {
|
||||
fromRevision: this.options.commitSha + '~1',
|
||||
toRevision: this.options.commitSha
|
||||
}
|
||||
};
|
||||
this.model.setContent({ rootUri: this.options.rootUri, diffOptions });
|
||||
}
|
||||
|
||||
get containerLayout(): PanelLayout {
|
||||
return this.panel.layout as PanelLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the view mode based on the preference value.
|
||||
* @param preference the view mode preference.
|
||||
*/
|
||||
protected updateViewMode(preference: 'tree' | 'list'): void {
|
||||
this.viewMode = preference;
|
||||
}
|
||||
|
||||
protected updateImmediately(): void {
|
||||
this.onUpdateRequest(Widget.Msg.UpdateRequest);
|
||||
}
|
||||
|
||||
protected override onUpdateRequest(msg: Message): void {
|
||||
MessageLoop.sendMessage(this.commitDetailHeaderWidget, msg);
|
||||
MessageLoop.sendMessage(this.resourceWidget, msg);
|
||||
super.onUpdateRequest(msg);
|
||||
}
|
||||
|
||||
protected override onAfterAttach(msg: Message): void {
|
||||
this.node.appendChild(this.commitDetailHeaderWidget.node);
|
||||
this.node.appendChild(this.resourceWidget.node);
|
||||
|
||||
super.onAfterAttach(msg);
|
||||
this.update();
|
||||
}
|
||||
|
||||
storeState(): any {
|
||||
const state: object = {
|
||||
changesTreeState: this.resourceWidget.storeState(),
|
||||
};
|
||||
return state;
|
||||
}
|
||||
|
||||
restoreState(oldState: any): void {
|
||||
const { changesTreeState } = oldState;
|
||||
this.resourceWidget.restoreState(changesTreeState);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2018 TypeFox 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
import { interfaces, Container } from '@theia/core/shared/inversify';
|
||||
import { WidgetFactory, OpenHandler, TreeModel } from '@theia/core/lib/browser';
|
||||
import { GitCommitDetailWidgetOptions } from './git-commit-detail-widget-options';
|
||||
import { GitCommitDetailWidget } from './git-commit-detail-widget';
|
||||
import { GitCommitDetailHeaderWidget } from './git-commit-detail-header-widget';
|
||||
import { GitDiffTreeModel } from '../diff/git-diff-tree-model';
|
||||
import { GitCommitDetailOpenHandler } from './git-commit-detail-open-handler';
|
||||
import { GitScmProvider } from '../git-scm-provider';
|
||||
import { createScmTreeContainer } from '@theia/scm/lib/browser/scm-frontend-module';
|
||||
import { GitResourceOpener } from '../diff/git-resource-opener';
|
||||
import { GitOpenerInSecondaryArea } from './git-opener-in-secondary-area';
|
||||
import '../../../src/browser/style/git-icons.css';
|
||||
|
||||
export function bindGitHistoryModule(bind: interfaces.Bind): void {
|
||||
|
||||
bind(WidgetFactory).toDynamicValue(ctx => ({
|
||||
id: GitScmProvider.GIT_COMMIT_DETAIL,
|
||||
createWidget: (options: GitCommitDetailWidgetOptions) => {
|
||||
const child = createGitCommitDetailWidgetContainer(ctx.container, options);
|
||||
return child.get(GitCommitDetailWidget);
|
||||
}
|
||||
}));
|
||||
|
||||
bind(GitCommitDetailOpenHandler).toSelf();
|
||||
bind(OpenHandler).toService(GitCommitDetailOpenHandler);
|
||||
|
||||
}
|
||||
|
||||
export function createGitCommitDetailWidgetContainer(parent: interfaces.Container, options: GitCommitDetailWidgetOptions): Container {
|
||||
const child = createScmTreeContainer(parent);
|
||||
child.bind(GitCommitDetailWidget).toSelf();
|
||||
child.bind(GitCommitDetailHeaderWidget).toSelf();
|
||||
child.bind(GitDiffTreeModel).toSelf();
|
||||
child.bind(TreeModel).toService(GitDiffTreeModel);
|
||||
child.bind(GitOpenerInSecondaryArea).toSelf();
|
||||
child.bind(GitResourceOpener).toService(GitOpenerInSecondaryArea);
|
||||
child.bind(GitCommitDetailWidgetOptions).toConstantValue(options);
|
||||
|
||||
const opener = child.get(GitOpenerInSecondaryArea);
|
||||
const widget = child.get(GitCommitDetailWidget);
|
||||
opener.setRefWidget(widget);
|
||||
|
||||
return child;
|
||||
}
|
||||
82
packages/git/src/browser/history/git-history-support.ts
Normal file
82
packages/git/src/browser/history/git-history-support.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2019 Arm 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||
import { Emitter, Disposable } from '@theia/core';
|
||||
import { Git } from '../../common';
|
||||
import { ScmHistorySupport, HistoryWidgetOptions } from '@theia/scm-extra/lib/browser/history/scm-history-widget';
|
||||
import { ScmHistoryCommit } from '@theia/scm-extra/lib/browser/scm-file-change-node';
|
||||
import { GitScmProvider } from '../git-scm-provider';
|
||||
import { GitRepositoryTracker } from '../git-repository-tracker';
|
||||
|
||||
@injectable()
|
||||
export class GitHistorySupport implements ScmHistorySupport {
|
||||
|
||||
@inject(GitScmProvider) protected readonly provider: GitScmProvider;
|
||||
@inject(Git) protected readonly git: Git;
|
||||
@inject(GitRepositoryTracker) protected readonly repositoryTracker: GitRepositoryTracker;
|
||||
|
||||
async getCommitHistory(options?: HistoryWidgetOptions): Promise<ScmHistoryCommit[]> {
|
||||
const repository = this.provider.repository;
|
||||
const gitOptions: Git.Options.Log = {
|
||||
uri: options ? options.uri : undefined,
|
||||
maxCount: options ? options.maxCount : undefined,
|
||||
range: options?.range,
|
||||
shortSha: true
|
||||
};
|
||||
|
||||
const commits = await this.git.log(repository, gitOptions);
|
||||
if (commits.length > 0) {
|
||||
return commits.map(commit => this.provider.createScmHistoryCommit(commit));
|
||||
} else {
|
||||
const pathIsUnderVersionControl = !options || !options.uri || await this.git.lsFiles(repository, options.uri, { errorUnmatch: true });
|
||||
if (!pathIsUnderVersionControl) {
|
||||
throw new Error('It is not under version control.');
|
||||
} else {
|
||||
throw new Error('No commits have been committed.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected readonly onDidChangeHistoryEmitter = new Emitter<void>({
|
||||
onFirstListenerAdd: () => this.onFirstListenerAdd(),
|
||||
onLastListenerRemove: () => this.onLastListenerRemove()
|
||||
});
|
||||
readonly onDidChangeHistory = this.onDidChangeHistoryEmitter.event;
|
||||
|
||||
protected onGitEventDisposable: Disposable | undefined;
|
||||
protected onFirstListenerAdd(): void {
|
||||
this.onGitEventDisposable = this.repositoryTracker.onGitEvent(event => {
|
||||
const { status, oldStatus } = event || { status: undefined, oldStatus: undefined };
|
||||
let isBranchChanged = false;
|
||||
let isHeaderChanged = false;
|
||||
if (oldStatus) {
|
||||
isBranchChanged = !!status && status.branch !== oldStatus.branch;
|
||||
isHeaderChanged = !!status && status.currentHead !== oldStatus.currentHead;
|
||||
}
|
||||
if (isBranchChanged || isHeaderChanged || oldStatus === undefined) {
|
||||
this.onDidChangeHistoryEmitter.fire(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected onLastListenerRemove(): void {
|
||||
if (this.onGitEventDisposable) {
|
||||
this.onGitEventDisposable.dispose();
|
||||
this.onGitEventDisposable = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// *****************************************************************************
|
||||
// Copyright (C) 2020 Arm 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-only WITH Classpath-exception-2.0
|
||||
// *****************************************************************************
|
||||
|
||||
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||
import { Widget } from '@theia/core/shared/@lumino/widgets';
|
||||
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
|
||||
import { GitResourceOpener } from '../diff/git-resource-opener';
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
|
||||
@injectable()
|
||||
export class GitOpenerInSecondaryArea implements GitResourceOpener {
|
||||
@inject(EditorManager) protected readonly editorManager: EditorManager;
|
||||
|
||||
protected refWidget: Widget;
|
||||
setRefWidget(refWidget: Widget): void {
|
||||
this.refWidget = refWidget;
|
||||
}
|
||||
|
||||
protected ref: Widget | undefined;
|
||||
async open(changeUri: URI): Promise<void> {
|
||||
const ref = this.ref;
|
||||
const widget = await this.editorManager.open(changeUri, {
|
||||
mode: 'reveal',
|
||||
widgetOptions: ref ?
|
||||
{ area: 'main', mode: 'tab-after', ref } :
|
||||
{ area: 'main', mode: 'split-right', ref: this.refWidget }
|
||||
});
|
||||
this.ref = widget instanceof Widget ? widget : undefined;
|
||||
if (this.ref) {
|
||||
this.ref.disposed.connect(() => {
|
||||
if (this.ref === widget) {
|
||||
this.ref = undefined;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user