Created
January 22, 2016 00:20
-
-
Save jbasinger/6cb45cf2dd0308be95a8 to your computer and use it in GitHub Desktop.
Meetup 1/21/16 - Checkpoint 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = require('app'); | |
| var BrowserWindow = require('browser-window'); | |
| var ipc = require('electron').ipcMain; | |
| var dialog = require('dialog'); | |
| var fs = require('fs'); | |
| var editorWindow; | |
| app.on('ready', function(){ | |
| editorWindow = new BrowserWindow({ | |
| width: 800, | |
| height: 600 | |
| }); | |
| editorWindow.on('close', function(){ | |
| editorWindow = null; | |
| }); | |
| editorWindow.loadURL('file://' + __dirname + '/main.html'); | |
| editorWindow.show(); | |
| ipc.on('saveFile', function(evt, data, index){ | |
| dialog.showSaveDialog({ | |
| title: 'Save File' | |
| }, function(filename){ | |
| fs.writeFile(filename, data, function(err){ | |
| if(err){ | |
| console.log(err); | |
| return; | |
| } | |
| evt.sender.send('savedFile', filename, index); | |
| }); | |
| }); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html ng-app="editor"> | |
| <head> | |
| <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css"/> | |
| <script src="bower_components/ace-builds/src-min-noconflict/ace.js"></script> | |
| <script src="bower_components/angular/angular.js"></script> | |
| <script src="bower_components/angular-ui-ace/ui-ace.js"></script> | |
| <script src="libs/ui-bootstrap-tpls-1.1.0.min.js"></script> | |
| <script src="browser_files/main.js"></script> | |
| <script src="bower_components/ace-builds/src-min-noconflict/mode-javascript.js"></script> | |
| <script src="bower_components/ace-builds/src-min-noconflict/mode-html.js"></script> | |
| <script> | |
| var AceModes = { | |
| JavaScript: ace.require('ace/mode/javascript').Mode, | |
| HTML: ace.require('ace/mode/html').Mode | |
| }; | |
| </script> | |
| <style> | |
| .ace_editor{ | |
| height: 550px; | |
| } | |
| </style> | |
| </head> | |
| <body ng-controller="main"> | |
| <nav class="navbar nav-default"> | |
| <div class="container-fluid"> | |
| <button type="button" class="btn btn-default navbar-btn" ng-click="newFile()">New</button> | |
| <button type="button" class="btn btn-default navbar-btn" ng-click="saveFile()">Save</button> | |
| </div> | |
| </nav> | |
| <uib-tabset> | |
| <uib-tab ng-repeat="tab in tabs" | |
| heading="{{tab.filename}}" | |
| active="tab.active" | |
| disabled="tab.disabled"> | |
| <div ui-ace ng-model="tab.data"></div> | |
| </uib-tab> | |
| </uib-tabset> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ipc = require('electron').ipcRenderer; | |
| var app = angular.module('editor',['ui.bootstrap','ui.ace']); | |
| app.controller('main',function($scope){ | |
| $scope.tabs = []; | |
| $scope.newFile = function(){ | |
| $scope.tabs.push({ | |
| filename:"untitled", | |
| data: "", | |
| active: true | |
| }); | |
| } | |
| $scope.saveFile = function(){ | |
| $scope.tabs.forEach(function(tab, index){ | |
| if(!tab.active){ | |
| return; | |
| } | |
| ipc.send('saveFile', tab.data, index); | |
| }); | |
| } | |
| ipc.on('savedFile', function(evt, filename, index){ | |
| $scope.$apply(function(){ | |
| var tab = $scope.tabs[index]; | |
| tab.filename = filename; | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment