Changeset 37011

Show
Ignore:
Timestamp:
03/14/10 20:07:23 (3 years ago)
Author:
anekos
Message:

tabuniq コマンドを追加 && サブコマンド式に

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/tabsort.js

    r35099 r37011  
    3737<VimperatorPlugin> 
    3838  <name>tabsort</name> 
    39   <description>Add ":tabsort" command.</description> 
    40   <description lang="ja">tabsort コマンドを追加する</description> 
    41   <version>1.0.1</version> 
     39  <description>Add ":tabsort" and ":tabuniq" command.</description> 
     40  <description lang="ja">":tabsort", ":tabuniq" コマンドを追加する</description> 
     41  <version>1.1.0</version> 
    4242  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> 
    43   <minVersion>2.2pre</minVersion> 
    44   <maxVersion>2.2pre</maxVersion> 
     43  <minVersion>2.3</minVersion> 
     44  <maxVersion>2.3</maxVersion> 
    4545  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/tabsort.js</updateURL> 
    4646  <license>new BSD License (Please read the source code comments of this plugin)</license> 
     
    6969    function (a, b) a[name].toString().localeCompare(b[name].toString()); 
    7070 
     71  function getTabs () [ 
     72    { 
     73      index: i, 
     74      tab: tab, 
     75      doc: #1=(tab.linkedBrowser.contentDocument), 
     76      url: #1#.location.href, 
     77      title: #1#.title, 
     78    } 
     79    for ([i, tab] in util.Array(config.browser.mTabs)) 
     80  ]; 
     81 
     82  function tabUniq (cmp) { 
     83    let rms = []; 
     84    let tabs = getTabs(); 
     85 
     86    for (let [i, tabA] in Iterator(tabs)) { 
     87      for each (let tabB in tabs.slice(i + 1)) { 
     88        if (cmp(tabA, tabB) === 0) 
     89          rms.push(tabB); 
     90      } 
     91    } 
     92 
     93    rms.forEach(function (rm) config.tabbrowser.removeTab(rm.tab)); 
     94  } 
     95 
    7196  function tabSort (cmp) { 
    72     let nbrowsers = getBrowser().browsers.length; 
    73     let ts = []; 
    74     for (let [i,] in tabs.browsers) { 
    75       let b = getBrowser().getBrowserAtIndex(i); 
    76       let c = b.contentDocument; 
    77       ts.push({ 
    78         index: i, 
    79         tab: gBrowser.mTabs[i], 
    80         url: c.location.href, 
    81         title: c.title 
    82       }); 
    83     } 
    84     ts.sort(cmp).forEach(function (it, i) (i == it.index) || getBrowser().moveTabTo(it.tab, i)); 
     97    getTabs().sort(cmp).forEach(function (it, i) (i == it.index) || config.tabbrowser.moveTabTo(it.tab, i)); 
    8598  } 
    8699 
     
    93106    targetOptions.some(function ([n,]) n == value); 
    94107 
     108  function completer (context) { 
     109    context.title = ['Target', 'Action']; 
     110    context.completions = targetOptions; 
     111  } 
     112 
     113  commands.addUserCommand( 
     114    ['tabu[niq]'], 
     115    'Uniq tabs', 
     116    function (arg) { 
     117      tabUniq(memberCompare(arg[0] || arg['-target'] || 'url')); 
     118    }, 
     119    { 
     120      options: [ 
     121        [['-target', '-t'], commands.OPTION_STRING, targetValidater, targetOptions], 
     122      ], 
     123      completer: completer 
     124    }, 
     125    true 
     126  ); 
     127 
    95128  commands.addUserCommand( 
    96129    ['tabso[rt]'], 
    97130    'Sort tabs', 
    98131    function (arg) { 
    99       tabSort(memberCompare(arg['-target'] || 'title')); 
     132      tabSort(memberCompare(arg[0] || arg['-target'] || 'title')); 
    100133    }, 
    101134    { 
    102       argCount: '0', 
    103135      options: [ 
    104136        [['-target', '-t'], commands.OPTION_STRING, targetValidater, targetOptions], 
    105137      ], 
     138      completer: completer 
    106139    }, 
    107140    true