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

Commit

Permalink
### Version 0.47.1 (Context Menu for Browser)
Browse files Browse the repository at this point in the history
#### Fix

- Upgrade dbl_dot_local_app cleaner_cli (9/25/2019)

### Version 0.47.0 (Context Menu for Browser)

#### Feature

- Add Edit > Find / Next / Backward to Browser Menus

(Merge branch 'begin_context_menu')
  • Loading branch information
ericpyle committed Sep 26, 2019
2 parents f5bd231 + c80e635 commit 65fdb8a
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### Version 0.47.1 (Context Menu for Browser)

#### Fix

- Upgrade dbl_dot_local_app cleaner_cli (9/25/2019)

### Version 0.47.0 (Context Menu for Browser)

#### Feature

- Add Edit > Find / Next / Backward to Browser Menus

### Version 0.46.0 (Context Menu for Browser)

#### Feature
Expand Down
97 changes: 94 additions & 3 deletions app/services/browserWindow.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import log from 'electron-log';
import fs from 'fs-extra';
import path from 'path';
import upath from 'upath';
import prompt from 'electron-prompt';
import { servicesHelpers } from '../helpers/services';

const {
Expand Down Expand Up @@ -43,6 +44,75 @@ function saveFileToFolder(browserWin) {
shell.showItemInFolder(targetFile);
}

let lastSearchText;
let lastSearchIndex;
let lastSearchResults;
const findNextLabel = 'Find Next';
const findNextShortcut = 'F3';
const findBackShortcut = 'Shift+F3';

function findNextInPageMenuItem(browserWin, searchText, forward = true) {
const findNextInfo = lastSearchResults
? ` (${lastSearchIndex}/${lastSearchResults})`
: '';
return findInPageMenuItem(
browserWin,
searchText,
false,
`${forward ? findNextLabel : 'Find Backward'}${findNextInfo}`,
forward ? findNextShortcut : findBackShortcut,
forward
);
}

function findInPageMenuItem(
browserWin,
selectionText,
openPrompt = true,
label = 'Find',
accelerator = 'CmdOrCtrl+F',
forward = true
) {
return {
label,
accelerator,
click: async () => {
const { webContents } = browserWin;
webContents.unselect();
if (openPrompt) {
try {
const promptResult = await prompt(
{
title: label,
label: '',
resizable: true,
value: selectionText,
inputAttrs: {
type: 'text'
}
},
browserWin
);
if (!promptResult || promptResult.length === 0) {
return;
}
lastSearchText = promptResult;
lastSearchIndex = undefined;
lastSearchResults = undefined;
webContents.findInPage(promptResult);
} catch (error) {
log.error(error);
}
} else {
if (!selectionText || selectionText.length === 0) {
return;
}
webContents.findInPage(selectionText, { forward });
}
}
};
}

function buildBrowserTemplate(browserWin) {
// console.log('menu/buildDefaultTemplate');
// console.log(loginLabel);
Expand All @@ -66,6 +136,11 @@ function buildBrowserTemplate(browserWin) {
{
role: 'copy'
},
{ type: 'separator' },
findInPageMenuItem(browserWin, lastSearchText),
findNextInPageMenuItem(browserWin, lastSearchText, true),
findNextInPageMenuItem(browserWin, lastSearchText, false),
{ type: 'separator' },
{
role: 'selectAll'
}
Expand Down Expand Up @@ -139,9 +214,25 @@ function openFileInChromeBrowser(
}
});
}

browserWin.webContents.on('context-menu', () => {
Menu.buildFromTemplate([{ role: 'copy' }]).popup(browserWin);
browserWin.webContents.on('found-in-page', (event, result) => {
const { activeMatchOrdinal, matches } = result;
lastSearchResults = matches;
lastSearchIndex = activeMatchOrdinal;
buildBrowserMenu(browserWin);
});
browserWin.webContents.on('context-menu', (event, params) => {
const { selectionText } = params;
const searchText =
selectionText && selectionText.length > 0
? selectionText
: lastSearchText;
Menu.buildFromTemplate([
{ role: 'copy' },
{ type: 'separator' },
findInPageMenuItem(browserWin, selectionText),
findNextInPageMenuItem(browserWin, searchText),
findNextInPageMenuItem(browserWin, searchText, false)
]).popup(browserWin);
});
return browserWin;
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nathanael",
"productName": "nathanael",
"version": "0.46.0",
"version": "0.47.1",
"description": "Electron frontend to DBL dot Local",
"scripts": {
"build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",
Expand Down Expand Up @@ -257,6 +257,7 @@
"devtron": "^1.4.0",
"electron-debug": "^2.1.0",
"electron-log": "^3.0.4",
"electron-prompt": "^1.3.1",
"electron-store": "^2.0.0",
"electron-updater": "^4.0.6",
"fast-sort": "^1.5.3",
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5249,6 +5249,13 @@ dns-txt@^2.0.2:
dependencies:
buffer-indexof "^1.0.0"

doc-ready@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/doc-ready/-/doc-ready-1.0.4.tgz#37f5391969cff994303fdfef2e5d50357f8164d3"
integrity sha1-N/U5GWnP+ZQwP9/vLl1QNX+BZNM=
dependencies:
eventie "^1"

[email protected]:
version "1.5.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa"
Expand Down Expand Up @@ -5500,6 +5507,13 @@ [email protected]:
minimist "^1.2.0"
plist "^3.0.1"

electron-prompt@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/electron-prompt/-/electron-prompt-1.3.1.tgz#547dfa6daa68264249c689f0086fdfad6c9bf52b"
integrity sha512-bCbDb9c9knx23PG6MfzBdYuffDZlZQ9gZhjTuUVCAwdCZv9hj/7IEguvBrP4DVDTouv+pYQ0LqCh5VuwYDktpg==
dependencies:
doc-ready "^1.0.4"

[email protected]:
version "20.39.0"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-20.39.0.tgz#a945d871b469b4160933d4e027612710b653f006"
Expand Down Expand Up @@ -6083,6 +6097,11 @@ eventemitter3@^3.0.0:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
integrity sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==

eventie@^1:
version "1.0.6"
resolved "https://registry.yarnpkg.com/eventie/-/eventie-1.0.6.tgz#d4ffc8b0c2b5e493c2aa1b22cbe918d3aee74437"
integrity sha1-1P/IsMK15JPCqhsiy+kY067nRDc=

events@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88"
Expand Down

0 comments on commit 65fdb8a

Please sign in to comment.