Skip to content

Commit 1d1af48

Browse files
committed
Merge pull request #99 from parallaxinc/open-last-file
start session on the last file accessed - closes #89
2 parents c5f83ff + c014ee6 commit 1d1af48

File tree

4 files changed

+41
-22
lines changed

4 files changed

+41
-22
lines changed

plugins/sidebar/file-list.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const FileList = React.createClass({
1212
componentWillUnmount: function(){
1313
if(this.remove_nextFile) {
1414
this.remove_nextFile();
15-
};
15+
};
1616
if(this.remove_previousFile) {
1717
this.remove_previousFile();
18-
};
18+
};
1919
},
2020
previousFile: function(){
2121
this.changeFile({ direction: 'prev' });
@@ -24,17 +24,17 @@ const FileList = React.createClass({
2424
this.changeFile({ direction: 'next' });
2525
},
2626
changeFile: function(move) {
27-
const space = this.props.workspace;
28-
const filename = space.filename.deref();
27+
const { workspace, loadFile } = this.props;
28+
const filename = workspace.filename.deref();
2929

30-
space.directory.forEach(function(x, i) {
30+
workspace.directory.forEach(function(x, i) {
3131
if(x.get('name') === filename) {
32-
if(i === space.directory.size - 1) {
32+
if(i === workspace.directory.size - 1) {
3333
i = -1;
3434
}
3535
const shift = move.direction === 'prev' ? i - 1 : i + 1;
36-
const switchFile = space.directory.getIn([shift, 'name']);
37-
space.loadFile(switchFile);
36+
const switchFile = workspace.directory.getIn([shift, 'name']);
37+
loadFile(switchFile);
3838
}
3939
});
4040
},

plugins/sidebar/file-operations.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ const FileOperations = React.createClass({
4040
.catch(this.handleError);
4141
},
4242
createFile: function(name){
43-
const space = this.props.workspace;
44-
const overlay = this.props.overlay;
43+
const { workspace, overlay, loadFile } = this.props;
4544

4645
if(!name){
4746
return;
4847
}
4948

50-
space.filename.update(() => name);
51-
space.current.update(() => '');
49+
workspace.filename.update(() => name);
50+
workspace.current.update(() => '');
5251
// TODO: these should transparently accept cursors for all non-function params
53-
space.saveFile(space.filename.deref(), space.current)
54-
.tap(() => this.handleSuccess(`'${name}' created successfully`))
52+
workspace.saveFile(workspace.filename.deref(), workspace.current)
53+
.tap(() => loadFile(name, () => this.handleSuccess(`'${name}' created successfully`)))
5554
.catch(this.handleError)
5655
.finally(overlay.hide);
5756
},
@@ -160,10 +159,10 @@ const FileOperations = React.createClass({
160159
componentWillUnmount: function(){
161160
if(this.remove_saveFile) {
162161
this.remove_saveFile();
163-
};
162+
};
164163
if(this.remove_closeDialog) {
165164
this.remove_closeDialog();
166-
};
165+
};
167166
},
168167
render: function(){
169168
return (

plugins/sidebar/file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const styles = require('./styles');
77

88
const File = React.createClass({
99
openFile: function(filename){
10-
const space = this.props.workspace;
11-
space.loadFile(filename);
10+
const { loadFile, config } = this.props;
11+
loadFile(filename);
1212
},
1313
render: function(){
1414
const { filename, temp } = this.props;

plugins/sidebar/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const File = require('./file');
99
const FileOperations = require('./file-operations');
1010
const ProjectOperations = require('./project-operations');
1111

12+
function noop(){}
13+
1214
function sidebar(app, opts, done){
1315

1416
const space = app.workspace;
@@ -18,27 +20,45 @@ function sidebar(app, opts, done){
1820
const logger = app.logger;
1921
const irken = app;
2022

23+
function loadFile(filename, cb = noop){
24+
if(filename){
25+
space.loadFile(filename, (err) => {
26+
if(err){
27+
cb(err);
28+
return;
29+
}
30+
31+
userConfig.set('last-file', filename);
32+
33+
cb();
34+
});
35+
} else {
36+
cb();
37+
}
38+
}
39+
2140
app.view('sidebar', function(el, cb){
2241
console.log('sidebar render');
2342
const directory = space.directory;
2443

2544
const Component = (
2645
<Sidebar>
2746
<ProjectOperations workspace={space} overlay={overlay} config={userConfig} />
28-
<FileList workspace={space}>
47+
<FileList workspace={space} loadFile={loadFile}>
2948
<ListItem icon="folder" disableRipple>{space.cwd.deref()}</ListItem>
30-
{directory.map((file) => <File key={file.get('name')} workspace={space} filename={file.get('name')} temp={file.get('temp')} />)}
49+
{directory.map((file) => <File key={file.get('name')} filename={file.get('name')} temp={file.get('temp')} loadFile={loadFile} />)}
3150
</FileList>
32-
<FileOperations workspace={space} overlay={overlay} toast={toast} irken={irken} logger={logger} />
51+
<FileOperations workspace={space} overlay={overlay} toast={toast} irken={irken} logger={logger} loadFile={loadFile} />
3352
</Sidebar>
3453
);
3554

3655
React.render(Component, el, cb);
3756
});
3857

3958
const cwd = userConfig.get('cwd') || opts.defaultProject;
59+
const lastFile = userConfig.get('last-file');
4060

41-
space.changeDir(cwd, done);
61+
space.changeDir(cwd, () => loadFile(lastFile, done));
4262
}
4363

4464
module.exports = sidebar;

0 commit comments

Comments
 (0)