Skip to content

Commit

Permalink
修复若干问题,加入打开新窗口的功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
topcss committed Nov 30, 2018
1 parent 6d4c707 commit d85ab11
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 74 deletions.
8 changes: 8 additions & 0 deletions doc/History.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

## 更新记录

### 3.1.0 / 2018-11-30

- 新增 窗口新窗口的功能
- 修复 无法保存的问题
- 修复 默认打开是英文界面的问题
- 自动升级配置文件
- 优化 程序的若干细节

### 3.0.0 / 2018-11-28

- 正式支持多语言。`鸣谢:涛`
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ gulp.task("copy-images-vendor", function() {

gulp.task("copy-html-vendor", function() {
gulp.src("./src/index.html").pipe(gulp.dest("dist"));
gulp.src("./src/favicon.*").pipe(gulp.dest("dist"));
});

gulp.task("copy-css", function() {
Expand Down
1 change: 1 addition & 0 deletions locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"mFile": "&File",
"miNewFile": "&New File",
"miOpenFile": "&Open File...",
"miOpenWindow": "Open a New Window",
"miOpenFolder": "Open &Folder...",
"miOpenRecent": "Open &Recent",
"miClearRecent": "&Clear Recently Opened",
Expand Down
1 change: 1 addition & 0 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"mFile": "&File",
"miNewFile": "&New File",
"miOpenFile": "&Open File...",
"miOpenWindow": "Open a New Window",
"miOpenFolder": "Open &Folder...",
"miOpenRecent": "Open &Recent",
"miClearRecent": "&Clear Recently Opened",
Expand Down
1 change: 1 addition & 0 deletions locale/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"mFile": "文件(&F)",
"miNewFile": "新建文件(&N)",
"miOpenFile": "打开文件(&O)...",
"miOpenWindow": "打开新窗口",
"miOpenFolder": "打开文件夹(&F)...",
"miOpenRecent": "打开最近的文件(&R)",
"miClearRecent": "清除最近打开记录",
Expand Down
1 change: 1 addition & 0 deletions locale/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"mFile": "文件(&F)",
"miNewFile": "新建文件(&N)",
"miOpenFile": "打開文件(&O)...",
"miOpenWindow": "打開新窗口",
"miOpenFolder": "打開文件夾(&F)...",
"miOpenRecent": "打開最近的文件(&R)",
"miClearRecent": "清除最近打開記錄",
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function createWindow() {

'fullscreenable': true,
'show': false,
'icon': `${__dirname}/favicon.ico`,
'icon': `${__dirname}/dist/favicon.ico`,
'backgroundColor': '#fbfbfb'
});

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "desktopnaotu",
"version": "3.0.0",
"version": "3.1.0",
"description": "桌面版脑图",
"main": "main.js",
"scripts": {
"start": "gulp default && electron main.js",
"packwin32": "electron-packager ./ DesktopNaotu --platform=win32 --arch=ia32 --out=../OutApp --icon=favicon.ico --electron-version=3.0.10 --app-version=3.0.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packwin64": "electron-packager ./ DesktopNaotu --platform=win32 --arch=x64 --out=../OutApp --icon=favicon.ico --electron-version=3.0.10 --app-version=3.0.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packmacos": "electron-packager ./ DesktopNaotu --platform=darwin --arch=x64 --out=../OutApp --icon=favicon.icns --electron-version=3.0.10 --app-version=3.0.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packlinux": "electron-packager ./ DesktopNaotu --platform=linux --arch=x64 --out=../OutApp --icon=favicon.png --electron-version=3.0.10 --app-version=3.0.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune"
"packwin32": "electron-packager ./ DesktopNaotu --platform=win32 --arch=ia32 --out=../OutApp --icon=src/favicon.ico --electron-version=3.0.10 --app-version=3.1.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packwin64": "electron-packager ./ DesktopNaotu --platform=win32 --arch=x64 --out=../OutApp --icon=src/favicon.ico --electron-version=3.0.10 --app-version=3.1.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packmacos": "electron-packager ./ DesktopNaotu --platform=darwin --arch=x64 --out=../OutApp --icon=src/favicon.icns --electron-version=3.0.10 --app-version=3.1.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune",
"packlinux": "electron-packager ./ DesktopNaotu --platform=linux --arch=x64 --out=../OutApp --icon=src/favicon.png --electron-version=3.0.10 --app-version=3.1.0 --ignore=\"(.git|screenshot|doc|src|bower_components|electron-packager)\" --overwrite --prune"
},
"repository": {
"type": "git",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
68 changes: 49 additions & 19 deletions src/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,37 @@ log4js.configure({
var logger = log4js.getLogger("NaoTuApp");
var confPath = path.join(getUserDataDir(), "/naotu.config.json");

try {
// 若没有用户文件夹,则创建
var defFolder = path.join(getUserDataDir(), "/");
if (!fs.existsSync(defFolder)) {
fs.mkdirSync(defFolder);
}

// 检查或创建配置文件
if (!fs.existsSync(confPath)) {
fs.writeFileSync(confPath, JSON.stringify(getDefConf()));
} else {
// 存在则更新
var newConf = getDefConf();
var oldConf = getConf();

newConf.defSavePath = oldConf.defSavePath;
newConf.recently = oldConf.recently;

fs.writeFileSync(confPath, JSON.stringify(newConf));
}
} catch (ex) {
logger.error(ex);
}

// init
$(function() {
getAppInstance().setTitle(i18n.__("sAppName"));
bootbox.setLocale("zh_CN");

// 欢迎语
logger.info("Jack welcomes you! v" + ver.version.slice(0, 3).join("."));

try {
// 若没有用户文件夹,则创建
var defFolder = path.join(getUserDataDir(), "/");
if (!fs.existsSync(defFolder)) {
fs.mkdirSync(defFolder);
}

// 检查或创建配置文件
fs.exists(confPath, function(exists) {
if (!exists) {
fs.writeFileSync(confPath, JSON.stringify(getDefConf()));
}
});
} catch (ex) {
logger.error(ex);
}
});

// 重选自动保存的目录
Expand Down Expand Up @@ -327,7 +334,7 @@ function about() {
dialog.showMessageBox({
type: "info",
title: i18n.__("sAppName"),
message: text.join('\r'),
message: text.join("\r"),
buttons: ["OK"]
});
}
Expand Down Expand Up @@ -396,5 +403,28 @@ function showFileName(fileName) {
}

function getAppInstance() {
return BrowserWindow.getAllWindows()[0];
return BrowserWindow.getFocusedWindow();
}

function openWindow() {
var subWinPath = path.join("file://", __dirname, "/index.html");
var subWinIcon = path.join("file://", __dirname, "/favicon.ico");

var newWin = new BrowserWindow({
minWidth: 700,
minHeight: 700,
width: 1000,
height: 800,

fullscreenable: true,
show: false,
icon: subWinIcon,
backgroundColor: "#fbfbfb"
});

newWin.on("close", function() {
newWin = null;
});
newWin.loadURL(subWinPath);
newWin.show();
}
25 changes: 10 additions & 15 deletions src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ function getDefConf() {
}

function getConf() {
var confObj = JSON.parse(fs.readFileSync(confPath));
if (confObj == null) {
confObj = getDefConf();
if (fs.existsSync(confPath)) {
return JSON.parse(fs.readFileSync(confPath));
} else {
fs.writeFileSync(confPath, JSON.stringify(getDefConf()));

// 创建文件
fs.writeFileSync(confPath, JSON.stringify(confObj));
return getDefConf();
}

return confObj;
}

function clearRecently() {
Expand Down Expand Up @@ -82,14 +80,11 @@ function updateMenus() {
var item = list[i];

// 追加到菜单
menus[0].submenu[4].submenu.splice(
menus[0].submenu[4].submenu.length - 2,
0,
{
label: item.path,
click: openRecently
}
);
var recentFiles = menus[0].submenu[5].submenu;
recentFiles.splice(recentFiles.length - 2, 0, {
label: item.path,
click: openRecently
});
}

// 更新菜单
Expand Down
10 changes: 1 addition & 9 deletions src/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
var loadedLanguage;
var i18n = {
lang: function() {
var lang = "en";

try {
var confObj = getConf();

lang = confObj.locale.replace("-", "_");
} catch (error) {}

return lang;
return getConf().locale.replace("-", "_") || "en";
},
__: function(phrase) {
if (loadedLanguage == undefined) {
Expand Down
7 changes: 2 additions & 5 deletions src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// window.$ = window.jQuery = require('../bower_components/jquery/dist/jquery.min.js');
window.$ = window.jQuery = require("./js/jquery.min.js");

// /*jshint esversion: 6 */
// var remote = require("electron").remote,
// argv = remote.getGlobal("sharedObject").prop1;

angular
.module("kityminderDemo", ["kityminderEditor"])
.config(function(configProvider) {
Expand Down Expand Up @@ -42,7 +38,8 @@ window.$(function() {
var menu = remote.Menu.getApplicationMenu();

// 对编辑菜单进行管理
menu.items[1].submenu.items[3].enabled = menu.items[1].submenu.items[4].enabled = menu.items[1].submenu.items[5].enabled = !!node;
var editItems = menu.items[1].submenu.items;
editItems[3].enabled = editItems[4].enabled = editItems[5].enabled = !!node;
});
}
});
9 changes: 5 additions & 4 deletions src/js/menu-bar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// /*jshint esversion: 6 */
// var remote = require("electron").remote;
// var Menu = remote.Menu;

var template = [
{
label: i18n.__("mFile"),
Expand All @@ -16,6 +12,11 @@ var template = [
accelerator: "CmdOrCtrl+O",
click: openDialog
},
{
label: i18n.__("miOpenWindow"),
accelerator: "CmdOrCtrl+Shift+N",
click: openWindow
},
{ type: "separator" },
{
label: i18n.__("miOpenFolder"),
Expand Down
26 changes: 13 additions & 13 deletions src/js/open-file.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 允许通过拖拽打开文件
// 允许通过拖拽打开文件
var body = document.body;

body.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
if (!file.name.toLowerCase().endsWith(".km")) {
bootbox.alert(i18n.__("sLoadedError"));
return false;
}
body.ondrop = function(e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
if (!file.name.toLowerCase().endsWith(".km")) {
bootbox.alert(i18n.__("sLoadedError"));
return false;
}

readFile(file.path);
readFile(file.path);

return false;
return false;
};

body.ondragover = body.ondragleave = body.ondragend = function () {
return false;
};
body.ondragover = body.ondragleave = body.ondragend = function() {
return false;
};
4 changes: 2 additions & 2 deletions src/js/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ function shortcut() {
var text = "";
for (var i = 0; i < shortcutKeys.length; i++) {
var group = shortcutKeys[i];
text += '\n' + group.groupName + '\n';
text += "\n" + group.groupName + "\n";
for (var j = 0; j < group.groupItem.length; j++) {
var item = group.groupItem[j];
text += ' ' + item.desc + ' ' + item.key + '\n';
text += " " + item.desc + " " + item.key + "\n";
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports.version = [3, 0, 0, 438];
exports.version = [3, 1, 0, 467];

0 comments on commit d85ab11

Please sign in to comment.