Skip to content

Commit

Permalink
remove lastfile && fix scroll sync
Browse files Browse the repository at this point in the history
  • Loading branch information
excaliburhan committed Sep 29, 2016
1 parent a32145a commit 953f965
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 37 deletions.
1 change: 0 additions & 1 deletion LittleMD.md

This file was deleted.

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<input style='display: none;' id='pdfFile' type='file' nwsaveas="LittleMD.pdf" />
<input style='display: none;' id='htmlFile' type='file' nwsaveas="LittleMD.html" />
</body>
<script src='/app.js'></script>
<!-- <script src='/node_modules/nw-dev/lib/dev.js' data-ignore='*.json|*.md'></script>
<!-- <script src='/app.js'></script>
<script src='/node_modules/nw-dev/lib/dev.js' data-ignore='*.json|*.md'></script>
<script>
const path = './'
const fs = require('fs')
Expand Down
4 changes: 0 additions & 4 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const fs = require('fs')
const marked = require('marked')
const emojify = require('emojify.js')
const vars = require('./vars.js')
const util = require('./util.js')

const $ = global.$
const hljs = global.hljs
Expand Down Expand Up @@ -81,9 +80,6 @@ module.exports = {
this.loadText(data)
vars.isSaved = true
vars.currentFilePath = filename
util.setSystem({
lastFile: filename,
})
})
},
chooseFile(selector, callback) { // save & export
Expand Down
13 changes: 5 additions & 8 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const tabOverride = require('tabOverride')
const editor = require('./editor.js')
const menu = require('./menu.js')
const qiniuUtil = require('./qiniuUtil.js')
const system = require('../system.json')

const $ = global.$
let scrollTimer = null
Expand All @@ -24,29 +23,27 @@ module.exports = {
const percentage = this.scrollTop / (this.scrollHeight - this.offsetHeight)
other.scrollTop = percentage * (other.scrollHeight - other.offsetHeight)
scrollTimer = setTimeout(() => {
$(other).on('scroll', this.scrollSync)
$(other).on('scroll', module.exports.scrollSync)
editor.checkLine() // line display
}, 150)
},

init() {
menu.initMenu()
$(() => {
// load last open file
if (system.lastFile && fs.existsSync(system.lastFile)) {
editor.loadFile(system.lastFile)
}
// file associations
if (global.gui.App.argv.length > 0) {
// fix path, cut 'file://'
const path = decodeURI(global.gui.App.argv[0].substr(7)) // decodeURI for Chinese
editor.loadFile(path)
if (!fs.statSync(path).isDirectory() && ~path.indexOf('.md')) { // open md file only
editor.loadFile(path)
}
}
// if app is open, trigger loadFile
global.gui.App.on('open', path => {
window.focus()
path = decodeURI(path.substr(7))
if (~path.indexOf('.md')) {
if (!fs.statSync(path).isDirectory() && ~path.indexOf('.md')) {
editor.loadFile(path)
}
})
Expand Down
15 changes: 4 additions & 11 deletions js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,13 @@ module.exports = {
editor.loadText('')
vars.isSaved = false
vars.currentFilePath = null
util.setSystem({
lastFile: null,
})
},
openFile() {
editor.chooseFile('#openFile', filename => {
editor.loadFile(filename)
})
},
saveFile(forceSaveAs) {
saveFile(forceSaveAs, withQuit) {
const editorDom = $('#editor')
if (vars.isSaved && !forceSaveAs) { // do save
fs.writeFile(vars.currentFilePath, editorDom.val(), err => {
Expand All @@ -61,7 +58,7 @@ module.exports = {
} else {
vars.isSaved = true
vars.currentContent = editorDom.val()
// util.showToast(langConf.saveToast)
withQuit && global.gui.App.quit()
}
})
} else { // do saveAs
Expand All @@ -74,10 +71,7 @@ module.exports = {
vars.isSaved = true
vars.currentFilePath = filename
vars.currentContent = editorDom.val()
util.setSystem({
lastFile: filename,
})
// util.showToast(langConf.saveToast)
withQuit && global.gui.App.quit()
}
})
})
Expand Down Expand Up @@ -134,8 +128,7 @@ module.exports = {
if (nowContent !== vars.currentContent) {
const confirm = langConf.closeConfirm
util.showConfirm(confirm.title, confirm.content, () => {
module.exports.saveFile()
global.gui.App.quit()
module.exports.saveFile(null, true)
})
} else {
global.gui.App.quit()
Expand Down
1 change: 0 additions & 1 deletion js/system.json

This file was deleted.

9 changes: 0 additions & 9 deletions js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@
* @util
*/

const path = require('path')
const fs = require('fs')
const system = require('../system.json')
const i18n = require('./i18n.js')

const lang = navigator.language || 'en-US'
const langConf = i18n[lang]

module.exports = {
// set system.json
setSystem(obj) {
const newObj = Object.assign({}, system, obj)
fs.writeFile(path.join(__dirname, './system.json'), JSON.stringify(newObj))
},

// closeDialog
closeDialog() {
$('#dialog').removeClass('show')
Expand Down
1 change: 0 additions & 1 deletion system.json

This file was deleted.

0 comments on commit 953f965

Please sign in to comment.