Skip to content

Commit

Permalink
fix: rename data backfill
Browse files Browse the repository at this point in the history
rename data backfill
  • Loading branch information
zhangtengjin authored and wewoor committed Mar 11, 2021
1 parent c3ac8af commit 0b0742d
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
verticalMenuClassName,
} from './base';

export interface IMenu extends ISubMenu { }
export interface IMenu extends ISubMenu {}

export function Menu(props: React.PropsWithChildren<IMenu>) {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/components/toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { prefixClaName, classNames } from 'mo/common/className';
import ActionBar, { IActionBar } from 'mo/components/actionBar';

export interface IToolBar<T = any> extends IActionBar { }
export interface IToolBar<T = any> extends IActionBar {}

const rootClassName = 'tool-bar';

Expand Down
12 changes: 6 additions & 6 deletions src/components/tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export interface ITreeProps {
expandedKeys?: Key[];
defaultCheckedKeys?: Key[];
checkedKeys?:
| Key[]
| {
checked: Key[];
halfChecked: Key[];
};
| Key[]
| {
checked: Key[];
halfChecked: Key[];
};
defaultSelectedKeys?: Key[];
selectedKeys?: Key[];
titleRender?: (node: DataNode) => React.ReactNode;
Expand Down Expand Up @@ -119,7 +119,7 @@ export interface ITreeProps {
draggable?: boolean;

data?: ITreeNodeItem[];
onSelectFile?: (IMenuItem) => void;
onSelectFile?: (IMenuItem, isAuto?) => void;
onSelectTree?: (id) => void;
renderTitle?: (node, index) => React.ReactDOM | string;
onDropTree?(treeNode): void;
Expand Down
9 changes: 5 additions & 4 deletions src/controller/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { IActionBarItem } from 'mo/components/actionBar';
// TODO: 自依赖问题 connect 失效,暂时手动引入 Controller 往 View 层传递
import { folderTreeController, explorerController } from 'mo/controller';
export interface IExplorerController {
onHeaderToolbarContextMenuClick?: (e: React.MouseEvent, item: IActionBarItem) => void;
onHeaderToolbarContextMenuClick?: (
e: React.MouseEvent,
item: IActionBarItem
) => void;
}

@singleton()
Expand Down Expand Up @@ -108,9 +111,7 @@ export class ExplorerController
},
};

explorerService.addPanel([
sampleFolderPanel,
]);
explorerService.addPanel([sampleFolderPanel]);
}

