Skip to content

Commit

Permalink
Implemented toolbar button. Closes #40.
Browse files Browse the repository at this point in the history
  • Loading branch information
mooz committed Apr 21, 2011
1 parent 2274535 commit a01e9f5
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 47 deletions.
1 change: 1 addition & 0 deletions chrome.manifest.pack
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
content keysnail jar:chrome/keysnail.jar!/content/keysnail

skin keysnail classic/1.0 jar:chrome/keysnail.jar!/skin/classic/keysnail/
style chrome://global/content/customizeToolbar.xul chrome://keysnail/skin/css/toolbar-button.css

locale keysnail en-US jar:chrome/keysnail.jar!/locale/en-US/
locale keysnail ja jar:chrome/keysnail.jar!/locale/ja/
Expand Down
38 changes: 38 additions & 0 deletions content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@

<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
<?xml-stylesheet href="chrome://keysnail/skin/css/prompt.css" type="text/css"?>
<?xml-stylesheet href="chrome://keysnail/skin/css/toolbar-button.css" type="text/css"?>

<!DOCTYPE dialog SYSTEM "chrome://keysnail/locale/statusbar.dtd">

<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton id="keysnail-toolbar-button"
class="toolbarbutton-1"
type="menu-button"
label="KeySnail"
tooltiptext="KeySnail"
oncommand="if (event.target === this) KeySnail.modules.key.toggleStatus();">
<menupopup onpopupshowing="KeySnail.modules.key.updateToolbarButtonMenu();">
<menuitem id="keysnail-toolbar-button-status"
label="&keySnail.statusbar.isEnabled;"
accesskey="t"
type="checkbox"
oncommand="KeySnail.modules.key.toggleStatus();" />
<menuitem label="&keySnail.statusbar.openPreference;"
accesskey="c"
oncommand="KeySnail.openPreference();" />
<menuitem label="&keySnail.statusbar.openPluginManager;"
accesskey="o"
oncommand="KeySnail.modules.userscript.openPluginManager();" />
<menuseparator/>
<menuitem label="&keySnail.statusbar.reloadUserScript;"
accesskey="r"
oncommand="KeySnail.modules.userscript.reload();" />
<menuitem label="&keySnail.statusbar.listKeyBindings;"
accesskey="v"
oncommand="KeySnail.modules.key.listKeyBindings();" />
<menuseparator/>
<menuitem label="&keySnail.statusbar.editInitFile;"
accesskey="e"
oncommand="KeySnail.modules.userscript.editInitFile();" />
<menuitem label="&keySnail.statusbar.wizard;"
accesskey="w"
oncommand="KeySnail.modules.userscript.beginRcFileWizard();" />
</menupopup>
</toolbarbutton>
</toolbarpalette>

<!-- tool menu -->
<menupopup id="menu_ToolsPopup">
<menu id="keysnail-tool-menu"
Expand Down
2 changes: 1 addition & 1 deletion content/keysnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
// main-window specific settings
if (this.isMainWindow) {
this.settingsForBrowserWindow();
key.updateStatusBar();
key.updateStatusDisplay();
}

