Browse Source

1.auto change file name
2.add new post menu
3.add cancle scroll together

zhuzhuyule 8 years ago
parent
commit
79b4d303da

+ 121 - 57
app/moe-action.js

@@ -30,43 +30,77 @@ let lastDir = '';
 
 class MoeditorAction {
     static openNew() {
-        moeApp.open();
+        let windows = require('electron').BrowserWindow.getAllWindows();
+        let w, i;
+        for (i = windows.length - 1; i > -1; i--) {
+            w = windows[i];
+            if (w.moeditorWindow && !w.moeditorWindow.changed) {
+                w.focus();
+                break;
+            }
+        }
+        if (i < 0)
+            moeApp.open();
     }
+
     static openNewHexo() {
+        let notOpened = false;
         try {
             let hexoDir = moeApp.config.get('hexo-root-dir');
-            let templateFile = path.resolve(hexoDir,'scaffolds','post.md');
+            let templateFile = path.resolve(hexoDir, 'scaffolds', 'post.md');
             let content = '' +
                 '---\n' +
                 'title: {{ title }}\n' +
                 'date: {{ date }}\n' +
                 'categories: \n' +
-                'tags: \n'
+                'tags: \n' +
                 '---';
-            let nowDate = moment().format('YYYY-MM-DD HH:mm:ss');
-            if (fs.existsSync(templateFile)){
-                content = fs.readFileSync(templateFile).toString()
-                    .replace(/title:\s+\{\{[^\}]+\}\}/,'title: '+ nowDate.replace(/[-: ]/g,''))
-                    .replace(/date:\s+/,'date: '+  nowDate)
-                    .replace(/\{\{[^\}]+\}\}/g,'');
-            }
-            let fileDir = path.resolve(hexoDir,'source','_posts');
 
-            if (fs.statSync(fileDir).isDirectory()){
+            let fileDir = path.resolve(hexoDir, 'source', '_posts');
+            if (fs.statSync(fileDir).isDirectory()) {
+                let nowDate, fileName, count = 0;
+                do {
+                    nowDate = moment().format('YYYY-MM-DD HH:mm:ss');
+                    if (count > 0)
+                        nowDate = nowDate + count;
+                    count += 1;
+                    fileName = path.resolve(fileDir, nowDate.replace(/[-: ]/g, '') + '.md');
+                    if (count > 50) {
+                        break;
+                    }
+                } while (fs.existsSync(fileName))
+                if (fs.existsSync(templateFile)) {
+                    content = fs.readFileSync(templateFile).toString()
+                        .replace(/title:\s+\{\{[^\}]+\}\}/, 'title: ' + nowDate.replace(/[-: ]/g, ''))
+                        .replace(/date:\s+/, 'date: ' + nowDate)
+                        .replace(/\{\{[^\}]+\}\}/g, '');
+                }
+
                 lastDir = fileDir;
-                let fileName = path.resolve(fileDir,nowDate.replace(/[-: ]/g,'')+'.md');
                 MoeditorFile.write(fileName, content);
-                if (fs.existsSync(fileName)){
-                    moeApp.addRecentDocument(fileName);
-                    moeApp.open(fileName);
-                } else {
-                    moeApp.open();
+                if (fs.existsSync(fileName)) {
+                    let w = require('electron').BrowserWindow.getFocusedWindow();
+                    if (typeof w.moeditorWindow == 'undefined' || w.moeditorWindow.changed) {
+                        app.addRecentDocument(fileName);
+                        moeApp.open(fileName);
+                    } else {
+                        w.moeditorWindow.fileName = fileName;
+                        w.moeditorWindow.directory = lastDir;
+                        w.moeditorWindow.fileContent = w.moeditorWindow.content = MoeditorFile.read(fileName).toString();
+                        w.moeditorWindow.changed = false;
+                        w.moeditorWindow.window.setDocumentEdited(false);
+                        w.moeditorWindow.window.setRepresentedFilename(w.moeditorWindow.fileName);
+                        w.moeditorWindow.window.webContents.send('refresh-editor', {});
+                        app.addRecentDocument(fileName);
+                    }
+                    notOpened = false;
                 }
-            }else {
-                moeApp.open();
             }
         } catch (e) {
-            moeApp.open();
+            console.log(e)
+        } finally {
+            if (notOpened)
+                moeApp.open();
         }
     }
 
