aboutsummaryrefslogtreecommitdiff
path: root/src/background/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-05-01 15:51:40 +0900
commit9da2f5fd786ff7ef64eca0a86efb1c0b9a164244 (patch)
treeb888349817d0016dc1499932671bbe6cd95efdaa /src/background/actions
parentf9889b7f2b634bfe5a540633d8952f4a6f900658 (diff)
parent89d6afecfd257ff4fc62748f771abf37ef3a2852 (diff)
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'src/background/actions')
-rw-r--r--src/background/actions/command.js79
-rw-r--r--src/background/actions/find.js10
-rw-r--r--src/background/actions/index.js8
-rw-r--r--src/background/actions/operation.js8
-rw-r--r--src/background/actions/setting.js21
-rw-r--r--src/background/actions/tab.js18
6 files changed, 141 insertions, 3 deletions
diff --git a/src/background/actions/command.js b/src/background/actions/command.js
new file mode 100644
index 0000000..4c52bca
--- /dev/null
+++ b/src/background/actions/command.js
@@ -0,0 +1,79 @@
+import actions from '../actions';
+import * as tabs from 'background/tabs';
+import * as parsers from 'shared/commands/parsers';
+import * as properties from 'shared/settings/properties';
+
+const openCommand = (url) => {
+ return browser.tabs.query({
+ active: true, currentWindow: true
+ }).then((gotTabs) => {
+ if (gotTabs.length > 0) {
+ return browser.tabs.update(gotTabs[0].id, { url: url });
+ }
+ });
+};
+
+const tabopenCommand = (url) => {
+ return browser.tabs.create({ url: url });
+};
+
+const winopenCommand = (url) => {
+ return browser.windows.create({ url });
+};
+
+const bufferCommand = (keywords) => {
+ if (keywords.length === 0) {
+ return Promise.resolve([]);
+ }
+ let keywordsStr = keywords.join(' ');
+ return browser.tabs.query({
+ active: true, currentWindow: true
+ }).then((gotTabs) => {
+ if (gotTabs.length > 0) {
+ if (isNaN(keywordsStr)) {
+ return tabs.selectByKeyword(gotTabs[0], keywordsStr);
+ }
+ let index = parseInt(keywordsStr, 10) - 1;
+ return tabs.selectAt(index);
+ }
+ });
+};
+
+const setCommand = (args) => {
+ if (!args[0]) {
+ return Promise.resolve();
+ }
+
+ let [name, value] = parsers.parseSetOption(args[0], properties.types);
+ return {
+ type: actions.SETTING_SET_PROPERTY,
+ name,
+ value
+ };
+};
+
+const exec = (line, settings) => {
+ let [name, args] = parsers.parseCommandLine(line);
+
+ switch (name) {
+ case 'o':
+ case 'open':
+ return openCommand(parsers.normalizeUrl(args, settings.search));
+ case 't':
+ case 'tabopen':
+ return tabopenCommand(parsers.normalizeUrl(args, settings.search));
+ case 'w':
+ case 'winopen':
+ return winopenCommand(parsers.normalizeUrl(args, settings.search));
+ case 'b':
+ case 'buffer':
+ return bufferCommand(args);
+ case 'set':
+ return setCommand(args);
+ case '':
+ return Promise.resolve();
+ }
+ throw new Error(name + ' command is not defined');
+};
+
+export { exec };
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
new file mode 100644
index 0000000..2bdaaf2
--- /dev/null
+++ b/src/background/actions/index.js
@@ -0,0 +1,8 @@
+export default {
+ // Settings
+ SETTING_SET_SETTINGS: 'setting.set.settings',
+ SETTING_SET_PROPERTY: 'setting.set.property',
+
+ // Find
+ FIND_SET_KEYWORD: 'find.set.keyword',
+};
diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js
index 1e4990c..56eb168 100644
--- a/src/background/actions/operation.js
+++ b/src/background/actions/operation.js
@@ -17,6 +17,8 @@ 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:
@@ -27,6 +29,8 @@ const exec = (operation, tab) => {
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:
@@ -69,6 +73,10 @@ const exec = (operation, tab) => {
return browser.tabs.sendMessage(tab.id, {
type: messages.CONSOLE_SHOW_FIND
});
+ case operations.CANCEL:
+ return browser.tabs.sendMessage(tab.id, {
+ type: messages.CONSOLE_HIDE,
+ });
default:
return Promise.resolve();
}
diff --git a/src/background/actions/setting.js b/src/background/actions/setting.js
new file mode 100644
index 0000000..773142f
--- /dev/null
+++ b/src/background/actions/setting.js
@@ -0,0 +1,21 @@
+import actions from '../actions';
+import * as settingsStorage from 'shared/settings/storage';
+
+const load = () => {
+ return settingsStorage.loadValue().then((value) => {
+ return {
+ type: actions.SETTING_SET_SETTINGS,
+ value,
+ };
+ });
+};
+
+const setProperty = (name, value) => {
+ return {
+ type: actions.SETTING_SET_PROPERTY,
+ name,
+ value,
+ };
+};
+
+export { load, setProperty };
diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js
index e512b6f..3c642fd 100644
--- a/src/background/actions/tab.js
+++ b/src/background/actions/tab.js
@@ -1,9 +1,21 @@
-const openNewTab = (url) => {
- return browser.tabs.create({ url: url });
+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 };
+export { openNewTab, openToTab };