Selaa lähdekoodia

1.fix close all app faild!
2.fix focus setting or about window
3.UI update

zhuzhuyule 8 vuotta sitten
vanhempi
commit
0baed4cf99

+ 12 - 1
app/moe-about.js

@@ -24,7 +24,10 @@ const {BrowserWindow, ipcMain} = require('electron');
 var aboutWindow;
 
 function showAboutWindow() {
-    if (typeof aboutWindow !== 'undefined') return;
+    if (typeof aboutWindow !== 'undefined') {
+        aboutWindow.focus();
+        return;
+    }
     const debug = (moeApp.flag.debug | moeApp.config.get('debug')) != 0;
     var conf = {
         icon: Const.path + "/icons/HexoEditor.ico",
@@ -50,6 +53,14 @@ function showAboutWindow() {
     })
 }
 
+
+function  closeWindow() {
+    if (typeof aboutWindow !== 'undefined')
+        aboutWindow.close()
+}
+
 ipcMain.on('show-about-window', showAboutWindow);
+ipcMain.on('close-all-window', closeWindow);
+
 
 module.exports = showAboutWindow;

+ 2 - 0
app/moe-app.js

@@ -207,4 +207,6 @@ class MoeditorApplication {
     }
 }
 
+MoeditorApplication.count = 0;
+
 module.exports = MoeditorApplication;

+ 11 - 1
app/moe-settings.js

@@ -24,7 +24,10 @@ const {BrowserWindow, ipcMain} = require('electron');
 let settingsWindow;
 
 function showSettingsWindow() {
-    if (typeof settingsWindow !== 'undefined') return;
+    if (typeof settingsWindow !== 'undefined') {
+        settingsWindow.focus();
+        return;
+    }
     const debug = (moeApp.flag.debug | moeApp.config.get('debug')) != 0;
     const conf = {
         icon: Const.path + "/icons/HexoEditor.ico",
@@ -50,6 +53,13 @@ function showSettingsWindow() {
     })
 }
 
+function  closeWindow() {
+    console.log('close setting')
+    if (typeof settingsWindow !== 'undefined')
+        settingsWindow.close()
+}
+
 ipcMain.on('show-settings-window', showSettingsWindow);
+ipcMain.on('close-all-window', closeWindow);
 
 module.exports = showSettingsWindow;

+ 9 - 3
app/moe-window.js

@@ -80,12 +80,18 @@ class MoeditorWindow {
                 );
 
                 if (choice == 0) {
-                    if (!MoeditorAction.save(this.window)) e.preventDefault();
-                } else if (choice == 2) e.preventDefault();
-            }
+                    if (!MoeditorAction.save(this.window))
+                        e.preventDefault();
+                } else if (choice == 2) {
+                    e.preventDefault() ;
+                }else {
 
+                }
+            }
             const index = moeApp.windows.indexOf(this);
             if (index !== -1) moeApp.windows.splice(index, 1);
+
+            if ( !moeApp.windows.length) app.quit()
         });
     }
 }

+ 1 - 1
package.json

@@ -38,7 +38,7 @@
       "target": [
         {
           "target": "nsis",
-          "arch": ["x64","ia32" ]
+          "arch": ["x64" ]
         }
       ],
       "icon": "icons/HexoEditor.ico"

+ 0 - 0
themes/GitHub/style.css → themes/GitHub/main.css


+ 0 - 0
themes/No Theme/style.css → themes/No Theme/main.css


+ 0 - 0
themes/next/style.css → themes/next/main.css


+ 0 - 1
views/main/hexo/plugins/helper/list_posts.js

@@ -54,5 +54,4 @@ function listPostsHelper(posts, options) {
 
   return result;
 }
-    console.log('list_post');
 module.exports = listPostsHelper;

+ 6 - 1
views/main/moe-document.js

