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

fix: improve editor actions #234

Merged
merged 4 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: improve interface name
  • Loading branch information
mortalYoung committed Jul 15, 2021
commit 0f6058a5dafef2fecce706c0a796075ac8ca902d
6 changes: 3 additions & 3 deletions src/controller/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EDITOR_MENU_CLOSE_TO_RIGHT,
EDITOR_MENU_CLOSE_TO_LEFT,
EDITOR_MENU_CLOSE_ALL,
EditorActionsProps,
IEditorActionsProps,
EDITOR_MENU_SHOW_OPENEDITORS,
EDITOR_MENU_SPILIT,
} from 'mo/model/workbench/editor';
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface IEditorController {
) => void;
onMoveTab?: <T = any>(updateTabs: IEditorTab<T>[], group: number) => void;
onSelectTab?: (tabId: string, group: number) => void;
onClickActions: (action: EditorActionsProps) => void;
onClickActions: (action: IEditorActionsProps) => void;
onUpdateEditorIns?: (editorInstance: any, groupId: number) => void;
onPaneSizeChange?: (newSize: number) => void;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ export class EditorController extends Controller implements IEditorController {
});
};

public onClickActions = (action: EditorActionsProps) => {
public onClickActions = (action: IEditorActionsProps) => {
const { current } = this.editorService.getState();
if (!current) return;

Expand Down
12 changes: 6 additions & 6 deletions src/model/workbench/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface BuiltInEditorTabDataType {
modified?: boolean;
}

export interface EditorActionsProps extends IMenuItemProps {
export interface IEditorActionsProps extends IMenuItemProps {
id: string;
/**
* Mark the action placed in More menus or outer
Expand All @@ -36,7 +36,7 @@ export interface IEditorTab<T = BuiltInEditorTabDataType> extends ITabProps<T> {
breadcrumb?: IBreadcrumbItemProps[];
}
export interface IEditorAction {
actions?: EditorActionsProps[];
actions?: IEditorActionsProps[];
menu?: IMenuItemProps[];
}
export interface IEditorGroup<E = any, T = any> extends ITabsProps<T> {
Expand All @@ -45,7 +45,7 @@ export interface IEditorGroup<E = any, T = any> extends ITabsProps<T> {
* Current editor group tab
*/
tab?: IEditorTab<T>;
actions?: EditorActionsProps[];
actions?: IEditorActionsProps[];
menu?: IMenuItemProps[];
editorInstance?: E;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export function getBaseMenu() {
];
}

export function getEditorInitialActions(): EditorActionsProps[] {
export function getEditorInitialActions(): IEditorActionsProps[] {
return [
{
id: EDITOR_MENU_SPILIT,
Expand Down Expand Up @@ -118,15 +118,15 @@ export class EditorGroupModel<E = any, T = any> implements IEditorGroup<E, T> {
id: number;
tab: IEditorTab<T>;
data: IEditorTab<T>[];
actions: EditorActionsProps[];
actions: IEditorActionsProps[];
menu: IMenuItemProps[];
editorInstance: E | undefined;

constructor(
id: number,
tab: IEditorTab<T>,
data: IEditorTab<T>[],
actions: EditorActionsProps[] = getEditorInitialActions(),
actions: IEditorActionsProps[] = getEditorInitialActions(),
menu: IMenuItemProps[] = getEditorInitialMenu(),
editorInstance?: E
) {
Expand Down
12 changes: 4 additions & 8 deletions src/services/workbench/editorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
IEditorTab,
EditorEvent,
getEditorInitialActions,
EditorActionsProps,
IEditorActionsProps,
} from 'mo/model';
import { searchById } from '../helper';
import { editor as monacoEditor, Uri } from 'mo/monaco';
Expand Down Expand Up @@ -74,7 +74,7 @@ export interface IEditorService extends Component<IEditor> {
/**
* Set default actions when create a new group
*/
setDefaultActions(actions: EditorActionsProps[]): void;
setDefaultActions(actions: IEditorActionsProps[]): void;
/**
* Update actions in specific group
*/
Expand All @@ -90,7 +90,7 @@ export class EditorService
extends Component<IEditor>
implements IEditorService {
protected state: IEditor;
protected defaultActions: EditorActionsProps[];
protected defaultActions: IEditorActionsProps[];
constructor() {
super();
this.state = container.resolve(EditorModel);
Expand All @@ -109,11 +109,7 @@ export class EditorService
return groups.some((group) => this.getTabById(tabId, group));
}

public updateGroupActions(actions: IMenuItemProps[]): void {
this.groupActions = actions;
}

public setDefaultActions(actions: EditorActionsProps[]): void {
public setDefaultActions(actions: IEditorActionsProps[]): void {
this.defaultActions = actions;
}

Expand Down
8 changes: 4 additions & 4 deletions src/workbench/editor/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { memo } from 'react';
import { Icon } from 'mo/components/icon';
import { Menu } from 'mo/components/menu';
import { DropDown, DropDownRef } from 'mo/components/dropdown';
import { EditorActionsProps, IEditorAction } from 'mo/model';
import { IEditorActionsProps, IEditorAction } from 'mo/model';
import {
groupActionItemDisabledClassName,
groupActionsClassName,
Expand All @@ -18,9 +18,9 @@ export interface IEditorActionProps extends IEditorAction {

const MAX_ACTIONS_LENGTH = 6;

function splitActions(actions: EditorActionsProps[]) {
const outerActions: EditorActionsProps[] = [];
const ellipsisActions: EditorActionsProps[] = [];
function splitActions(actions: IEditorActionsProps[]) {
const outerActions: IEditorActionsProps[] = [];
const ellipsisActions: IEditorActionsProps[] = [];
mumiao marked this conversation as resolved.
Show resolved Hide resolved

actions.forEach((action) => {
if (action.place === 'outer') {
Expand Down