commit 8ff6c48001a617ac08b6fd594182d546cc113ab9
parent 47d59f2dc133a86d6f68e356f721a2e1060c2b52
Author: David Norton <david@nortoncrew.com>
Date: Fri, 16 Jun 2006 14:39:18 +0000
[interface] Custom textbox binding: multiline and timed together.
[interface] Multiple notes: works like a charm
Diffstat:
4 files changed, 87 insertions(+), 15 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/customControls.xml b/chrome/chromeFiles/content/scholar/customControls.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0"?>
+<bindings xmlns="http://www.mozilla.org/xbl"
+ xmlns:xbl="http://www.mozilla.org/xbl"
+ xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <binding id="timed-textarea" extends="chrome://global/content/bindings/textbox.xml#textarea">
+ <implementation>
+ <field name="_timer">null</field>
+ <property name="timeout"
+ onset="this.setAttribute('timeout', val); return val;"
+ onget="return parseInt(this.getAttribute('timeout')) || 0;"/>
+ <property name="value">
+ <getter>
+ return this.inputField.value;
+ </getter>
+ <setter>
+ <![CDATA[
+ this.inputField.value = val;
+ if (this._timer)
+ clearTimeout(this._timer);
+ return val;
+ ]]>
+ </setter>
+ </property>
+ <method name="_fireCommand">
+ <parameter name="me"/>
+ <body>
+ <![CDATA[
+ me._timer = null;
+ me.doCommand();
+ ]]>
+ </body>
+ </method>
+ </implementation>
+ <handlers>
+ <handler event="input">
+ <![CDATA[
+ if (this._timer)
+ clearTimeout(this._timer);
+ this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this);
+ ]]>
+ </handler>
+ </handlers>
+ </binding>
+</bindings>
+\ No newline at end of file
diff --git a/chrome/chromeFiles/content/scholar/itemPane.js b/chrome/chromeFiles/content/scholar/itemPane.js
@@ -107,6 +107,8 @@ ScholarItemPane = new function()
_updateNoteCount();
_notesMenu.selectedIndex = 0;
+
+ onNoteSelected();
}
function addDynamicRow(label, value, beforeElement)
@@ -269,8 +271,8 @@ ScholarItemPane = new function()
if(_notesMenu.selectedIndex == -1)
return;
- var id = _notesMenu.selectedItem.value;
- if(id)
+ var id = _selectedNoteID();
+ if(id && id != "undefined")
{
_itemBeingEdited.updateNote(id,_notesField.value);
}
@@ -279,24 +281,33 @@ ScholarItemPane = new function()
id = _itemBeingEdited.addNote(_notesField.value);
_notesMenu.selectedItem.value = id;
}
- var label = _notesField.value;
- _notesMenu.selectedItem.label = _noteToTitle(_notesField.value);
+ var label = _noteToTitle(_notesField.value);
+ _notesMenu.selectedItem.setAttribute('label', label);
+ _notesMenu.setAttribute('label', label);
}
function removeSelectedNote()
{
- var id = _notesMenu.selectedItem.value;
- if(id)
+ var id = _selectedNoteID();
+ if(id && id != "undefined")
{
_itemBeingEdited.removeNote(id);
}
- _notesMenu.removeitemAt(_notesMenu.selectedIndex);
+
+ var oldIndex = _notesMenu.selectedIndex;
+ _notesMenu.removeItemAt(oldIndex);
+ _notesMenu.selectedIndex = Math.max(oldIndex-1,0);
if(_notesMenu.firstChild.childNodes.length == 0)
+ {
addNote();
-
- _updateNoteCount();
+ }
+ else
+ {
+ onNoteSelected();
+ _updateNoteCount();
+ }
}
function addNote()
@@ -305,13 +316,17 @@ ScholarItemPane = new function()
_notesMenu.appendItem('Untitled Note');
_notesMenu.selectedIndex = _notesMenu.firstChild.childNodes.length-1;
+ onNoteSelected();
_updateNoteCount();
}
function onNoteSelected()
{
- var id = _notesMenu.selectedItem.value;
- if(id)
+ var id = _selectedNoteID();
+
+ Scholar.debug(id);
+
+ if(id && id != "undefined")
_notesField.value = _itemBeingEdited.getNote(id);
else
_notesField.value = "";
@@ -319,9 +334,11 @@ ScholarItemPane = new function()
function _noteToTitle(text)
{
- var t = text.substring(0, 30);
+ var MAX_LENGTH = 100;
+
+ var t = text.substring(0, MAX_LENGTH);
var ln = t.indexOf("\n");
- if (ln>-1 && ln<30)
+ if (ln>-1 && ln<MAX_LENGTH)
{
t = t.substring(0, ln);
}
@@ -342,6 +359,11 @@ ScholarItemPane = new function()
_notesLabel.value = c + " note" + (c != 1 ? "s" : "") + ":";
}
+
+ function _selectedNoteID()
+ {
+ return _notesMenu.selectedItem.getAttribute('value'); //for some reason, selectedItem.value is null sometimes.
+ }
}
addEventListener("load", function(e) { ScholarItemPane.onLoad(e); }, false);
diff --git a/chrome/chromeFiles/content/scholar/itemPane.xul b/chrome/chromeFiles/content/scholar/itemPane.xul
@@ -14,7 +14,7 @@
<vbox>
<hbox align="center">
<label id="scholar-notes-label"/>
- <menulist flex="1" id="scholar-notes-menu" onselect="ScholarItemPane.onNoteSelected();">
+ <menulist flex="1" id="scholar-notes-menu" oncommand="ScholarItemPane.onNoteSelected();">
<menupopup/>
</menulist>
<toolbarbutton label="-" class="addremove" oncommand="ScholarItemPane.removeSelectedNote();"/>
@@ -23,7 +23,7 @@
<textbox id="scholar-notes-field"
type="timed" timeout="1000" oncommand="ScholarItemPane.modifySelectedNote();"
multiline="true" flex="1"
- onblur="ScholarItemPane.modifyField('notes',this.value);"/>
+ onblur="ScholarItemPane.modifySelectedNote();"/>
</vbox>
<vbox id="scholar-metadata" flex="1">
<popupset>
diff --git a/chrome/chromeFiles/skin/default/scholar/overlay.css b/chrome/chromeFiles/skin/default/scholar/overlay.css
@@ -71,4 +71,9 @@ tree #items-tree
{
color: white;
background: #666666;
+}
+
+textbox[multiline="true"][type="timed"]
+{
+ -moz-binding: url('chrome://scholar/content/customControls.xml#timed-textarea');
}
\ No newline at end of file