Bläddra i källkod

Ajout contexte menu

Arthur Brandao 5 år sedan
förälder
incheckning
cbec61e7bc
4 ändrade filer med 52 tillägg och 7 borttagningar
  1. 4 7
      app/main/application-menu.js
  2. 33 0
      app/main/context-menu.js
  3. 11 0
      app/main/function/menu.js
  4. 4 0
      app/render/event.js

+ 4 - 7
app/main/application-menu.js

@@ -1,4 +1,5 @@
-const {Menu, shell} = require('electron')
+const {Menu, shell} = require('electron');
+const func = require('./function/menu');
 const demo = require('./function/demo-application-menu');
 
 let template = [
@@ -8,15 +9,11 @@ let template = [
       {
         label: 'Nouveau',
         accelerator: 'CmdOrCtrl+N',
-        click: () => {
-          mainWindow.webContents.send('new-note');
-        }
+        click: func.new
       },
       {
         label: 'Importer',
-        click: () => {
-          console.log('Reset');
-        }
+        click: func.import
       },
       {
         type: 'separator'

+ 33 - 0
app/main/context-menu.js

@@ -0,0 +1,33 @@
+const { Menu, MenuItem, app } = require('electron');
+const func = require('./function/menu');
+
+const menu = new Menu();
+menu.append(new MenuItem({
+    label: 'Retour',
+    click: () => {
+
+    }
+}));
+menu.append(new MenuItem({
+    label: 'Nouveau',
+    click: func.new
+}));
+menu.append(new MenuItem({
+    label: 'Importer',
+    click: func.import
+}));
+menu.append(new MenuItem({type: 'separator'}));
+menu.append(new MenuItem({
+    label: 'Afficher chargement',
+    type: 'checkbox',
+    checked: false,
+    click: () => {
+        mainWindow.webContents.send('loader');
+    }
+}));
+
+app.on('browser-window-created', (event, win) => {
+    win.webContents.on('context-menu', (evt, params) => {
+        menu.popup(win, params.x, params.y);
+    });
+});

+ 11 - 0
app/main/function/menu.js

@@ -0,0 +1,11 @@
+const menuFunction = {};
+
+menuFunction.new = function() {
+    mainWindow.webContents.send('new-note');
+};
+
+menuFunction.import = function() {
+    console.log('Import');
+}
+
+module.exports = menuFunction;

+ 4 - 0
app/render/event.js

@@ -9,4 +9,8 @@ ipcRenderer.on('new-note', (event, arg) => {
     if (current !== 'edit.html' || (document.location.search.trim() !== '' && current === 'edit.html')) {
         document.location = 'edit.html';
     }
+});
+
+ipcRenderer.on('loader', (event, arg) => {
+    console.log('loader');
 });