feat: tree selectd support
This commit is contained in:
1 parent
8c5e43b9e7
commit
40b83c2876
4 files changed
+40
-11
No files matched your search
@@ -348,12 +348,19 @@ export default class Explorer extends Component<ExplorerProps> {
|
|||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectNode(id:string){
|
||||||
|
this.setState({
|
||||||
|
selectedKey:id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
renderItem(node: FileDataNode) {
|
renderItem(node: FileDataNode) {
|
||||||
if(!node.visible){
|
if(!node.visible){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const titleStr = node.text;
|
const titleStr = node.text;
|
||||||
const searchKey = this.state.searchKey;
|
const searchKey = this.state.searchKey;
|
||||||
|
const isSelected = this.state.selectedKey==node.id;
|
||||||
const index = titleStr.indexOf(searchKey);
|
const index = titleStr.indexOf(searchKey);
|
||||||
const beforeStr = titleStr.substr(0, index);
|
const beforeStr = titleStr.substr(0, index);
|
||||||
const afterStr = titleStr.substr(index + searchKey.length);
|
const afterStr = titleStr.substr(index + searchKey.length);
|
||||||
@@ -361,7 +368,7 @@ export default class Explorer extends Component<ExplorerProps> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="explorer-node"
|
className={isSelected?"explorer-node-selected":"explorer-node"}
|
||||||
key={node.id}
|
key={node.id}
|
||||||
onMouseMove={() => {}}
|
onMouseMove={() => {}}
|
||||||
>
|
>
|
||||||
@@ -407,10 +414,8 @@ export default class Explorer extends Component<ExplorerProps> {
|
|||||||
<DirectoryTree
|
<DirectoryTree
|
||||||
keygen="id"
|
keygen="id"
|
||||||
data={nodes}
|
data={nodes}
|
||||||
line={true}
|
line={false}
|
||||||
doubleClickExpand
|
doubleClickExpand
|
||||||
// expandIcons={[<DownOutlined />, <RightOutlined />]}
|
|
||||||
//defaultValue={[root.id]}
|
|
||||||
defaultExpanded={[root.id]}
|
defaultExpanded={[root.id]}
|
||||||
expanded={this.state.expandedKeys}
|
expanded={this.state.expandedKeys}
|
||||||
value={[this.state.selectedKey]}
|
value={[this.state.selectedKey]}
|
||||||
@@ -422,9 +427,6 @@ export default class Explorer extends Component<ExplorerProps> {
|
|||||||
onClick={(node: FileDataNode) => {
|
onClick={(node: FileDataNode) => {
|
||||||
if (!node.isFolder) {
|
if (!node.isFolder) {
|
||||||
onOpenTree(node.path);
|
onOpenTree(node.path);
|
||||||
// this.setState({
|
|
||||||
// selectedKey:node.id
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
></DirectoryTree>
|
></DirectoryTree>
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import { BehaviorTreeModel } from "../common/BehaviorTreeModel";
|
|||||||
|
|
||||||
const { TabPane } = Tabs;
|
const { TabPane } = Tabs;
|
||||||
|
|
||||||
interface TreeTabsProps {}
|
interface TreeTabsProps {
|
||||||
|
onTabSelected:(path:string)=>void;
|
||||||
|
}
|
||||||
|
|
||||||
interface TreeTabsState {
|
interface TreeTabsState {
|
||||||
filepaths: string[];
|
filepaths: string[];
|
||||||
@@ -97,9 +99,13 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
if (this.state.filepaths.indexOf(path) < 0) {
|
if (this.state.filepaths.indexOf(path) < 0) {
|
||||||
const filepaths = this.state.filepaths;
|
const filepaths = this.state.filepaths;
|
||||||
filepaths.push(path);
|
filepaths.push(path);
|
||||||
this.setState({ filepaths, curPath: path });
|
this.setState({ filepaths, curPath: path },()=>{
|
||||||
|
this.props.onTabSelected(path);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({ curPath: path });
|
this.setState({ curPath: path },()=>{
|
||||||
|
this.props.onTabSelected(path);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +134,9 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
|||||||
defaultActiveKey={curPath}
|
defaultActiveKey={curPath}
|
||||||
activeKey={curPath}
|
activeKey={curPath}
|
||||||
onChange={(activeKey) => {
|
onChange={(activeKey) => {
|
||||||
this.setState({ curPath: activeKey });
|
this.setState({ curPath: activeKey },()=>{
|
||||||
|
this.props.onTabSelected(activeKey);
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onEdit={(targetKey, action) => {
|
onEdit={(targetKey, action) => {
|
||||||
if (action == "remove") {
|
if (action == "remove") {
|
||||||
|
|||||||
@@ -58,6 +58,17 @@ body {
|
|||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.explorer-node-selected {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
line-height: 20px;
|
||||||
|
white-space: nowrap;
|
||||||
|
list-style: none;
|
||||||
|
outline: 0;
|
||||||
|
color: #ffffff;
|
||||||
|
background-color: #818181;
|
||||||
|
}
|
||||||
|
|
||||||
.explorer-node-title {
|
.explorer-node-title {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default class Main extends Component {
|
|||||||
|
|
||||||
settings: Settings;
|
settings: Settings;
|
||||||
tabs: TreeTabs;
|
tabs: TreeTabs;
|
||||||
|
explorer: Explorer;
|
||||||
session = 0;
|
session = 0;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -88,6 +89,9 @@ export default class Main extends Component {
|
|||||||
<Sider className="sider" width={250}>
|
<Sider className="sider" width={250}>
|
||||||
{workdir !== "" ? (
|
{workdir !== "" ? (
|
||||||
<Explorer
|
<Explorer
|
||||||
|
ref={(ref) => {
|
||||||
|
this.explorer = ref;
|
||||||
|
}}
|
||||||
workdir={workdir}
|
workdir={workdir}
|
||||||
onOpenTree={(path) => {
|
onOpenTree={(path) => {
|
||||||
this.tabs.openFile(path);
|
this.tabs.openFile(path);
|
||||||
@@ -105,6 +109,10 @@ export default class Main extends Component {
|
|||||||
ref={(ref) => {
|
ref={(ref) => {
|
||||||
this.tabs = ref;
|
this.tabs = ref;
|
||||||
}}
|
}}
|
||||||
|
onTabSelected={(path)=>{
|
||||||
|
this.explorer.selectNode(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
Reference in new issue
Block a user