Skip to content

Commit

Permalink
Implementation of TabsMain
Browse files Browse the repository at this point in the history
  • Loading branch information
jbicker committed Jan 18, 2023
1 parent 4456d4a commit d5c9423
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/main/browser/main-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { WebviewViewsMainImpl } from './webview-views/webview-views-main';
import { MonacoLanguages } from '@theia/monaco/lib/browser/monaco-languages';
import { UntitledResourceResolver } from '@theia/core/lib/common/resource';
import { ThemeService } from '@theia/core/lib/browser/theming';
import { TabsMainImp } from './tabs/tabs-main';

export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container): void {
const authenticationMain = new AuthenticationMainImpl(rpc, container);
Expand Down Expand Up @@ -180,4 +181,7 @@ export function setUpPluginApi(rpc: RPCProtocol, container: interfaces.Container

const commentsMain = new CommentsMainImp(rpc, container);
rpc.set(PLUGIN_RPC_CONTEXT.COMMENTS_MAIN, commentsMain);

const tabsMain = new TabsMainImp(rpc, container);
rpc.set(PLUGIN_RPC_CONTEXT.TABS_MAIN, tabsMain);
}
63 changes: 58 additions & 5 deletions packages/plugin-ext/src/main/browser/tabs/tabs-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,81 @@
// *****************************************************************************

import { interfaces } from '@theia/core/shared/inversify';

import { TabsMain } from '../../../common/plugin-api-rpc';
import { ApplicationShell, TabBar, Widget } from '@theia/core/lib/browser';
import { MAIN_RPC_CONTEXT, TabDto, TabGroupDto, TabsExt, TabsMain } from '../../../common/plugin-api-rpc';
import { RPCProtocol } from '../../../common/rpc-protocol';

export class TabsMainImp implements TabsMain {

private readonly proxy: TabsExt;
private tabGroupModel: TabGroupDto[] = [];
private tabBars: Map<number, TabBar<Widget>> = new Map();

private applicationShell: ApplicationShell;

constructor(
rpc: RPCProtocol,
container: interfaces.Container
) {}
) {
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.TABS_EXT);
this.applicationShell = container.get(ApplicationShell);
this.applicationShell.onDidChangeActiveWidget(() => this.createTabsModel());
this.createTabsModel();
}

private createTabsModel(): void {
const activeWidget = this.applicationShell.activeWidget;
this.tabGroupModel = this.applicationShell.mainAreaTabBars.map((tabBar: TabBar<Widget>, groupId: number) => {
let tabBarIsActive = false;
const tabs: TabDto[] = tabBar.titles.map((title, titleIndex) => {
const titleIsActive = title.owner === activeWidget;
if (titleIsActive) {
tabBarIsActive = true;
}
return {
id: title.owner.id,
input: '',
isActive: titleIsActive,
isDirty: false,
isPinned: false,
isPreview: false,
label: title.label
};
});
this.tabBars.set(groupId, tabBar);
const viewColumn = 1;
return {
groupId, tabs, isActive: tabBarIsActive, viewColumn
};
});
this.proxy.$acceptEditorTabModel(this.tabGroupModel);
}

// #region Messages received from Ext Host
$moveTab(tabId: string, index: number, viewColumn: number, preserveFocus?: boolean): void {
return;
}

async $closeTab(tabIds: string[], preserveFocus?: boolean): Promise<boolean> {
return false;
const widgets: Widget[] = [];
for (const tabId of tabIds) {
const widget = this.applicationShell.getWidgetById(tabId);
if (widget) {
widgets.push(widget);
}
}
await this.applicationShell.closeMany(widgets);
return true;
}

async $closeGroup(groupIds: number[], preserveFocus?: boolean): Promise<boolean> {
return false;
for (const groupId of groupIds) {
const tabBar = this.tabBars.get(groupId);
if (tabBar) {
await this.applicationShell.closeTabs(tabBar);
}
}
return true;
}
// #endregion
}

0 comments on commit d5c9423

Please sign in to comment.