consome as store/reducers
This commit is contained in:
parent
6127fdc285
commit
83cb277ba2
17 changed files with 171 additions and 236 deletions
|
@ -1,11 +0,0 @@
|
|||
import actions from '../actions';
|
||||
|
||||
export function requestCompletions(line) {
|
||||
let command = line.split(' ', 1)[0];
|
||||
let keywords = line.replace(command + ' ', '');
|
||||
return {
|
||||
type: actions.BACKGROUND_REQUEST_COMPLETIONS,
|
||||
command,
|
||||
keywords
|
||||
};
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import actions from '../actions';
|
||||
import * as tabs from '../background/tabs';
|
||||
import * as consoleActions from './console';
|
||||
|
||||
const normalizeUrl = (string) => {
|
||||
try {
|
||||
|
@ -8,28 +9,76 @@ const normalizeUrl = (string) => {
|
|||
}
|
||||
}
|
||||
|
||||
export function exec(line) {
|
||||
let name = line.split(' ')[0];
|
||||
let remaining = line.replace(name + ' ', '');
|
||||
const openCommand = (url) => {
|
||||
return browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
|
||||
if (tabs.length > 0) {
|
||||
return browser.tabs.update(tabs[0].id, { url: url });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const tabopenCommand = (url) => {
|
||||
return browser.tabs.create({ url: url });
|
||||
}
|
||||
|
||||
const bufferCommand = (keywords) => {
|
||||
return browser.tabs.query({ active: true, currentWindow: true }).then((tabss) => {
|
||||
if (tabss.length > 0) {
|
||||
if (isNaN(keywords)) {
|
||||
return tabs.selectByKeyword(tabss[0], keywords);
|
||||
} else {
|
||||
let index = parseInt(keywords, 10) - 1;
|
||||
return tabs.selectAt(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const doCommand = (name, remaining) => {
|
||||
switch (name) {
|
||||
case 'open':
|
||||
// TODO use search engined and pass keywords to them
|
||||
return {
|
||||
type: actions.COMMAND_OPEN_URL,
|
||||
url: normalizeUrl(remaining)
|
||||
};
|
||||
return openCommand(normalizeUrl(remaining));
|
||||
case 'tabopen':
|
||||
return {
|
||||
type: actions.COMMAND_TABOPEN_URL,
|
||||
url: normalizeUrl(remaining)
|
||||
};
|
||||
return tabopenCommand(normalizeUrl(remaining));
|
||||
case 'b':
|
||||
case 'buffer':
|
||||
return {
|
||||
type: actions.COMMAND_BUFFER,
|
||||
keywords: remaining
|
||||
};
|
||||
return bufferCommand(remaining);
|
||||
}
|
||||
throw new Error(name + ' command is not defined');
|
||||
}
|
||||
|
||||
const getCompletions = (command, keywords) => {
|
||||
switch (command) {
|
||||
case 'buffer':
|
||||
return tabs.getCompletions(keywords).then((tabs) => {
|
||||
let items = tabs.map((tab) => {
|
||||
return {
|
||||
caption: tab.title,
|
||||
content: tab.title,
|
||||
url: tab.url,
|
||||
icon: tab.favIconUrl
|
||||
}
|
||||
});
|
||||
return [{
|
||||
name: "Buffers",
|
||||
items: items
|
||||
}];
|
||||
});
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
};
|
||||
|
||||
export function exec(line) {
|
||||
let name = line.split(' ')[0];
|
||||
let remaining = line.replace(name + ' ', '');
|
||||
return doCommand(name, remaining).then(() => {
|
||||
return consoleActions.hide();
|
||||
});
|
||||
}
|
||||
|
||||
export function complete(line) {
|
||||
let command = line.split(' ', 1)[0];
|
||||
let keywords = line.replace(command + ' ', '');
|
||||
return getCompletions(command, keywords).then(consoleActions.setCompletions);
|
||||
}
|
||||
|
|
|
@ -5,19 +5,7 @@ export default {
|
|||
CONSOLE_SHOW_ERROR: 'vimvixen.console.show.error',
|
||||
CONSOLE_HIDE: 'vimvixen.console.hide',
|
||||
|
||||
// Background commands
|
||||
BACKGROUND_REQUEST_COMPLETIONS: 'vimvixen.background.request.completions',
|
||||
|
||||
// content commands
|
||||
CMD_OPEN: 'cmd.open',
|
||||
CMD_TABS_OPEN: 'cmd.tabs.open',
|
||||
CMD_BUFFER: 'cmd.buffer',
|
||||
|
||||
// User input
|
||||
INPUT_KEY_PRESS: 'input.key,press',
|
||||
INPUT_CLEAR_KEYS: 'input.clear.keys',
|
||||
|
||||
COMMAND_OPEN_URL: 'command.open.url',
|
||||
COMMAND_TABOPEN_URL: 'command.tabopen.url',
|
||||
COMMAND_BUFFER: 'command.buffer',
|
||||
};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import operations from '../operations';
|
||||
import * as consoleActions from './console';
|
||||
import * as tabs from '../background/tabs';
|
||||
import * as zooms from '../background/zooms';
|
||||
|
||||
|
@ -20,6 +21,17 @@ export function exec(operation, tab) {
|
|||
return zooms.zoomOut();
|
||||
case operations.ZOOM_NEUTRAL:
|
||||
return zooms.neutral();
|
||||
case operations.COMMAND_OPEN:
|
||||
return consoleActions.showCommand('');
|
||||
case operations.COMMAND_TABS_OPEN:
|
||||
if (operations.alter) {
|
||||
// alter url
|
||||
return consoleActions.showCommand('open ' + tab.url);
|
||||
} else {
|
||||
return consoleActions.showCommand('open ');
|
||||
}
|
||||
case operations.COMMAND_BUFFER:
|
||||
return consoleActions.showCommand('buffer ');
|
||||
default:
|
||||
return browser.tabs.sendMessage(tab.id, {
|
||||
type: 'require.content.operation',
|
||||
|
|
Reference in a new issue