Commit 64440cc3 authored by antoor's avatar antoor

Added plug-in list to contextmenu

新增右键菜单插件列表
parent 943feaa3
// /**
// 插件中心 * 插件中心
// * 开写:2016/05/09
* 更新:-
* 作者:蚁逅 <https://github.com/antoor>
*/
const LANG = antSword['language']['plugin']; 'use strict';
const LANG_T = antSword['language']['toastr'];
class Plugin { const path = global.require('path');
class Plugin {
constructor() { constructor() {
antSword['menubar'].reg('plugin', this.open.bind(this)); // 注册菜单事件
this.homepage = 'http://u.uyu.us/'; antSword['menubar'].reg(
} 'plugin-store',
this.initWin.bind(this, 'ant-views://plugin.html')
open() {
const tabbar = antSword['tabbar'];
// 判断是否已经打开
if (tabbar.tabs('tab_plugin')) {
return tabbar.tabs('tab_plugin').setActive();
};
tabbar.addTab(
'tab_plugin',
'<i class="fa fa-cart-arrow-down"></i>',
null, null, true, true
); );
const cell = tabbar.tabs('tab_plugin'); this.win = null;
// }
// @创建浏览器工具栏:后退、前进、刷新、主页、停止
//
const toolbar = cell.attachToolbar();
toolbar.loadStruct([
{ id: 'back', type: 'button', text: '', icon: 'chevron-left' },
{ id: 'forward', type: 'button', text: '', icon: 'chevron-right' },
{ id: 'refresh', type: 'button', text: '', icon: 'refresh' },
{ id: 'home', type: 'button', text: '', icon: 'home' },
{ id: 'stop', type: 'button', text: '', icon: 'remove' }
]);
// 开始加载web
cell.progressOn();
const frame = cell.attachURI(this.homepage);
frame.addEventListener('did-start-loading', cell.progressOn.bind(cell));
frame.addEventListener('did-finish-load', cell.progressOff.bind(cell));
frame.addEventListener('did-fail-load', (err) => {
cell.progressOff();
// cell.close();
let err_msg = `Code: ${err['errorCode']}`;
err_msg += err['errorDescription'] ? `<br/>Desc: ${err['errorDescription']}` : '';
return toastr.error(LANG['error'](err_msg), LANG_T['error']);
});
// 工具栏点击事件 /**
toolbar.attachEvent('onClick', (id) => { * 初始化新窗口
switch(id) { * @param {String} url 要加载的URL
case 'back': * @return {Object} BrowserWindow窗口对象
frame.goBack(); */
break; initWin(url) {
case 'forward': if (this.win) {
frame.goForward(); return this.win.focus();
break;
case 'refresh':
frame.reloadIgnoringCache();
break;
case 'home':
frame.goToIndex(0);
break;
case 'stop':
frame.stop();
break;
} }
let win = new antSword['remote'].BrowserWindow({
width: 930,
height: 666,
minWidth: 888,
minHeight: 555,
show: false,
title: 'AntSword.Store'
}); });
win.on('close', () => {
this.win = win = null;
});
win.loadURL(url);
win.show();
// win.openDevTools();
this.win = win;
} }
} }
// export default Plugin;
module.exports = Plugin; module.exports = Plugin;
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
* 左侧shell数据管理模块 * 左侧shell数据管理模块
*/ */
// import Terminal from '../terminal/'; const path = require('path');
// import Database from '../database/';
// import FileManager from '../filemanager/';
const Terminal = require('../terminal/'); const Terminal = require('../terminal/');
const Database = require('../database/'); const Database = require('../database/');
const FileManager = require('../filemanager/'); const FileManager = require('../filemanager/');
...@@ -55,20 +53,21 @@ class List { ...@@ -55,20 +53,21 @@ class List {
ids = [id]; ids = [id];
} }
// 获取选择数据信息
let infos = [];
if (ids.length >= 1) {
infos = antSword['ipcRenderer'].sendSync(
'shell-find',
{ _id: { $in: ids } }
)
}
// 获取选中的单条数据 // 获取选中的单条数据
let info = {}; let info = infos[0];
if (id && ids.length === 1) { // let info = {};
info = antSword['ipcRenderer'].sendSync('shell-findOne', id); // if (id && ids.length === 1) {
// info = { // info = antSword['ipcRenderer'].sendSync('shell-findOne', id);
// id: id, // };
// ip: grid.getRowAttribute(id, 'data')[1],
// url: grid.getRowAttribute(id, 'data')[0],
// pwd: grid.getRowAttribute(id, 'pwd'),
// type: grid.getRowAttribute(id, 'type'),
// encode: grid.getRowAttribute(id, 'encode') || 'utf-8',
// encoder: grid.getRowAttribute(id, 'encoder') || 'default'
// }
};
bmenu([ bmenu([
{ text: LANG['contextmenu']['terminal'], icon: 'fa fa-terminal', disabled: !id || ids.length !== 1, action: () => { { text: LANG['contextmenu']['terminal'], icon: 'fa fa-terminal', disabled: !id || ids.length !== 1, action: () => {
...@@ -81,8 +80,81 @@ class List { ...@@ -81,8 +80,81 @@ class List {
new Database(info); new Database(info);
} }, } },
{ divider: true }, { divider: true },
{ text: LANG['contextmenu']['plugin'], icon: 'fa fa-puzzle-piece', disabled: !id || ids.length !== 1 || true, subMenu: [] }, // 加载插件列表
{ text: LANG['contextmenu']['pluginCenter'], icon: 'fa fa-cart-arrow-down', action: antSword['menubar'].run.bind(antSword['menubar'], 'plugin') }, { text: LANG['contextmenu']['plugin'], icon: 'fa fa-folder-o', disabled: !id, subMenu: (() => {
// 1. 遍历插件分类信息
let plugins = {
default: []
};
for (let _ in antSword['plugins']) {
let p = antSword['plugins'][_];
plugins[
p['info']['category'] || 'default'
] = plugins[
p['info']['category'] || 'default'
] || [];
plugins[
p['info']['category'] || 'default'
].push(p);
}
// 2. 解析分类数据
let pluginItems = [];
for (let _ in plugins) {
// 0x01 添加分类目录
pluginItems.push({
text: antSword.noxss(_ === 'default' ? LANG['contextmenu']['pluginDefault'] : _),
icon: 'fa fa-folder-open-o',
disabled: plugins[_].length === 0,
subMenu: ((plugs) => {
let plugItems = [];
// 0x02 添加目录数据
plugs.map((p) => {
plugItems.push({
text: antSword.noxss(p['info']['name']),
icon: `fa fa-${p['info']['icon'] || 'puzzle-piece'}`,
disabled: ids.length > 1 ? (() => {
let ret = false;
// 判断脚本是否支持,不支持则禁止
if (p['info']['scripts'] && p['info']['scripts'].length > 0) {
infos.map((_info) => {
if (p['info']['scripts'].indexOf(_info['type']) === -1) {
// 如果检测到不支持的脚本,则禁止
ret = true;
}
});
}
// 判断是否支持多目标执行
return ret || !p['info']['multiple'];
})() : info && (p['info']['scripts'] || []).indexOf(info['type']) === -1,
action: ((plug) => () => {
// 如果没有加载到内存,则加载
if (!antSword['plugins'][plug['_id']]['module']) {
antSword['plugins'][plug['_id']]['module'] = require(
path.join(plug['path'], plug['info']['main'] || 'index.js')
);
}
// 执行插件
new antSword['plugins'][plug['_id']]['module'](
infos.length === 1 && !plug['info']['multiple'] ? info : infos
);
})(p)
})
});
return plugItems;
})(plugins[_])
})
}
return pluginItems;
})() },
{
// text: LANG['contextmenu']['pluginManager'],
// icon: 'fa fa-th-large',
// action: antSword['menubar'].run.bind(antSword['menubar'], 'plugin-local')
// }, {
text: LANG['contextmenu']['pluginStore'],
icon: 'fa fa-cart-arrow-down',
action: antSword['menubar'].run.bind(antSword['menubar'], 'plugin-store')
},
{ divider: true }, { divider: true },
{ text: LANG['contextmenu']['add'], icon: 'fa fa-plus-circle', action: manager.addData.bind(manager) }, { text: LANG['contextmenu']['add'], icon: 'fa fa-plus-circle', action: manager.addData.bind(manager) },
{ text: LANG['contextmenu']['edit'], icon: 'fa fa-edit', disabled: !id || ids.length !== 1, action: () => { { text: LANG['contextmenu']['edit'], icon: 'fa fa-edit', disabled: !id || ids.length !== 1, action: () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment