Keyboard shortcuts optimizations (#70)

Folder list focused state
This commit is contained in:
RainLoop Team 2014-04-13 04:32:07 +04:00
parent d961fa480a
commit 0fad66c452
53 changed files with 2231 additions and 1181 deletions

View file

@ -75,7 +75,7 @@ AbstractSystemDropDownViewModel.prototype.onBuild = function ()
{
var self = this;
key('`', [Enums.KeyState.MessageList, Enums.KeyState.MessageView, Enums.KeyState.Settings], function () {
if (RL.data().useKeyboardShortcuts() && !RL.popupVisibility() && !Globals.dropdownVisibility() && self.viewModelVisibility())
if (self.viewModelVisibility())
{
self.accountMenuDropdownTrigger(true);
}

View file

@ -7,11 +7,14 @@
function MailBoxFolderListViewModel()
{
KnoinAbstractViewModel.call(this, 'Left', 'MailFolderList');
var oData = RL.data();
this.folderList = RL.data().folderList;
this.folderListSystem = RL.data().folderListSystem;
this.foldersChanging = RL.data().foldersChanging;
this.messageList = oData.messageList;
this.folderList = oData.folderList;
this.folderListSystem = oData.folderListSystem;
this.foldersChanging = oData.foldersChanging;
this.iDropOverTimer = 0;
this.allowContacts = !!RL.settingsGet('ContactsIsAllowed');
@ -23,16 +26,12 @@ Utils.extendAsViewModel('MailBoxFolderListViewModel', MailBoxFolderListViewModel
MailBoxFolderListViewModel.prototype.onBuild = function (oDom)
{
var self = this;
oDom
.on('click', '.b-folders .b-content', function () {
if (RL.data().useKeyboardShortcuts() && RL.data().message.focused())
{
RL.data().message.focused(false);
}
})
.on('click', '.b-folders .e-item .e-link .e-collapsed-sign', function (oEvent) {
var
var
oFolder = ko.dataFor(this),
bCollapsed = false
;
@ -72,6 +71,61 @@ MailBoxFolderListViewModel.prototype.onBuild = function (oDom)
}
})
;
key('up, down', Enums.KeyState.FolderList, function (event, handler) {
var
iIndex = -1,
iKeyCode = handler && 'up' === handler.shortcut ? 38 : 40,
$items = $('.b-folders .e-item .e-link:not(.hidden):visible', oDom)
;
if (event && $items.length)
{
iIndex = $items.index($items.filter('.focused'));
if (-1 < iIndex)
{
$items.eq(iIndex).removeClass('focused');
}
if (iKeyCode === 38 && iIndex > 0)
{
iIndex--;
}
else if (iKeyCode === 40 && iIndex < $items.length - 1)
{
iIndex++;
}
$items.eq(iIndex).addClass('focused');
}
return false;
});
key('enter', Enums.KeyState.FolderList, function () {
var $items = $('.b-folders .e-item .e-link:not(.hidden).focused', oDom);
if ($items.length && $items[0])
{
self.folderList.focused(false);
$items.click();
}
return false;
});
key('esc, tab, shift+tab', Enums.KeyState.FolderList, function () {
self.folderList.focused(false);
return false;
});
self.folderList.focused.subscribe(function (bValue) {
$('.b-folders .e-item .e-link.focused', oDom).removeClass('focused');
if (bValue)
{
$('.b-folders .e-item .e-link.selected', oDom).addClass('focused');
}
});
};
MailBoxFolderListViewModel.prototype.messagesDropOver = function (oFolder)

View file

@ -18,6 +18,7 @@ function MailBoxMessageListViewModel()
this.message = oData.message;
this.messageList = oData.messageList;
this.folderList = oData.folderList;
this.currentMessage = oData.currentMessage;
this.isMessageSelected = oData.isMessageSelected;
this.messageListSearch = oData.messageListSearch;
@ -207,7 +208,6 @@ function MailBoxMessageListViewModel()
return oMessage ? oMessage.generateUid() : '';
});
// this.selector.autoSelect(false);
oData.layout.subscribe(function (mValue) {
this.selector.autoSelect(Enums.Layout.NoPreview !== mValue);
}, this);
@ -618,7 +618,7 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
oDom
.on('click', '.messageList .b-message-list-wrapper', function () {
if (oData.useKeyboardShortcuts() && self.message.focused())
if (self.message.focused())
{
self.message.focused(false);
}
@ -657,30 +657,28 @@ MailBoxMessageListViewModel.prototype.onBuild = function (oDom)
MailBoxMessageListViewModel.prototype.initShortcuts = function ()
{
var
self = this,
oData = RL.data()
;
var self = this;
// disable print
key('ctrl+p, command+p', Enums.KeyState.MessageList, function () {
if (oData.useKeyboardShortcuts())
{
return false;
}
return false;
});
// TODO // more toggle
// key('', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
// self.moreDropdownTrigger(true);
// return false;
// });
// archive (zip)
key('z', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.moreDropdownTrigger(true);
return false;
}
self.archiveCommand();
return false;
});
// delete
key('delete, shift+delete', Enums.KeyState.MessageList, function (event, handler) {
if (oData.useKeyboardShortcuts() && event)
if (event)
{
if (0 < RL.data().messageListCheckedOrSelected().length)
{
@ -700,92 +698,60 @@ MailBoxMessageListViewModel.prototype.initShortcuts = function ()
// check all
key('ctrl+a, command+a', Enums.KeyState.MessageList, function () {
if (oData.useKeyboardShortcuts())
{
self.checkAll(!(self.checkAll() && !self.isIncompleteChecked()));
return false;
}
self.checkAll(!(self.checkAll() && !self.isIncompleteChecked()));
return false;
});
// write/compose (open compose popup)
key('w,c', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
kn.showScreenPopup(PopupsComposeViewModel);
return false;
}
kn.showScreenPopup(PopupsComposeViewModel);
return false;
});
// important - star/flag messages
key('i', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.flagMessagesFast();
return false;
}
self.flagMessagesFast();
return false;
});
// move
key('m', Enums.KeyState.MessageList, function () {
if (oData.useKeyboardShortcuts())
{
self.moveDropdownTrigger(true);
return false;
}
self.moveDropdownTrigger(true);
return false;
});
// read
key('q', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.seenMessagesFast(true);
return false;
}
self.seenMessagesFast(true);
return false;
});
// unread
key('u', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.seenMessagesFast(false);
return false;
}
self.seenMessagesFast(false);
return false;
});
// shortcuts help
key('shift+/', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
kn.showScreenPopup(PopupsKeyboardShortcutsHelpViewModel);
return false;
}
kn.showScreenPopup(PopupsKeyboardShortcutsHelpViewModel);
return false;
});
key('shift+f', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.multyForwardCommand();
return false;
}
self.multyForwardCommand();
return false;
});
// search input focus
key('/', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
if (self.message())
{
self.message.focused(false);
}
self.inputMessageListSearchFocus(true);
return false;
}
self.inputMessageListSearchFocus(true);
return false;
});
// cancel search
key('esc', Enums.KeyState.MessageList, function () {
if (oData.useKeyboardShortcuts() && '' !== self.messageListSearchDesc())
if ('' !== self.messageListSearchDesc())
{
self.cancelSearch();
return false;
@ -793,32 +759,27 @@ MailBoxMessageListViewModel.prototype.initShortcuts = function ()
});
// change focused state
key('tab, shift+tab', Enums.KeyState.MessageList, function () {
if (oData.useKeyboardShortcuts())
key('tab, shift+tab', Enums.KeyState.MessageList, function (event, handler) {
if (event && handler && 'shift+tab' === handler.shortcut)
{
if (self.message())
{
self.message.focused(true);
}
return false;
self.folderList.focused(true);
}
else if (self.message())
{
self.message.focused(true);
}
return false;
});
// TODO
key('ctrl+left, command+left', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
{
// TODO
return false;
}
return false;
});
// TODO
key('ctrl+right, command+right', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
{
// TODO
return false;
}
return false;
});
};

