Skip to content

Commit 0b0742d

Browse files
zhangtengjinwewoor
authored andcommitted
fix: rename data backfill
rename data backfill
1 parent c3ac8af commit 0b0742d

File tree

11 files changed

+112
-72
lines changed

11 files changed

+112
-72
lines changed

src/components/menu/menu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
verticalMenuClassName,
99
} from './base';
1010

11-
export interface IMenu extends ISubMenu { }
11+
export interface IMenu extends ISubMenu {}
1212

1313
export function Menu(props: React.PropsWithChildren<IMenu>) {
1414
const {

src/components/toolbar/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { prefixClaName, classNames } from 'mo/common/className';
44
import ActionBar, { IActionBar } from 'mo/components/actionBar';
55

6-
export interface IToolBar<T = any> extends IActionBar { }
6+
export interface IToolBar<T = any> extends IActionBar {}
77

88
const rootClassName = 'tool-bar';
99

src/components/tree/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export interface ITreeProps {
5252
expandedKeys?: Key[];
5353
defaultCheckedKeys?: Key[];
5454
checkedKeys?:
55-
| Key[]
56-
| {
57-
checked: Key[];
58-
halfChecked: Key[];
59-
};
55+
| Key[]
56+
| {
57+
checked: Key[];
58+
halfChecked: Key[];
59+
};
6060
defaultSelectedKeys?: Key[];
6161
selectedKeys?: Key[];
6262
titleRender?: (node: DataNode) => React.ReactNode;
@@ -119,7 +119,7 @@ export interface ITreeProps {
119119
draggable?: boolean;
120120

121121
data?: ITreeNodeItem[];
122-
onSelectFile?: (IMenuItem) => void;
122+
onSelectFile?: (IMenuItem, isAuto?) => void;
123123
onSelectTree?: (id) => void;
124124
renderTitle?: (node, index) => React.ReactDOM | string;
125125
onDropTree?(treeNode): void;

src/controller/explorer/explorer.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import { IActionBarItem } from 'mo/components/actionBar';
1313
// TODO: 自依赖问题 connect 失效,暂时手动引入 Controller 往 View 层传递
1414
import { folderTreeController, explorerController } from 'mo/controller';
1515
export interface IExplorerController {
16-
onHeaderToolbarContextMenuClick?: (e: React.MouseEvent, item: IActionBarItem) => void;
16+
onHeaderToolbarContextMenuClick?: (
17+
e: React.MouseEvent,
18+
item: IActionBarItem
19+
) => void;
1720
}
1821

1922
@singleton()
@@ -108,9 +111,7 @@ export class ExplorerController
108111
},
109112
};
110113

111-
explorerService.addPanel([
112-
sampleFolderPanel,
113-
]);
114+
explorerService.addPanel([sampleFolderPanel]);
114115
}
115116

116117
private createFile = (e, type) => {

src/controller/explorer/folderTree.tsx

+23-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import Modal from 'mo/components/dialog';
1010
const confirm = Modal.confirm;
1111

1212
export interface IFolderTreeController {
13-
readonly onSelectFile?: (file: ITreeNodeItem) => void;
13+
readonly onSelectFile?: (file: ITreeNodeItem, isAuto?: boolean) => void;
1414
readonly onSelectTree?: (id: number) => void;
1515
readonly onDropTree?: (treeNode: ITreeNodeItem[]) => void;
1616
readonly onClickContextMenu?: (
1717
e: React.MouseEvent,
1818
item: IMenuItem,
1919
node: ITreeNodeItem,
20-
callback?: Function
20+
events?: Object
2121
) => void;
2222
readonly filterContextMenu?: (
2323
menus: IMenuItem[],
@@ -36,7 +36,7 @@ export class FolderTreeController
3636

3737
private initView() { }
3838

39-
public readonly onSelectFile = (file: ITreeNodeItem) => {
39+
public readonly onSelectFile = (file: ITreeNodeItem, isAuto?: boolean) => {
4040
const tabData = {
4141
...file,
4242
id: `${file.id}`,
@@ -48,7 +48,21 @@ export class FolderTreeController
4848
},
4949
breadcrumb: [{ id: `${file.id}`, name: 'editor.js' }],
5050
};
51-
editorService.open(tabData);
51+
if (isAuto) {
52+
// 更新文件自动回调
53+
const editorState = editorService.getState();
54+
55+
const { id, data = [] } = editorState?.current || {};
56+
const tabId = file.id;
57+
const index = data?.findIndex(tab => tab.id == tabId);
58+
if (index > -1) {
59+
if (id) editorService.updateTab(tabData, id)
60+
} else {
61+
editorService.open(tabData);
62+
}
63+
} else {
64+
editorService.open(tabData);
65+
}
5266
};
5367

5468
public onSelectTree = (id: number) => {
@@ -63,14 +77,15 @@ export class FolderTreeController
6377
e: React.MouseEvent,
6478
item: IMenuItem,
6579
node: ITreeNodeItem,
66-
callback?: Function
80+
events?: Object
6781
) => {
6882
const menuId = item.id;
6983
const { id: nodeId, name } = node as any;
7084
switch (menuId) {
7185
case 'rename': {
7286
explorerService.rename(nodeId, () => {
73-
if (callback) callback();
87+
events?.['setValue'](name);
88+
events?.['onFocus']();
7489
});
7590
break;
7691
}
@@ -91,13 +106,13 @@ export class FolderTreeController
91106
}
92107
case 'newFile': {
93108
explorerService.newFile(nodeId, () => {
94-
if (callback) callback();
109+
events?.['onFocus']();
95110
});
96111
break;
97112
}
98113
case 'newFolder': {
99114
explorerService.newFolder(nodeId, () => {
100-
if (callback) callback();
115+
events?.['onFocus']();
101116
});
102117
break;
103118
}

src/model/workbench/explorer.tsx

+25-23
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,31 @@ export interface IExplorer {
2424
folderTree?: IFolderTree;
2525
}
2626

27-
const builtInHeaderToolbar: IActivityBarItem[] = [{
28-
id: 'explorer-more',
29-
name: 'View and More Actions...',
30-
iconName: 'codicon-ellipsis',
31-
type: 'global',
32-
contextMenu: [
33-
{
34-
id: 'OpenEditors',
35-
name: 'Open Editors',
36-
icon: 'check'
37-
},
38-
{
39-
id: 'Folders',
40-
name: 'Folders',
41-
icon: 'check'
42-
},
43-
{
44-
id: 'Outline',
45-
name: 'Outline',
46-
icon: 'check'
47-
},
48-
],
49-
}]
27+
const builtInHeaderToolbar: IActivityBarItem[] = [
28+
{
29+
id: 'explorer-more',
30+
name: 'View and More Actions...',
31+
iconName: 'codicon-ellipsis',
32+
type: 'global',
33+
contextMenu: [
34+
{
35+
id: 'OpenEditors',
36+
name: 'Open Editors',
37+
icon: 'check',
38+
},
39+
{
40+
id: 'Folders',
41+
name: 'Folders',
42+
icon: 'check',
43+
},
44+
{
45+
id: 'Outline',
46+
name: 'Outline',
47+
icon: 'check',
48+
},
49+
],
50+
},
51+
];
5052

5153
const commonContextMenu = [
5254
{

src/services/workbench/explorerService.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import {
55
IExplorer,
66
IExplorerModel,
77
} from 'mo/model/workbench/explorer';
8-
import {
9-
DEFAULT_PANELS
10-
} from 'mo/model/workbench/explorer';
8+
import { DEFAULT_PANELS } from 'mo/model/workbench/explorer';
119
import { TreeViewUtil, searchById } from '../helper';
1210
import { ITreeNodeItem, FileTypes, FileType } from 'mo/components/tree';
1311
import { editorService } from 'mo';
@@ -65,11 +63,11 @@ export class ExplorerService
6563
const next = [...data!];
6664
const index = next.findIndex(searchById(id));
6765
if (index > -1) {
68-
this.remove(id)
66+
this.remove(id);
6967
} else {
70-
const existPanel = DEFAULT_PANELS.find(searchById(id))
68+
const existPanel = DEFAULT_PANELS.find(searchById(id));
7169
if (!existPanel) return;
72-
this.addPanel(existPanel)
70+
this.addPanel(existPanel);
7371
}
7472
}
7573

src/workbench/activityBar/activityBarItem.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function ActivityBarItem(props: IActivityBarItem & IActivityBarController) {
2424
id,
2525
onClick,
2626
contextMenu = [],
27-
className
27+
className,
2828
} = props;
2929
let content: React.ReactNode = '';
3030
if (render) {
@@ -33,10 +33,13 @@ function ActivityBarItem(props: IActivityBarItem & IActivityBarController) {
3333

3434
let contextViewMenu;
3535

36-
const onClickMenuItem = useCallback((e, item) => {
37-
if (onClick) onClick(e, item);
38-
contextViewMenu?.dispose();
39-
}, [contextMenu]);
36+
const onClickMenuItem = useCallback(
37+
(e, item) => {
38+
if (onClick) onClick(e, item);
39+
contextViewMenu?.dispose();
40+
},
41+
[contextMenu]
42+
);
4043
const renderContextMenu = () => (
4144
<Menu onClick={onClickMenuItem} data={contextMenu} />
4245
);

src/workbench/sidebar/explore/base.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import { getBEMElement, getBEMModifier, prefixClaName } from 'mo/common/className';
1+
import {
2+
getBEMElement,
3+
getBEMModifier,
4+
prefixClaName,
5+
} from 'mo/common/className';
26
import { ID_ACTIVITY_BAR, ID_SIDE_BAR, ID_EXPLORER } from 'mo/common/id';
37

48
export const defaultClassName = prefixClaName(ID_SIDE_BAR);
59
const defaultExplorerClassName = prefixClaName(ID_EXPLORER, defaultClassName);
6-
const activityBarItemFloatClassName = getBEMModifier(getBEMElement(defaultExplorerClassName, ID_ACTIVITY_BAR), 'float')
10+
const activityBarItemFloatClassName = getBEMModifier(
11+
getBEMElement(defaultExplorerClassName, ID_ACTIVITY_BAR),
12+
'float'
13+
);
714

8-
export {
9-
defaultExplorerClassName,
10-
activityBarItemFloatClassName
11-
}
15+
export { defaultExplorerClassName, activityBarItemFloatClassName };

src/workbench/sidebar/explore/explore.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import ActivityBarItem from 'mo/workbench/activityBar/activityBarItem';
77
import { IActivityBarItem } from 'mo/model/workbench/activityBar';
88
import {
99
defaultExplorerClassName,
10-
activityBarItemFloatClassName
10+
activityBarItemFloatClassName,
1111
} from './base';
1212

1313
export const Explorer: React.FunctionComponent<IExplorer> = (
1414
props: IExplorer & IExplorerController
1515
) => {
16-
const { data = [], headerToolBar = [], onHeaderToolbarContextMenuClick } = props;
16+
const {
17+
data = [],
18+
headerToolBar = [],
19+
onHeaderToolbarContextMenuClick,
20+
} = props;
1721
const renderItems = (item: IActivityBarItem, index: number) => {
1822
return (
1923
<ActivityBarItem

src/workbench/sidebar/explore/folderTree.tsx

+23-10
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,38 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
2626

2727
const contextView = useContextView();
2828

29+
const onFocus = () => {
30+
setTimeout(() => {
31+
if (inputRef.current) {
32+
inputRef.current.focus();
33+
}
34+
});
35+
};
36+
37+
const setInputVal = (val) => {
38+
setTimeout(() => {
39+
if (inputRef.current) {
40+
inputRef.current.value = val
41+
}
42+
});
43+
}
44+
45+
const inputEvents = {
46+
onFocus,
47+
setValue: (val) => setInputVal(val)
48+
}
49+
2950
const handleRightClick = ({ event, node }) => {
3051
const menuItems = filterContextMenu?.(contextMenu, node.data);
3152
const handleOnMenuClick = (e: React.MouseEvent, item) => {
32-
onClickContextMenu?.(e, item, node.data, onFocus);
53+
onClickContextMenu?.(e, item, node.data, inputEvents);
3354
contextView.hide();
3455
};
3556
contextView?.show(getEventPosition(event), () => (
3657
<Menu onClick={handleOnMenuClick} data={menuItems} />
3758
));
3859
};
3960

40-
const onFocus = () => {
41-
setTimeout(() => {
42-
if (inputRef.current) {
43-
inputRef.current.focus();
44-
}
45-
});
46-
};
47-
4861
const handleUpdateFile = (e, node) => {
4962
const newName = (e.target as HTMLInputElement).value;
5063
explorerService.updateFile(
@@ -57,7 +70,7 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
5770
onSelectFile?.({
5871
...node,
5972
name: newName,
60-
});
73+
}, true);
6174
}
6275
}
6376
);

0 commit comments

Comments
 (0)