Update window title and tab label on document load and tab select; b=356959, r=brade

This commit is contained in:
daniel%glazman.org 2006-10-20 07:56:20 +00:00
Родитель 2722eb51e3
Коммит e7d1699315
7 изменённых файлов: 128 добавлений и 14 удалений

Просмотреть файл

@ -97,6 +97,16 @@
]]>
</constructor>
<destructor>
<![CDATA[
const editors = this.mTabPanels.childNodes;
for (var i = 0; i < editors.length; i++)
{
editors[i].removeEventListener("DOMTitleChanged", this.changeTabTitle, false);
}
]]>
</destructor>
<property name="selectedTab">
<getter>
<![CDATA[
@ -259,6 +269,7 @@
newTab.setAttribute("width", 0);
newTab.setAttribute("minwidth", 30);
newTab.setAttribute("flex", 100);
newTab.setAttribute("crop", "end");
this.mTabpanels.appendChild(newEditorElement);
@ -270,6 +281,7 @@
progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
newEditorElement.addEventListener("pageshow", function(evt) { if (evt.originalTarget == content.document){} }, true);
newEditorElement.addEventListener("DOMTitleChanged", this.changeTabTitle, false);
// select that new tab
this.selectedTab = newTab;
@ -284,6 +296,33 @@
</body>
</method>
<method name="changeTabTitle">
<parameter name="aEvent" />
<body>
<![CDATA[
var e = aEvent.currentTarget;
var title = aEvent.target.title;
if (!e.getEditor(e.contentWindow) && !title)
return;
var tabeditor = this.parentNode.parentNode.parentNode;
var tabs = tabeditor.mTabs.childNodes;
var editors = tabeditor.mTabpanels.childNodes;
var l = editors.length;
for (var i = 0; i < l; i++)
{
if (editors.item(i) == e)
{
var tab = tabs.item(i);
tab.label = title;
return;
}
}
]]>
</body>
</method>
<method name="stopWebNavigation">
<body>
<![CDATA[
@ -348,6 +387,8 @@
window.content.focus();
window.updateCommands("navigation");
window.updateCommands("style");
window.UpdateWindowTitle();
]]>
</body>
</method>

Просмотреть файл

@ -140,3 +140,31 @@ function onButtonUpdate(button, commmandID)
var state = commandNode.getAttribute("state");
button.checked = state == "true";
}
function UpdateWindowTitle()
{
try {
var windowTitle = EditorUtils.getDocumentTitle();
if (!windowTitle)
windowTitle = L10NUtils.getString("untitled");
// Append just the 'leaf' filename to the Doc. Title for the window caption
var docUrl = UrlUtils.getDocumentUrl();
if (docUrl && !UrlUtils.isUrlAboutBlank(docUrl))
{
var scheme = UrlUtils.getScheme(docUrl);
var filename = UrlUtils.getFilename(docUrl);
if (filename)
windowTitle += " [" + scheme + ":/.../" + filename + "]";
// TODO: 1. Save changed title in the recent pages data in prefs
}
// Set window title with
var titleModifier = L10NUtils.getString("titleModifier");
document.title = L10NUtils.getBundle()
.formatStringFromName("titleFormat",
[windowTitle, titleModifier],
2);
} catch (e) { dump(e); }
}

Просмотреть файл

@ -59,16 +59,19 @@ var EditorUtils = {
getCurrentEditor: function getCurrentEditor()
{
// Get the active editor from the <editor> tag
var editor;
var editor = null;
try {
var editorElement = this.getCurrentEditorElement();
editor = editorElement.getEditor(editorElement.contentWindow);
if (editorElement)
{
editor = editorElement.getEditor(editorElement.contentWindow);
// Do QIs now so editor users won't have to figure out which interface to use
// Using "instanceof" does the QI for us.
editor instanceof nsIPlaintextEditor;
editor instanceof nsIHTMLEditor;
} catch (e) { dump("Error in GetCurrentEditor: " + e); }
// Do QIs now so editor users won't have to figure out which interface to use
// Using "instanceof" does the QI for us.
editor instanceof nsIPlaintextEditor;
editor instanceof nsIHTMLEditor;
}
} catch (e) { dump("Error in GetCurrentEditor: " + e + "\n"); }
return editor;
},
@ -169,6 +172,35 @@ var EditorUtils = {
return "";
},
isHTMLEditor: function isHTMLEditor()
{
// We don't have an editorElement, just return false
if (!this.getCurrentEditorElement())
return false;
var editortype = this.getCurrentEditorType();
switch (editortype)
{
case "html":
case "htmlmail":
return true;
case "text":
case "textmail":
return false
default:
dump("INVALID EDITOR TYPE: " + editortype + "\n");
break;
}
return false;
},
isEditingRenderedHTML: function isEditingRenderedHTML()
{
return this.isHTMLEditor(); // && !this.isInHTMLSourceMode();
},
setDocumentTitle: function setDocumentTitle(title)
{
try {

Просмотреть файл

@ -63,6 +63,9 @@ var gEditorDocumentObserver =
if (editorStatus)
return;
// Set window title
UpdateWindowTitle();
window.content.focus();
break;

Просмотреть файл

@ -77,7 +77,7 @@ var L10NUtils = {
var stringBundle;
if (this._getStringBundleService())
try {
stringBundle = this.mStringBundleService.createBundle(this.kCOMPOSER_PROPERTIES);
stringBundle = this.mStringBundleService.createBundle(aProperties);
} catch (e) { dump (e)+"\n"; }
return stringBundle;
},
@ -86,7 +86,7 @@ var L10NUtils = {
getString: function getString(aName)
{
return this.getStringFromURL(aName, this.kCOMPOSER_PROPERTIES);
return this._getStringFromBundle(this.getBundle(), aName);
},
getStringFromURL: function getStringFromURL(aName, aProperties)
@ -97,6 +97,15 @@ var L10NUtils = {
} catch (e) { dump (e)+"\n"; }
return this._getStringFromBundle(stringBundle, aName);
}
},
getBundle: function getBundle()
{
if (!this.mStringBundle)
try {
this.mStringBundle = this._getBundleFromURL(this.kCOMPOSER_PROPERTIES);
} catch (e) { dump (e)+"\n"; }
return this.mStringBundle;
}
};

Просмотреть файл

@ -63,6 +63,7 @@ composer-locale.jar:
% locale branding en-US %locale/en-US/branding/
locale/en-US/composer/aboutDialog.dtd (locale/en-US/composer/aboutDialog.dtd)
locale/en-US/composer/composer.dtd (locale/en-US/composer/composer.dtd)
locale/en-US/composer/composer.properties (locale/en-US/composer/composer.properties)
locale/en-US/composer/credits.html (locale/en-US/composer/credits.html)
locale/en-US/composer/openLocation.dtd (locale/en-US/composer/openLocation.dtd)
locale/en-US/composer/openLocation.properties (locale/en-US/composer/openLocation.properties)

Просмотреть файл

@ -11,7 +11,7 @@
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Mozilla Composer.
- The Original Code is Composer.
-
- The Initial Developer of the Original Code is
- Disruptive Innovations SARL.
@ -35,7 +35,7 @@
-
- ***** END LICENSE BLOCK ***** -->
<!ENTITY window.title "Mozilla Composer">
<!ENTITY window.title "Composer">
<!ENTITY fileMenu.label "File">
<!ENTITY fileMenu.accesskey "f">
@ -69,7 +69,7 @@
<!ENTITY helpMenu.accesskey "h">
<!ENTITY aboutComposer.label "About Composer">
<!ENTITY throbber.tooltip "Mozilla Composer">
<!ENTITY throbber.tooltip "Composer">
<!ENTITY newMenu.label "New">
<!ENTITY newToolbarCmd.tooltip "Create a new page">