TagSpaces is an offline, open source, document manager with tagging support
introduce context menu
Borislav Sapundzhiev3b44406f3555
diff --git a/data/electron/electron.api.js b/data/electron/electron.api.jsindex a72d96500..8bd6995b9 100644--- a/data/electron/electron.api.js+++ b/data/electron/electron.api.js@@ -5,7 +5,7 @@const fs = require('fs-extra'); // jshint ignore:lineconst pathUtils = require('path'); // jshint ignore:lineconst electron = require('electron');-+const remote = electron.remote;/*** A implementation of the IOAPI for the nw.js platform* @class NWJS@@ -14,16 +14,15 @@ const electron = require('electron');define(function(require, exports, module) {"use strict";-console.log("Loading electron.api.js..");var TSCORE = require("tscore");var TSPOSTIO = require("tspostioapi");var fsWatcher;-+ var win = remote.getCurrentWindow();+var showMainWindow = function() {- //win.show();- console.log("TODO: showMainWindow");+ win.show();};process.on("uncaughtException", function(err) {@@ -46,140 +45,32 @@ define(function(require, exports, module) {function handleTray() {// TODO disable in Ubuntu until node-webkit issue in unity fixedconsole.log("TODO: handleTray");- // Reference to window and tray- /*var win = gui.Window.get();- var tray;-- // Get the minimize event- win.on('minimize', function() {- // Hide window- this.hide();-- // Show tray- tray = new gui.Tray({- title: 'Tray',- icon: 'icon128.png'- });-- // Show window and remove tray when clicked- tray.on('click', function() {- win.show();- this.remove();- tray = null;- });- });*/}function handleStartParameters() {console.log("TODO: handleStartParameters");- /*var cmdArguments = gui.App.argv;- if (cmdArguments && cmdArguments.length > 0) {- console.log("CMD Arguments: " + cmdArguments[0] + " Process running in " + process.cwd());- var dataPathIndex;- cmdArguments.forEach(function(part, index) {- if (part.indexOf("--data-path") === 0) {- dataPathIndex = index;- }- });- if (dataPathIndex >= 0 && cmdArguments.length >= dataPathIndex + 1) {- cmdArguments.splice(dataPathIndex, 2);- }- console.log("CMD Arguments cleaned: " + cmdArguments);- var filePath = "" + cmdArguments;- if (filePath.length > 1) {- var dirPath = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);- TSCORE.FileOpener.openFileOnStartup(filePath);- //TSCORE.IO.listDirectoryPromise(dirPath).then();- }- }*/}function initMainMenu() {- if (isOSX) {- rootMenu.createMacBuiltin("TagSpaces");- }- if (TSCORE.Config.getShowMainMenu() && !menuInitialuzed) {- aboutMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:aboutTagSpaces"),- click: function() {- TSCORE.UI.showAboutDialog();- }- }));-- viewMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:showTagLibraryTooltip") + " (" + TSCORE.Config.getShowTagLibraryKeyBinding() + ")",- click: function() {- TSCORE.UI.showTagsPanel();- }- }));-- viewMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:showLocationNavigatorTooltip") + " (" + TSCORE.Config.getShowFolderNavigatorBinding() + ")",- click: function() {- TSCORE.UI.showLocationsPanel();- }- }));-- viewMenu.append(new gui.MenuItem({- type: 'separator'- }));-- viewMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:toggleFullScreen") + " (" + TSCORE.Config.getToggleFullScreenKeyBinding().toUpperCase() + ")",- click: function() {- win.toggleFullscreen();- }- }));-- viewMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:showDevTools") + " (" + TSCORE.Config.getOpenDevToolsScreenKeyBinding().toUpperCase() + ")",- click: function() {- win.showDevTools();- }- }));-- viewMenu.append(new gui.MenuItem({- type: 'separator'- }));-- viewMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:settings"),- click: function() {- TSCORE.UI.showOptionsDialog();- }- }));-- rootMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:view"),- submenu: viewMenu- }));-- rootMenu.append(new gui.MenuItem({- type: 'normal',- label: $.i18n.t("ns.common:help"),- submenu: aboutMenu- }));- win.menu = rootMenu;-- menuInitialuzed = true;- } else {- if (isOSX) {- win.menu = rootMenu;- }- }+ var Menu = remote.Menu;+ var MenuItem = remote.MenuItem;+ var menu = new Menu();+ menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log('item 1 clicked'); } }));+ menu.append(new MenuItem({ label: 'MenuItem2', click: function() { console.log('item 2 clicked'); } }));++ //menu.append(new MenuItem({ type: 'separator' }));+ // menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));++ window.addEventListener('contextmenu', function (e) {+ e.preventDefault();+ menu.popup(remote.getCurrentWindow());+ }, false);}+// Brings the TagSpaces window on top of the windowsfunction focusWindow() {- console.log("TODO: focusWindow");- //gui.Window.get().focus();+ win.focus();}function trash(files) {diff --git a/data/js/core.api.js b/data/js/core.api.jsindex cabecd385..e877d216a 100644--- a/data/js/core.api.js+++ b/data/js/core.api.js@@ -99,7 +99,7 @@ define(function(require, exports, module) {if (tsSettings.Settings.tagspacesList.length < 1) {tsCoreUI.startGettingStartedTour();}- if (isNode || isChrome) {+ if (isNode || isChrome || isElectron) {// Handle command line argument in node-webkittsIOApi.handleStartParameters(); // Handle minimizing to the tray in node-webkit//tsIOApi.handleTray();@@ -124,7 +124,7 @@ define(function(require, exports, module) {fallbackLng: 'en_US'}, function() {$('[data-i18n]').i18n();- if (isNode) {+ if (isNode || isElectron) {tsIOApi.initMainMenu();}});diff --git a/data/js/core.ui.js b/data/js/core.ui.jsindex 5c8d5bbfd..d51378997 100644--- a/data/js/core.ui.js+++ b/data/js/core.ui.js@@ -393,7 +393,7 @@ define(function(require, exports, module) {event.preventDefault();});// Managing droping of files in the perspectives- if (isNode) {+ if (isNode || isElectron) {$('#viewContainers').on('dragenter', function(event) {event.preventDefault();$('#viewContainers').attr('style', 'border:2px dashed #098ddf');@@ -823,10 +823,10 @@ define(function(require, exports, module) {} else if (isFirefox) {$('#openNatively').hide();$('#fileMenuOpenNatively').parent().hide();- } else if (isNode) {+ } else if (isNode || isElectron) {$('#openFileInNewWindow').hide();//handling window maximization- var nwwin = gui.Window.get();+ var nwwin = isNode ? gui.Window.get() : remote.getCurrentWindow();nwwin.on('maximize', function() {TSCORE.Config.setIsWindowMaximized(true);TSCORE.Config.saveSettings();diff --git a/data/js/perspective.manager.js b/data/js/perspective.manager.jsindex e44553f44..ec23e6ba1 100644--- a/data/js/perspective.manager.js+++ b/data/js/perspective.manager.js@@ -62,7 +62,7 @@ define(function(require, exports, module) {$("#viewContainers").removeClass("appBackgroundTile");}$('#loading').hide();- if (isNode) {+ if (isNode || isElectron) {TSCORE.IO.showMainWindow();}return true;