root/lang/javascript/vimperator-plugins/trunk/adddialog.js

Revision 36272, 3.8 kB (checked in by AmaiSaeta, 8 months ago)

first commit

Line 
1/**
2 * ==VimperatorPlugin==
3 * @name           adddialog.js
4 * @description    Add/Delete a :dialog argument.
5 * @description-ja :dialog コマンドで開けるダイアログを追加/削除する。
6 * @author         AmaiSaeta <amaisaeta@gmail.com>
7 * @version        1.01.20091226
8 * @minVersion     2.1
9 * @maxVersion     2.1
10 * ==/VimperatorPlugin==
11 */
12/* {{{ License
13The MIT License
14
15Copyright (c) 2009 AmaiSaeta
16
17Permission is hereby granted, free of charge, to any person obtaining a copy
18of this software and associated documentation files (the "Software"), to deal
19in the Software without restriction, including without limitation the rights
20to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21copies of the Software, and to permit persons to whom the Software is
22furnished to do so, subject to the following conditions:
23
24The above copyright notice and this permission notice shall be included in
25all copies or substantial portions of the Software.
26
27THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33THE SOFTWARE.
34   }}} */
35
36let PLUGIN_INFO = // {{{
37<VimperatorPlugin>
38<name>{NAME}</name>
39<description>Add/Delete a :dialog argument.</description>
40<description lang="ja">:dialogコマンドで開けるダイアログを追加/削除する。</description>
41<version>1.00.20091021</version>
42<author mail="amaisaeta@gmail.com" homepage="http://amaisaeta.seesaa.net/">AmaiSaeta</author>
43<license>MIT License</license>
44<minVersion>2.1</minVersion>
45<maxVersion>2.1</maxVersion>
46<detail lang="ja"><![CDATA[
47== 概要 ==
48:dialog コマンドで開けるダイアログを追加/削除する。
49
50== 使用法 ==
51:adddia[log] name {description} uri
52        uriが指し示すダイアログを、 :dialog name で開けるようにする。
53        descriptionで説明文を指定する事も可能。
54
55:deldia[log] name
56        nameという名前のダイアログを、 :dialog の候補から削除する。
57
58== 用法 ==
59>||
60:adddialog gmmanage "Greasemonkeyの『ユーザスクリプトの管理』ダイアログを開く" chrome://greasemonkey/content/manage.xul
61
62:deldialog gmmanage
63||<
64]]></detail>
65</VimperatorPlugin>;
66/// }}}
67
68liberator.plugins.adddialog = (function(args) { // {{{
69        var name, desc, uri;
70
71        if(args.length < 2) {
72                liberator.echoerr("The arguments is not worth.", commandline.APPEND_TO_MESSAGES);
73                return;
74        }
75
76        if(args.length == 2) { // omitted description.
77                name = args[0];
78                desc = args[1];
79                uri  = args[1];
80        } else {
81                name = args[0];
82                desc = args[1];
83                uri  = args[2];
84        }
85        config.dialogs.push([name, desc, function() openDialog(uri, "_blank")]);
86});
87/// }}}
88
89liberator.plugins.deldialog = function(args) { // {{{
90        var index, dialogLen = config.dialogs.length;
91        var i;
92
93        if(args.length < 1) {
94                liberator.echoerr("The argument is not worth.");
95                return;
96        }
97
98        for(index = 0; index < dialogLen; ++index) {
99                if(config.dialogs[index][0] === args[0]) { // found!
100                        for(var i = index + 1; i < dialogLen; ++i) {
101                                config.dialogs[i - 1] = config.dialogs[i];
102                        }
103                        config.dialogs.pop();
104                        return; // success deleted
105                }
106        }
107        liberator.echoerr("'" + args[0] + "' dialog is not found."); // not found
108};
109/// }}}
110
111commands.addUserCommand(['adddia[log]'], 'Add a new :dialog argument.', liberator.plugins.adddialog);
112commands.addUserCommand(['deldia[log]'], 'Delete a :dialog argument.', liberator.plugins.deldialog);
113
114// vim: set autoindent tabstop=4 shiftwidth=4 softtabstop=4 textwidth=0 foldmethod=marker :
Note: See TracBrowser for help on using the browser.