diff options
Diffstat (limited to 'background_scripts/main.coffee')
| -rw-r--r-- | background_scripts/main.coffee | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f564f477..3b7670d4 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -24,9 +24,11 @@ completionSources = history: new HistoryCompleter() domains: new DomainCompleter() tabs: new TabCompleter() + seachEngines: new SearchEngineCompleter() completers = omni: new MultiCompleter([ + completionSources.seachEngines, completionSources.bookmarks, completionSources.history, completionSources.domains]) @@ -217,6 +219,12 @@ repeatFunction = (func, totalCount, currentCount, frameId) -> -> repeatFunction(func, totalCount, currentCount + 1, frameId), frameId) +moveTab = (callback, direction) -> + chrome.tabs.getSelected(null, (tab) -> + # Use Math.max to prevent -1 as the new index, otherwise the tab of index n will wrap to the far RHS when + # moved left by exactly (n+1) places. + chrome.tabs.move(tab.id, {index: Math.max(0, tab.index + direction) }, callback)) + # Start action functions # These are commands which are bound to keystroke which must be handled by the background page. They are @@ -238,29 +246,39 @@ BackgroundCommands = chrome.tabs.getSelected(null, (tab) -> chrome.tabs.remove(tab.id)) restoreTab: (callback) -> - # TODO(ilya): Should this be getLastFocused instead? - chrome.windows.getCurrent((window) -> - return unless (tabQueue[window.id] && tabQueue[window.id].length > 0) - tabQueueEntry = tabQueue[window.id].pop() - # Clean out the tabQueue so we don't have unused windows laying about. - delete tabQueue[window.id] if (tabQueue[window.id].length == 0) - - # We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the - # tab is created because the content script is not available during the "loading" state. We need to - # wait until that's over before we can call setScrollPosition. - chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) -> - tabLoadedHandlers[tab.id] = -> - chrome.tabs.sendMessage(tab.id, - name: "setScrollPosition", - scrollX: tabQueueEntry.scrollX, - scrollY: tabQueueEntry.scrollY) - callback())) + # TODO: remove if-else -block when adopted into stable + if chrome.sessionRestore + chrome.sessionRestore.getRecentlyClosed((closed) -> + chrome.sessionRestore.restore(closed[0])) + else + # TODO(ilya): Should this be getLastFocused instead? + chrome.windows.getCurrent((window) -> + return unless (tabQueue[window.id] && tabQueue[window.id].length > 0) + tabQueueEntry = tabQueue[window.id].pop() + # Clean out the tabQueue so we don't have unused windows laying about. + delete tabQueue[window.id] if (tabQueue[window.id].length == 0) + + # We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the + # tab is created because the content script is not available during the "loading" state. We need to + # wait until that's over before we can call setScrollPosition. + chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) -> + tabLoadedHandlers[tab.id] = -> + chrome.tabs.sendRequest(tab.id, + name: "setScrollPosition", + scrollX: tabQueueEntry.scrollX, + scrollY: tabQueueEntry.scrollY) + callback())) openCopiedUrlInCurrentTab: (request) -> openUrlInCurrentTab({ url: Clipboard.paste() }) openCopiedUrlInNewTab: (request) -> openUrlInNewTab({ url: Clipboard.paste() }) + togglePinTab: (request) -> + chrome.tabs.getSelected(null, (tab) -> + chrome.tabs.update(tab.id, { pinned: !tab.pinned })) showHelp: (callback, frameId) -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.sendMessage(tab.id, { name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId })) + moveTabLeft: (count) -> moveTab(null, -count) + moveTabRight: (count) -> moveTab(null, count) nextFrame: (count) -> chrome.tabs.getSelected(null, (tab) -> frames = framesForTab[tab.id].frames @@ -596,3 +614,6 @@ chrome.windows.getAll { populate: true }, (windows) -> createScrollPositionHandler = -> (response) -> updateScrollPosition(tab, response.scrollX, response.scrollY) if response? chrome.tabs.sendMessage(tab.id, { name: "getScrollPosition" }, createScrollPositionHandler()) + +# Start pulling changes from synchronized storage. +Sync.init() |