document.addEventListener("copy", function () { command.clipboardChanged(); }, true);
Expand Down
107 changes: 68 additions & 39 deletions content/modules/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,23 @@ const key = {
* toggle current keyhandler status
* when init file is not loaded, reject
*/
toggleStatus: function () {
toggleStatus: function (elem) {
let name = elem ? elem.localName : "<not given>";
util.message("toggleStatus called " + this.status + " " + name);

if (this.status)
{
this.stop();
}
else
{
else {
if (!userscript.initFileLoaded)
{
// load init file
userscript.load();
}

if (!userscript.initFileLoaded)
{
// Failed to load init file
// display.notify(util.getLocaleString("noUserScriptLoaded"));
this.status = false;
}
else
{
this.run();
}
}

this.updateMenu();
this.updateStatusBar();
key.updateStatusDisplay();
},

/**
Expand All @@ -213,41 +204,68 @@ const key = {
this.suspended = false;
}

this.updateStatusBar();
this.updateStatusDisplay();
},

// }} ======================================================================= //

// Update GUI {{ ============================================================ //

STATUSES: {
ENABLED: "enabled",
DISABLED: "disabled",
SUSPENDED: "suspended"
},

get statusString() {
if (!this.status)
return this.STATUSES.DISABLED;
if (this.suspended)
return this.STATUSES.SUSPENDED;
return this.STATUSES.ENABLED;
},

updateStatusDisplay: function () {
this.updateMenu();
this.updateToolbarButton();
this.updateStatusBar();
},

updateToolbarButton: function () {
let button = document.getElementById("keysnail-toolbar-button");
if (!button)
return;

button.setAttribute("data-ks-status", this.statusString);
},

/**
* update the status bar icon
*/
updateStatusBar: function () {
var icon = document.getElementById("keysnail-statusbar-icon");
let icon = document.getElementById("keysnail-statusbar-icon");
if (!icon)
return;

if (this.status)
{
// enabled
if (this.suspended)
{
icon.src = "chrome://keysnail/skin/icon16suspended.png";
icon.tooltipText = util.getLocaleString("keySnailSuspended");
}
else
{
icon.src = "chrome://keysnail/skin/icon16.png";
icon.tooltipText = util.getLocaleString("keySnailEnabled");
}
}
else
{
// disabled
icon.src = "chrome://keysnail/skin/icon16gray.png";
icon.tooltipText = util.getLocaleString("keySnailDisabled");
let src, tooltip;

switch (this.statusString) {
case this.STATUSES.ENABLED:
src = "chrome://keysnail/skin/icon16.png";
tooltip = util.getLocaleString("keySnailEnabled");
break;
case this.STATUSES.DISABLED:
src = "chrome://keysnail/skin/icon16gray.png";
tooltip = util.getLocaleString("keySnailDisabled");
break;
default:
src = "chrome://keysnail/skin/icon16suspended.png";
tooltip = util.getLocaleString("keySnailSuspended");
break;
}

icon.src = src;
icon.tooltipText = tooltip;
},

/**
Expand All @@ -262,7 +280,7 @@ const key = {
},

/**
* update the tool box menu
* update the tool box menu (from onpopupshowing)
*/
updateToolMenu: function () {
var checkbox = document.getElementById("keysnail-tool-menu-status");
Expand All @@ -272,6 +290,17 @@ const key = {
checkbox.setAttribute('checked', this.status);
},

/**
* update the toolbar button menu (from onpopupshowing)
*/
updateToolbarButtonMenu: function () {
var checkbox = document.getElementById("keysnail-toolbar-button-status");
if (!checkbox)
return;

checkbox.setAttribute('checked', this.status);
},

// }} ======================================================================= //

// Mode {{ ================================================================== //
Expand Down Expand Up @@ -411,7 +440,7 @@ const key = {
{
util.stopEventPropagation(aEvent);
this.suspended = !this.suspended;
this.updateStatusBar();
this.updateStatusDisplay();
this.backToNeutral("Suspension switched", 1000);
return;
}
Expand Down
6 changes: 2 additions & 4 deletions content/modules/userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ const userscript = {
this.initFileLoaded = false;

key.stop();
key.updateMenu();
key.updateStatusBar();
key.updateStatusDisplay();
}

return this.initFileLoaded;
Expand Down Expand Up @@ -1136,8 +1135,7 @@ const userscript = {
{
this.initFileLoaded = true;
key.run();
key.updateMenu();
key.updateStatusBar();
key.updateStatusDisplay();
}

return loadStatus;
Expand Down
3 changes: 1 addition & 2 deletions content/preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ var ksPreference = {
this.modules.display.clearNotify();

this.modules.key.run();
this.modules.key.updateMenu();
this.modules.key.updateStatusBar();
this.modules.key.updateStatusDisplay();

this.modules.util.parent.openPreference(true);
}
Expand Down
3 changes: 2 additions & 1 deletion createpackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ zip -r -0 chrome/keysnail.jar \
content/prettifier/*~*~ \
content/modules/*.js~(*~) \
locale/**/*.*~(*~) \
skin/**/*.*~(*~|*.svg)
skin/**/*.*~(*~|*.svg) \
skin/**/filter.svg

echo "====================== Create xpi file ========================="

Expand Down
16 changes: 16 additions & 0 deletions skin/classic/keysnail/css/toolbar-button.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#keysnail-toolbar-button {
list-style-image: url("../icon24.png");
}

toolbar[iconsize="small"] #keysnail-toolbar-button {
list-style-image: url("../icon16.png");
}

#keysnail-toolbar-button[data-ks-status=disabled] *|image {
filter: url("../filter/filter.svg#grayscale");
opacity: 0.7;
}

#keysnail-toolbar-button[data-ks-status=suspended] *|image {
filter: url("../filter/filter.svg#hue240");
}
31 changes: 31 additions & 0 deletions skin/classic/keysnail/filter/filter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skin/classic/keysnail/icon24.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 a01e9f5

Please sign in to comment.