Restructure multiline toggling. Move multiline progress bar next to the search button.

This commit is contained in:
aurimasv 2012-11-08 05:58:43 -06:00
parent 1b9c89fd59
commit 1ca0eb3965
3 changed files with 62 additions and 37 deletions

View file

@ -92,9 +92,7 @@ const Zotero_Lookup = new function () {
collection = ZoteroPane_Local.getSelectedCollection(); collection = ZoteroPane_Local.getSelectedCollection();
} catch(e) {} } catch(e) {}
textBox.style.opacity = 0.5; Zotero_Lookup.toggleProgress(true);
textBox.disabled = true;
document.getElementById("zotero-lookup-progress").setAttribute("collapsed", false);
var item; var item;
while(item = items.pop()) { while(item = items.pop()) {
@ -111,9 +109,7 @@ const Zotero_Lookup = new function () {
successful += success; successful += success;
if(!notDone) { //i.e. done if(!notDone) { //i.e. done
textBox.style.opacity = 1; Zotero_Lookup.toggleProgress(false);
textBox.disabled = false;
document.getElementById("zotero-lookup-progress").setAttribute("collapsed", true);
if(successful) { if(successful) {
document.getElementById("zotero-lookup-panel").hidePopup(); document.getElementById("zotero-lookup-panel").hidePopup();
} else { } else {
@ -147,8 +143,9 @@ const Zotero_Lookup = new function () {
if(keyCode === 13 || keyCode === 14) { if(keyCode === 13 || keyCode === 14) {
if(search) { if(search) {
Zotero_Lookup.accept(textBox); Zotero_Lookup.accept(textBox);
event.stopImmediatePropagation();
} else if(!multiline) { //switch to multiline } else if(!multiline) { //switch to multiline
var mlTextbox = Zotero_Lookup.switchToMultiline(textBox); var mlTextbox = Zotero_Lookup.toggleMultiline(true);
mlTextbox.value = mlTextbox.value + '\n'; mlTextbox.value = mlTextbox.value + '\n';
} }
} else if(keyCode == event.DOM_VK_ESCAPE) { } else if(keyCode == event.DOM_VK_ESCAPE) {
@ -163,10 +160,8 @@ const Zotero_Lookup = new function () {
this.onShowing = function() { this.onShowing = function() {
document.getElementById("zotero-lookup-panel").style.padding = "10px"; document.getElementById("zotero-lookup-panel").style.padding = "10px";
document.getElementById("zotero-lookup-progress").hidden = false; var identifierElement = Zotero_Lookup.toggleMultiline(false);
var identifierElement = document.getElementById("zotero-lookup-textbox"); Zotero_Lookup.toggleProgress(false);
identifierElement.style.opacity = 1;
identifierElement.disabled = false;
identifierElement.focus(); identifierElement.focus();
} }
@ -174,15 +169,10 @@ const Zotero_Lookup = new function () {
* Cancels the popup and resets fields * Cancels the popup and resets fields
*/ */
this.onHidden = function() { this.onHidden = function() {
var txtBox = document.getElementById("zotero-lookup-textbox"); var txtBox = Zotero_Lookup.toggleMultiline(false);
var mlTextbox = document.getElementById("zotero-lookup-textbox-multiline"); var mlTextbox = document.getElementById("zotero-lookup-multiline-textbox");
txtBox.value = ""; txtBox.value = "";
mlTextbox.value = ""; mlTextbox.value = "";
//switch back to single line textbox
mlTextbox.setAttribute("collapsed", true);
document.getElementById("zotero-lookup-buttons").setAttribute("collapsed", true);
txtBox.setAttribute("collapsed", false);
txtBox.focus();
} }
/** /**
@ -190,7 +180,7 @@ const Zotero_Lookup = new function () {
*/ */
this.adjustTextbox = function(txtBox) { this.adjustTextbox = function(txtBox) {
if(txtBox.value.trim().match(/[\r\n]/)) { if(txtBox.value.trim().match(/[\r\n]/)) {
Zotero_Lookup.switchToMultiline(txtBox); Zotero_Lookup.toggleMultiline(true);
} else { } else {
//since we ignore trailing and leading newlines, we should also trim them for display //since we ignore trailing and leading newlines, we should also trim them for display
//can't use trim, because then we cannot add leading/trailing spaces to the single line textbox //can't use trim, because then we cannot add leading/trailing spaces to the single line textbox
@ -201,15 +191,42 @@ const Zotero_Lookup = new function () {
/** /**
* Performs the switch to multiline textbox and returns that textbox * Performs the switch to multiline textbox and returns that textbox
*/ */
this.switchToMultiline = function(txtBox) { this.toggleMultiline = function(on) {
var mlPanel = document.getElementById("zotero-lookup-multiline");
var mlTxtBox = document.getElementById("zotero-lookup-multiline-textbox");
var slPanel = document.getElementById("zotero-lookup-singleLine");
var slTxtBox = document.getElementById("zotero-lookup-textbox");
var source = on ? slTxtBox : mlTxtBox;
var dest = on ? mlTxtBox : slTxtBox;
if((mlPanel.collapsed && !on) || (!mlPanel.collapsed && on)) return dest;
//copy over the value //copy over the value
var mlTextbox = document.getElementById("zotero-lookup-textbox-multiline"); dest.value = source.value;
mlTextbox.value = txtBox.value;
//switch textboxes //switch textboxes
txtBox.setAttribute("collapsed", true); mlPanel.setAttribute("collapsed", !on);
mlTextbox.setAttribute("collapsed", false); slPanel.setAttribute("collapsed", !!on);
mlTextbox.focus(); dest.focus();
document.getElementById("zotero-lookup-buttons").setAttribute("collapsed", false); return dest;
return mlTextbox; }
this.toggleProgress = function(on) {
//single line
var txtBox = document.getElementById("zotero-lookup-textbox");
txtBox.style.opacity = on ? 0.5 : 1;
txtBox.disabled = !!on;
document.getElementById("zotero-lookup-progress").setAttribute("collapsed", !on);
//multiline
document.getElementById("zotero-lookup-multiline-textbox").disabled = !!on;
document.getElementById("zotero-lookup-multiline-progress").setAttribute("collapsed", !on);
}
this.getActivePanel = function() {
var mlPanel = document.getElementById("zotero-lookup-multiline");
if(mlPanel.collapsed) return document.getElementById("zotero-lookup-singleLine");
return mlPanel;
} }
} }

View file

@ -145,17 +145,20 @@
onpopuphidden="Zotero_Lookup.onHidden(event)"> onpopuphidden="Zotero_Lookup.onHidden(event)">
<vbox> <vbox>
<description>&zotero.lookup.description;</description> <description>&zotero.lookup.description;</description>
<vbox id="zotero-lookup-singleLine">
<stack> <stack>
<progressmeter id="zotero-lookup-progress" mode="undetermined" collapsed="true"/> <progressmeter id="zotero-lookup-progress" mode="undetermined" collapsed="true"/>
<vbox>
<textbox id="zotero-lookup-textbox" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" oninput="Zotero_Lookup.adjustTextbox(this)" flex="1" newlines="pasteintact"/> <textbox id="zotero-lookup-textbox" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" oninput="Zotero_Lookup.adjustTextbox(this)" flex="1" newlines="pasteintact"/>
<textbox id="zotero-lookup-textbox-multiline" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" multiline="true" rows="5" wrap="off" collapsed="true" flex="1"/>
</vbox>
</stack> </stack>
<hbox align="start" id="zotero-lookup-buttons" class="zotero-button-clear-image" collapsed="true"> </vbox>
<button label="&zotero.lookup.button.search;" align="start" oncommand="Zotero_Lookup.accept(document.getElementById('zotero-lookup-textbox-multiline'))"/> <vbox id="zotero-lookup-multiline" collapsed="true">
<textbox id="zotero-lookup-multiline-textbox" onkeypress="return Zotero_Lookup.onKeyPress(event, this)" multiline="true" rows="5" wrap="off" flex="1"/>
<hbox align="start" id="zotero-lookup-buttons" class="zotero-button-clear-image">
<button label="&zotero.lookup.button.search;" align="start" oncommand="Zotero_Lookup.accept(document.getElementById('zotero-lookup-multiline-textbox'))"/>
<progressmeter id="zotero-lookup-multiline-progress" mode="undetermined" collapsed="true" flex="1"/>
</hbox> </hbox>
</vbox> </vbox>
</vbox>
</panel> </panel>
</toolbarbutton> </toolbarbutton>
<!--<toolbarbutton id="zotero-tb-note-add" class="zotero-tb-button" tooltiptext="&zotero.toolbar.note.standalone;" oncommand="ZoteroPane_Local.newNote(event.shiftKey);"/>--> <!--<toolbarbutton id="zotero-tb-note-add" class="zotero-tb-button" tooltiptext="&zotero.toolbar.note.standalone;" oncommand="ZoteroPane_Local.newNote(event.shiftKey);"/>-->

View file

@ -308,6 +308,11 @@
list-style-image: url('chrome://zotero/skin/toolbar-lookup.png'); list-style-image: url('chrome://zotero/skin/toolbar-lookup.png');
} }
#zotero-lookup-multiline-progress
{
height: 2em;
}
#zotero-tb-item-from-page #zotero-tb-item-from-page
{ {
list-style-image: url('chrome://zotero/skin/toolbar-item-from-page.png'); list-style-image: url('chrome://zotero/skin/toolbar-item-from-page.png');