From 69de6b46b2eba1a02808fcb420745e985e97dbbb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 15 Jan 2011 20:14:45 +0300 Subject: [PATCH] implement j/k hotkeys to move between feeds (closes #292) --- FeedTree.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ help/3.php | 2 +- tt-rss.js | 12 ++++++++++-- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/FeedTree.js b/FeedTree.js index 26629e8c..a0d4fc7e 100644 --- a/FeedTree.js +++ b/FeedTree.js @@ -52,6 +52,55 @@ dojo.declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, { if (treeItem) return this.store.setValue(treeItem, key, value); }, + getNextFeed: function (feed, is_cat) { + if (is_cat) { + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + } else { + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + } + + items = this.store._arrayOfAllItems; + var item = items[0]; + + for (var i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + item = items[i+1]; + break; + } + } + + if (item) { + return [this.store.getValue(item, 'bare_id'), + !this.store.getValue(item, 'id').match('FEED:')]; + } else { + return false; + } + }, + getPreviousFeed: function (feed, is_cat) { + if (is_cat) { + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + } else { + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + } + + items = this.store._arrayOfAllItems; + var item = items[items.length-1]; + + for (var i = 0; i < items.length; i++) { + if (items[i] == treeItem) { + item = items[i-1]; + break; + } + } + + if (item) { + return [this.store.getValue(item, 'bare_id'), + !this.store.getValue(item, 'id').match('FEED:')]; + } else { + return false; + } + }, + getNextUnreadFeed: function (feed, is_cat) { if (is_cat) { treeItem = this.store._itemsByIdentity['CAT:' + feed]; diff --git a/help/3.php b/help/3.php index c45da863..d48adc61 100644 --- a/help/3.php +++ b/help/3.php @@ -5,7 +5,7 @@

- +
j/k
n/p
/
diff --git a/tt-rss.js b/tt-rss.js index 546c2213..9c8f5590 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -704,12 +704,20 @@ function hotkey_handler(e) { } if (keycode == 74) { // j - // TODO: move to previous feed + var rv = dijit.byId("feedTree").model.getPreviousFeed( + getActiveFeedId(), activeFeedIsCat()); + + if (rv) viewfeed(rv[0], '', rv[1]); + return; } if (keycode == 75) { // k - // TODO: move to next feed + var rv = dijit.byId("feedTree").model.getNextFeed( + getActiveFeedId(), activeFeedIsCat()); + + if (rv) viewfeed(rv[0], '', rv[1]); + return; } -- 2.39.5