Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef802dc

Browse files
use workdirs instead of project paths
1 parent 810ad66 commit ef802dc

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

lib/controllers/root-controller.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ export default class RootController extends React.Component {
285285
discardWorkDirChangesForPaths={this.discardWorkDirChangesForPaths}
286286
undoLastDiscard={this.undoLastDiscard}
287287
refreshResolutionProgress={this.refreshResolutionProgress}
288+
getCurrentWorkDirs={this.props.workdirContextPool.getCurrentWorkDirs}
289+
onDidChangeWorkDirs={this.props.workdirContextPool.onDidChangePoolContexts}
288290
changeWorkingDirectory={this.props.changeWorkingDirectory}
289291
/>
290292
)}
@@ -298,8 +300,9 @@ export default class RootController extends React.Component {
298300
ref={itemHolder.setter}
299301
repository={this.props.repository}
300302
loginModel={this.props.loginModel}
301-
project={this.props.project}
302303
workspace={this.props.workspace}
304+
getCurrentWorkDirs={this.props.workdirContextPool.getCurrentWorkDirs}
305+
onDidChangeWorkDirs={this.props.workdirContextPool.onDidChangePoolContexts}
303306
changeWorkingDirectory={this.props.changeWorkingDirectory}
304307
/>
305308
)}

lib/models/workdir-context-pool.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ export default class WorkdirContextPool {
112112
}
113113
}
114114

115+
getCurrentWorkDirs() {
116+
return this.context.keys();
117+
}
118+
115119
withResidentContexts(callback) {
116120
const results = [];
117121
for (const [workdir, context] of this.contexts) {

lib/views/git-tab-view.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export default class GitTabView extends React.Component {
6262
discardWorkDirChangesForPaths: PropTypes.func.isRequired,
6363
openFiles: PropTypes.func.isRequired,
6464
changeWorkingDirectory: PropTypes.func.isRequired,
65+
onDidChangeWorkDirs: PropTypes.func.isRequired,
66+
getCurrentWorkDirs: PropTypes.func.isRequired,
6567
};
6668

6769
constructor(props, context) {
@@ -118,9 +120,10 @@ export default class GitTabView extends React.Component {
118120
renderHeader() {
119121
return (
120122
<TabHeaderView
121-
handleProjectSelect={e => this.props.changeWorkingDirectory(e.target.value)}
122-
currentProject={this.props.workingDirectoryPath}
123-
projectPaths={this.props.project.getPaths()}
123+
handleWorkDirSelect={e => this.props.changeWorkingDirectory(e.target.value)}
124+
currentWorkDir={this.props.workingDirectoryPath}
125+
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
126+
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
124127
/>
125128
);
126129
}

lib/views/github-tab-view.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default class GitHubTabView extends React.Component {
3131
handlePushBranch: PropTypes.func.isRequired,
3232
handleRemoteSelect: PropTypes.func.isRequired,
3333
changeWorkingDirectory: PropTypes.func.isRequired,
34+
onDidChangeWorkDirs: PropTypes.func.isRequired,
35+
getCurrentWorkDirs: PropTypes.func.isRequired,
3436
}
3537

3638
render() {
@@ -97,9 +99,10 @@ export default class GitHubTabView extends React.Component {
9799
renderHeader() {
98100
return (
99101
<TabHeaderView
100-
handleProjectSelect={e => this.props.changeWorkingDirectory(e.target.value)}
101-
currentProject={this.props.workingDirectory}
102-
projectPaths={this.props.project.getPaths()}
102+
handleWorkDirSelect={e => this.props.changeWorkingDirectory(e.target.value)}
103+
currentWorkDir={this.props.workingDirectory}
104+
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
105+
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
103106
/>
104107
);
105108
}

lib/views/tab-header-view.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,48 @@ import path from 'path';
44

55
export default class TabHeaderView extends React.Component {
66
static propTypes = {
7-
currentProject: PropTypes.string,
8-
projectPaths: PropTypes.arrayOf(PropTypes.string),
7+
currentWorkDir: PropTypes.string,
98

10-
handleProjectSelect: PropTypes.func.isRequired,
9+
handleWorkDirSelect: PropTypes.func,
10+
onDidChangeWorkDirs: PropTypes.func,
11+
getCurrentWorkDirs: PropTypes.func,
12+
}
13+
14+
constructor(props) {
15+
super(props);
16+
this.state = {currentWorkDirs: props.getCurrentWorkDirs()};
17+
this.disposable = props.onDidChangeWorkDirs(this.updateWorkDirs);
1118
}
1219

1320
render() {
1421
return (
1522
<header className="github-Project">
1623
<select className="github-Project-path input-select"
17-
value={this.props.currentProject ? this.props.currentProject : undefined}
18-
onChange={this.props.handleProjectSelect}>
19-
{this.renderProjects()}
24+
value={this.props.currentWorkDir ? this.props.currentWorkDir : undefined}
25+
onChange={this.props.handleWorkDirSelect ? this.props.handleWorkDirSelect : () => {}}>
26+
{this.renderWorkDirs()}
2027
</select>
2128
</header>
2229
);
2330
}
2431

25-
renderProjects() {
26-
const projects = [];
27-
for (const projectPath of this.props.projectPaths) {
28-
projects.push(<option key={projectPath} value={projectPath}>{path.basename(projectPath)}</option>);
32+
renderWorkDirs() {
33+
const workdirs = [];
34+
for (const workdir of this.state.currentWorkDirs) {
35+
workdirs.push(<option key={workdir} value={workdir}>{path.basename(workdir)}</option>);
36+
}
37+
return workdirs;
38+
}
39+
40+
updateWorkDirs = () => {
41+
this.setState((state, props) => ({
42+
currentWorkDirs: props.getCurrentWorkDirs(),
43+
}));
44+
}
45+
46+
componentWillUnmount() {
47+
if (this.disposable && this.disposable.dispose) {
48+
this.disposable.dispose();
2949
}
30-
return projects;
31-
};
50+
}
3251
}

0 commit comments

Comments
 (0)