Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"frylord": "^0.6.0",
"holovisor": "^0.2.0",
"iggins": "^0.2.1",
"irken": "^0.7.0",
"irken": "^0.7.1",
"lodash": "^3.9.1",
"react": "^0.13.1",
"react-loader": "^1.2.0",
Expand Down
42 changes: 39 additions & 3 deletions plugins/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ require('codemirror/addon/selection/mark-selection');
require('codemirror/lib/codemirror.css');
require('../../assets/theme/parallax.css');

const React = require('react');
const CodeMirror = require('codemirror');
require('./pbasic')(CodeMirror);

const keyExtension = require('./key-extension');

const consoleStore = require('../../src/stores/console');
const editorStore = require('../../src/stores/editor');
const deviceStore = require('../../src/stores/device');
const fileStore = require('../../src/stores/file');

const { handleInput } = require('../../src/actions/editor');
const DocumentsStore = require('../../src/stores/documents');

const React = require('react');
const TransmissionBar = require('./transmission-bar');

const makeToasts = require('../../src/lib/toasts');

function editor(app, opts, done){

var codeEditor;
Expand All @@ -37,9 +42,39 @@ function editor(app, opts, done){
}
}

function highlighter(position, length) {
if(!codeEditor){
return;
}

const doc = codeEditor.getDoc();

const anchor = doc.posFromIndex(position);
const head = doc.posFromIndex(position + length);

doc.setSelection(anchor, head, { scroll: false });

const charRect = codeEditor.charCoords(anchor, 'local');
const halfHeight = codeEditor.getScrollerElement().offsetHeight / 2;
const halfTextHeight = Math.floor((charRect.bottom - charRect.top) / 2);
codeEditor.scrollTo(null, charRect.top - halfHeight - halfTextHeight);
}

consoleStore.listen(refreshConsole);

var space = app.workspace;
const space = app.workspace;
const compile = app.compile.bind(app);
// seems strange to pass highlighter to toasts
// maybe this should be named "handlers" or something
const toasts = makeToasts(app.toast, highlighter);

editorStore.toasts = toasts;
editorStore.compile = compile;
editorStore.workspace = space;

// really stinks to attach these in here
fileStore.toasts = toasts;
deviceStore.toasts = toasts;

app.view('editor', function(el, cb){
console.log('editor render');
Expand Down Expand Up @@ -67,7 +102,8 @@ function editor(app, opts, done){
'Ctrl-Up': false,
'Ctrl-Down': false,
'Tab': false,
'Shift-Tab': false
'Shift-Tab': false,
'Ctrl-T': false
});
keyExtension.setup(app);
editorStore.cm = codeEditor;
Expand Down
8 changes: 8 additions & 0 deletions plugins/editor/key-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { findNext, findPrevious, replace } = require('../../src/actions/find');
const { moveByScrollUpLine, moveByScrollDownLine } = require('../../src/actions/editor-move');
const { dedent, indent } = require('../../src/actions/text-move');
const { print } = require('../../src/actions/system');
const { syntaxCheck } = require('../../src/actions/editor');
const { newFile, saveFile } = require('../../src/actions/file');
const { hideOverlays, showSave, showDownload, showProjects } = require('../../src/actions/overlay');
const { disableAuto, enableAuto } = require('../../src/actions/device');
Expand Down Expand Up @@ -120,6 +121,13 @@ const keyExtension = {
evt.preventDefault();
showProjects();
}
},
syntaxCheck: {
code: ['CTRL_T', 'F7'],
exec(evt){
evt.preventDefault();
syntaxCheck();
}
}
};

Expand Down
7 changes: 2 additions & 5 deletions plugins/overlays/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const overlayStore = require('../../src/stores/overlay');
const projectStore = require('../../src/stores/project');

const { confirmDelete, changeProject, deleteProject } = require('../../src/actions/project');
const { handleError, handleSuccess, deleteFile, saveFileAs } = require('../../src/actions/file');
const { deleteFile, saveFileAs } = require('../../src/actions/file');
const { hideSave, hideDelete, hideDownload, showProjects, hideProjects } = require('../../src/actions/overlay');

