Skip to content

Commit

Permalink
Core: Do no expand the widgets on the side-bars for the context menu
Browse files Browse the repository at this point in the history
Before, right clicking on different menus would focus the menu item and open it, however this should not be the case. There was a dangling code in the handleContextMenu which causes this effect, as it was checking for the id when right clicked and looked up the ID for the menu-item and set the current title to the menu-item.
Issue ID: 4367

Signed-off-by: Muhammad Anas Shahid <muhammad.shahid@ericsson.com>
  • Loading branch information
Muhammad Anas Shahid committed Mar 10, 2020
1 parent 42b73d5 commit faf5af7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
25 changes: 21 additions & 4 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
}
});
commandRegistry.registerCommand(CommonCommands.TOGGLE_MAXIMIZED, {
isEnabled: () => this.shell.canToggleMaximized(),
isVisible: () => this.shell.canToggleMaximized(),
execute: () => this.shell.toggleMaximized()
isEnabled: (event?: Event) => this.canToggleMaximized(event),
isVisible: (event?: Event) => this.canToggleMaximized(event),
execute: (event?: Event) => this.toggleMaximized(event)
});

commandRegistry.registerCommand(CommonCommands.SAVE, {
Expand All @@ -628,6 +628,19 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
});
}

private canToggleMaximized(event?: Event): boolean {
const targetTabBar = this.findTabBar(event);
if (targetTabBar) {
return this.shell.canToggleMaximized({ targetTabBar });
}
return false;
}

private toggleMaximized(event?: Event): void {
const targetTabBar = this.findTabBar(event)!;
this.shell.toggleMaximized({ targetTabBar });
}

private findTabBar(event?: Event): TabBar<Widget> | undefined {
if (event && event.target) {
const tabBar = this.shell.findWidgetForElement(event.target as HTMLElement);
Expand All @@ -653,7 +666,11 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
tabNode = tabNode.parentElement;
}
if (tabNode && tabNode.title) {
const title = tabBar.titles.find(t => t.label === tabNode!.title);
let title = tabBar.titles.find(t => t.caption === tabNode!.title);
if (title) {
return title;
}
title = tabBar.titles.find(t => t.label === tabNode!.title);
if (title) {
return title;
}
Expand Down
44 changes: 38 additions & 6 deletions packages/core/src/browser/shell/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1618,15 +1618,47 @@ export class ApplicationShell extends Widget {
return [...this.tracker.widgets];
}

canToggleMaximized(): boolean {
const area = this.currentWidget && this.getAreaFor(this.currentWidget);
/**
* Determines if the target widget is located in an area which can be successfully maximized.
* - If `options` is provided, determine the area/location of the passed widget, else use the `currentWidget`.
* @param options: optional `targetTabBar` to be used when searching.
*
* @returns `true` if the widget is located in the `main` or `bottom` area, and `false` otherwise.
*/
canToggleMaximized(options?: { targetTabBar: TabBar<Widget> }): boolean {
let area: ApplicationShell.Area | undefined;
if (options) {
const { targetTabBar } = options;
area = this.getAreaFor(targetTabBar);
} else {
area = this.currentWidget && this.getAreaFor(this.currentWidget);
}
return area === 'main' || area === 'bottom';
}

toggleMaximized(): void {
const area = this.currentWidget && this.getAreaPanelFor(this.currentWidget);
if (area instanceof TheiaDockPanel && (area === this.mainPanel || area === this.bottomPanel)) {
area.toggleMaximized();
/**
* Maximizes the target widget in the target area/location. Otherwise, throw a warning.
* - If `options` is provided, determine the area/location of the passed widget, else use the `currentWidget`.
* @param options: optional `targetTabBar` to be used when searching.
*/
toggleMaximized(options?: { targetTabBar: TabBar<Widget> }): void {
let area: String | undefined;
if (options) {
const { targetTabBar } = options;
if (targetTabBar instanceof Widget && this.currentWidget) {
area = this.getAreaFor(targetTabBar ? targetTabBar : this.currentWidget);
}
}
if (!area && this.currentWidget) {
area = this.getAreaFor(this.currentWidget);
}

if (area === 'bottom') {
this.bottomPanel.toggleMaximized();
} else if (area === 'main') {
this.mainPanel.toggleMaximized();
} else {
console.warn('Could not find area for widget');
}
}

Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/browser/shell/tab-bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,6 @@ export class TabBarRenderer extends TabBar.Renderer {
if (this.contextMenuRenderer && this.contextMenuPath && event.currentTarget instanceof HTMLElement) {
event.stopPropagation();
event.preventDefault();

if (this.tabBar) {
const id = event.currentTarget.id;
// eslint-disable-next-line no-null/no-null
const title = this.tabBar.titles.find(t => this.createTabId(t) === id) || null;
this.tabBar.currentTitle = title;
this.tabBar.activate();
if (title) {
title.owner.activate();
}
}

this.contextMenuRenderer.render(this.contextMenuPath, event);
}
};
Expand Down

0 comments on commit faf5af7

Please sign in to comment.