diff options
Diffstat (limited to 'src/background/actions')
-rw-r--r-- | src/background/actions/command.js | 51 | ||||
-rw-r--r-- | src/background/actions/find.js | 10 | ||||
-rw-r--r-- | src/background/actions/index.js | 6 | ||||
-rw-r--r-- | src/background/actions/operation.js | 82 | ||||
-rw-r--r-- | src/background/actions/tab.js | 27 |
5 files changed, 89 insertions, 87 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js index 4c52bca..f1ee5b5 100644 --- a/src/background/actions/command.js +++ b/src/background/actions/command.js @@ -1,5 +1,7 @@ +import messages from 'shared/messages'; import actions from '../actions'; -import * as tabs from 'background/tabs'; +import * as tabs from '../shared/tabs'; +import * as bookmarks from '../shared/bookmarks'; import * as parsers from 'shared/commands/parsers'; import * as properties from 'shared/settings/properties'; @@ -17,6 +19,14 @@ const tabopenCommand = (url) => { return browser.tabs.create({ url: url }); }; +const tabcloseCommand = () => { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((tabList) => { + return browser.tabs.remove(tabList.map(tab => tab.id)); + }); +}; + const winopenCommand = (url) => { return browser.windows.create({ url }); }; @@ -39,6 +49,14 @@ const bufferCommand = (keywords) => { }); }; +const addBookmarkCommand = (tab, args) => { + if (!args[0]) { + return Promise.resolve(); + } + + return bookmarks.create(args.join(' '), tab.url); +}; + const setCommand = (args) => { if (!args[0]) { return Promise.resolve(); @@ -52,7 +70,8 @@ const setCommand = (args) => { }; }; -const exec = (line, settings) => { +// eslint-disable-next-line complexity +const exec = (tab, line, settings) => { let [name, args] = parsers.parseCommandLine(line); switch (name) { @@ -68,8 +87,36 @@ const exec = (line, settings) => { case 'b': case 'buffer': return bufferCommand(args); + case 'bd': + case 'bdel': + case 'bdelete': + return tabs.closeTabByKeywords(args.join(' ')); + case 'bd!': + case 'bdel!': + case 'bdelete!': + return tabs.closeTabByKeywordsForce(args.join(' ')); + case 'bdeletes': + return tabs.closeTabsByKeywords(args.join(' ')); + case 'bdeletes!': + return tabs.closeTabsByKeywordsForce(args.join(' ')); + case 'addbookmark': + return addBookmarkCommand(tab, args).then((item) => { + if (!item) { + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: 'Could not create a bookmark', + }); + } + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_INFO, + text: 'Saved current page: ' + item.url, + }); + }); case 'set': return setCommand(args); + case 'q': + case 'quit': + return tabcloseCommand(); case '': return Promise.resolve(); } diff --git a/src/background/actions/find.js b/src/background/actions/find.js new file mode 100644 index 0000000..8da5572 --- /dev/null +++ b/src/background/actions/find.js @@ -0,0 +1,10 @@ +import actions from './index'; + +const setKeyword = (keyword) => { + return { + type: actions.FIND_SET_KEYWORD, + keyword, + }; +}; + +export { setKeyword }; diff --git a/src/background/actions/index.js b/src/background/actions/index.js index efe4074..3833389 100644 --- a/src/background/actions/index.js +++ b/src/background/actions/index.js @@ -2,4 +2,10 @@ export default { // Settings SETTING_SET_SETTINGS: 'setting.set.settings', SETTING_SET_PROPERTY: 'setting.set.property', + + // Find + FIND_SET_KEYWORD: 'find.set.keyword', + + // Tab + TAB_SELECTED: 'tab.selected', }; diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js deleted file mode 100644 index 1188ea2..0000000 --- a/src/background/actions/operation.js +++ /dev/null @@ -1,82 +0,0 @@ -import operations from 'shared/operations'; -import messages from 'shared/messages'; -import * as tabs from 'background/tabs'; -import * as zooms from 'background/zooms'; - -const sendConsoleShowCommand = (tab, command) => { - return browser.tabs.sendMessage(tab.id, { - type: messages.CONSOLE_SHOW_COMMAND, - command, - }); -}; - -// This switch statement is only gonna get longer as more -// features are added, so disable complexity check -/* eslint-disable complexity */ -const exec = (operation, tab) => { - switch (operation.type) { - case operations.TAB_CLOSE: - return tabs.closeTab(tab.id); - case operations.TAB_CLOSE_FORCE: - return tabs.closeTabForce(tab.id); - case operations.TAB_REOPEN: - return tabs.reopenTab(); - case operations.TAB_PREV: - return tabs.selectPrevTab(tab.index, operation.count); - case operations.TAB_NEXT: - return tabs.selectNextTab(tab.index, operation.count); - case operations.TAB_FIRST: - return tabs.selectFirstTab(); - case operations.TAB_LAST: - return tabs.selectLastTab(); - case operations.TAB_PREV_SEL: - return tabs.selectPrevSelTab(); - case operations.TAB_RELOAD: - return tabs.reload(tab, operation.cache); - case operations.TAB_PIN: - return tabs.updateTabPinned(tab, true); - case operations.TAB_UNPIN: - return tabs.updateTabPinned(tab, false); - case operations.TAB_TOGGLE_PINNED: - return tabs.toggleTabPinned(tab); - case operations.TAB_DUPLICATE: - return tabs.duplicate(tab.id); - case operations.ZOOM_IN: - return zooms.zoomIn(); - case operations.ZOOM_OUT: - return zooms.zoomOut(); - case operations.ZOOM_NEUTRAL: - return zooms.neutral(); - case operations.COMMAND_SHOW: - return sendConsoleShowCommand(tab, ''); - case operations.COMMAND_SHOW_OPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'open ' + tab.url); - } - return sendConsoleShowCommand(tab, 'open '); - case operations.COMMAND_SHOW_TABOPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'tabopen ' + tab.url); - } - return sendConsoleShowCommand(tab, 'tabopen '); - case operations.COMMAND_SHOW_WINOPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'winopen ' + tab.url); - } - return sendConsoleShowCommand(tab, 'winopen '); - case operations.COMMAND_SHOW_BUFFER: - return sendConsoleShowCommand(tab, 'buffer '); - case operations.FIND_START: - return browser.tabs.sendMessage(tab.id, { - type: messages.CONSOLE_SHOW_FIND - }); - default: - return Promise.resolve(); - } -}; -/* eslint-enable complexity */ - -export { exec }; diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js index e512b6f..0d439fd 100644 --- a/src/background/actions/tab.js +++ b/src/background/actions/tab.js @@ -1,9 +1,30 @@ -const openNewTab = (url) => { - return browser.tabs.create({ url: url }); +import actions from './index'; + +const openNewTab = (url, openerTabId, background = false, adjacent = false) => { + if (adjacent) { + return browser.tabs.query({ + active: true, currentWindow: true + }).then((tabs) => { + return browser.tabs.create({ + url, + openerTabId, + active: !background, + index: tabs[0].index + 1 + }); + }); + } + return browser.tabs.create({ url, active: !background }); }; const openToTab = (url, tab) => { return browser.tabs.update(tab.id, { url: url }); }; -export { openToTab, openNewTab }; +const selected = (tabId) => { + return { + type: actions.TAB_SELECTED, + tabId, + }; +}; + +export { openNewTab, openToTab, selected }; |