Skip to content

Commit

Permalink
Added a warning when Mudim is enabled and turned on, along with a but…
Browse files Browse the repository at this point in the history
…ton to turn Mudim off.
  • Loading branch information
1ec5 committed Jul 3, 2008
1 parent f342a46 commit fbe0e0d
Show file tree
Hide file tree
Showing 7 changed files with 251 additions and 80 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ Version 20080224.87 (Wednesday, July 2, 2008)
Accents" option.
- Removed the menu item to toggle the status bar panel, since it is redundant
with the preference window now.

Version ${Version} (${Date})
- Added a warning that indicates when Mudim is enabled and turned on, along
with a button to turn Mudim off (as opposed to disabling the extension).
Mudim often interferes with AVIM, since the two extensions serve the same
purpose.
- Optimized the toolbar button images.
156 changes: 152 additions & 4 deletions content/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
* A controller for the AVIM Options panel.
*/
function AVIMOptionsPanel() {
this.broadcasters = {
disabled: "disabled-bc"
}
const MUDIM_ID = "[email protected]";

this.broadcasters = {disabled: "disabled-bc"};

this.notificationBoxId = "general-note";

this.tabBoxId = "general-tabbox";
this.tabsId = "general-tabs";
Expand Down Expand Up @@ -105,6 +107,18 @@ function AVIMOptionsPanel() {
this.validateRemoveButton();
};

/**
* Enables or disables Input Editing panel preferences, and displays or
* hides the Mudim conflict warning based on whether there is a conflict.
*/
this.validateForEnabled = function() {
var bc = document.getElementById(this.broadcasters.disabled);
bc.setAttribute("disabled", "" + !this.prefs.getBoolPref("enabled"));

if (this.mudimMonitor.conflicts()) this.mudimMonitor.displayWarning();
else this.mudimMonitor.hideWarning();
};

/**
* Updates the panel's current state to reflect the stored preferences.
*
Expand All @@ -115,6 +129,7 @@ function AVIMOptionsPanel() {
var bc = document.getElementById(this.broadcasters.disabled);
bc.setAttribute("disabled",
"" + !this.prefs.getBoolPref("enabled"));
this.validateForEnabled();
}
if (!changedPref || changedPref == "ignoredFieldIds") {
this.updateIgnoredIds();
Expand Down Expand Up @@ -217,13 +232,17 @@ function AVIMOptionsPanel() {
var lineCount = descs[i].getAttribute("linecount");
descs[i].style.height = lineCount * lineHeight + "px";
}
}
};

/**
* Initializes the AVIM Options panel's controller. This method should only
* be called once the panel itself has finished loading.
*/
this.initialize = function() {
this.mudimMonitor = new MudimMonitor(this.prefs,
this.notificationBoxId);
this.mudimMonitor.registerPrefs();

this.registerPrefs();
this.validateRemoveButton();

Expand All @@ -238,6 +257,135 @@ function AVIMOptionsPanel() {
this.finalize = function() {
this.unregisterPrefs();
};

/**
* An inner class that detects when Mudim is installed and enabled.
*/
function MudimMonitor(avimPrefs, notificationBoxId) {
this.avimPrefs = avimPrefs;
this.notificationBoxId = notificationBoxId;

this.stringBundleId = "bundle";
this.noteValue = "mudim-note";

// Mudim itself
this.mudim = Application.extensions.get(MUDIM_ID);

// Root for Mudim preferences
this.prefs =
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("chimmudim.settings.");

/**
* Registers an observer so that a warning is displayed if Mudim is
* enabled.
*/
this.registerPrefs = function() {
this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefs.addObserver("", this, false);
this.getPrefs();
};

/**
* Unregisters the preferences observer as the window is being closed.
*/
this.unregisterPrefs = function() {
this.setPrefs();
this.prefs.removeObserver("", this);
};

/**
* Returns whether Mudim conflicts with AVIM.
*
* @returns {boolean} true if Mudim conflicts with AVIM; false
* otherwise.
*/
this.conflicts = function() {
var avimEnabled = this.avimPrefs.getBoolPref("enabled");
return avimEnabled && this.mudim && this.mudim.enabled &&
this.prefs.getIntPref("method") != 0;
};

/**
* Disables the Mudim extension, because it may interfere with AVIM's
* operation. Unfortunately, we can't just set Mudim's method preference
* to 0 (off), because Mudim doesn't observe preference changes.
*
* @param note {object} the <notification> element whose button
* triggered the call to this method.
* @param desc {string} the button's description.
*/
this.disableMudim = function(note, desc) {
var mediator =
Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var enumerator = mediator.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
if (win && win.CHIM && win.CHIM.SetMethod &&
win.CHIM.SetMethod instanceof Function) {
win.CHIM.SetMethod(0);
}
}
};

/**
* Displays a notification that Mudim is enabled.
*/
this.displayWarning = function() {
var noteBox = document.getElementById(this.notificationBoxId);
if (noteBox.getNotificationWithValue(this.noteValue)) return;

var stringBundle = document.getElementById(this.stringBundleId);
var noteLabel = stringBundle.getString("mudim-note.label");
var noteBtns = [{
accessKey: stringBundle.getString("mudim-button.accesskey"),
callback: this.disableMudim,
label: stringBundle.getString("mudim-button.label"),
popup: null
}];
noteBox.appendNotification(noteLabel, this.noteValue,
URI_NOTIFICATION_ICON_WARNING,
noteBox.PRIORITY_WARNING_MEDIUM,
noteBtns);
};

/**
* Hides the notification that Mudim is enabled.
*/
this.hideWarning = function() {
var noteBox = document.getElementById(this.notificationBoxId);
var note = noteBox.getNotificationWithValue(this.noteValue);
if (note) noteBox.removeNotification(note);
};

/**
* Updates the panel's current state to reflect the stored preferences.
*
* @param changedPref {string} the name of the preference that
* changed.
*/
this.getPrefs = function(changedPref) {
if (!changedPref || changedPref == "method") {
if (this.conflicts()) this.displayWarning();
else this.hideWarning();
}
};

/**
* Responds to changes to Mudim preferences, namely the method
* preference.
*
* @param subject
* @param topic {string} the type of event that occurred.
* @param data {string} the name of the preference that changed.
*/
this.observe = function(subject, topic, data) {
if (topic != "nsPref:changed") return;
this.getPrefs(data);
};
}
}
var options;
if (!options) {
Expand Down
147 changes: 77 additions & 70 deletions content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<!DOCTYPE prefwindow SYSTEM "chrome://avim/locale/options.dtd">

<prefwindow id="avim-preferences" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="&avim-preferences.title;" style="&avim-preferences.style;">
<script type="application/x-javascript" src="chrome://mozapps/content/extensions/extensions.js" />
<script type="application/x-javascript" src="chrome://avim/content/options.js" />

<stringbundleset>
<stringbundle id="bundle" src="chrome://avim/locale/options.properties" />
</stringbundleset>

<commandset>
<command id="ignore-cmd" oncommand="options.ignoreIdsInTextBox();" />
<command id="remove-cmd" oncommand="options.removeSelectedIds();" />
Expand All @@ -16,76 +21,78 @@
<broadcaster id="disabled-bc" />
</broadcasterset>

<prefpane id="general-pane" label="&avim-preferences.title;">
<preferences>
<preference id="enabled-pref" name="extensions.avim.enabled" type="bool" />
<preference id="method-pref" name="extensions.avim.method" type="int" />
<preference id="spell-pref" name="extensions.avim.ignoreMalformed" type="bool" />
<preference id="oldaccents-pref" name="extensions.avim.oldAccents" type="bool" />
<preference id="statuspanel-pref" name="extensions.avim.statusBarPanel" type="bool" />
<!-- <preference id="ignoredids-pref" name="extensions.avim.ignoredFieldIds" type="unichar" /> -->
<preference id="auto-telex-pref" name="extensions.avim.auto.telex" type="bool" />
<preference id="auto-vni-pref" name="extensions.avim.auto.vni" type="bool" />
<preference id="auto-viqr-pref" name="extensions.avim.auto.viqr" type="bool" />
<preference id="auto-viqr-star-pref" name="extensions.avim.auto.viqrStar" type="bool" />
</preferences>

<vbox flex="1">
<checkbox id="enabled-check" preference="enabled-pref" label="&enabled-check.label;" accesskey="&enabled-check.accesskey;" />
<prefpane id="general-pane" label="&avim-preferences.title;">
<preferences>
<preference id="enabled-pref" name="extensions.avim.enabled" type="bool" />
<preference id="method-pref" name="extensions.avim.method" type="int" />
<preference id="spell-pref" name="extensions.avim.ignoreMalformed" type="bool" />
<preference id="oldaccents-pref" name="extensions.avim.oldAccents" type="bool" />
<preference id="statuspanel-pref" name="extensions.avim.statusBarPanel" type="bool" />
<!-- <preference id="ignoredids-pref" name="extensions.avim.ignoredFieldIds" type="unichar" /> -->
<preference id="auto-telex-pref" name="extensions.avim.auto.telex" type="bool" />
<preference id="auto-vni-pref" name="extensions.avim.auto.vni" type="bool" />
<preference id="auto-viqr-pref" name="extensions.avim.auto.viqr" type="bool" />
<preference id="auto-viqr-star-pref" name="extensions.avim.auto.viqrStar" type="bool" />
</preferences>

<tabbox id="general-tabbox">
<tabs id="general-tabs">
<tab label="&input-panel.label;" linkedpanel="input-panel" />
<tab label="&ignored-panel.label;" linkedpanel="ignored-panel" />
</tabs>
<tabpanels>
<tabpanel id="input-panel" orient="vertical">
<hbox align="center">
<label accesskey="&method-menu.accesskey;" control="method-menu" observes="disabled-bc">&method-menu.label;</label>
<menulist id="method-menu" preference="method-pref" observes="disabled-bc">
<menupopup>
<menuitem id="method-auto-item" value="0" label="&method-auto-item.label;" />
<menuitem id="method-telex-item" value="1" label="&method-telex-item.label;" />
<menuitem id="method-vni-item" value="2" label="&method-vni-item.label;" />
<menuitem id="method-viqr-item" value="3" label="&method-viqr-item.label;" />
<menuitem id="method-viqr-star-item" value="4" label="&method-viqr-star-item.label;" />
</menupopup>
</menulist>
</hbox>

<checkbox id="spell-check" preference="spell-pref" label="&spell-check.label;" accesskey="&spell-check.accesskey;" observes="disabled-bc" />
<checkbox id="oldaccents-check" preference="oldaccents-pref" label="&oldaccents-check.label;" accesskey="&oldaccents-check.accesskey;" observes="disabled-bc" />
<vbox flex="1">
<checkbox id="enabled-check" preference="enabled-pref" label="&enabled-check.label;" accesskey="&enabled-check.accesskey;" oncommand="options.validateForEnabled(); return true;" />

<tabbox id="general-tabbox">
<tabs id="general-tabs">
<tab label="&input-panel.label;" linkedpanel="input-panel" />
<tab label="&ignored-panel.label;" linkedpanel="ignored-panel" />
</tabs>
<tabpanels>
<tabpanel id="input-panel" orient="vertical">
<notificationbox id="general-note" flex="1">
<hbox align="center">
<label accesskey="&method-menu.accesskey;" control="method-menu" observes="disabled-bc">&method-menu.label;</label>
<menulist id="method-menu" preference="method-pref" observes="disabled-bc">
<menupopup>
<menuitem id="method-auto-item" value="0" label="&method-auto-item.label;" />
<menuitem id="method-telex-item" value="1" label="&method-telex-item.label;" />
<menuitem id="method-vni-item" value="2" label="&method-vni-item.label;" />
<menuitem id="method-viqr-item" value="3" label="&method-viqr-item.label;" />
<menuitem id="method-viqr-star-item" value="4" label="&method-viqr-star-item.label;" />
</menupopup>
</menulist>
</hbox>

<checkbox id="spell-check" preference="spell-pref" label="&spell-check.label;" accesskey="&spell-check.accesskey;" observes="disabled-bc" />
<checkbox id="oldaccents-check" preference="oldaccents-pref" label="&oldaccents-check.label;" accesskey="&oldaccents-check.accesskey;" observes="disabled-bc" />

<separator class="thin" />

<label observes="disabled-bc">&auto-methods.label;</label>
<vbox id="auto-methods-box" class="indent"><!-- Turn this into an <hbox> once this panel gets longer. -->
<checkbox id="auto-telex-check" preference="auto-telex-pref" label="&method-auto-item.label;" accesskey="&auto-telex-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-vni-check" preference="auto-vni-pref" label="&method-vni-item.label;" accesskey="&auto-vni-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-viqr-check" preference="auto-viqr-pref" label="&method-viqr-item.label;" accesskey="&auto-viqr-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-viqr-star-check" preference="auto-viqr-star-pref" label="&method-viqr-star-item.label;" accesskey="&auto-viqr-star-check.accesskey;" observes="disabled-bc" />
</vbox>
</notificationbox>
</tabpanel>

<separator class="thin" />

<label observes="disabled-bc">&auto-methods.label;</label>
<vbox id="auto-methods-box" class="indent"><!-- Turn this into an <hbox> once this panel gets longer. -->
<checkbox id="auto-telex-check" preference="auto-telex-pref" label="&method-auto-item.label;" accesskey="&auto-telex-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-vni-check" preference="auto-vni-pref" label="&method-vni-item.label;" accesskey="&auto-vni-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-viqr-check" preference="auto-viqr-pref" label="&method-viqr-item.label;" accesskey="&auto-viqr-check.accesskey;" observes="disabled-bc" />
<checkbox id="auto-viqr-star-check" preference="auto-viqr-star-pref" label="&method-viqr-star-item.label;" accesskey="&auto-viqr-star-check.accesskey;" observes="disabled-bc" />
</vbox>
</tabpanel>

<tabpanel id="ignored-panel" orient="vertical">
<description id="ignored-desc" linecount="&ignored-desc.line-count;">&ignored-desc.label;</description>
<description id="ignored-instructions" linecount="&ignored-instructions.line-count;">&ignored-instructions.label;</description>
<hbox align="center">
<label control="ignore-text">&ignore-text.label;</label>
<textbox id="ignore-text" flex="1" oninput="options.validateIgnoreButton();" />
<button id="ignore-button" label="&ignore-button.label;" accesskey="&ignore-button.accesskey;" command="ignore-cmd" disabled="true" />
</hbox>
<separator class="thin" />
<listbox id="ignoredids-list" rows="10" seltype="multiple" onselect="options.validateRemoveButton();" />
<hbox class="actionButtons">
<button id="remove-button" label="&remove-button.label;" accesskey="&remove-button.accesskey;" command="remove-cmd" />
</hbox>
</tabpanel>
</tabpanels>
</tabbox>

<!-- Display -->
<checkbox id="statuspanel-check" preference="statuspanel-pref" label="&statuspanel-check.label;" accesskey="&statuspanel-check.accesskey;" />
</vbox>
</prefpane>
<tabpanel id="ignored-panel" orient="vertical">
<description id="ignored-desc" linecount="&ignored-desc.line-count;">&ignored-desc.label;</description>
<description id="ignored-instructions" linecount="&ignored-instructions.line-count;">&ignored-instructions.label;</description>
<hbox align="center">
<label control="ignore-text">&ignore-text.label;</label>
<textbox id="ignore-text" flex="1" oninput="options.validateIgnoreButton();" />
<button id="ignore-button" label="&ignore-button.label;" accesskey="&ignore-button.accesskey;" command="ignore-cmd" disabled="true" />
</hbox>
<separator class="thin" />
<listbox id="ignoredids-list" rows="10" seltype="multiple" onselect="options.validateRemoveButton();" />
<hbox class="actionButtons">
<button id="remove-button" label="&remove-button.label;" accesskey="&remove-button.accesskey;" command="remove-cmd" />
</hbox>
</tabpanel>
</tabpanels>
</tabbox>

<!-- Display -->
<checkbox id="statuspanel-check" preference="statuspanel-pref" label="&statuspanel-check.label;" accesskey="&statuspanel-check.accesskey;" />
</vbox>
</prefpane>
</prefwindow>
Loading

0 comments on commit fbe0e0d

Please sign in to comment.