Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Mar 16, 2012
0 parents commit d898539
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
2 changes: 2 additions & 0 deletions chrome.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
content commando chrome/content/
overlay chrome://komodo/content/komodo.xul chrome://commando/content/overlay.xul
244 changes: 244 additions & 0 deletions chrome/content/commando.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
commando = new function()
{

var $this = this;

var $commands = null;
var $tools = {};

var ko = parent.opener.ko;
var mainDocument = parent.opener.document;
var mainWindow = parent.opener.window;

this.onLoad = function()
{
document.getElementById("commando-search").focus();
this.loadCommands();
window.addEventListener('keypress', $this.onKeyPressWindow, true);
};

this.onInput = function(e)
{
$this.loadCommands(e.value);

var list = document.getElementById('commando-results');
list.selectItem(list.getItemAtIndex(0));
};

this.onKeyPressWindow = function(e)
{
var list = document.getElementById('commando-results');

switch (e.keyCode)
{
case 13:
setTimeout(window.close, 50);
$this.runSelected();
e.preventDefault();
e.stopPropagation();
break;
case 27:
window.close();
e.preventDefault();
e.stopPropagation();
break;
case 38:
list.selectItem(list.getItemAtIndex(list.selectedIndex - 1));
list.ensureIndexIsVisible(list.selectedIndex);
e.preventDefault();
e.stopPropagation();
break;
case 40:
case 9:
list.selectItem(list.getItemAtIndex(list.selectedIndex + 1));
list.ensureIndexIsVisible(list.selectedIndex);
e.preventDefault();
e.stopPropagation();
break;
}
};

this.onKeyPress = function(e)
{

};

this.onSelect = function()
{

};

this.runSelected = function()
{
var list = document.getElementById('commando-results');
var item = list.getItemAtIndex(list.selectedIndex);

if ( ! item)
{
return false;
}

if (!isNaN(item.value))
{
if ($tools[item.value] === undefined)
{
return false;
}

ko.toolbox2.invokeTool($tools[item.value].koTool);
}
else
{
var commands = $this.getCommands();

if (commands[item.value] === undefined)
{
return false;
}

ko.commands.doCommand(item.value)
}

};

this.loadCommands = function(string)
{
var list = document.getElementById('commando-results');
var cmds = $this.getCommands();

$this.emptyList();

var listItems = [];

if (string === undefined)
{
string = "";
}

words = string.split(" ");

for (cmd in cmds)
{
if (string == "" || $this.hasWords(cmds[cmd],words))
{
listItems.push({value: cmd, label: cmds[cmd]});
}
}

listItems.sort(function(a,b) {
if (a.label.toLowerCase() < b.label.toLowerCase())
return -1;
if (a.label.toLowerCase() > b.label.toLowerCase())
return 1;
return 0;
});

for (var x=0;x<listItems.length;x++)
{
list.appendItem(listItems[x].label, listItems[x].value);
}
};

this.hasWords = function(string,words)
{
string = string.toLowerCase();
for (var i=0;i<words.length;i++)
{
if (string.indexOf(words[i].toLowerCase())==-1)
{
return false;
}
}

return true;
}

this.emptyList = function()
{
var list = document.getElementById('commando-results');

while (list.firstChild) {
list.removeChild(list.firstChild);
}
};

this.getCommands = function()
{
if ($commands != null)
{
return $commands;
}

$commands = {};
var shortcuts = ko.keybindings.manager.activeCommands;
var commands = $this.getAvailableCommands();

for (var cmd in commands)
{
if ($commands[cmd] !== undefined)
{
continue;
}

var shortcut = '';
if (shortcuts[cmd] != undefined && shortcuts[cmd][0] != undefined)
{
shortcut = " \u2014 " + shortcuts[cmd][0];
}

$commands[cmd] = commands[cmd] + " (command"+shortcut+")"
}

var tbSvc = Components.classes["@activestate.com/koToolbox2Service;1"].getService(Components.interfaces.koIToolbox2Service);
var hits = tbSvc.findTools("", 0, [], {});

$tools = {};
for (var x=0;x<hits.length;x++)
{
var label = hits[x].name;

if (hits[x].subDir)
{
label += " ("+hits[x].type+" \u2014 "+hits[x].subDir+")";
}
else
{
label += " ("+hits[x].type+")"
}

$tools[hits[x].path_id] = hits[x];
$commands[hits[x].path_id] = label;
}

return $commands;
};

this.getAvailableCommands = function()
{
ko.keybindings.manager.parseGlobalData();

var cmds = {};
var avCmds = ko.keybindings.manager.commanditems;

for (var x=0;x<avCmds.length;x++)
{

var desc = avCmds[x].desc;

if (desc == "")
{
desc = avCmds[x].name;
desc = desc.replace('cmd_','');
desc = desc.replace(/([A-Z][a-z])/g,' $1');
desc = desc.replace(/_/g,' ');
desc = desc.replace(/(?:^|\s)([a-z])/g, function($1) { return $1.toUpperCase(); });
desc = desc.trim();
}

cmds[avCmds[x].name] = desc;
}

return cmds;
}

};
18 changes: 18 additions & 0 deletions chrome/content/commando.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Invoke Command"
id="commando"
minwidth="200" minheight="200"
persist="width height"
onload="commando.onLoad();"
>

