Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filebrowser Component #132

Merged
merged 2 commits into from
Apr 1, 2016
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
5 changes: 4 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"jquery-fullscreen": "~1.1.4",
"cjs": "*",
"ace": "~1.2.2",
"browserfs": "0.5.8"
"browserfs": "0.5.8",
"ace": "~1.2.2",
"bootstrap-contextmenu": "^0.3.4",
"bootbox.js": "^4.4.0"
},
"devDependencies": {},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions gulp-tasks/build-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const requireJsOptimizerFilesConfig = [
'components/vm-state-label/vm-state-label',
'components/compiler-state-label/compiler-state-label',
'components/not-found-page/not-found-page',
'components/file-browser/file-browser',
'ace/mode/c_cpp',
'ace/theme/monokai',
'ace/theme/terminal',
Expand Down
7 changes: 6 additions & 1 deletion src/app/require.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ require.config({
"FileSaver": "bower_modules/FileSaver/FileSaver.min", // exports window global "saveAs"
"Blob": "bower_modules/Blob/Blob", // exports window global "Blob"
"browserfs": "bower_modules/browserfs/dist/browserfs.min",
"bootstrap-contextmenu":"bower_modules/bootstrap-contextmenu/bootstrap-contextmenu",
"bootbox": "bower_modules/bootbox.js/bootbox",


// Application-specific modules
"app/config": "app/config/config.dev" // overridden to 'config.dist' in build config
Expand All @@ -38,7 +41,9 @@ require.config({
"jquery-ui": { deps: ["jquery"] },
"jquery-ui-layout": { deps: ["jquery", "jquery-ui"] },
"jquery-fullscreen": { deps: ["jquery"] },
"typeahead-jquery": { deps: ["jquery"] }
"typeahead-jquery": { deps: ["jquery"] },
"bootbox": { deps: ["jquery"] },
"bootstrap-contextmenu": { deps: ["bootstrap"] }
},
packages: [
{
Expand Down
1 change: 1 addition & 0 deletions src/app/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ko.components.register('playground-footer', { require: 'components/playground-fo
ko.components.register('vm-state-label', { require: 'components/vm-state-label/vm-state-label' });
ko.components.register('compiler-state-label', { require: 'components/compiler-state-label/compiler-state-label' });
ko.components.register('not-found-page', { require: 'components/not-found-page/not-found-page' });
ko.components.register('file-browser', { require: 'components/file-browser/file-browser' });
// [Scaffolded component registrations will be inserted here. To retain this feature, don't remove this comment.]

// Start the application
Expand Down
5 changes: 5 additions & 0 deletions src/app/sys-global-observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ export var gccErrorCount = ko.observable(0);
export var gccWarningCount = ko.observable(0);
export var editorAnnotations = ko.observableArray([]);

export var currentFileName = ko.observable('untitled');
export var currentFilePath = ko.observable('');

export var projectLicense = ko.observable('');

export var Editor = {};
6 changes: 5 additions & 1 deletion src/components/editor/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
<label class="control-label sr-only" for="editor-font-size">font size (in pixels)</label>
<input data-bind="value: prefs.fontSize" id="editor-font-size" type="number" class="form-control input-sm">
</div>
<div class="col-md-2"></div>
<div class="col-md-2">
<button id="current-code-btn" type="button" class="btn btn-default btn-sm center-block">
<span class="glyphicon glyphicon-file"></span> <span class="file-name" data-bind="text: currentFileName">untitled</span>
</button>
</div>
<div class="col-md-2">
<button id="autoindent-code-btn" type="button" class="btn btn-default btn-sm center-block">
<span class="glyphicon glyphicon-indent-left"></span> Indent code
Expand Down
17 changes: 15 additions & 2 deletions src/components/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'bloodhound';
import TokenHighlighter from 'components/editor/token-highlighter';
import 'Blob';
import 'FileSaver';
import * as SysGlobalObservables from 'app/sys-global-observables';

class Editor {
constructor(params) {
Expand All @@ -18,6 +19,8 @@ class Editor {
prefs.fontSize = params.fontSize;
this.prefs = prefs;

this.currentFileName = SysGlobalObservables.currentFileName;

this.availableThemes = ko.observableArray(['monokai', 'terminal', 'tomorrow', 'xcode']);

this.annotations = params.annotations;
Expand All @@ -42,8 +45,8 @@ class Editor {

$('#download-file-btn').click(() => {
var text = this.getText();
var blob = new Blob([text], {type: 'text/plain;charset=utf-8'});
saveAs(blob, 'program.c');
var blob = new Blob([text]);
saveAs(blob, SysGlobalObservables.currentFileName());
});

$('#autoindent-code-btn').click(() => {
Expand All @@ -54,6 +57,8 @@ class Editor {
$(window).resize(this.resize.bind(this));

params.editorTextGetter(this.getText.bind(this));

SysGlobalObservables.Editor = this;
}

initAce(editorDivId) {
Expand Down Expand Up @@ -227,6 +232,14 @@ class Editor {
return this.aceEditor.getSession().getValue();
}

setFile(path, filename, text) {
var session = this.aceEditor.getSession();

session.setValue(text);

return;
}

resize() {
// We resize after a timeout because when the window resize handler is called,
// the window may not have resized completely, and hence the calculation below would
Expand Down
7 changes: 7 additions & 0 deletions src/components/file-browser/file-browser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="file-browser">
<div id="file-browser-context-menu">
<ul class="dropdown-menu" role="menu">
</ul>
</div>
<div id="file-browser-body"><span class="loading">Loading...</span></div>
</div>
Loading