function overlays(app, opts, done){
Expand Down Expand Up @@ -61,10 +61,7 @@ function overlays(app, opts, done){
if(showDownloadOverlay){
component = (
<DownloadOverlay
onCancel={hideDownload}
handleSuccess={handleSuccess}
handleError={handleError}
handleComplete={hideDownload} />
onCancel={hideDownload} />
);
}

Expand Down
15 changes: 4 additions & 11 deletions plugins/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ const FileOperations = require('./file-operations');
const ProjectOperations = require('./project-operations');

const deviceStore = require('../../src/stores/device');
const editorStore = require('../../src/stores/editor');
const fileStore = require('../../src/stores/file');

const { loadFile } = require('../../src/actions/file');

const makeToasts = require('../../src/lib/toasts');

function sidebar(app, opts, done){

const space = app.workspace;
const toast = app.toast;
const overlay = app.overlay;
const userConfig = app.userConfig;
const irken = app;
const getBoard = app.getBoard.bind(irken);
const scanBoards = app.scanBoards.bind(irken);
const getBoard = app.getBoard.bind(app);
const scanBoards = app.scanBoards.bind(app);

function refreshDirectory(){
// TODO: expose a method to refresh directory without changing it
Expand Down Expand Up @@ -58,16 +56,11 @@ function sidebar(app, opts, done){

// Store bindings
deviceStore.workspace = space;
deviceStore.toast = toast;
deviceStore.overlay = overlay;
deviceStore.getBoard = getBoard;
deviceStore.scanBoards = scanBoards;

editorStore.workspace = space;

fileStore.workspace = space;
fileStore.userConfig = userConfig;
fileStore.toast = toast;

done();
}
Expand Down
6 changes: 0 additions & 6 deletions plugins/sidebar/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ const styles = {
},
fileHasTemp: {
backgroundColor: red
},
errorToast: {
backgroundColor: red
},
successToast: {
backgroundColor: green
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/actions/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class EditorActions {
handleInput(inst) {
this.dispatch(inst);
}

syntaxCheck(){
this.dispatch();
}
}

module.exports = alt.createActions(EditorActions);
8 changes: 0 additions & 8 deletions src/actions/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ class FileActions {
saveFileAs(name) {
this.dispatch(name);
}

handleError(err) {
this.dispatch(err);
}

handleSuccess(msg) {
this.dispatch(msg);
}
}

module.exports = alt.createActions(FileActions);
47 changes: 47 additions & 0 deletions src/lib/toasts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const red = '#da2100';
const green = '#159600';

const styles = {
errorToast: {
backgroundColor: red
},
successToast: {
backgroundColor: green
}
};

function toasts(api, highlighter){

function success(msg){
api.show(msg, { style: styles.successToast, timeout: 5000 });
}

function error(err){
// leaving this in for better debugging of errors
console.log(err);

api.show(err.message, { style: styles.errorToast });

if(typeof highlighter !== 'function'){
return;
}

if(err && err.errorLength){
highlighter(err.errorPosition, err.errorLength);
}
}

function clear(){
api.clear();
}

return {
success,
error,
clear
};
}

module.exports = toasts;
30 changes: 24 additions & 6 deletions src/stores/device.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const alt = require('../alt');
const _ = require('lodash');

const alt = require('../alt');

const { rx, tx } = require('../actions/transmission');
const { hideDownload, showDownload } = require('../actions/overlay');
const { clearOutput, output } = require('../actions/console');
const { enableAuto, disableAuto, reloadDevices, updateSelected } = require('../actions/device');
const { handleSuccess, handleError } = require('../actions/file');

class DeviceStore {
constructor() {
Expand Down Expand Up @@ -134,7 +134,7 @@ class DeviceStore {
this.setState({ progress: progress });
}

const { workspace, toast, getBoard } = this.getInstance();
const { workspace, getBoard } = this.getInstance();
const { selectedDevice } = this.state;

const name = workspace.filename.deref();
Expand All @@ -155,16 +155,34 @@ class DeviceStore {
.tap(() => clearOutput())
.then(() => board.on('terminal', output))
.then(() => board.on('terminal', rx))
.tap(() => toast.clear())
.tap(() => handleSuccess(`'${name}' downloaded successfully`))
.catch(handleError)
.tap(() => this._handleClear())
.tap(() => this._handleSuccess(`'${name}' downloaded successfully`))
.catch((err) => this._handleError(err))
.finally(() => {
board.removeListener('progress', updateProgress);
this.setState({ progress: 0 });
hideDownload();
});
}

_handleClear(){
const { toasts } = this.getInstance();

toasts.clear();
}

_handleError(err){
const { toasts } = this.getInstance();

toasts.error(err);
}

_handleSuccess(msg){
const { toasts } = this.getInstance();

toasts.success(msg);
}

}

DeviceStore.config = {
Expand Down
35 changes: 33 additions & 2 deletions src/stores/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const alt = require('../alt');

const { findNext, findPrevious, replace } = require('../actions/find');
const { handleInput } = require('../actions/editor');
const { handleInput, syntaxCheck } = require('../actions/editor');
const { moveByScrollUpLine, moveByScrollDownLine } = require('../actions/editor-move');
const { dedent, indent } = require('../actions/text-move');
const { print } = require('../actions/system');
Expand All @@ -20,7 +20,8 @@ class EditorStore {
onMoveByScrollUpLine: moveByScrollUpLine,
onMoveByScrollDownLine: moveByScrollDownLine,
onPrint: print,
onReplace: replace
onReplace: replace,
onSyntaxCheck: syntaxCheck
});

}
Expand Down Expand Up @@ -77,7 +78,37 @@ class EditorStore {

cm.execCommand('replace');
}
onSyntaxCheck() {
const { workspace, compile } = this.getInstance();
const result = compile({
type: 'bs2',
source: workspace.current.deref()
});
if(result.error){
this._handleError(result.error);
} else {
this._handleClear();
this._handleSuccess('Tokenization successful!');
}
}

_handleClear(){
const { toasts } = this.getInstance();

toasts.clear();
}

_handleError(err){
const { toasts } = this.getInstance();

toasts.error(err);
}

_handleSuccess(msg){
const { toasts } = this.getInstance();

toasts.success(msg);
}
}

EditorStore.config = {
Expand Down
Loading