зеркало из https://github.com/mozilla/snowl.git
factor out interface for writing message so we can overlay it onto river view in addition to stream view
This commit is contained in:
Родитель
993980fec4
Коммит
7a8ae5200d
|
@ -19,6 +19,10 @@ style chrome://global/content/customizeToolbar.xul chrome://snowl/content/browse
|
|||
# on exact matches of the entire URL.
|
||||
overlay chrome://snowl/content/list-sidebar.xul chrome://snowl/content/collections.xul
|
||||
|
||||
# Add the interface for writing messages to the stream and river views.
|
||||
overlay chrome://snowl/content/stream.xul chrome://snowl/content/write.xul
|
||||
overlay chrome://snowl/content/river.xul chrome://snowl/content/write.xul
|
||||
|
||||
# Add the toolbar to the collections and stream views.
|
||||
# XXX Should we add the toolbar directly to the list and river views
|
||||
# rather than indirectly via the collections view?
|
||||
|
|
|
@ -85,34 +85,14 @@ let SnowlMessageView = {
|
|||
getService(Ci.nsIFaviconService);
|
||||
},
|
||||
|
||||
get _stringBundle() {
|
||||
delete this._stringBundle;
|
||||
return this._stringBundle = document.getElementById("snowlStringBundle");
|
||||
get _writeButton() {
|
||||
delete this._writeButton;
|
||||
return this._writeButton = document.getElementById("snowlWriteButton");
|
||||
},
|
||||
|
||||
get _writeMessageButton() {
|
||||
delete this._writeMessageButton;
|
||||
return this._writeMessageButton = document.getElementById("snowlWriteMessageButton");
|
||||
},
|
||||
|
||||
get _writeBox() {
|
||||
delete this._writeBox;
|
||||
return this._writeBox = document.getElementById("writeBox");
|
||||
},
|
||||
|
||||
get _writeTextbox() {
|
||||
delete this._writeTextbox;
|
||||
return this._writeTextbox = document.getElementById("writeTextbox");
|
||||
},
|
||||
|
||||
get _writeCounter() {
|
||||
delete this._writeCounter;
|
||||
return this._writeCounter = document.getElementById("writeCounter");
|
||||
},
|
||||
|
||||
get _sendButton() {
|
||||
delete this._sendButton;
|
||||
return this._sendButton = document.getElementById("sendButton");
|
||||
get _writeForm() {
|
||||
delete this._writeForm;
|
||||
return this._writeForm = document.getElementById("writeForm");
|
||||
},
|
||||
|
||||
_window: null,
|
||||
|
@ -194,10 +174,10 @@ let SnowlMessageView = {
|
|||
gBrowserWindow.Snowl._initSnowlToolbar();
|
||||
|
||||
// For some reason setting hidden="true" in the XUL file prevents us
|
||||
// from showing the box later via writeBox.hidden = false, so we set it
|
||||
// from showing the box later via writeForm.hidden = false, so we set it
|
||||
// here instead.
|
||||
// FIXME: file a bug on this abnormality.
|
||||
this._writeBox.hidden = true;
|
||||
this._writeForm.hidden = true;
|
||||
|
||||
this._updateWriteButton();
|
||||
},
|
||||
|
@ -214,10 +194,10 @@ let SnowlMessageView = {
|
|||
window.setTimeout(function() { SnowlMessageView.onMidnight() }, msUntilMidnight);
|
||||
},
|
||||
|
||||
// Selectively show/hide the button for writing a message depending on
|
||||
// Selectively enable/disable the button for writing a message depending on
|
||||
// whether or not the user has an account that supports writing.
|
||||
_updateWriteButton: function() {
|
||||
this._writeMessageButton.disabled = (SnowlService.targets.length == 0);
|
||||
this._writeButton.disabled = (SnowlService.targets.length == 0);
|
||||
},
|
||||
|
||||
|
||||
|
@ -282,53 +262,20 @@ let SnowlMessageView = {
|
|||
//**************************************************************************//
|
||||
// Writing and Sending Messages
|
||||
|
||||
// FIXME: if there is more than one target, let the user choose which one to use.
|
||||
_target: null,
|
||||
|
||||
onWriteMessage: function(event) {
|
||||
this._writeBox.hidden = !event.target.checked;
|
||||
this._target = SnowlService.targets[0];
|
||||
this.onInputMessage();
|
||||
},
|
||||
|
||||
onInputMessage: function() {
|
||||
// Update the counter to reflect how many characters the user can still type.
|
||||
this._writeCounter.value =
|
||||
this._target.maxMessageLength - this._writeTextbox.value.length;
|
||||
|
||||
// If the user has typed more than they can send, disable the Send button.
|
||||
this._sendButton.disabled =
|
||||
(this._writeTextbox.value.length > this._target.maxMessageLength);
|
||||
},
|
||||
|
||||
onSendMessage: function() {
|
||||
this._sendButton.setAttribute("state", "sending");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label.sending");
|
||||
this._sendButton.disabled = true;
|
||||
this._writeTextbox.disabled = true;
|
||||
|
||||
let content = this._writeTextbox.value;
|
||||
let callback = function() { SnowlMessageView.onMessageSent() };
|
||||
// FIXME: pass an error callback and display a message to users on error.
|
||||
this._target.send(content, callback);
|
||||
onToggleWrite: function(event) {
|
||||
if (event.target.checked) {
|
||||
this._writeForm.hidden = false;
|
||||
// FIXME: only do this when the user first starts to write a message,
|
||||
// not every time they show the write form.
|
||||
WriteForm.init();
|
||||
}
|
||||
else
|
||||
this._writeForm.hidden = true;
|
||||
},
|
||||
|
||||
onMessageSent: function() {
|
||||
this._sendButton.setAttribute("state", "sent");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label.sent");
|
||||
|
||||
window.setTimeout(function() { SnowlMessageView._resetWriteForm() }, 5000);
|
||||
},
|
||||
|
||||
_resetWriteForm: function() {
|
||||
this._writeBox.hidden = true;
|
||||
this._writeMessageButton.checked = false;
|
||||
this._sendButton.removeAttribute("state");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label");
|
||||
this._sendButton.disabled = false;
|
||||
this._writeTextbox.disabled = false;
|
||||
this._writeTextbox.value = "";
|
||||
this._target = null;
|
||||
this._writeButton.checked = false;
|
||||
this._writeForm.hidden = true;
|
||||
},
|
||||
|
||||
|
||||
|
|
|
@ -53,20 +53,11 @@
|
|||
<script type="application/javascript" src="chrome://snowl/content/strands.js"/>
|
||||
<script type="application/javascript" src="chrome://snowl/content/stream.js"/>
|
||||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="snowlStringBundle" src="chrome://snowl/locale/stream.properties"/>
|
||||
</stringbundleset>
|
||||
<stringbundleset id="stringbundleset"/>
|
||||
|
||||
<toolbar id="snowlToolbar"/>
|
||||
|
||||
<vbox id="writeBox">
|
||||
<textbox id="writeTextbox" multiline="true" rows="3" oninput="SnowlMessageView.onInputMessage()"/>
|
||||
<hbox>
|
||||
<description id="writeCounter"/>
|
||||
<spacer flex="1"/>
|
||||
<button id="sendButton" label="&sendButton.label;" oncommand="SnowlMessageView.onSendMessage()"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
<vbox id="writeForm"/>
|
||||
|
||||
<vbox id="contentBox"/>
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ let SnowlToolbar = {
|
|||
SnowlOPML.export(window);
|
||||
},
|
||||
|
||||
onWriteMessage: function(event) {
|
||||
SnowlMessageView.onWriteMessage(event);
|
||||
onToggleWrite: function(event) {
|
||||
SnowlMessageView.onToggleWrite(event);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -62,10 +62,10 @@
|
|||
oncommand="SnowlToolbar.onExportOPML()"
|
||||
tooltiptext="&exportButton.tooltip;"/>
|
||||
<toolbarspring/>
|
||||
<toolbarbutton id="snowlWriteMessageButton" type="checkbox"
|
||||
<toolbarbutton id="snowlWriteButton" type="checkbox"
|
||||
image="chrome://snowl/content/icons/email_add.png"
|
||||
oncommand="SnowlToolbar.onWriteMessage(event)"
|
||||
tooltiptext="&writeMessageButton.tooltip;"/>
|
||||
oncommand="SnowlToolbar.onToggleWrite(event)"
|
||||
tooltiptext="&writeButton.tooltip;"/>
|
||||
</toolbar>
|
||||
|
||||
</overlay>
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Snowl.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Myk Melez <myk@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// Since we're an overlay, we assume the main XUL document has defined these.
|
||||
//const Cc = Components.classes;
|
||||
//const Ci = Components.interfaces;
|
||||
//const Cr = Components.results;
|
||||
//const Cu = Components.utils;
|
||||
|
||||
// modules that come with Firefox
|
||||
|
||||
// modules that are generic
|
||||
|
||||
// modules that are Snowl-specific
|
||||
Cu.import("resource://snowl/modules/service.js");
|
||||
|
||||
/**
|
||||
* The controller for the write message form.
|
||||
*/
|
||||
let WriteForm = {
|
||||
get _writeTextbox() {
|
||||
delete this._writeTextbox;
|
||||
return this._writeTextbox = document.getElementById("writeTextbox");
|
||||
},
|
||||
|
||||
get _writeCounter() {
|
||||
delete this._writeCounter;
|
||||
return this._writeCounter = document.getElementById("writeCounter");
|
||||
},
|
||||
|
||||
get _sendButton() {
|
||||
delete this._sendButton;
|
||||
return this._sendButton = document.getElementById("sendButton");
|
||||
},
|
||||
|
||||
get _stringBundle() {
|
||||
dump('document.getElementById("snowlWriteBundle"): ' + document.getElementById("snowlWriteBundle") + "\n");
|
||||
delete this._stringBundle;
|
||||
return this._stringBundle = document.getElementById("snowlWriteBundle");
|
||||
},
|
||||
|
||||
// FIXME: if there is more than one target, let the user choose which one to use.
|
||||
_target: null,
|
||||
|
||||
init: function() {
|
||||
this._target = SnowlService.targets[0];
|
||||
|
||||
// Set the initial state of the length counter and send button.
|
||||
this.onInputMessage();
|
||||
},
|
||||
|
||||
onInputMessage: function() {
|
||||
// Update the counter to reflect how many characters the user can still type.
|
||||
this._writeCounter.value =
|
||||
this._target.maxMessageLength - this._writeTextbox.value.length;
|
||||
|
||||
// If the user has typed more than they can send, disable the Send button.
|
||||
this._sendButton.disabled =
|
||||
(this._writeTextbox.value.length > this._target.maxMessageLength);
|
||||
},
|
||||
|
||||
onSendMessage: function() {
|
||||
this._sendButton.setAttribute("state", "sending");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label.sending");
|
||||
this._sendButton.disabled = true;
|
||||
this._writeTextbox.disabled = true;
|
||||
|
||||
let content = this._writeTextbox.value;
|
||||
let callback = function() { WriteForm.onMessageSent() };
|
||||
// FIXME: pass an error callback and display a message to users on error.
|
||||
this._target.send(content, callback);
|
||||
},
|
||||
|
||||
onMessageSent: function() {
|
||||
this._sendButton.setAttribute("state", "sent");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label.sent");
|
||||
|
||||
window.setTimeout(function() { WriteForm.reset() }, 5000);
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this._sendButton.removeAttribute("state");
|
||||
this._sendButton.label = this._stringBundle.getString("sendButton.label");
|
||||
this._sendButton.disabled = false;
|
||||
this._writeTextbox.disabled = false;
|
||||
this._writeTextbox.value = "";
|
||||
this._target = null;
|
||||
|
||||
// Let the view know the message was sent so it can do any necessary cleanup.
|
||||
SnowlMessageView.onMessageSent();
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- ***** BEGIN LICENSE BLOCK *****
|
||||
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
-
|
||||
- The contents of this file are subject to the Mozilla Public License Version
|
||||
- 1.1 (the "License"); you may not use this file except in compliance with
|
||||
- the License. You may obtain a copy of the License at
|
||||
- http://www.mozilla.org/MPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS IS" basis,
|
||||
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
- for the specific language governing rights and limitations under the
|
||||
- License.
|
||||
-
|
||||
- The Original Code is Snowl.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Mozilla.
|
||||
- Portions created by the Initial Developer are Copyright (C) 2008
|
||||
- the Initial Developer. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Myk Melez <myk@mozilla.org>
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the terms of
|
||||
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
- in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
- of those above. If you wish to allow use of your version of this file only
|
||||
- under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
- use your version of this file under the terms of the MPL, indicate your
|
||||
- decision by deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this file under
|
||||
- the terms of any one of the MPL, the GPL or the LGPL.
|
||||
-
|
||||
- ***** END LICENSE BLOCK ***** -->
|
||||
|
||||
<?xml-stylesheet href="chrome://snowl/content/write.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE page SYSTEM "chrome://snowl/locale/write.dtd">
|
||||
|
||||
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
id="snowlWriteOverlay">
|
||||
|
||||
<script type="application/javascript" src="chrome://snowl/content/write.js"/>
|
||||
|
||||
<stringbundleset id="stringbundleset">
|
||||
<stringbundle id="snowlWriteBundle" src="chrome://snowl/locale/write.properties"/>
|
||||
</stringbundleset>
|
||||
|
||||
<vbox id="writeForm">
|
||||
<textbox id="writeTextbox" multiline="true" rows="3" oninput="WriteForm.onInputMessage()"/>
|
||||
<hbox>
|
||||
<description id="writeCounter"/>
|
||||
<spacer flex="1"/>
|
||||
<button id="sendButton" label="&sendButton.label;" oncommand="WriteForm.onSendMessage()"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
||||
</overlay>
|
|
@ -1,2 +1 @@
|
|||
<!ENTITY page.title "Snowl Message Stream">
|
||||
<!ENTITY sendButton.label "Send">
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
<!ENTITY unsubscribeButton.tooltip "Unsubscribe from message sources.">
|
||||
<!ENTITY refreshButton.tooltip "Refresh message sources.">
|
||||
<!ENTITY exportButton.tooltip "Export message sources as OPML.">
|
||||
<!ENTITY writeMessageButton.tooltip "Write a message.">
|
||||
<!ENTITY writeButton.tooltip "Write a message.">
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<!ENTITY sendButton.label "Send">
|
Загрузка…
Ссылка в новой задаче