Skip to content

Commit

Permalink
fix: sync menuBar mode status (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiwong authored Jan 20, 2022
1 parent f355c88 commit ecdb312
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/controller/menuBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export class MenuBarController
this.automation[key] = value;
}
});

this.subscribe(MenuBarEvent.onChangeMode, this.updateMenuBarData);
}

public updateFocusinEle = (ele: HTMLElement | null) => {
Expand Down Expand Up @@ -209,6 +211,9 @@ export class MenuBarController

public updateMenuBarMode = (mode: keyof typeof MenuBarMode) => {
this.layoutService.setMenuBarMode(mode);
};

public updateMenuBarData = (mode: keyof typeof MenuBarMode) => {
const { builtInMenuBarData } = this.builtinService.getModules();
const menuBarData = this.getMenuBarDataByMode(mode, builtInMenuBarData);
this.menuBarService.setMenus(menuBarData);
Expand Down
1 change: 1 addition & 0 deletions src/model/workbench/menuBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum MenuBarEvent {
* Selected an activity bar
*/
onSelect = 'menuBar.onSelect',
onChangeMode = 'menuBar.onChangeMode',
}

export interface IMenuBarItem {
Expand Down
2 changes: 2 additions & 0 deletions src/services/workbench/layoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LayoutModel,
MenuBarMode,
} from 'mo/model/workbench/layout';
import { MenuBarEvent } from 'mo/model/workbench/menuBar';

export interface ILayoutService extends Component<ILayout> {
/**
Expand Down Expand Up @@ -155,6 +156,7 @@ export class LayoutService
const { mode: preMode } = menuBar;
if (preMode !== mode) {
this.setState({ menuBar: { ...menuBar, mode, hidden: false } });
this.emit(MenuBarEvent.onChangeMode, mode);
}
}

Expand Down
10 changes: 10 additions & 0 deletions stories/extensions/test/testPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ PARTITIONED BY (ds string) lifecycle 1000;
);
};

const toggleMenuBarMode = () => {
const currentMode = molecule.layout.getMenuBarMode();
const newMode =
currentMode === 'horizontal' ? 'vertical' : 'horizontal';
molecule.layout.setMenuBarMode(newMode);
};

return (
<Scrollable isShowShadow>
<div>
Expand Down Expand Up @@ -361,6 +368,9 @@ PARTITIONED BY (ds string) lifecycle 1000;
<Button onClick={addSettingsItem}>
Append Settings Item
</Button>
<Button onClick={toggleMenuBarMode}>
Toggle MenuBar mode
</Button>
</div>
<div style={{ margin: '50px 20px' }}>
<h2>Exploer:</h2>
Expand Down

0 comments on commit ecdb312

Please sign in to comment.