| 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 |
|---|
| 13 | The MIT License |
|---|
| 14 | |
|---|
| 15 | Copyright (c) 2009 AmaiSaeta |
|---|
| 16 | |
|---|
| 17 | Permission is hereby granted, free of charge, to any person obtaining a copy |
|---|
| 18 | of this software and associated documentation files (the "Software"), to deal |
|---|
| 19 | in the Software without restriction, including without limitation the rights |
|---|
| 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|---|
| 21 | copies of the Software, and to permit persons to whom the Software is |
|---|
| 22 | furnished to do so, subject to the following conditions: |
|---|
| 23 | |
|---|
| 24 | The above copyright notice and this permission notice shall be included in |
|---|
| 25 | all copies or substantial portions of the Software. |
|---|
| 26 | |
|---|
| 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|---|
| 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|---|
| 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|---|
| 33 | THE SOFTWARE. |
|---|
| 34 | }}} */ |
|---|
| 35 | |
|---|
| 36 | let 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 | |
|---|
| 68 | liberator.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 | |
|---|
| 89 | liberator.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 | |
|---|
| 111 | commands.addUserCommand(['adddia[log]'], 'Add a new :dialog argument.', liberator.plugins.adddialog); |
|---|
| 112 | commands.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 : |
|---|