[interface] Custom textbox binding: multiline and timed together.

[interface] Multiple notes: works like a charm
This commit is contained in:
David Norton 2006-06-16 14:39:18 +00:00
parent 47d59f2dc1
commit 8ff6c48001
4 changed files with 86 additions and 15 deletions

View file

@ -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>

View file

@ -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,25 +281,34 @@ 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();
}
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);

View file

@ -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>

View file

@ -72,3 +72,8 @@ tree #items-tree
color: white;
background: #666666;
}
textbox[multiline="true"][type="timed"]
{
-moz-binding: url('chrome://scholar/content/customControls.xml#timed-textarea');
}