Skip to content

Commit ecdb312

Browse files
authored
fix: sync menuBar mode status (#637)
1 parent f355c88 commit ecdb312

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/controller/menuBar.ts

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ export class MenuBarController
106106
this.automation[key] = value;
107107
}
108108
});
109+
110+
this.subscribe(MenuBarEvent.onChangeMode, this.updateMenuBarData);
109111
}
110112

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

210212
public updateMenuBarMode = (mode: keyof typeof MenuBarMode) => {
211213
this.layoutService.setMenuBarMode(mode);
214+
};
215+
216+
public updateMenuBarData = (mode: keyof typeof MenuBarMode) => {
212217
const { builtInMenuBarData } = this.builtinService.getModules();
213218
const menuBarData = this.getMenuBarDataByMode(mode, builtInMenuBarData);
214219
this.menuBarService.setMenus(menuBarData);

src/model/workbench/menuBar.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export enum MenuBarEvent {
1111
* Selected an activity bar
1212
*/
1313
onSelect = 'menuBar.onSelect',
14+
onChangeMode = 'menuBar.onChangeMode',
1415
}
1516

1617
export interface IMenuBarItem {

src/services/workbench/layoutService.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
LayoutModel,
88
MenuBarMode,
99
} from 'mo/model/workbench/layout';
10+
import { MenuBarEvent } from 'mo/model/workbench/menuBar';
1011

1112
export interface ILayoutService extends Component<ILayout> {
1213
/**
@@ -155,6 +156,7 @@ export class LayoutService
155156
const { mode: preMode } = menuBar;
156157
if (preMode !== mode) {
157158
this.setState({ menuBar: { ...menuBar, mode, hidden: false } });
159+
this.emit(MenuBarEvent.onChangeMode, mode);
158160
}
159161
}
160162

stories/extensions/test/testPane.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ PARTITIONED BY (ds string) lifecycle 1000;
316316
);
317317
};
318318

319+
const toggleMenuBarMode = () => {
320+
const currentMode = molecule.layout.getMenuBarMode();
321+
const newMode =
322+
currentMode === 'horizontal' ? 'vertical' : 'horizontal';
323+
molecule.layout.setMenuBarMode(newMode);
324+
};
325+
319326
return (
320327
<Scrollable isShowShadow>
321328
<div>
@@ -361,6 +368,9 @@ PARTITIONED BY (ds string) lifecycle 1000;
361368
<Button onClick={addSettingsItem}>
362369
Append Settings Item
363370
</Button>
371+
<Button onClick={toggleMenuBarMode}>
372+
Toggle MenuBar mode
373+
</Button>
364374
</div>
365375
<div style={{ margin: '50px 20px' }}>
366376
<h2>Exploer:</h2>

0 commit comments

Comments
 (0)