继上一篇 node webkit 用javascript打造web native之后,终于算是可以做出一个atom编辑器,只是这里是为了记念一下Nokia的Lumia手机,最后代码见https://github.com/gmszone/lumia
# alias to nw alias nw="/Applications/node-webkit.app/Contents/MacOS/node-webkit"应用一下
source ~/.bash_profile启动应用的方式是
nw app.nw启动之前需要
zip -r app.nw *
这样我们就有了一个基本的框架了
https://github.com/zcbenz/nw-sample-apps
也就是node-webkit官网给的示例<body style="background:#fff"> <div class="workspace" background="#fff"> <div class="horizontal"> <div class="vertical"> <div class="panes"> <div class="pane" style="min-width:100%;"> <ul tabindex="-1" class="list-inline tab-bar inset-panel"> <li class="tab active"> <div class="title" id="title">untitled</div> <div class="close-icon"></div> </li> </ul> <div class="editor"> <div id="editor"></div> </div> </div> </div> <div class="status-bar tool-panel panel-bottom"> <div class="flexbox-repaint-hack"> <div class="status-bar-left"> <div class="cursor-position inline-block" id="mode"> </a> <div class="status-image inline-block"> <span class="image-size" style="display: none;"></span> </div> </div> </div> </div> </div> </div> <input style="display:none;" id="newFile" type="file" /> <input style="display:none;" id="openFile" type="file" /> <input style="display:none;" id="saveFile" type="file" nwsaveas /> </div> <div style="display:none"> <button style="display:none;" id="new">New</button> <button style="display:none;" id="open">Open</button> <button style="display:none;" id="save">Save</button> </div> </body>
.tab-bar .tab:before { content:''; position: absolute; top: -1px; left: -16px; height: 26px; width: 30px; border-top-left-radius: 3px; border-left: 1px solid #b9b9b9; box-shadow: inset 1px -1px 1px rgba(0, 0, 0, 0.05); -webkit-transform: skewX(133deg); } .tab-bar:after { content:""; position: absolute; bottom: 0; height: 5px; left: 0px; width: 100%; background-color: #f0f0f0; border-bottom: 1px solid #dddddd; border-top: 1px solid #b9b9b9; }
onload = function() { newButton = document.getElementById("new"); openButton = document.getElementById("open"); saveButton = document.getElementById("save"); newButton.addEventListener("click", handleNewButton); openButton.addEventListener("click", handleOpenButton); saveButton.addEventListener("click", handleSaveButton); $("#saveFile").change(function(evt) { onChosenFileToSave($(this).val()); }); $("#openFile").change(function(evt) { onChosenFileToOpen($(this).val()); }); editor = CodeMirror( document.getElementById("editor"), { lineNumbers: true, keyMap: "sublime", autoCloseBrackets: true, matchBrackets: true, showCursorWhenSelecting: true, extraKeys: { "Cmd-N": function(instance) { handleNewButton() }, "Ctrl-N": function(instance) { handleNewButton() }, "Cmd-O": function(instance) { handleOpenButton() }, "Ctrl-O": function(instance) { handleOpenButton() }, "Cmd-S": function(instance) { handleSaveButton() }, "Ctrl-S": function(instance) { handleSaveButton() }, "Cmd-Shift-P": function(instance) { console.log("hello".green) } } }); newFile(); onresize(); gui.Window.get().show(); };
function handleDocumentChange(title) { var mode = "javascript"; var modeName = "JavaScript"; if (title) { title = title.match(/[^/]+$/)[0]; document.getElementById("title").innerHTML = title; document.title ="Lumia"+title; _.each(m.allmodes, function(modes) { if (S(title).contains(modes["filename"])) { mode = modes["mode"]; modeName = modes["modeName"]; console.log(mode); } }); } else { document.getElementById("title").innerHTML = "[no document loaded]"; } editor.setOption("mode", mode); document.getElementById("mode").innerHTML = modeName; }
var m = require('./allmodes')