@@ -76,38 +110,44 @@ class MoeditorAction {
                 defaultPath: lastDir,
                 properties: ['openFile'/*, 'multiSelections'*/],
                 filters: [
-                    { name: __("Markdown Documents"), extensions: [ 'md', 'mkd', 'markdown' ] },
-                    { name: __("All Files"), extensions: [ '*' ] }
+                    {name: __("Markdown Documents"), extensions: ['md', 'mkd', 'markdown']},
+                    {name: __("All Files"), extensions: ['*']}
                 ]
             }
         );
 
         if (typeof files == 'undefined') return;
-        // for (var file of files) {
-        //     app.addRecentDocument(file);
-        //     moeApp.open(file);
-        // }
         let filename = files[0];
         if (filename) {
-            let w = require('electron').BrowserWindow.getFocusedWindow();
-            lastDir = path.dirname(filename);
-
-            if (typeof w.moeditorWindow == 'undefined' || w.moeditorWindow.changed ) {
+            let windows = require('electron').BrowserWindow.getAllWindows();
+            let w, i;
+            for (i = windows.length - 1; i > -1; i--) {
+                w = windows[i];
+                if (w.moeditorWindow) {
+                    if (w.moeditorWindow.fileName == filename) {
+                        w.focus();
+                        break;
+                    } else if (w.moeditorWindow.fileName == '' && !w.moeditorWindow.changed) {
+                        try {
+                            w.moeditorWindow.fileName = filename;
+                            w.moeditorWindow.directory = lastDir;
+                            w.moeditorWindow.fileContent = w.moeditorWindow.content = MoeditorFile.read(filename).toString();
+                            w.moeditorWindow.changed = false;
+                            w.moeditorWindow.window.setDocumentEdited(false);
+                            w.moeditorWindow.window.setRepresentedFilename(w.moeditorWindow.fileName);
+                            w.moeditorWindow.window.webContents.send('refresh-editor', {});
+                            app.addRecentDocument(filename);
+                            w.focus();
+                            break;
+                        } catch (e) {
+                            console.log(e);
+                        }
+                    }
+                }
+            }
+            if (i < 0) {
                 app.addRecentDocument(filename);
                 moeApp.open(filename);
-            } else {
-                try {
-                    w.moeditorWindow.fileName = filename;
-                    w.moeditorWindow.directory = lastDir;
-                    w.moeditorWindow.fileContent = w.moeditorWindow.content = MoeditorFile.read(filename).toString();
-                    w.moeditorWindow.changed = false;
-                    w.moeditorWindow.window.setDocumentEdited(false);
-                    w.moeditorWindow.window.setRepresentedFilename(w.moeditorWindow.fileName);
-                    w.moeditorWindow.window.webContents.send('refresh-editor', {});
-                    moeApp.addRecentDocument(filename);
-                } catch (e) {
-
-                }
             }
         }
     }
@@ -125,10 +165,16 @@ class MoeditorAction {
                 w.moeditorWindow.changed = false;
                 w.moeditorWindow.window.setDocumentEdited(false);
                 w.moeditorWindow.window.setRepresentedFilename(w.moeditorWindow.fileName);
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'success', content: __('Saved successfully.') });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'success',
+                    content: __('Saved successfully.')
+                });
                 moeApp.addRecentDocument(w.moeditorWindow.fileName);
             } catch (e) {
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'error', content: __('Can\'t save file') + ', ' + e.toString() });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'error',
+                    content: __('Can\'t save file') + ', ' + e.toString()
+                });
                 console.log('Can\'t save file: ' + e.toString());
                 return false;
             }
@@ -144,8 +190,8 @@ class MoeditorAction {
             {
                 defaultPath: lastDir,
                 filters: [
-                    { name: __("Markdown Documents"), extensions: ['md', 'mkd', 'markdown' ] },
-                    { name: __("All Files"), extensions: [ '*' ] }
+                    {name: __("Markdown Documents"), extensions: ['md', 'mkd', 'markdown']},
+                    {name: __("All Files"), extensions: ['*']}
                 ]
             }
         );