private createFile = (e, type) => {
Expand Down
31 changes: 23 additions & 8 deletions src/controller/explorer/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Modal from 'mo/components/dialog';
const confirm = Modal.confirm;

export interface IFolderTreeController {
readonly onSelectFile?: (file: ITreeNodeItem) => void;
readonly onSelectFile?: (file: ITreeNodeItem, isAuto?: boolean) => void;
readonly onSelectTree?: (id: number) => void;
readonly onDropTree?: (treeNode: ITreeNodeItem[]) => void;
readonly onClickContextMenu?: (
e: React.MouseEvent,
item: IMenuItem,
node: ITreeNodeItem,
callback?: Function
events?: Object
) => void;
readonly filterContextMenu?: (
menus: IMenuItem[],
Expand All @@ -36,7 +36,7 @@ export class FolderTreeController

private initView() { }

public readonly onSelectFile = (file: ITreeNodeItem) => {
public readonly onSelectFile = (file: ITreeNodeItem, isAuto?: boolean) => {
const tabData = {
...file,
id: `${file.id}`,
Expand All @@ -48,7 +48,21 @@ export class FolderTreeController
},
breadcrumb: [{ id: `${file.id}`, name: 'editor.js' }],
};
editorService.open(tabData);
if (isAuto) {
// 更新文件自动回调
const editorState = editorService.getState();

const { id, data = [] } = editorState?.current || {};
const tabId = file.id;
const index = data?.findIndex(tab => tab.id == tabId);
if (index > -1) {
if (id) editorService.updateTab(tabData, id)
} else {
editorService.open(tabData);
}
} else {
editorService.open(tabData);
}
};

public onSelectTree = (id: number) => {
Expand All @@ -63,14 +77,15 @@ export class FolderTreeController
e: React.MouseEvent,
item: IMenuItem,
node: ITreeNodeItem,
callback?: Function
events?: Object
) => {
const menuId = item.id;
const { id: nodeId, name } = node as any;
switch (menuId) {
case 'rename': {
explorerService.rename(nodeId, () => {
if (callback) callback();
events?.['setValue'](name);
events?.['onFocus']();
});
break;
}
Expand All @@ -91,13 +106,13 @@ export class FolderTreeController
}
case 'newFile': {
explorerService.newFile(nodeId, () => {
if (callback) callback();
events?.['onFocus']();
});
break;
}
case 'newFolder': {
explorerService.newFolder(nodeId, () => {
if (callback) callback();
events?.['onFocus']();
});
break;
}
Expand Down
48 changes: 25 additions & 23 deletions src/model/workbench/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ export interface IExplorer {
folderTree?: IFolderTree;
}

const builtInHeaderToolbar: IActivityBarItem[] = [{
id: 'explorer-more',
name: 'View and More Actions...',
iconName: 'codicon-ellipsis',
type: 'global',
contextMenu: [
{
id: 'OpenEditors',
name: 'Open Editors',
icon: 'check'
},
{
id: 'Folders',
name: 'Folders',
icon: 'check'
},
{
id: 'Outline',
name: 'Outline',
icon: 'check'
},
],
}]
const builtInHeaderToolbar: IActivityBarItem[] = [
{
id: 'explorer-more',
name: 'View and More Actions...',
iconName: 'codicon-ellipsis',
type: 'global',
contextMenu: [
{
id: 'OpenEditors',
name: 'Open Editors',
icon: 'check',
},
{
id: 'Folders',
name: 'Folders',
icon: 'check',
},
{
id: 'Outline',
name: 'Outline',
icon: 'check',
},
],
},
];

const commonContextMenu = [
{
Expand Down
10 changes: 4 additions & 6 deletions src/services/workbench/explorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
IExplorer,
IExplorerModel,
} from 'mo/model/workbench/explorer';
import {
DEFAULT_PANELS
} from 'mo/model/workbench/explorer';
import { DEFAULT_PANELS } from 'mo/model/workbench/explorer';
import { TreeViewUtil, searchById } from '../helper';
import { ITreeNodeItem, FileTypes, FileType } from 'mo/components/tree';
import { editorService } from 'mo';
Expand Down Expand Up @@ -65,11 +63,11 @@ export class ExplorerService
const next = [...data!];
const index = next.findIndex(searchById(id));
if (index > -1) {
this.remove(id)
this.remove(id);
} else {
const existPanel = DEFAULT_PANELS.find(searchById(id))
const existPanel = DEFAULT_PANELS.find(searchById(id));
if (!existPanel) return;
this.addPanel(existPanel)
this.addPanel(existPanel);
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/workbench/activityBar/activityBarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function ActivityBarItem(props: IActivityBarItem & IActivityBarController) {
id,
onClick,
contextMenu = [],
className
className,
} = props;
let content: React.ReactNode = '';
if (render) {
Expand All @@ -33,10 +33,13 @@ function ActivityBarItem(props: IActivityBarItem & IActivityBarController) {

let contextViewMenu;

const onClickMenuItem = useCallback((e, item) => {
if (onClick) onClick(e, item);
contextViewMenu?.dispose();
}, [contextMenu]);
const onClickMenuItem = useCallback(
(e, item) => {
if (onClick) onClick(e, item);
contextViewMenu?.dispose();
},
[contextMenu]
);
const renderContextMenu = () => (
<Menu onClick={onClickMenuItem} data={contextMenu} />
);
Expand Down
16 changes: 10 additions & 6 deletions src/workbench/sidebar/explore/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { getBEMElement, getBEMModifier, prefixClaName } from 'mo/common/className';
import {
getBEMElement,
getBEMModifier,
prefixClaName,
} from 'mo/common/className';
import { ID_ACTIVITY_BAR, ID_SIDE_BAR, ID_EXPLORER } from 'mo/common/id';

export const defaultClassName = prefixClaName(ID_SIDE_BAR);
const defaultExplorerClassName = prefixClaName(ID_EXPLORER, defaultClassName);
const activityBarItemFloatClassName = getBEMModifier(getBEMElement(defaultExplorerClassName, ID_ACTIVITY_BAR), 'float')
const activityBarItemFloatClassName = getBEMModifier(
getBEMElement(defaultExplorerClassName, ID_ACTIVITY_BAR),
'float'
);

export {
defaultExplorerClassName,
activityBarItemFloatClassName
}
export { defaultExplorerClassName, activityBarItemFloatClassName };
8 changes: 6 additions & 2 deletions src/workbench/sidebar/explore/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import ActivityBarItem from 'mo/workbench/activityBar/activityBarItem';
import { IActivityBarItem } from 'mo/model/workbench/activityBar';
import {
defaultExplorerClassName,
activityBarItemFloatClassName
activityBarItemFloatClassName,
} from './base';

export const Explorer: React.FunctionComponent<IExplorer> = (
props: IExplorer & IExplorerController
) => {
const { data = [], headerToolBar = [], onHeaderToolbarContextMenuClick } = props;
const {
data = [],
headerToolBar = [],
onHeaderToolbarContextMenuClick,
} = props;
const renderItems = (item: IActivityBarItem, index: number) => {
return (
<ActivityBarItem
Expand Down
33 changes: 23 additions & 10 deletions src/workbench/sidebar/explore/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,38 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (

const contextView = useContextView();

const onFocus = () => {
setTimeout(() => {
if (inputRef.current) {
inputRef.current.focus();
}
});
};

const setInputVal = (val) => {
setTimeout(() => {
if (inputRef.current) {
inputRef.current.value = val
}
});
}

const inputEvents = {
onFocus,
setValue: (val) => setInputVal(val)
}

const handleRightClick = ({ event, node }) => {
const menuItems = filterContextMenu?.(contextMenu, node.data);
const handleOnMenuClick = (e: React.MouseEvent, item) => {
onClickContextMenu?.(e, item, node.data, onFocus);
onClickContextMenu?.(e, item, node.data, inputEvents);
contextView.hide();
};
contextView?.show(getEventPosition(event), () => (
<Menu onClick={handleOnMenuClick} data={menuItems} />
));
};

const onFocus = () => {
setTimeout(() => {
if (inputRef.current) {
inputRef.current.focus();
}
});
};

const handleUpdateFile = (e, node) => {
const newName = (e.target as HTMLInputElement).value;
explorerService.updateFile(
Expand All @@ -57,7 +70,7 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
onSelectFile?.({
...node,
name: newName,
});
}, true);
}
}
);
Expand Down

0 comments on commit 0b0742d

Please sign in to comment.