From 796b7f3f1eeaee548a9df67e9a72bd849bc97afb Mon Sep 17 00:00:00 2001 From: Kumar Priyansh Date: Sat, 18 Jul 2020 01:02:26 +0530 Subject: Rename Chapter Function: Event Handling --- src/views/system/chapterRename.html | 49 +++++++++++++++++++++++++ src/views/templates/blank/template.html | 31 +++++++++++++++- src/views/templates/blank/template.js | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/views/system/chapterRename.html (limited to 'src/views') diff --git a/src/views/system/chapterRename.html b/src/views/system/chapterRename.html new file mode 100644 index 0000000..28a6ee8 --- /dev/null +++ b/src/views/system/chapterRename.html @@ -0,0 +1,49 @@ + + + + + + + Document + + + + +
+
+

Change Chapter Name

+
+
+ +
+
+
+ + +
+
+
+ + + + + \ No newline at end of file diff --git a/src/views/templates/blank/template.html b/src/views/templates/blank/template.html index 7a07207..a1d8477 100644 --- a/src/views/templates/blank/template.html +++ b/src/views/templates/blank/template.html @@ -1,11 +1,40 @@ + Document + + + -

The Blank Template

+
+
+

Blank Template

+
+ + + +
+
+
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/src/views/templates/blank/template.js b/src/views/templates/blank/template.js index e69de29..d20f8ea 100644 --- a/src/views/templates/blank/template.js +++ b/src/views/templates/blank/template.js @@ -0,0 +1,65 @@ +const remote = require('electron').remote +const Menu = remote.Menu; +const MenuItem = remote.MenuItem; +const { ipcRenderer } = require('electron'); + +const chapterList = ['Chapterfl1']; +const chapterCount = chapterList.length; + +$(document).ready(function () { + updateChapters(); +}); + +function updateChapters() { + $('#chapters').empty(); + chapterList.forEach(chapter => { + const chapterName = chapter.replace(/fl/g, ' '); + $('#chapters').append(`${chapterName}`) + }); +} + +let currentSelectedChapterForContextAction = null; +let rightClickPosition = null; +const chapterMenu = new Menu() +const chapterContextItems = new MenuItem({ + label: 'Rename Chapter', + click: (e) => { + const currentChapter = currentSelectedChapterForContextAction.replace(/fl/g, ' '); + let child = new remote.BrowserWindow({ + parent: remote.getCurrentWindow(), + modal: true, + width: 360, + height: 135, + frame: false, + show: false, + titleBarStyle: 'hidden', + webPreferences: { + nodeIntegration: true, + enableRemoteModule: true + } + }) + child.loadURL('file://' + __dirname + '/../../system/chapterRename.html') + child.once('show', function () { + child.webContents.send('currentChapterName', currentChapter); + }); + child.once('ready-to-show', () => { + child.show() + }); + ipcRenderer.on('renamedChapter', (event, message) => { + const newChapterName = message; + const index = chapterList.findIndex(chapter => chapter === currentSelectedChapterForContextAction); + const newChapterId = newChapterName.replace(/ /g, 'fl'); + chapterList[index] = newChapterId; + currentSelectedChapterForContextAction = null; + updateChapters(); + }); + } +}) +chapterMenu.append(chapterContextItems); + +$(document).on('contextmenu', '.chapter_navigation', (e) => { + e.preventDefault(); + currentSelectedChapterForContextAction = e.target.id; + rightClickPosition = { x: e.x, y: e.y }; + chapterMenu.popup(remote.getCurrentWindow()); +}); -- cgit v1.2.3