@@ -33,7 +33,7 @@ $(() => {
     document.querySelector('#editor textarea').innerText = w.content;
 
     var editor = CodeMirror.fromTextArea(document.querySelector('#editor textarea'), {
-        lineNumbers: !!moeApp.config.get('editor-ShowLineNumber'),
+        lineNumbers: true,
         mode: moeApp.config.get('math') ? 'gfm_math' : 'gfm',
         matchBrackets: true,
         theme: moeApp.config.get('editor-theme'),
@@ -192,4 +192,9 @@ $(() => {
             rightpanel.appendChild(script);
         }
     }, true);
+
+
+    window.addEventListener('resize',function(){
+        $('#right-panel .CodeMirror-vscrollbar div').height(document.getElementById('container-wrapper').scrollHeight);
+    })
 });

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

@@ -30,8 +30,8 @@ module.exports = {
         const theme = moeApp.config.get('render-theme');
         moeApp.defTheme = ['GitHub','No Theme'].indexOf(theme) > -1;
         let res;
-        if (builtin.includes(theme)) res = path.resolve(app.getAppPath(), 'themes', theme, 'style.css');
-        else res = path.resolve(moeApp.config.get('custom-render-themes')[theme], 'style.css');
+        if (builtin.includes(theme)) res = path.resolve(app.getAppPath(), 'themes', theme, 'main.css');
+        else res = path.resolve(moeApp.config.get('custom-render-themes')[theme], 'main.css');
         if (forURL) res = url.resolve('file://', res);
         return res;
     }

+ 65 - 52
views/main/moe-settings.js

@@ -24,36 +24,27 @@ const fs = require('fs');
 const body = document.body;
 const codemirror = document.querySelector('#editor > .CodeMirror');
 
+function tryRun(callback, val){
+    try{
+        callback(val)
+    } catch (e){
+        console.log(e)
+    }
+}
+
 function setEditorFont(val) {
     body.setAttribute('settings-editor-font', val);
 }
 
 function setShowLineNumber(val) {
-    const editor = document.querySelector('#editor');
-    const scrollpos = editor.querySelector('.CodeMirror-vscrollbar').scrollTop;
-    editor.querySelectorAll('.CodeMirror').forEach(function (i) {
-        editor.removeChild(i);
-    });
-    window.editor = CodeMirror.fromTextArea(editor.querySelector('textarea'), {
-        lineNumbers: val,
-        mode: moeApp.config.get('math') ? 'gfm_math' : 'gfm',
-        matchBrackets: true,
-        theme: moeApp.config.get('editor-theme'),
-        lineWrapping: true,
-        extraKeys: {
-            Enter: 'newlineAndIndentContinueMarkdownList',
-            Home: 'goLineLeft',
-            End: 'goLineRight',
-            'Shift-Tab': 'indentLess'
-        },
-        fixedGutter: false,
-        tabSize: moeApp.config.get('tab-size'),
-        indentUnit: moeApp.config.get('tab-size'),
-        viewportMargin: Infinity,
-        styleActiveLine: true,
-        showCursorWhenSelecting: true
-    });
-    editor.querySelector('.CodeMirror-vscrollbar').scrollTop = scrollpos;
+    let editor = document.querySelector('#editor');
+    if (val){
+        editor.classList.remove('nogutter');
+        editor.classList.add('gutter');
+    } else {
+        editor.classList.remove('gutter')
+        editor.classList.add('nogutter')
+    }
 }
 
 function setEditorTheme(val) {
@@ -64,6 +55,15 @@ function setEditorTheme(val) {
         }
     }
     codemirror.classList.add('cm-s-' + val);
+
+    // let link = document.getElementById('editor-theme');
+    // if (!link) {
+    //     link = document.createElement('link');
+    //     document.head.appendChild(link);
+    //     link.rel = 'stylesheet';
+    //     link.id = 'editor-theme';
+    // }
+    // link.href = path.resolve(path.dirname(path.dirname(require.resolve('codemirror'))), 'theme', val+'.css');
 }
 
 function setEditorFontSize(val) {
@@ -169,7 +169,6 @@ function setTabSize(val) {
 function setCustomCSSs(val) {
     let a = document.getElementsByClassName('link-custom-csss');
     if (a.length !== 0) for (let e of a) e.parentNode.removeChild(e);
-    console.log(val);
     if (Object.getOwnPropertyNames(val).length !== 0) for (let x in val) if (val[x].selected) {
         let link = document.createElement('link');
         link.href = val[x].fileName;
@@ -179,49 +178,63 @@ function setCustomCSSs(val) {
     }
 }
 
-setEditorFont(moeApp.config.get('editor-font'));
-setEditorTheme(moeApp.config.get('editor-theme'));
-setEditorFontSize(moeApp.config.get('editor-font-size'));
-setEditorLineHeight(moeApp.config.get('editor-line-height'));
-setRenderTheme(moeApp.config.get('render-theme'));
-setHighlightTheme(moeApp.config.get('highlight-theme'));
-setCustomCSSs(moeApp.config.get('custom-csss'));
-setHexoAutoSetting(moeApp.config.get('hexo-auto-setting'));
-setHexoConfigEnable(moeApp.config.get('hexo-config-enable'));
-setHexoConfig(moeApp.config.get('hexo-config'));
-setHexoTagPaths(moeApp.config.get('hexo-tag-paths'));
+
+tryRun(setEditorFont, moeApp.config.get('editor-font'));
+tryRun(setShowLineNumber, !!moeApp.config.get('editor-ShowLineNumber'));
+tryRun(setEditorTheme, moeApp.config.get('editor-theme'));
+tryRun(setEditorFontSize, moeApp.config.get('editor-font-size'));
+tryRun(setEditorLineHeight, moeApp.config.get('editor-line-height'));
+tryRun(setRenderTheme, moeApp.config.get('render-theme'));
+tryRun(setHighlightTheme, moeApp.config.get('highlight-theme'));
+tryRun(setCustomCSSs, moeApp.config.get('custom-csss'));
+tryRun(setHexoAutoSetting, moeApp.config.get('hexo-auto-setting'));
+tryRun(setHexoConfigEnable, moeApp.config.get('hexo-config-enable'));
+tryRun(setHexoConfig, moeApp.config.get('hexo-config'));
+tryRun(setHexoTagPaths, moeApp.config.get('hexo-tag-paths'));
+// setEditorFont(moeApp.config.get('editor-font'));
+// setShowLineNumber(!!moeApp.config.get('editor-ShowLineNumber'));
+// setEditorTheme(moeApp.config.get('editor-theme'));
+// setEditorFontSize(moeApp.config.get('editor-font-size'));
+// setEditorLineHeight(moeApp.config.get('editor-line-height'));
+// setRenderTheme(moeApp.config.get('render-theme'));
+// setHighlightTheme(moeApp.config.get('highlight-theme'));
+// setCustomCSSs(moeApp.config.get('custom-csss'));
+// setHexoAutoSetting(moeApp.config.get('hexo-auto-setting'));
+// setHexoConfigEnable(moeApp.config.get('hexo-config-enable'));
+// setHexoConfig(moeApp.config.get('hexo-config'));
+// setHexoTagPaths(moeApp.config.get('hexo-tag-paths'));
 
 const ipcRenderer = require('electron').ipcRenderer;
 ipcRenderer.on('setting-changed', (e, arg) => {
     if (arg.key === 'editor-font') {
-        setEditorFont(arg.val);
+        tryRun(setEditorFont, arg.val);
     } else if (arg.key === 'editor-ShowLineNumber') {
-        setShowLineNumber(arg.val);
+        tryRun(setShowLineNumber, arg.val);
     } else if (arg.key === 'editor-theme') {
-        setEditorTheme(arg.val);
+        tryRun(setEditorTheme, arg.val);
     } else if (arg.key === 'editor-font-size') {
-        setEditorFontSize(arg.val);
+        tryRun(setEditorFontSize, arg.val);
     } else if (arg.key === 'editor-line-height') {
-        setEditorLineHeight(arg.val);
+        tryRun(setEditorLineHeight, arg.val);
     } else if (arg.key === 'math') {
-        setMath(arg.val);
+        tryRun(setMath, arg.val);
     } else if (arg.key === 'uml-diagrams') {
-        setUMLDiagrams(arg.val);
+        tryRun(setUMLDiagrams, arg.val);
     } else if (arg.key === 'highlight-theme') {
-        setHighlightTheme(arg.val);
+        tryRun(setHighlightTheme, arg.val);
     } else if (arg.key === 'render-theme') {
-        setRenderTheme(arg.val);
+        tryRun(setRenderTheme, arg.val);
     } else if (arg.key === 'tab-size') {
-        setTabSize(arg.val);
+        tryRun(setTabSize, arg.val);
     } else if (arg.key === 'hexo-auto-setting') {
-        setHexoAutoSetting(arg.val);
+        tryRun(setHexoAutoSetting, arg.val);
     } else if (arg.key === 'hexo-config-enable') {
-        setHexoConfigEnable(arg.val);
+        tryRun(setHexoConfigEnable, arg.val);
     } else if (arg.key === 'hexo-config') {
-        setHexoConfig(arg.val);
+        tryRun(setHexoConfig, arg.val);
     } else if (arg.key === 'hexo-tag-paths') {
-        setHexoTagPaths(arg.val);
+        tryRun(setHexoTagPaths, arg.val);
     } else if (arg.key === 'custom-csss') {
-        setCustomCSSs(arg.val);
+        tryRun(setCustomCSSs, arg.val);
     }
 });

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

@@ -18,6 +18,18 @@
  *  along with Moeditor. If not, see <http://www.gnu.org/licenses/>.
  */
 
+
+.notransition, .notransition *:not(.CodeMirror-cursors):not(.CodeMirror-lines):not(.CodeMirror-sizer):not(.CodeMirror-vscrollbar) {
+    transition: none !important;
+}
+
+/* Specail Transition Class  */
+
+.CodeMirror-sizer {
+    transition: none !important;
+    transition: margin-left .5s !important;
+}
+
 html, body {
     margin: 0;
     padding: 0;
@@ -38,7 +50,7 @@ html, body {
     cursor: default;
     z-index: 1;
     position: absolute;
-    border-right: 1px solid #ccc;
+    /*border-right: 1px solid #ccc;*/
 }
 
 #side-menu #logo {
@@ -101,8 +113,9 @@ html, body {
     position: fixed;
     left: 0;
     top: 0;
-    width: 100%;
-    height: 100%;
+    width: calc(100% - 2px);
+    height: calc(100% - 2px);
+    border: 1px solid rgba(128, 128, 128, 0.3);
 }
 
 #main-container {
@@ -479,10 +492,6 @@ body[settings-mode=read] #drag-right, body[settings-mode=write] #drag-right {
     right: 0;
 }
 
-.notransition, .notransition *:not(.CodeMirror-cursors):not(.CodeMirror-lines):not(.CodeMirror-vscrollbar) {
-    transition: none !important;
-}
-
 .biu-instance {
     -webkit-app-region: no-drag;
     font-size: 14px;
@@ -492,3 +501,49 @@ body[settings-mode=read] #drag-right, body[settings-mode=write] #drag-right {
 .invalidFile{
     background: red;
 }
+
+/*.CodeMirror-linenumber.CodeMirror-gutter-elt {*/
+    /*!* border-right: 1px solid #cfeacf; *!*/
+    /*color: #a3a3a3;*/
+    /*background: #e8e8e8;*/
+    /*box-shadow: 2px 1px 1px 0px #bbb;*/
+    /*margin-left: -3px;*/
+    /*padding-right: 4px;*/
+/*}*/
+
+
+.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;
+}
+
+div#cover-bottom {
+    line-height: 1 !important;
+}

+ 1 - 0
views/main/moe-treeview.css

@@ -18,6 +18,7 @@
  */
 
 #file-tree {
+    display: none;
     width: 250px;
     margin-left: -250px;
     height: calc(100% - 45px);

+ 7 - 8
views/settings/moe-settings.js

@@ -82,7 +82,7 @@ document.addEventListener('DOMContentLoaded', () => {
         for (const x in custom) {
             const option = document.createElement('option');
             option.value = option.text = x;
-            if (fs.existsSync(path.resolve( custom[x],'style.css')))
+            if (fs.existsSync(path.resolve( custom[x],'main.css')))
                 option.classList.add('invalidFile');
             renderThemeSelect.appendChild(option);
         }
@@ -109,7 +109,7 @@ document.addEventListener('DOMContentLoaded', () => {
             const a = fileNames.filter((s) => {
                 try {
                     let files = fs.readdirSync(s);
-                    if (files.includes('style.css')){
+                    if (files.includes('main.css')){
                         return true;
                     } else if (files.includes('.css')){
                         let stylecss = [];
@@ -119,7 +119,7 @@ document.addEventListener('DOMContentLoaded', () => {
                            }
                            return false;
                         })
-                        fs.writeFileSync(path.join(s,'style.css'),stylecss);
+                        fs.writeFileSync(path.join(s,'main.css'),stylecss);
                         return true;
                     }
                     return false;
@@ -372,7 +372,7 @@ document.addEventListener('DOMContentLoaded', () => {
                 return false;
             });
             if (stylecss.length > 0) {
-                fs.writeFileSync(path.resolve(dir, 'style.css'), stylecss.toString());
+                fs.writeFileSync(path.resolve(dir, 'main.css'), stylecss.toString());
 
                 themes[hexoTheme] = dir;
                 moeApp.config.set('custom-render-themes', themes);
@@ -403,7 +403,7 @@ document.addEventListener('DOMContentLoaded', () => {
             let hexoTheme = hexoConfig.theme;
             let isFindStyle = false;
             if (themes[hexoTheme]){
-                if (fs.existsSync(path.resolve( themes[hexoTheme],'style.css'))) {
+                if (fs.existsSync(path.resolve( themes[hexoTheme],'main.css'))) {
                     renderThemeSelect.value = hexoTheme;
                     reloadHighlightSelect(hexoTheme);
                     isFindStyle = true;
@@ -414,12 +414,12 @@ document.addEventListener('DOMContentLoaded', () => {
                 }
             }
             //未配置主题,自动配置
+            let classDir = path.join(hexoConfig.__basedir,hexoConfig.public_dir,'css');
             if (!isFindStyle){
-                let classDir = path.join(hexoConfig.__basedir,hexoConfig.public_dir,'css');
                 if (fs.lstatSync(classDir).isDirectory()){
                     try {
                         let fileNames = fs.readdirSync(classDir);
-                        if (fileNames.includes('style.css')){
+                        if (fileNames.includes('main.css')){
                             isFindStyle = true;
                         } else {
                             isFindStyle = newCustomeTheme(classDir);
@@ -427,7 +427,6 @@ document.addEventListener('DOMContentLoaded', () => {
                     } catch (err) {
                     }
                 }
-
             }
             if (isFindStyle) {
                 themes[hexoTheme] = classDir;

+ 9 - 2
views/settings/settings.html

@@ -147,7 +147,14 @@
                                 <!--<td width="40%" class="l10n">Color Theme</td>-->
                                 <!--<td width="60%">-->
                                     <!--<select class="settings-item" data-key="editor-theme">-->
-                                        <!--<option value="base16-light">Base16 Light</option>-->
+                                            <!--<script>-->
+                                                <!--fs.readdirSync(path.resolve(path.dirname(path.dirname(require.resolve('codemirror'))), 'theme'))-->
+                                                    <!--.filter(s => s.endsWith('.css'))-->
+                                                    <!--.map(s => s.substr(0, s.length - 4))-->
+                                                    <!--.forEach(s => {-->
+                                                        <!--document.write(`<option value="${s}">${s}</option>`)-->
+                                                    <!--});-->
+                                            <!--</script>-->
                                     <!--</select>-->
                                 <!--</td>-->
                             <!--</tr>-->
@@ -231,7 +238,7 @@
 
                                             const custom = moeApp.config.get('custom-render-themes');
                                             for (const s in custom) {
-                                                if (fs.existsSync(path.resolve( custom[s],'style.css')))
+                                                if (fs.existsSync(path.resolve( custom[s],'main.css')))
                                                     document.write(`<option value="${s}">${s}</option>`);
                                                 else
                                                     document.write(`<option class="invalidFile" value="${s}">${s}</option>`);