Merge branch 'baumhoto-globalshortcut' into develop

This commit is contained in:
Antelle 2016-02-28 20:13:23 +03:00
commit 12cb153939
8 changed files with 77 additions and 30 deletions

View File

@ -16,6 +16,12 @@ var FeatureDetector = {
altShortcutSymbol: function(formatting) {
return this.isMac() ? '⌥' : formatting ? '<span class="thin">alt + </span>' : 'alt-';
},
globalShortcutSymbol: function(formatting) {
return this.isMac() ? '⌃⌥' : formatting ? '<span class="thin">shift+alt+</span>' : 'shift-alt-';
},
globalShortcutIsLarge: function() {
return !this.isMac();
},
shouldMoveHiddenInputToCopySource: function() {
return /(iPad|iPhone)/i.test(navigator.userAgent);
},

View File

@ -289,6 +289,7 @@ var Locale = {
setShEntry: 'go to entry',
setShCopyPass: 'copy password or selected field',
setShCopyUser: 'copy username',
setShCopyUrl: 'copy website',
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 (when app is in background)',
setShCopyUserGlobal: 'copy username (when app is in background)',
setShCopyUrlGlobal: 'copy website (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', this.copyPassword);
this.listenTo(Backbone, 'copy-user', this.copyUserName);
this.listenTo(Backbone, 'copy-url', this.copyUrl);
KeyHandler.onKey(Keys.DOM_VK_C, this.copyPassword, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_B, this.copyUserName, this, KeyHandler.SHORTCUT_ACTION, false, true);
KeyHandler.onKey(Keys.DOM_VK_U, this.copyUrl, 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, this.copyPassword, this);
KeyHandler.offKey(Keys.DOM_VK_B, this.copyUserName, this);
KeyHandler.offKey(Keys.DOM_VK_U, this.copyUrl, 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,38 +286,33 @@ 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 fieldValue = editView.value;
var fieldText = fieldValue.isProtected ? fieldValue.getText() : fieldValue;
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 });
}
}
copyPassword: function() {
this.copyKeyPress(this.passEditView);
},
copyUserName: function() {
this.copyKeyPress(this.userEditView);
},
copyUrl: function() {
this.copyKeyPress(this.urlEditView);
},
showCopyTip: function() {

View File

@ -9,7 +9,9 @@ var SettingsShortcutsView = Backbone.View.extend({
render: function() {
this.renderTemplate({
cmd: FeatureDetector.actionShortcutSymbol(true),
alt: FeatureDetector.altShortcutSymbol(true)
alt: FeatureDetector.altShortcutSymbol(true),
global: FeatureDetector.globalShortcutSymbol(true),
globalIsLarge: FeatureDetector.globalShortcutIsLarge()
});
}
});

View File

@ -26,6 +26,9 @@
text-align: center;
padding: $base-padding;
margin: 0 $base-padding-h $base-padding-v $base-padding-h;
&-large {
width: 80px;
}
&:first-of-type {
margin-left: 0;
}

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 {{#if globalIsLarge}}shortcut-large{{/if}}">{{{global}}}C</span> {{res 'setShCopyPassGlobal'}}</div>
<div><span class="shortcut {{#if globalIsLarge}}shortcut-large{{/if}}">{{{global}}}B</span> {{res 'setShCopyUserGlobal'}}</div>
<div><span class="shortcut {{#if globalIsLarge}}shortcut-large{{/if}}">{{{global}}}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');
@ -45,6 +47,7 @@ app.on('window-all-closed', function() {
});
app.on('ready', function() {
createMainWindow();
setGlobalShortcuts();
});
app.on('open-file', function(e, path) {
e.preventDefault();
@ -58,6 +61,9 @@ app.on('activate', function() {
}
}
});
app.on('will-quit', function() {
globalShortcut.unregisterAll();
});
app.restartApp = function() {
restartPending = true;
mainWindow.close();
@ -235,3 +241,21 @@ function notifyOpenFile() {
openFile = null;
}
}
function setGlobalShortcuts() {
var shortcutModifiers = process.platform === 'darwin' ? 'Ctrl+Alt+' : 'Shift+Alt+';
var shortcuts = {
C: 'copy-password',
B: 'copy-user',
U: 'copy-url'
};
Object.keys(shortcuts).forEach(function(key) {
var shortcut = shortcutModifiers + key;
var eventName = shortcuts[key];
try {
globalShortcut.register(shortcut, function () {
emitBackboneEvent(eventName);
});
} catch (e) {}
});
}

View File

@ -12,6 +12,8 @@ Storage providers, usability improvements
`+` option to search in title
`+` open files created without password
`+` usernames autocomplete
`+` shortcut to copy website
`+` shortcuts while the app is in background
`-` fix #88: capslock indicator
##### v1.0.4 (2016-02-25)