Skip to content

Commit

Permalink
start session on the last file accessed - closes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 21, 2015
1 parent c5f83ff commit c014ee6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
16 changes: 8 additions & 8 deletions plugins/sidebar/file-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const FileList = React.createClass({
componentWillUnmount: function(){
if(this.remove_nextFile) {
this.remove_nextFile();
};
};
if(this.remove_previousFile) {
this.remove_previousFile();
};
};
},
previousFile: function(){
this.changeFile({ direction: 'prev' });
Expand All @@ -24,17 +24,17 @@ const FileList = React.createClass({
this.changeFile({ direction: 'next' });
},
changeFile: function(move) {
const space = this.props.workspace;
const filename = space.filename.deref();
const { workspace, loadFile } = this.props;
const filename = workspace.filename.deref();

space.directory.forEach(function(x, i) {
workspace.directory.forEach(function(x, i) {
if(x.get('name') === filename) {
if(i === space.directory.size - 1) {
if(i === workspace.directory.size - 1) {
i = -1;
}
const shift = move.direction === 'prev' ? i - 1 : i + 1;
const switchFile = space.directory.getIn([shift, 'name']);
space.loadFile(switchFile);
const switchFile = workspace.directory.getIn([shift, 'name']);
loadFile(switchFile);
}
});
},
Expand Down
15 changes: 7 additions & 8 deletions plugins/sidebar/file-operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@ const FileOperations = React.createClass({
.catch(this.handleError);
},
createFile: function(name){
const space = this.props.workspace;
const overlay = this.props.overlay;
const { workspace, overlay, loadFile } = this.props;

if(!name){
return;
}

space.filename.update(() => name);
space.current.update(() => '');
workspace.filename.update(() => name);
workspace.current.update(() => '');
// TODO: these should transparently accept cursors for all non-function params
space.saveFile(space.filename.deref(), space.current)
.tap(() => this.handleSuccess(`'${name}' created successfully`))
workspace.saveFile(workspace.filename.deref(), workspace.current)
.tap(() => loadFile(name, () => this.handleSuccess(`'${name}' created successfully`)))
.catch(this.handleError)
.finally(overlay.hide);
},
Expand Down Expand Up @@ -160,10 +159,10 @@ const FileOperations = React.createClass({
componentWillUnmount: function(){
if(this.remove_saveFile) {
this.remove_saveFile();
};
};
if(this.remove_closeDialog) {
this.remove_closeDialog();
};
};
},
render: function(){
return (
Expand Down
4 changes: 2 additions & 2 deletions plugins/sidebar/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const styles = require('./styles');

const File = React.createClass({
openFile: function(filename){
const space = this.props.workspace;
space.loadFile(filename);
const { loadFile, config } = this.props;
loadFile(filename);
},
render: function(){
const { filename, temp } = this.props;
Expand Down
28 changes: 24 additions & 4 deletions plugins/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const File = require('./file');
const FileOperations = require('./file-operations');
const ProjectOperations = require('./project-operations');

function noop(){}

function sidebar(app, opts, done){

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

function loadFile(filename, cb = noop){
if(filename){
space.loadFile(filename, (err) => {
if(err){
cb(err);
return;
}

userConfig.set('last-file', filename);

cb();
});
} else {
cb();
}
}

app.view('sidebar', function(el, cb){
console.log('sidebar render');
const directory = space.directory;

const Component = (
<Sidebar>
<ProjectOperations workspace={space} overlay={overlay} config={userConfig} />
<FileList workspace={space}>
<FileList workspace={space} loadFile={loadFile}>
<ListItem icon="folder" disableRipple>{space.cwd.deref()}</ListItem>
{directory.map((file) => <File key={file.get('name')} workspace={space} filename={file.get('name')} temp={file.get('temp')} />)}
{directory.map((file) => <File key={file.get('name')} filename={file.get('name')} temp={file.get('temp')} loadFile={loadFile} />)}
</FileList>
<FileOperations workspace={space} overlay={overlay} toast={toast} irken={irken} logger={logger} />
<FileOperations workspace={space} overlay={overlay} toast={toast} irken={irken} logger={logger} loadFile={loadFile} />
</Sidebar>
);

React.render(Component, el, cb);
});

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

space.changeDir(cwd, done);
space.changeDir(cwd, () => loadFile(lastFile, done));
}

module.exports = sidebar;

0 comments on commit c014ee6

Please sign in to comment.