1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-21 07:06:39 +02:00

Merge branch 'globalshortcut' of https://github.com/baumhoto/keeweb into baumhoto-globalshortcut

This commit is contained in:
Antelle 2016-02-28 19:25:01 +03:00
commit 8e208e28be
4 changed files with 50 additions and 32 deletions

View File

@ -289,6 +289,7 @@ var Locale = {
setShEntry: 'go to entry',
setShCopyPass: 'copy password or selected field',
setShCopyUser: 'copy username',
setShCopyUrl: 'copy url',
setShPrev: 'go to previous item',
setShNext: 'go to next item',
setShCreateEntry: 'create entry',
@ -296,6 +297,9 @@ var Locale = {
setShSave: 'save all files',
setShGen: 'generate password',
setShSet: 'app settings',
setShCopyPassGlobal: 'copy password global (works when app is in background)',
setShCopyUserGlobal: 'copy username global (works when app is in background)',
setShCopyUrlGlobal: 'copy url global (works when app is in background)',
setAboutTitle: 'About',
setAboutBuilt: 'This app is built with these awesome tools',

View File

@ -35,6 +35,7 @@ var DetailsView = Backbone.View.extend({
views: null,
passEditView: null,
userEditView: null,
urlEditView: null,
addNewFieldView: null,
fieldCopyTip: null,
@ -57,15 +58,20 @@ var DetailsView = Backbone.View.extend({
this.views = {};
this.initScroll();
this.listenTo(Backbone, 'select-entry', this.showEntry);
KeyHandler.onKey(Keys.DOM_VK_C, this.copyKeyPress, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_B, this.copyUserKeyPress, this, KeyHandler.SHORTCUT_ACTION, false, true);
this.listenTo(Backbone, 'copy-password', function() { this.copyKeyPress(this.passEditView); } );
this.listenTo(Backbone, 'copy-user', function() { this.copyKeyPress(this.userEditView); } );
this.listenTo(Backbone, 'copy-url', function() { this.copyKeyPress(this.urlEditView); } );
KeyHandler.onKey(Keys.DOM_VK_C, function() { this.copyKeyPress(this.passEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_B, function() { this.copyKeyPress(this.userEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_U, function() { this.copyKeyPress(this.urlEditView); }, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION);
KeyHandler.onKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION);
},
remove: function() {
KeyHandler.offKey(Keys.DOM_VK_C, this.copyKeyPress, this);
KeyHandler.offKey(Keys.DOM_VK_B, this.copyUserKeyPress, this);
KeyHandler.offKey(Keys.DOM_VK_C, function() { this.copyKeyPress(this.passEditView); }, this);
KeyHandler.offKey(Keys.DOM_VK_B, function() { this.copyKeyPress(this.userEditView); }, this);
KeyHandler.offKey(Keys.DOM_VK_U, function() { this.copyKeyPress(this.urlEditView); }, this);
KeyHandler.offKey(Keys.DOM_VK_DELETE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION);
KeyHandler.offKey(Keys.DOM_VK_BACK_SPACE, this.deleteKeyPress, this, KeyHandler.SHORTCUT_ACTION);
this.removeFieldViews();
@ -125,8 +131,9 @@ var DetailsView = Backbone.View.extend({
this.passEditView = new FieldViewText({ model: { name: '$Password', title: Locale.detPassword, canGen: true,
value: function() { return model.password; } } });
this.fieldViews.push(this.passEditView);
this.fieldViews.push(new FieldViewUrl({ model: { name: '$URL', title: Locale.detWebsite,
value: function() { return model.url; } } }));
this.urlEditView = new FieldViewUrl({ model: { name: '$URL', title: Locale.detWebsite,
value: function() { return model.url; } } });
this.fieldViews.push(this.urlEditView);
this.fieldViews.push(new FieldViewText({ model: { name: '$Notes', title: Locale.detNotes, multiline: 'true',
value: function() { return model.notes; } } }));
this.fieldViews.push(new FieldViewTags({ model: { name: 'Tags', title: Locale.detTags, tags: this.appModel.tags,
@ -279,40 +286,23 @@ var DetailsView = Backbone.View.extend({
}
},
copyKeyPress: function() { // TODO: fix this in Safari
copyKeyPress: function(editView) {
if (!window.getSelection().toString()) {
var pw = this.model.password;
var password = pw.isProtected ? pw.getText() : pw;
if (!password) {
var field = editView.value;
var fieldText = field.isProtected ? field.getText() : field;
if (!fieldText) {
return;
}
if (!CopyPaste.simpleCopy) {
CopyPaste.createHiddenInput(password);
CopyPaste.createHiddenInput(fieldText);
}
var copyRes = CopyPaste.copy(password);
var copyRes = CopyPaste.copy(fieldText);
if (copyRes) {
this.fieldCopied({ source: this.passEditView, copyRes: copyRes });
this.fieldCopied({ source: editView, copyRes: copyRes });
}
}
},
copyUserKeyPress: function() {
if (!window.getSelection().toString()) {
var userField = this.model.user;
var user = userField.isProtected ? userField.getText() : userField;
if (!user) {
return;
}
if (!CopyPaste.simpleCopy) {
CopyPaste.createHiddenInput(user);
}
var copyRes = CopyPaste.copy(user);
if (copyRes) {
this.fieldCopied({ source: this.userEditView, copyRes: copyRes });
}
}
},
showCopyTip: function() {
if (this.helpTipCopyShown) {
return;

View File

@ -8,6 +8,7 @@
<div><span class="shortcut">⏎</span> {{res 'setShEntry'}}</div>
<div><span class="shortcut">{{{cmd}}}C</span> {{res 'setShCopyPass'}}</div>
<div><span class="shortcut">{{{cmd}}}B</span> {{res 'setShCopyUser'}}</div>
<div><span class="shortcut">{{{cmd}}}U</span> {{res 'setShCopyUrl'}}</div>
<div><span class="shortcut">&uarr;</span> {{res 'setShPrev'}}</div>
<div><span class="shortcut">&darr;</span> {{res 'setShNext'}}</div>
<div><span class="shortcut">{{{alt}}}N</span> {{res 'setShCreateEntry'}}</div>
@ -15,4 +16,7 @@
<div><span class="shortcut">{{{cmd}}}S</span> {{res 'setShSave'}}</div>
<div><span class="shortcut">{{{cmd}}}G</span> {{res 'setShGen'}}</div>
<div><span class="shortcut">{{{cmd}}},</span> {{res 'setShSet'}}</div>
<div><span class="shortcut">{{{ctrl}}}{{{alt}}}C</span> {{res 'setShCopyPassGlobal'}}</div>
<div><span class="shortcut">{{{ctrl}}}{{{alt}}}B</span> {{res 'setShCopyUserGlobal'}}</div>
<div><span class="shortcut">{{{ctrl}}}{{{alt}}}U</span> {{res 'setShCopyUrlGlobal'}}</div>
</div>

View File

@ -8,7 +8,8 @@ var app = require('app'),
fs = require('fs'),
BrowserWindow = require('browser-window'),
Menu = require('menu'),
Tray = require('tray');
Tray = require('tray'),
globalShortcut = require('electron').globalShortcut;
var mainWindow = null,
appIcon = null,
@ -29,6 +30,7 @@ process.argv.forEach(function(arg) {
app.on('window-all-closed', function() {
if (restartPending) {
// unbind all handlers, load new app.js module and pass control to it
globalShortcut.unregisterAll();
app.removeAllListeners('window-all-closed');
app.removeAllListeners('ready');
app.removeAllListeners('open-file');
@ -44,6 +46,15 @@ app.on('window-all-closed', function() {
}
});
app.on('ready', function() {
if (process.platform === 'darwin') {
createGlobalShortcut('Ctrl+Alt+B', 'copy-user');
createGlobalShortcut('Ctrl+Alt+C', 'copy-password');
createGlobalShortcut('Ctrl+Alt+U', 'copy-url');
} else {
createGlobalShortcut('Shift+Alt+B', 'copy-user');
createGlobalShortcut('Shift+Alt+C', 'copy-password');
createGlobalShortcut('Shift+Alt+U', 'copy-url');
}
createMainWindow();
});
app.on('open-file', function(e, path) {
@ -58,6 +69,9 @@ app.on('activate', function() {
}
}
});
app.on('will-quit', function() {
globalShortcut.unregisterAll();
});
app.restartApp = function() {
restartPending = true;
mainWindow.close();
@ -235,3 +249,9 @@ function notifyOpenFile() {
openFile = null;
}
}
function createGlobalShortcut(shortcut, backboneEventname) {
globalShortcut.register(shortcut, function() {
emitBackboneEvent(backboneEventname);
});
}