@@ -160,10 +206,16 @@ class MoeditorAction {
             moeApp.addRecentDocument(fileName);
             w.moeditorWindow.window.setDocumentEdited(false);
             w.moeditorWindow.window.setRepresentedFilename(fileName);
-            w.moeditorWindow.window.webContents.send('pop-message', { type: 'success', content: __('Saved successfully.') });
+            w.moeditorWindow.window.webContents.send('pop-message', {
+                type: 'success',
+                content: __('Saved successfully.')
+            });
             w.moeditorWindow.window.webContents.send('set-title', fileName);
         } catch (e) {
-            w.moeditorWindow.window.webContents.send('pop-message', { type: 'error', content: __('Can\'t save file') + ', ' + e.toString() });
+            w.moeditorWindow.window.webContents.send('pop-message', {
+                type: 'error',
+                content: __('Can\'t save file') + ', ' + e.toString()
+            });
             console.log('Can\'t save file: ' + e.toString());
             return false;
         }
@@ -177,7 +229,7 @@ class MoeditorAction {
             {
                 defaultPath: lastDir,
                 filters: [
-                    { name: __("HTML Documents"), extensions: ['html', 'htm'] },
+                    {name: __("HTML Documents"), extensions: ['html', 'htm']},
                 ]
             }
         );
@@ -186,12 +238,18 @@ class MoeditorAction {
 
         f((s) => {
             try {
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'info', content: __('Exporting as HTML, please wait ...') });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'info',
+                    content: __('Exporting as HTML, please wait ...')
+                });
                 MoeditorFile.write(fileName, s);
                 const {shell} = require('electron');
                 shell.openItem(fileName);
             } catch (e) {
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'error', content: __('Can\'t export as HTML') + ', ' + e.toString() });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'error',
+                    content: __('Can\'t export as HTML') + ', ' + e.toString()
+                });
                 console.log('Can\'t export as HTML: ' + e.toString());
             }
         });
@@ -205,7 +263,7 @@ class MoeditorAction {
             {
                 defaultPath: lastDir,
                 filters: [
-                    { name: __("PDF Documents"), extensions: ['pdf'] },
+                    {name: __("PDF Documents"), extensions: ['pdf']},
                 ]
             }
         );
@@ -214,13 +272,19 @@ class MoeditorAction {
 
         f((s) => {
             let errorHandler = (e) => {
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'error', content: __('Can\'t export as PDF') + ', ' + e.toString() });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'error',
+                    content: __('Can\'t export as PDF') + ', ' + e.toString()
+                });
                 console.log('Can\'t export as PDF: ' + e.toString());
             }
             try {
-                w.moeditorWindow.window.webContents.send('pop-message', { type: 'info', content: __('Exporting as PDF, please wait ...') });
+                w.moeditorWindow.window.webContents.send('pop-message', {
+                    type: 'info',
+                    content: __('Exporting as PDF, please wait ...')
+                });
                 const exportPDF = require('./moe-pdf');
-                exportPDF({ s: s, path: fileName }, errorHandler);
+                exportPDF({s: s, path: fileName}, errorHandler);
             } catch (e) {
                 errorHandler(e);
             }

+ 1 - 0
app/moe-config-default.js