<script type="application/x-javascript"
src="chrome://commando/content/commando.js"/>

<vbox flex="1">
<textbox id="commando-search" oninput="commando.onInput(this);" onkeypress="commando.onKeyPress(event);"/>
<listbox id="commando-results" flex="1" ondblclick="commando.onSelect(event);"/>
</vbox>
</window>
4 changes: 4 additions & 0 deletions chrome/content/overlay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function showCommandoDialog(event) {
window.openDialog('chrome://commando/content/commando.xul',
null, 'chrome,centerscreen,resizable=yes,dependent=yes');
}
18 changes: 18 additions & 0 deletions chrome/content/overlay.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE overlay PUBLIC "-//MOZILLA//DTD XUL V1.0//EN" "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<overlay id="commandoOverlay"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<script type="application/x-javascript"
src="chrome://commando/content/overlay.js"/>

<broadcasterset id="broadcasterset_global">
<broadcaster id="cmd_commando_show"
key="key_cmd_commando_show"
desc="Commando"
oncommand="showCommandoDialog(event)"/>
</broadcasterset>
</overlay>
2 changes: 2 additions & 0 deletions chrome/locale/en-US/commando.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!ENTITY quickopen.desc "General: Commando">
<!ENTITY quickopen.dialog.title "Commando">
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions install.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>Commando</em:name>
<em:version>1.0</em:version>
<em:description></em:description>
<em:iconURL>chrome://commando/skin/icon.png</em:iconURL>
<em:creator>Nathan Rijksen</em:creator>
<em:homepageURL>https://github.com/Naatan/Komodo-Commando</em:homepageURL>
<em:type>2</em:type> <!-- type=extension -->
<em:unpack>true</em:unpack>

<em:targetApplication> <!-- Komodo IDE -->
<Description>
<em:id>{36E66FA0-F259-11D9-850E-000D935D3368}</em:id>
<em:minVersion>4.1</em:minVersion>
<em:maxVersion>7.*</em:maxVersion>
</Description>
</em:targetApplication>
<em:targetApplication> <!-- Komodo Edit -->
<Description>
<em:id>{b1042fb5-9e9c-11db-b107-000d935d3368}</em:id>
<em:minVersion>4.1</em:minVersion>
<em:maxVersion>7.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
Binary file added komodo-commando-1.0-ko.xpi
Binary file not shown.
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Quite simply this adds a dialog in the same style of "Fast Open" that allows you to invoke commands, macro's and snippets.

It's basically the Invoke Tool with the look of "Fast Open" and the added functionality that you can use it to invoke any of the 450+ commands included with Komodo without having to use your mouse or needing to set a shortcut for them.

Screenshot:

[![Commando](http://thumbs.cl.ly/0E2R2C1s093k0n320W2B)](http://cl.ly/0E2R2C1s093k0n320W2B)
Binary file added skin/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d898539

Please sign in to comment.