2001-10-30 09:46:14 +03:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* 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 mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998-1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* Implementations of nsIControllerCommand for composer commands */
|
|
|
|
|
|
|
|
function initEditorContextMenuItems(aEvent)
|
|
|
|
{
|
|
|
|
var shouldShowEditPage = !gContextMenu.onImage && !gContextMenu.onLink && !gContextMenu.onTextInput && !gContextMenu.inDirList;
|
|
|
|
gContextMenu.showItem( "context-editpage", shouldShowEditPage );
|
|
|
|
|
|
|
|
var shouldShowEditLink = gContextMenu.onSaveableLink;
|
|
|
|
gContextMenu.showItem( "context-editlink", shouldShowEditLink );
|
|
|
|
|
|
|
|
// Hide the applications separator if there's no add-on apps present.
|
2001-12-18 01:51:00 +03:00
|
|
|
gContextMenu.showItem("context-sep-apps", gContextMenu.shouldShowSeparator("context-sep-apps"));
|
2001-10-30 09:46:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function initEditorContextMenuListener(aEvent)
|
|
|
|
{
|
|
|
|
var popup = document.getElementById("contentAreaContextMenu");
|
2002-03-14 11:01:54 +03:00
|
|
|
if (popup)
|
|
|
|
popup.addEventListener("popupshowing", initEditorContextMenuItems, false);
|
2001-10-30 09:46:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener("load", initEditorContextMenuListener, false);
|
2002-01-24 18:36:36 +03:00
|
|
|
|
2002-01-29 03:56:08 +03:00
|
|
|
function editDocument(aDocument)
|
|
|
|
{
|
|
|
|
if (!aDocument)
|
|
|
|
aDocument = window._content.document;
|
2002-04-06 04:45:54 +04:00
|
|
|
|
2002-01-29 03:56:08 +03:00
|
|
|
editPage(aDocument.URL, window, false);
|
|
|
|
}
|
|
|
|
|
2002-01-24 18:36:36 +03:00
|
|
|
function editPageOrFrame()
|
|
|
|
{
|
|
|
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
|
2002-10-21 05:10:06 +04:00
|
|
|
// if the uri is a specific frame, grab it, else use the frameset uri
|
|
|
|
// and let Composer handle error if necessary
|
|
|
|
var url = getContentFrameURI(focusedWindow);
|
2002-01-24 18:36:36 +03:00
|
|
|
editPage(url, window, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Any non-editor window wanting to create an editor with a URL
|
|
|
|
// should use this instead of "window.openDialog..."
|
|
|
|
// We must always find an existing window with requested URL
|
|
|
|
// (When calling from a dialog, "launchWindow" is dialog's "opener"
|
|
|
|
// and we need a delay to let dialog close)
|
|
|
|
function editPage(url, launchWindow, delay)
|
|
|
|
{
|
2002-09-04 03:27:33 +04:00
|
|
|
// Always strip off "view-source:"
|
|
|
|
if (url.slice(0,12) == "view-source:")
|
|
|
|
url = url.slice(13);
|
|
|
|
|
2002-01-24 18:36:36 +03:00
|
|
|
// User may not have supplied a window
|
|
|
|
if (!launchWindow)
|
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
launchWindow = window;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dump("No window to launch an editor from!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the current window is a browser window, then extract the current charset menu setting from the current
|
|
|
|
// document and use it to initialize the new composer window...
|
|
|
|
|
|
|
|
var wintype = document.firstChild.getAttribute('windowtype');
|
|
|
|
var charsetArg;
|
|
|
|
|
2002-03-14 11:01:54 +03:00
|
|
|
if (launchWindow && (wintype == "navigator:browser") && launchWindow._content.document)
|
2002-01-24 18:36:36 +03:00
|
|
|
charsetArg = "charset=" + launchWindow._content.document.characterSet;
|
|
|
|
|
2002-03-14 11:01:54 +03:00
|
|
|
try {
|
2002-04-06 04:45:54 +04:00
|
|
|
var uri = createURI(url, null, null);
|
|
|
|
|
2002-04-30 05:36:59 +04:00
|
|
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
|
2002-03-14 11:01:54 +03:00
|
|
|
var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
|
|
|
|
var enumerator = windowManagerInterface.getEnumerator( "composer:html" );
|
2002-03-27 04:35:32 +03:00
|
|
|
var emptyWindow;
|
2002-03-14 11:01:54 +03:00
|
|
|
while ( enumerator.hasMoreElements() )
|
2002-01-24 18:36:36 +03:00
|
|
|
{
|
2002-04-22 18:02:48 +04:00
|
|
|
var win = enumerator.getNext().QueryInterface(Components.interfaces.nsIDOMWindowInternal);
|
2002-10-09 04:26:08 +04:00
|
|
|
if ( win && win.IsWebComposer())
|
2002-01-24 18:36:36 +03:00
|
|
|
{
|
2002-04-06 04:45:54 +04:00
|
|
|
if (CheckOpenWindowForURIMatch(uri, win))
|
2002-03-14 11:01:54 +03:00
|
|
|
{
|
|
|
|
// We found an editor with our url
|
2002-03-27 04:35:32 +03:00
|
|
|
win.focus();
|
2002-03-14 11:01:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-03-27 04:35:32 +03:00
|
|
|
else if (!emptyWindow && win.PageIsEmptyAndUntouched())
|
|
|
|
{
|
|
|
|
emptyWindow = win;
|
|
|
|
}
|
2002-01-24 18:36:36 +03:00
|
|
|
}
|
|
|
|
}
|
2002-03-27 04:35:32 +03:00
|
|
|
|
|
|
|
if (emptyWindow)
|
|
|
|
{
|
|
|
|
// we have an empty window we can use
|
|
|
|
if (emptyWindow.IsInHTMLSourceMode())
|
2002-07-23 09:30:16 +04:00
|
|
|
emptyWindow.SetEditMode(emptyWindow.PreviousNonSourceDisplayMode);
|
2002-03-27 04:35:32 +03:00
|
|
|
emptyWindow.editorShell.LoadUrl(url);
|
|
|
|
emptyWindow.focus();
|
|
|
|
emptyWindow.SetSaveAndPublishUI(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-14 11:01:54 +03:00
|
|
|
// Create new Composer window
|
|
|
|
if (delay)
|
2002-03-27 04:35:32 +03:00
|
|
|
{
|
|
|
|
launchWindow.delayedOpenWindow("chrome://editor/content", "chrome,all,dialog=no", url);
|
|
|
|
}
|
2002-03-14 11:01:54 +03:00
|
|
|
else
|
|
|
|
launchWindow.openDialog("chrome://editor/content", "_blank", "chrome,all,dialog=no", url, charsetArg);
|
2002-01-24 18:36:36 +03:00
|
|
|
|
2002-03-14 11:01:54 +03:00
|
|
|
} catch(e) {}
|
2002-01-24 18:36:36 +03:00
|
|
|
}
|
|
|
|
|
2002-04-06 04:45:54 +04:00
|
|
|
function createURI(urlstring)
|
|
|
|
{
|
|
|
|
try {
|
2002-06-03 22:05:02 +04:00
|
|
|
var ioserv = Components.classes["@mozilla.org/network/io-service;1"]
|
2002-04-06 04:45:54 +04:00
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
return ioserv.newURI(urlstring, null, null);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CheckOpenWindowForURIMatch(uri, win)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
var contentWindow = win.content; // need to QI win to nsIDOMWindowInternal?
|
|
|
|
var contentDoc = contentWindow.document;
|
|
|
|
var htmlDoc = contentDoc.QueryInterface(Components.interfaces.nsIDOMHTMLDocument);
|
|
|
|
var winuri = createURI(htmlDoc.URL);
|
|
|
|
return winuri.equals(uri);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-24 18:36:36 +03:00
|
|
|
function NewEditorFromTemplate()
|
|
|
|
{
|
|
|
|
// XXX not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
function NewEditorFromDraft()
|
|
|
|
{
|
|
|
|
// XXX not implemented
|
|
|
|
}
|