@@ -40,6 +40,7 @@ module.exports = {
     'render-theme': 'GitHub',
     'custom-render-themes': {},
     'custom-csss': {},
+    'editor-ShowLineNumber': false,
     'hexo-auto-setting': false,
     'hexo-config-enable': false,
     'hexo-config': '',

+ 9 - 0
app/moe-l10n.js

@@ -103,6 +103,7 @@ const strings = {
         "_name": "English",
 
         "New": "New",
+        "New Post": "New Post",
         "Open": "Open",
         "Save": "Save",
         "Save as": "Save as",
@@ -164,7 +165,11 @@ const strings = {
         "Render Theme": "Render Theme",
         "Custom CSSs": "Custom CSSs",
 
+
+        "Def Show Number": "Default Show Line Number",
         "Show Number": "Show Line Number",
+        "Scroll Sync": "Scroll Sync",
+        "File Rename": "File Rename",
         "Hexo Auto": "Auto Hexo Setting",
         "Hexo": "Hexo",
         "Extend Highlight": "Extend Highlight",
@@ -213,6 +218,7 @@ const strings = {
         "_name": "简体中文",
 
         "New": "新建",
+        "New Post": "新建Post",
         "Open": "打开",
         "Save": "保存",
         "Save as": "另存为",
@@ -273,7 +279,10 @@ const strings = {
         "Render Theme": "渲染主题",
         "Custom CSSs": "自定义 CSS",
 
+        "Def Show Number": "默认显示行号",
         "Show Number": "显示行号",
+        "Scroll Sync": "同步滚动",
+        "File Rename": "同步文件名",
         "Hexo Auto": "Hexo自动设置",
         "Hexo": "Hexo",
         "Extend Highlight": "自定义代码块",

+ 1 - 1
app/moe-menu.js

@@ -30,7 +30,7 @@ module.exports = (cb) => {
                     }
                 },
                 {
-                    localize() { this.label = 'New Hexo'; },
+                    localize() { this.label = __('New Post'); },
                     accelerator: 'Command + H',
                     click(item, w) {
                         cb.fileNewHexo(w);

+ 4 - 1
app/moe-window.js

@@ -82,10 +82,13 @@ class MoeditorWindow {
                 if (choice == 0) {
                     if (!MoeditorAction.save(this.window))
                         e.preventDefault();
+                        return;
                 } else if (choice == 2) {
-                    e.preventDefault() ;
+                    e.preventDefault();
+                    return;
                 }
             }
+
             const index = moeApp.windows.indexOf(this);
             if (index !== -1) moeApp.windows.splice(index, 1);
 

+ 8 - 8
views/main/index.html

@@ -101,7 +101,6 @@
         <script type="text/javascript" src="main/moe-mode.js"></script>
         <script type="text/javascript" src="main/moe-export.js"></script>
         <script type="text/javascript" src="main/moe-popmessage.js"></script>
-        <script type="text/javascript" src="main/moe-watchfile.js"></script>
         <script type="text/javascript" src="main/moe-contextmenu.js"></script>
 
         <script type="text/javascript" src="moe-localize.js"></script>
@@ -119,7 +118,7 @@
             <div id="logo">HexoEditor</div>
             <ul>
                 <li data-action="new" class="l10n">New</li>
-                <li data-action="newhexo" >New Hexo</li>
+                <li data-action="newhexo" class="l10n">New Post</li>
                 <li data-action="open" class="l10n">Open</li>
                 <li data-action="save" class="l10n">Save</li>
                 <li data-action="save-as" class="l10n">Save as</li>
@@ -179,12 +178,12 @@
                     <div class="button-bottom l10n-title" id="button-bottom-menu" title="Menu">
                         <i class="fa fa-bars" aria-hidden="true"></i>
                     </div>
-                    <div class="button-bottom l10n-title"  title="Refresh" onclick="location.reload(true)">
-                        <i class="fa fa-refresh" aria-hidden="true"></i>
-                    </div>
-                    <!--div class="button-bottom l10n-title" id="button-bottom-file-tree" title="Directory">
-                        <i class="fa fa-folder-o" aria-hidden="true"></i>
-                    </div-->
+                    <!--<div class="button-bottom l10n-title"  title="Refresh" onclick="location.reload(true)">-->
+                        <!--<i class="fa fa-refresh" aria-hidden="true"></i>-->
+                    <!--</div>-->
+                    <!--<div class="button-bottom l10n-title" id="button-bottom-file-tree" title="Directory">-->
+                        <!--<i class="fa fa-folder-o" aria-hidden="true"></i>-->
+                    <!--</div>-->
                 </div>
                 <div id="cover-bottom-right">
                     <script type="text/javascript">
@@ -192,6 +191,7 @@
                             var modeMenu = document.getElementById('popup-menu-mode');
                             var modeMenuItems = modeMenu.getElementsByTagName('li');
                             modeMenuItems[index].click();
+                            window.updatePreview(true);
                         }
                     </script>
 

+ 33 - 0
views/main/moe-contextmenu.js

@@ -79,6 +79,39 @@ document.addEventListener('DOMContentLoaded', () => {
                             sel.addRange(rg);
                         }
                     }
+                },
+                {
+                    type: 'separator'
+                },
+                {
+                    label: __('File Rename'),
+                    visible: !moeApp.defTheme,
+                    click(item, w) {
+                        window.changeFileName(true);
+                    }
+                },
+                {
+                    label: __('Show Number'),
+                    type: 'checkbox',
+                    checked: window.editor.getOption('lineNumbers'),
+                    click(item, w) {
+                        let editor = document.querySelector('#editor');
+                        if (item.checked){
+                            editor.classList.add('gutter');
+                        } else {
+                            editor.classList.remove('gutter')
+                        }
+                        window.editor.setOption('lineNumbers', item.checked);
+                        window.editor.refresh();
+                    }
+                },
+                {
+                    label: __('Scroll Sync'),
+                    type: 'checkbox',
+                    checked: window.scrollTogether,
+                    click(item, w) {
+                        window.scrollTogether = !window.scrollTogether;
+                    }
                 }
             ];
             Menu.buildFromTemplate(template).popup(remote.getCurrentWindow());

+ 127 - 4
views/main/moe-document.js

@@ -24,16 +24,26 @@ window.moeApp = app.moeApp;
 window.w = moeApp.newWindow;
 require('electron-titlebar');
 
+let gSavedContent;
+let gTitle;
+let gIsChangeFile = false;
+
 $(() => {
+    const fs = require('fs');
+    const path = require('path');
+    const dialog = require('electron').remote.dialog;
+    const YMAL = require('yamljs');
+
+
     const MoeditorPreview = require('./moe-preview');
 
     if (w.fileName !== '') {
-        document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + require('path').basename(w.fileName);
+        document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + path.basename(w.fileName);
     }
     document.querySelector('#editor textarea').innerText = w.content;
 
     var editor = CodeMirror.fromTextArea(document.querySelector('#editor textarea'), {
-        lineNumbers: true,
+        lineNumbers: false,
         mode: moeApp.config.get('math') ? 'gfm_math' : 'gfm',
         matchBrackets: true,
         theme: moeApp.config.get('editor-theme'),
@@ -62,16 +72,86 @@ $(() => {
         });
     };
 
+    window.changeFileName = (force)=> {
+        if( gIsChangeFile && !force) return;
+
+        let title,fileNameNew;
+        let filename = path.basename(w.fileName,path.extname(w.fileName));
+
+        w.content.replace(/^---+([\w\W]+?)---+/, function () {
+            title = YMAL.parse(arguments[1]).title;
+            return '';
+        });
+
+        if (!gTitle) {
+            if (filename == title) {
+                gTitle = title;
+                gIsChangeFile = false;
+                return;
+            }
+        }
+
+        if (!force && !gIsChangeFile && title === gTitle) {
+            return
+        }
+
+        try {
+            filename = title.toString().replace(/[ \\\/:\*\?"<>\|]+/g,'-');
+            let dir = path.dirname(w.fileName);
+            let ext = path.extname(w.fileName);
+            let count = -1;
+            do {
+                count++;
+                fileNameNew = filename + (count > 0 ? count:'');
+                fileNameNew = path.resolve(dir, fileNameNew + ext);
+                if (w.fileName == fileNameNew || count > 50) {
+                    return;
+                }
+            } while (fs.existsSync(fileNameNew))
+
+            fs.renameSync(w.fileName,fileNameNew);
+            gIsChangeFile = true;
+            w.fileName = fileNameNew;
+            w.window.setRepresentedFilename(fileNameNew);
+            app.addRecentDocument(fileNameNew);
+            document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + path.basename(fileNameNew);
+        } catch (e) {
+            console.log(e);
+        }
+    }
+
+    window.autoSave = ()=> {
+        const option = moeApp.config.get('auto-save');
+        if (option === 'disabled') return;
+        if (w.content === gSavedContent) return;
+
+        fs.writeFile(w.fileName, w.content, (err) => {
+            if (err) {
+                w.changed = true;
+                w.window.setDocumentEdited(true);
+                return;
+            }
+            gSavedContent = w.content;
+            w.changed = false;
+            w.window.setDocumentEdited(false);
+        });
+    }
+
     editor.on('change', (editor, obj) => {
         window.updatePreview(false)
     });
 
+    editor.on('blur',() => {
+        if (w.fileName === '') return;
+        window.changeFileName(false);
+        window.autoSave();
+    });
+
     setTimeout(() => {
         window.updatePreview(true);
     }, 0);
 
     window.editor = editor;
-
     // workaround for the .button is still :hover after maximize window
     $('#cover-bottom .button-bottom').mouseover(function() {
         $(this).addClass('hover');
@@ -122,7 +202,7 @@ $(() => {
     // });
 
     require('electron').ipcRenderer.on('set-title', (e, fileName) => {
-        document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + require('path').basename(fileName);
+        document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + path.basename(fileName);
     });
 
     require('./moe-settings');
@@ -197,4 +277,47 @@ $(() => {
     window.addEventListener('resize',function(){
         $('#right-panel .CodeMirror-vscrollbar div').height(document.getElementById('container-wrapper').scrollHeight);
     })
+
+
+    window.onfocus = (e) => {
+        if (w.fileName === '') return;
+        fs.readFile(w.fileName, (err, res) => {
+            if (err) {
+                w.changed = true;
+                w.window.setDocumentEdited(true);
+                return;
+            }
+            let s = res.toString();
+            if (s !== w.fileContent) {
+                const option = moeApp.config.get('auto-reload');
+                let flag = false;
+                if (option === 'auto') flag = true;
+                else if (option === 'never') flag = false;
+                else {
+                    flag = dialog.showMessageBox(
+                        w.window,
+                        {
+                            type: 'question',
+                            buttons: [__("Yes"), __("No")],
+                            title: __("Confirm"),
+                            message: __("File changed by another program, reload?")
+                        }
+                    ) === 0;
+                }
+
+                w.fileContent = w.content = s;
+
+                if (!flag) {
+                    w.changed = true;
+                    w.window.setDocumentEdited(true);
+                    return;
+                }
+
+                window.editor.setValue(s);
+                w.changed = false;
+                w.window.setDocumentEdited(false);
+                window.updatePreview(true);
+            }
+        });
+    };
 });

+ 2 - 2
views/main/moe-scroll.js

@@ -76,7 +76,7 @@ function checkScrollToBottom(self, other) {
 }
 
 function editorToPreviewer() {
-    if (window.editMode !== 'preview') {
+    if (!window.scrollTogether || window.editMode !== 'preview') {
         window.scrollMap = undefined;
         return;
     }
@@ -90,7 +90,7 @@ function editorToPreviewer() {
 }
 
 function previewerToEditor() {
-    if (window.editMode !== 'preview') {
+    if (!window.scrollTogether || window.editMode !== 'preview') {
         window.scrollMap = undefined;
         return;
     }

+ 12 - 2
views/main/moe-settings.js

@@ -32,19 +32,26 @@ function tryRun(callback, val){
     }
 }
 
+
 function setEditorFont(val) {
     body.setAttribute('settings-editor-font', val);
 }
 
+function setScrollTogether(val) {
+    moeApp.config.set('scroll-Together',val);
+    window.scrollTogether = val;
+}
+
 function setShowLineNumber(val) {
     let editor = document.querySelector('#editor');
     if (val){
-        editor.classList.remove('nogutter');
         editor.classList.add('gutter');
     } else {
         editor.classList.remove('gutter')
-        editor.classList.add('nogutter')
     }
+
+    window.editor.setOption('lineNumbers', !!val);
+    window.editor.refresh();
 }
 
 function setEditorTheme(val) {
@@ -181,6 +188,7 @@ function setCustomCSSs(val) {
 
 tryRun(setEditorFont, moeApp.config.get('editor-font'));
 tryRun(setShowLineNumber, !!moeApp.config.get('editor-ShowLineNumber'));
+tryRun(setScrollTogether, moeApp.config.get('scroll-Together'));
 tryRun(setEditorTheme, moeApp.config.get('editor-theme'));
 tryRun(setEditorFontSize, moeApp.config.get('editor-font-size'));
 tryRun(setEditorLineHeight, moeApp.config.get('editor-line-height'));
@@ -210,6 +218,8 @@ ipcRenderer.on('setting-changed', (e, arg) => {
         tryRun(setEditorFont, arg.val);
     } else if (arg.key === 'editor-ShowLineNumber') {
         tryRun(setShowLineNumber, arg.val);
+    } else if (arg.key === 'scroll-Together') {
+        tryRun(setScrollTogether, arg.val);
     } else if (arg.key === 'editor-theme') {
         tryRun(setEditorTheme, arg.val);
     } else if (arg.key === 'editor-font-size') {

+ 37 - 7
views/main/moe-style.css

@@ -75,8 +75,8 @@ html, body {
 #side-menu li {
     font-family: Roboto, Helvetica, 'Segoe UI', Arial, sans-serif;;
     list-style-type: none;
-    height: 50px;
-    line-height: 50px;
+    height: 40px;
+    line-height: 40px;
     padding-left: 30px;
     text-align: left;
     vertical-align: middle;
@@ -512,16 +512,46 @@ body[settings-mode=read] #drag-right, body[settings-mode=write] #drag-right {
 /*}*/
 
 
+/*.CodeMirror-gutter-wrapper {*/
+    /*display: none;*/
+/*}*/
+
+
+/*#editor.nogutter .CodeMirror-sizer {*/
+    /*margin-left: 0 !important;*/
+/*}*/
+
+/*#editor.gutter .CodeMirror-gutter-wrapper {*/
+    /*display: block;*/
+    /*position: absolute;*/
+    /*z-index: 4;*/
+    /*background: none !important;*/
+    /*border: none !important;*/
+/*}*/
+
+/*#editor.gutter .CodeMirror-code {*/
+    /*box-shadow: inset 3px -2px 3px #ddd;*/
+    /*padding-bottom: 3px;*/
+/*}*/
+
+/*#editor.gutter .CodeMirror-code::after {*/
+    /*content: "";*/
+    /*position: relative;*/
+    /*bottom: -3px;*/
+    /*height: 4px;*/
+    /*width: 100%;*/
+    /*background-color: whitesmoke;*/
+    /*display: block;*/
+/*}*/
+
+
+
 .CodeMirror-gutter-wrapper {
     display: none;
 }
 
 
-#editor.nogutter .CodeMirror-sizer {
-    margin-left: 0 !important;
-}
-
-#editor.gutter .CodeMirror-gutter-wrapper {
+#editor .CodeMirror-gutter-wrapper {
     display: block;
     position: absolute;
     z-index: 4;

+ 0 - 88
views/main/moe-watchfile.js

@@ -1,88 +0,0 @@
-/*
-*  This file is part of Moeditor.
-*
-*  Copyright (c) 2016 Menci <huanghaorui301@gmail.com>
-*
-*  Moeditor is free software: you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation, either version 3 of the License, or
-*  (at your option) any later version.
-*
-*  Moeditor is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  You should have received a copy of the GNU General Public License
-*  along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-'use strict';
-
-let savedContent;
-
-document.addEventListener('DOMContentLoaded', () => {
-    const fs = require('fs');
-    const dialog = require('electron').remote.dialog;
-
-    window.onfocus = (e) => {
-        if (w.fileName === '') return;
-        fs.readFile(w.fileName, (err, res) => {
-            if (err) {
-                w.changed = true;
-                w.window.setDocumentEdited(true);
-                return;
-            }
-            let s = res.toString();
-            if (s !== w.fileContent) {
-                const option = moeApp.config.get('auto-reload');
-                let flag = false;
-                if (option === 'auto') flag = true;
-                else if (option === 'never') flag = false;
-                else {
-                    flag = dialog.showMessageBox(
-                        w.window,
-                        {
-                            type: 'question',
-                            buttons: [__("Yes"), __("No")],
-                            title: __("Confirm"),
-                            message: __("File changed by another program, reload?")
-                        }
-                    ) === 0;
-                }
-
-                w.fileContent = w.content = s;
-
-                if (!flag) {
-                    w.changed = true;
-                    w.window.setDocumentEdited(true);
-                    return;
-                }
-
-                window.editor.setValue(s);
-                w.changed = false;
-                w.window.setDocumentEdited(false);
-                window.updatePreview(true);
-            }
-        });
-    };
-
-    window.onblur = () => {
-        const option = moeApp.config.get('auto-save');
-        if (option === 'disabled') return;
-        if (w.fileName === '') return;
-        if (w.content === savedContent) return;
-
-        fs.writeFile(w.fileName, w.content, (err) => {
-            if (err) {
-                w.changed = true;
-                w.window.setDocumentEdited(true);
-                return;
-            }
-
-            savedContent = w.content;
-            w.changed = false;
-            w.window.setDocumentEdited(false);
-        });
-    };
-});

+ 1 - 1
views/settings/settings.html

@@ -105,7 +105,7 @@
                     <div class="panel" data-tab="edit">
                         <table width="80%" align="center">
                             <tr>
-                                <td width="40%" class="l10n" >Show Number</td>
+                                <td width="40%" class="l10n" >Def Show Number</td>
                                 <td width="60%">
                                     <input class="settings-item"  type="checkbox" data-key="editor-ShowLineNumber">
                                 </td>