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

Commit

Permalink
Add commands-main and execCommand in the main process
Browse files Browse the repository at this point in the history
commands-main contains commands which are available in the main process to use
when no window open (OSX).
  • Loading branch information
brrd committed Apr 15, 2016
1 parent bba393c commit 8d41c50
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/abr-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

var AbrWindow = require.main.require("./abr-window.js"),
BrowserWindow = require("browser-window"),
commands = require.main.require("./commands-main.js"),
files = require.main.require("./files.js"),
ipcServer = require.main.require("./ipc-server.js"),
parsePath = require("parse-filepath"),
Expand Down Expand Up @@ -108,6 +109,14 @@ AbrApplication.prototype = {
openContextMenu: function (arg, winId) {
var abrWin = this.getFocusedAbrWindow(winId);
abrWin.contextMenu.popup();
},

execCommand: function (command, parameters) {
if (commands && commands[command]) {
commands[command](this, parameters);
} else {
console.error("Unknown command '" + command + "'");
}
}
};

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

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

// Commands used in the main process (for OSX menu when no opened windows)
var commands = {
new: function (abrApp) {
abrApp.open();
},

open: function (abrApp) {
var path = dialogs.askOpenPath();
if (!path) {
return false;
}
abrApp.open(path);
},

quit: function (abrApp) {
app.quit();
},

editConfigFile: function (abrApp) {
var dirPath = constants.path.userConfig;
shell.openItem(dirPath);
},

openConfigDir: function (abrApp) {
var dirPath = constants.path.userData;
shell.openItem(dirPath);
},

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

homepage: function (win, abrDoc, cm) {
var homepageURL = constants.homepageURL;
shell.openExternal(homepageURL);
}
};

module.exports = commands;

0 comments on commit 8d41c50

Please # to comment.