View file

@ -386,7 +386,7 @@ MailBoxMessageViewViewModel.prototype.onBuild = function (oDom)
*/
MailBoxMessageViewViewModel.prototype.escShortcuts = function ()
{
if (this.viewModelVisibility() && RL.data().useKeyboardShortcuts() && this.message())
if (this.viewModelVisibility() && this.message())
{
if (this.fullScreenMode())
{
@ -417,24 +417,19 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// fullscreen
key('enter', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
{
self.toggleFullScreen();
return false;
}
self.toggleFullScreen();
return false;
});
key('x', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts())
{
self.moreDropdownTrigger(true);
return false;
}
});
// TODO // more toggle
// key('', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
// self.moreDropdownTrigger(true);
// return false;
// });
// reply
key('r', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts() && oData.message())
if (oData.message())
{
self.replyCommand();
return false;
@ -443,7 +438,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// replaAll
key('a', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts() && oData.message())
if (oData.message())
{
self.replyAllCommand();
return false;
@ -452,7 +447,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// forward
key('f', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts() && oData.message())
if (oData.message())
{
self.forwardCommand();
return false;
@ -461,7 +456,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// message information
// key('i', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
// if (oData.useKeyboardShortcuts())
// if (oData.message())
// {
// self.showFullInfo(!self.showFullInfo());
// return false;
@ -470,7 +465,7 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// toggle message blockquotes
key('b', [Enums.KeyState.MessageList, Enums.KeyState.MessageView], function () {
if (oData.useKeyboardShortcuts() && oData.message() && oData.message().body)
if (oData.message() && oData.message().body)
{
Utils.toggleMessageBlockquote(oData.message().body);
return false;
@ -478,37 +473,28 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
});
key('ctrl+left, command+left, ctrl+up, command+up', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
{
self.goUpCommand();
return false;
}
self.goUpCommand();
return false;
});
key('ctrl+right, command+right, ctrl+down, command+down', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
{
self.goDownCommand();
return false;
}
self.goDownCommand();
return false;
});
// print
key('ctrl+p, command+p', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
if (self.message())
{
if (self.message())
{
self.message().printMessage();
}
return false;
self.message().printMessage();
}
return false;
});
// delete
key('delete, shift+delete', Enums.KeyState.MessageView, function (event, handler) {
if (oData.useKeyboardShortcuts() && event)
if (event)
{
if (handler && 'shift+delete' === handler.shortcut)
{
@ -525,15 +511,12 @@ MailBoxMessageViewViewModel.prototype.initShortcuts = function ()
// change focused state
key('tab, shift+tab', Enums.KeyState.MessageView, function () {
if (oData.useKeyboardShortcuts())
if (!self.fullScreenMode() && self.message())
{
if (!self.fullScreenMode() && self.message())
{
self.message.focused(false);
}
return false;
self.message.focused(false);
}
return false;
});
};

View file

@ -21,8 +21,6 @@ function PopupsAskViewModel()
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = Enums.KeyState.PopupAsk;
this.sKeyScope = Enums.KeyState.MessageList;
Knoin.constructorEnd(this);
}
@ -94,7 +92,7 @@ PopupsAskViewModel.prototype.onFocus = function ()
PopupsAskViewModel.prototype.onBuild = function ()
{
key('tab, right, left', Enums.KeyState.PopupAsk, _.bind(function () {
key('tab, shift+tab, right, left', Enums.KeyState.PopupAsk, _.bind(function () {
if (this.yesFocus())
{
this.noFocus(true);

View file

@ -31,6 +31,8 @@ function PopupsComposeViewModel()
this.resizer = ko.observable(false).extend({'throttle': 50});
this.identitiesDropdownTrigger = ko.observable(false);
this.to = ko.observable('');
this.to.focusTrigger = ko.observable(false);
this.cc = ko.observable('');
@ -915,43 +917,33 @@ PopupsComposeViewModel.prototype.tryToClosePopup = function ()
}]);
};
PopupsComposeViewModel.prototype.useShortcuts = function ()
{
return RL.data().useKeyboardShortcuts();
};
PopupsComposeViewModel.prototype.onBuild = function ()
{
this.initUploader();
var
self = this,
oData = RL.data(),
oScript = null
;
key('ctrl+q, command+q', Enums.KeyState.Compose, function () {
self.identitiesDropdownTrigger(true);
return false;
});
key('ctrl+s, command+s', Enums.KeyState.Compose, function () {
if (oData.useKeyboardShortcuts())
{
self.saveCommand();
return false;
}
self.saveCommand();
return false;
});
key('ctrl+enter, command+enter', Enums.KeyState.Compose, function () {
if (oData.useKeyboardShortcuts())
{
self.sendCommand();
return false;
}
self.sendCommand();
return false;
});
key('esc', Enums.KeyState.Compose, function () {
if (oData.useKeyboardShortcuts())
{
self.tryToClosePopup();
return false;
}
self.tryToClosePopup();
return false;
});
$window.on('resize', function () {

View file

@ -582,11 +582,8 @@ PopupsContactsViewModel.prototype.onBuild = function (oDom)
var self = this;
key('delete', Enums.KeyState.ContactList, function () {
if (RL.data().useKeyboardShortcuts())
{
self.deleteCommand();
return false;
}
self.deleteCommand();
return false;
});
oDom

View file

@ -8,7 +8,39 @@ function PopupsKeyboardShortcutsHelpViewModel()
{
KnoinAbstractViewModel.call(this, 'Popups', 'PopupsKeyboardShortcutsHelp');
this.sDefaultKeyScope = Enums.KeyState.PopupKeyboardShortcutsHelp;
Knoin.constructorEnd(this);
}
Utils.extendAsViewModel('PopupsKeyboardShortcutsHelpViewModel', PopupsKeyboardShortcutsHelpViewModel);
PopupsKeyboardShortcutsHelpViewModel.prototype.onBuild = function (oDom)
{
key('tab, shift+tab', Enums.KeyState.PopupKeyboardShortcutsHelp, _.bind(function (event, handler) {
if (event && handler)
{
var
$tabs = oDom.find('.nav.nav-tabs > li'),
bNext = handler && 'tab' === handler.shortcut,
iIndex = $tabs.index($tabs.filter('.active'))
;
if (!bNext && iIndex > 0)
{
iIndex--;
}
else if (bNext && iIndex < $tabs.length - 1)
{
iIndex++;
}
else
{
iIndex = bNext ? 0 : $tabs.length - 1;
}
$tabs.eq(iIndex).find('a[data-toggle="tab"]').tab('show');
return false;
}
}, this));
};

View file

@ -17,10 +17,7 @@ SettingsPaneViewModel.prototype.onBuild = function ()
{
var self = this;
key('esc', Enums.KeyState.Settings, function () {
if (RL.data().useKeyboardShortcuts())
{
self.backToMailBoxClick();
}
self.backToMailBoxClick();
});
};