Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
brrd committed Mar 13, 2017
2 parents ac7d25d + bdeb9d4 commit ea2b00f
Show file tree
Hide file tree
Showing 38 changed files with 99,264 additions and 335 deletions.
28 changes: 18 additions & 10 deletions app/abr-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ var AbrMenu = require.main.require("./abr-menu.js"),
AbrWindow = require.main.require("./abr-window.js"),
BrowserWindow = require("electron").BrowserWindow,
commands = require.main.require("./commands-main.js"),
createConfig = require.main.require("./config.js"),
Dialogs = require.main.require("./dialogs.js"),
files = require.main.require("./files.js"),
ipcServer = require.main.require("./ipc-server.js"),
Localizer = require("./localize.js"),
menuTemplate = require.main.require("./menu-window.json"),
parsePath = require("parse-filepath");

function AbrApplication (osxOpenFilePaths) {
// Config
this.config = createConfig();
// Localizer
this.localizer = new Localizer(this.config.get("lang"));
// Dialogs
this.dialogs = new Dialogs(this.localizer);
// Windows reference
this.windows = [];
// IPC get & set
Expand Down Expand Up @@ -44,21 +53,22 @@ AbrApplication.prototype = {

// trigger
setConfig: function (args, winId, callback) {
var abrWin = this.getFocusedAbrWindow(winId);
if (!abrWin || typeof args.key === "undefined" || typeof args.value === "undefined") {
if (typeof args.key === "undefined" || typeof args.value === "undefined") {
return;
}
var abrWin = this.getFocusedAbrWindow(winId),
config = abrWin ? abrWin.config : this.config;
// Update window menu if needed (args.menu indicates the menu id)
if (args.menu && typeof args.value === "boolean") {
var menuItem = abrWin.menu.findItem(args.menu);
if (menuItem) {
menuItem.checked = args.value;
}
}
// Set window config
abrWin.config.set(args.key, args.value);
// Set config
config.set(args.key, args.value);
// Save the config each time it is modified, so the next opened window would get the latest config
abrWin.config.save(function (err) {
config.save(function (err) {
if (typeof callback === "function") {
callback(err);
}
Expand All @@ -67,11 +77,9 @@ AbrApplication.prototype = {

// trigger
getConfig: function (arg, winId, callback) {
var abrWin = this.getFocusedAbrWindow(winId);
if (!abrWin) {
return;
}
var res = abrWin.config.get(arg);
var abrWin = this.getFocusedAbrWindow(winId),
config = abrWin ? abrWin.config : this.config,
res = config.get(arg);
if (typeof callback === "function") {
callback(res);
} else {
Expand Down
7 changes: 7 additions & 0 deletions app/abr-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ function preprocessTemplate (abrApp, element, config, abrWin) {
if (item.condition) {
delete item.condition;
}
if (item.labelKey) {
var newLabel = abrApp.localizer.get(item.labelKey);
if (newLabel !== null) {
item.label = abrApp.localizer.get(item.labelKey);
}
delete item.labelKey;
}
if (item.command) {
item.click = (function (command, parameters) {
return function () { sendCommand(command, parameters); };
Expand Down
28 changes: 8 additions & 20 deletions app/abr-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ var AbrMenu = require.main.require("./abr-menu.js"),
BrowserWindow = require("electron").BrowserWindow,
constants = require.main.require("./constants.js"),
contextMenuTemplate = require.main.require("./menu-context.json"),
defaultConfig = require.main.require("../default/config.json"),
createConfig = require.main.require("./config.js"),
menuTemplate = require.main.require("./menu-window.json"),
nconf = require('nconf'),
windowStateKeeper = require('electron-window-state');

function alreadyOpen (abrApp, path) {
Expand All @@ -27,17 +26,6 @@ function alreadyOpen (abrApp, path) {
return false;
}

// Config creation (config is specific to the window)
function createConfig () {
var config = new nconf.Provider(); // https://github.com/indexzero/nconf/issues/39
config.overrides({
"debug": process.argv.indexOf("--debug") !== -1
})
.file(constants.path.userConfig)
.defaults(defaultConfig);
return config;
}

function AbrWindow (abrApp, path) {
this.abrApp = abrApp;
if (path) {
Expand Down Expand Up @@ -83,13 +71,13 @@ AbrWindow.prototype = {
win = new BrowserWindow({
title: constants.appName || "Abricotine",
icon: constants.path.icon,
"min-width": 100,
"min-height": 100,
"x": mainWindowState.x,
"y": mainWindowState.y,
"width": mainWindowState.width,
"height": mainWindowState.height,
"auto-hide-menu-bar": typeof showMenubar !== "undefined" ? !showMenubar : false
minWidth: 100,
minHeight: 100,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
autoHideMenuBar: typeof showMenubar !== "undefined" ? !showMenubar : false
});
mainWindowState.manage(win);

Expand Down
5 changes: 2 additions & 3 deletions app/commands-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

var app = require("electron").app,
dialogs = require("./dialogs.js"),
constants = require("./constants.js"),
shell = require("electron").shell;

Expand All @@ -16,7 +15,7 @@ var commands = {
},

open: function (abrApp) {
var path = dialogs.askOpenPath();
var path = abrApp.dialogs.askOpenPath();
if (!path) {
return false;
}
Expand All @@ -38,7 +37,7 @@ var commands = {
},

about: function (abrApp) {
dialogs.about();
abrApp.dialogs.about();
},

homepage: function (win, abrDoc, cm) {
Expand Down
18 changes: 0 additions & 18 deletions app/config-user-default.json

This file was deleted.

24 changes: 24 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Abricotine - Markdown Editor
* Copyright (c) 2015 Thomas Brouard
* Licensed under GNU-GPLv3 <http://www.gnu.org/licenses/gpl.html>
*/

var constants = require.main.require("./constants.js"),
defaultConfig = require.main.require("../default/config.json"),
nconf = require('nconf');

// Config creation
// Each AbrWindow has its own config (because different settings are possible)
// AbrApplication also has a config, which is used when loading app and when no window (OSX)
function createConfig () {
var config = new nconf.Provider(); // https://github.com/indexzero/nconf/issues/39
config.overrides({
"debug": process.argv.indexOf("--debug") !== -1
})
.file(constants.path.userConfig)
.defaults(defaultConfig);
return config;
}

module.exports = createConfig;
3 changes: 3 additions & 0 deletions app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var app = require("electron").app,
pathModule = require("path"),
pkg = require.main.require("../package.json"),
appPath = app.getAppPath(),
documentsPath = app.getPath("documents"),
userDataPath = pathModule.join(app.getPath("userData"), "/app"),
tmpPath = pathModule.join(app.getPath("temp"), "/Abricotine"),
isAsar = appPath.match(/\.asar$/) !== null;
Expand All @@ -22,6 +23,8 @@ module.exports = {
icon: pathModule.join(appPath, "/icons/abricotine.png"),
defaultDir: isAsar ? appPath + ".unpacked/default" : appPath + "/default",
dictionaries: pathModule.join(userDataPath, "/dict"),
documents: documentsPath,
languages: pathModule.join(userDataPath, "/lang"),
schema: pathModule.join(userDataPath, "/schema.json"),
templatesDir: pathModule.join(userDataPath, "/templates"),
themesDir: pathModule.join(userDataPath, "/themes"),
Expand Down
22 changes: 17 additions & 5 deletions app/creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var constants = require.main.require("./constants.js"),
dialog = require("electron").dialog,
files = require.main.require("./files.js"),
Localizer = require.main.require("./localize.js"),
pathModule = require("path"),
pkg = require("../package.json");

Expand Down Expand Up @@ -43,7 +44,14 @@ creator.create = function () {
}
}),
new Promise (function (resolve, reject) {
// Copy default templates
if (!files.dirExists(constants.path.languages)) {
files.copyLocalDir(pathModule.join(constants.path.defaultDir, "/lang"), constants.path.languages, resolve);
} else {
resolve();
}
}),
new Promise (function (resolve, reject) {
// Copy default template
if (!files.dirExists(constants.path.templatesDir)) {
files.copyLocalDir(pathModule.join(constants.path.defaultDir, "/templates"), constants.path.templatesDir, resolve);
} else {
Expand Down Expand Up @@ -77,12 +85,16 @@ creator.reset = function () {
};

function askForReset (callback) {
//TODO use Localizer from AbrApplication
var localizer = new Localizer();

var userChoice = dialog.showMessageBox({
title: "Abricotine - Configuration update",
message: "The current configuration is deprecated and need to be updated. Do you want to reset Abricotine configuration? \n\nWARNING: Your previous configuration (including custom templates and dictonaries) will be lost.",
title: localizer.get("reset-dialog"),
message: localizer.get("reset-dialog-message"),
type: "question",
buttons: ["No", "Yes (recommended)"],
defaultId: 1
buttons: [localizer.get("button-no"), localizer.get("button-yes-recommended")],
defaultId: 1,
noLink: true
});
if (userChoice === 1) {
creator.reset().then(callback);
Expand Down
Loading

0 comments on commit ea2b00f

Please sign in to comment.