diff --git a/app/abr-application.js b/app/abr-application.js index 837b530..34ea5b2 100644 --- a/app/abr-application.js +++ b/app/abr-application.js @@ -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"), @@ -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 + "'"); + } } }; diff --git a/app/commands-main.js b/app/commands-main.js new file mode 100644 index 0000000..3304adc --- /dev/null +++ b/app/commands-main.js @@ -0,0 +1,50 @@ +/* +* Abricotine - Markdown Editor +* Copyright (c) 2015 Thomas Brouard +* Licensed under GNU-GPLv3 +*/ + +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;