Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(activitybar): update the ActivityBarService interfaces #289

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/controller/activityBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class ActivityBarController
);
};

// TODO: Menu 按钮是否提取至 activityBar 外
public readonly onContextMenuClick = (
e: React.MouseEvent,
item: IMenuItemProps | undefined
Expand All @@ -95,17 +94,13 @@ export class ActivityBarController
// activityBar contextMenu
case CONTEXT_MENU_MENU: {
this.menuBarController.updateMenuBar!();
this.activityBarService.toggleContextMenuCheckStatus(
contextMenuId
);
this.activityBarService.toggleContextMenuChecked(contextMenuId);
break;
}
case CONTEXT_MENU_EXPLORER:
case CONTEXT_MENU_SEARCH: {
this.activityBarService.toggleBar(contextMenuId);
this.activityBarService.toggleContextMenuCheckStatus(
contextMenuId
);
this.activityBarService.toggleContextMenuChecked(contextMenuId);
break;
}
case CONTEXT_MENU_HIDE: {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ExplorerController
},
};

this.activityBarService.addBar(builtInExplorerActivityItem(), true);
this.activityBarService.add(builtInExplorerActivityItem(), true);
this.sidebarService.add(explorePane, true);
// add folder panel
this.explorerService.addPanel({
Expand Down
2 changes: 1 addition & 1 deletion src/controller/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class SearchController extends Controller implements ISearchController {
});

this.sidebarService.add(searchSidePane);
this.activityBarService.addBar(builtInSearchActivityItem());
this.activityBarService.add(builtInSearchActivityItem());
}

public validateValue = (
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/activityBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CommandQuickSideBarViewAction } from 'mo/monaco/quickToggleSideBarActio
export const ExtendsActivityBar: IExtension = {
activate(extensionCtx: IExtensionService) {
const { data = [], contextMenu = [] } = builtInActivityBar();
molecule.activityBar.addBar(data);
molecule.activityBar.add(data);
molecule.activityBar.addContextMenu(contextMenu);

molecule.activityBar.onChange((pre, cur) => {
Expand Down
49 changes: 35 additions & 14 deletions src/services/workbench/activityBarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,44 @@ import logger from 'mo/common/logger';
import { ISidebarService, SidebarService } from './sidebarService';

export interface IActivityBarService extends Component<IActivityBar> {
/**
* Reset the activityBar state data,
* if you want to whole customize the activityBar, you can reset it first,
* and then using the activityBar.add() method to fill the data you need.
*/
reset(): void;
/**
*
* Add IActivityBarItem data
* @param isActive If provide, Activity Bar will set data active automatically. Only works in one data
*/
addBar(
data: IActivityBarItem | IActivityBarItem[],
isActive?: boolean
): void;
add(data: IActivityBarItem | IActivityBarItem[], isActive?: boolean): void;
/**
* set active bar
* Set active bar
*/
setActive(id?: string): void;
/**
* Remove the specific activity bar by id
* @param id
*/
remove(id: string): void;
/**
* Toggle the specific activity bar between show or hide
* @param id activity bar id
*/
toggleBar(id: string): void;
toggleContextMenuCheckStatus(id: string): void;
addContextMenu(contextMenu: IMenuItemProps | IMenuItemProps[]): void;
/**
* Toggle the contextMenu between checked or unchecked
* @param id contextmenu id
*/
toggleContextMenuChecked(id: string): void;
/**
* Add new contextMenus for the activityBar
*/
addContextMenu(data: IMenuItemProps | IMenuItemProps[]): void;
/**
* Remove the specific contextMenu item by id
* @param id contextmenu id
*/
removeContextMenu(id: string): void;
/**
* Add click event listener
Expand Down Expand Up @@ -69,10 +90,7 @@ export class ActivityBarService
});
}

public addBar(
data: IActivityBarItem | IActivityBarItem[],
isActive = false
) {
public add(data: IActivityBarItem | IActivityBarItem[], isActive = false) {
let next = [...this.state.data!];
if (Array.isArray(data)) {
next = next?.concat(data);
Expand Down Expand Up @@ -119,7 +137,7 @@ export class ActivityBarService
}
}

public toggleContextMenuCheckStatus(id: string) {
public toggleContextMenuChecked(id: string) {
const { contextMenu = [] } = this.state;
const newActions = contextMenu.concat();
const target = newActions.find(searchById(id));
Expand All @@ -129,7 +147,10 @@ export class ActivityBarService
contextMenu: newActions,
});
} else {
logger.error('toggle context menu failed, please check your id');
throw new Error(
'Toggle the contextmenu failed, can not found any menu by id' +
id
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion stories/extensions/data-sync/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const ExtendDataSync: IExtension = {
name: '数据同步',
};
console.log('extend a new activity bar item:', newItem);
molecule.activityBar.addBar(newItem);
molecule.activityBar.add(newItem);
},
};
2 changes: 1 addition & 1 deletion stories/extensions/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ExtendTestPane: IExtension = {
name: '测试',
};

molecule.activityBar.addBar(newItem);
molecule.activityBar.add(newItem);
molecule.sidebar.add(testSidePane);

molecule.editor.setEntry(<Entry />);
Expand Down
2 changes: 1 addition & 1 deletion stories/extensions/test/testPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class TestPane extends React.Component {
render() {
const addABar = function () {
const id = Math.random() * 10 + 1;
molecule.activityBar.addBar({
molecule.activityBar.add({
id: id + '',
name: 'folder' + id,
iconName: 'codicon-edit',
Expand Down