Ver código fonte

Fix open new post ,but image dir name fail.

zhuzhuyule 7 anos atrás
pai
commit
e12f72704c
3 arquivos alterados com 14 adições e 19 exclusões
  1. 0 4
      app/moe-action.js
  2. 4 14
      views/main/moe-document.js
  3. 10 1
      views/main/moe-popmessage.js

+ 0 - 4
app/moe-action.js

@@ -95,8 +95,6 @@ class MoeditorAction {
                             hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
                             hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
                             app.addRecentDocument(fileName);
-                            // TODO-ly 解决第一次图片保存地址不对的问题
-                            hexoWindow.hexoeditorWindow.window.webContents.send('open-newfile', {});
                         }
                         notOpened = false;
                     }
@@ -143,8 +141,6 @@ class MoeditorAction {
                             hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
                             hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
                             app.addRecentDocument(filename);
-                            // TODO-ly 解决第一次图片保存地址不对的问题
-                            hexoWindow.hexoeditorWindow.window.webContents.send('open-newfile', {});
                             hexoWindow.focus();
                             break;
                         } catch (e) {

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

@@ -29,8 +29,6 @@ window.path = require('path');
 window.url = require('url');
 global.log4js = window.log4js = moeApp.getLog4js();
 global.log = window.log = log4js.getLogger('Front');
-// TODO-ly 引入平台判断库
-const platform = require('electron-platform');
 
 $(() => {
     const dialog = require('electron').remote.dialog;
@@ -168,13 +166,6 @@ $(() => {
     require('electron').ipcRenderer.on('set-title', (e, fileName) => {
         document.getElementsByTagName('title')[0].innerText = 'HexoEditor - ' + path.basename(fileName);
     });
-    // TODO-ly 解决第一次图片保存地址不对的问题
-    require('electron').ipcRenderer.on('open-newfile', () => {
-        let fileName = path.basename(hexoWindow.fileName, path.extname(hexoWindow.fileName));
-        if(fileName !== imgManager.postName){
-            imgManager.renameDirPath(fileName);
-        }
-    });
 
     //加载填图功能
     const ImgManager = require('./hexo-image');
@@ -291,7 +282,8 @@ $(() => {
                     })
                 } else {
                     // TODO-ly 解决图片路径不对的问题
-                    imgManager.renameDirPath(nameNew);
+                    if(nameNew !== imgManager.postName)
+                        imgManager.renameDirPath(nameNew);
                 }
             }
             if (force) {
@@ -390,11 +382,9 @@ $(() => {
     }, true);
     document.getElementById("editor").addEventListener("click", e => {
         // TODO-ly 判断按下的按键
-        let key = platform.isDarwin ? e.metaKey : e.ctrlKey;
-        if (key) {
+        if ( (process.platform === 'darwin' ? e.metaKey : e.ctrlKey)  ) {
             $('span.cm-string.cm-url').unbind('click').click(e => {
-                key = platform.isDarwin ? e.metaKey : e.ctrlKey;
-                if (key) {
+                if ( (process.platform === 'darwin' ? e.metaKey : e.ctrlKey) ) {
                     e.stopPropagation();
                     // e.defaultPrevented();
                     const innerLink = e.target.innerText.replace(/^\((.*)\)$/, '$1');

+ 10 - 1
views/main/moe-popmessage.js

@@ -67,10 +67,19 @@ document.addEventListener('DOMContentLoaded', () => {
 
 
     ipcRenderer.on('refresh-editor', function () {
+        const path = require('path');
         let hexoWindow  = window.hexoWindow;
+
         if (hexoWindow.fileName !== '') {
-            document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + require('path').basename(hexoWindow.fileName);
+            document.getElementsByTagName('title')[0].innerText = 'Moeditor - ' + path.basename(hexoWindow.fileName);
+        }
+
+        // TODO-ly 解决第一次图片保存地址不对的问题
+        let fileName = path.basename(hexoWindow.fileName, path.extname(hexoWindow.fileName));
+        if(fileName !== imgManager.postName){
+            imgManager.renameDirPath(fileName);
         }
+
         document.querySelector('#editor textarea').innerText = hexoWindow.content;
         window.editor.setValue(hexoWindow.content);
         window.updatePreview(true);