diff --git a/mozilla/extensions/xmlterm/base/mozIXMLTermShell.idl b/mozilla/extensions/xmlterm/base/mozIXMLTermShell.idl index 90653261670..1f3e2a06ca8 100644 --- a/mozilla/extensions/xmlterm/base/mozIXMLTermShell.idl +++ b/mozilla/extensions/xmlterm/base/mozIXMLTermShell.idl @@ -51,48 +51,57 @@ interface mozIXMLTermShell : nsISupports * @param args argument string to be passed to XMLterm * (at the moment this just contains any initial input data) */ - void Init(in nsIDOMWindowInternal aContentWin, in wstring URL, in wstring args); + void init(in nsIDOMWindowInternal aContentWin, in wstring URL, in wstring args); /** Closes XMLterm, freeing resources * @param aCookie document.cookie string for authentication */ - void Close(in wstring aCookie); + void close(in wstring aCookie); /** Polls for readable data from XMLterm */ - void Poll(); + void poll(); /** Resizes XMLterm to match a resized window. */ - void Resize(); + void resize(); /** Writes string to terminal as if the user had typed it (command input) * @param buf string to be transmitted to terminal * @param aCookie document.cookie string for authentication */ - void SendText(in wstring aString, in wstring aCookie); + void sendText(in wstring aString, in wstring aCookie); /** Sets command history buffer count * @param aHistory history buffer count * @param aCookie document.cookie string for authentication */ - void SetHistory(in long aHistory, in wstring aCookie); + void setHistory(in long aHistory, in wstring aCookie); /** Sets command prompt * @param aPrompt command prompt string (HTML) * @param aCookie document.cookie string for authentication */ - void SetPrompt(in wstring aPrompt, in wstring aCookie); + void setPrompt(in wstring aPrompt, in wstring aCookie); + + /** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ + boolean exportHTML(in wstring aFilename, in long permissions, + in wstring style, in unsigned long refreshSeconds, + in boolean forceRefresh, in wstring aCookie); /** Ignore key press events * (workaround for form input being transmitted to xmlterm) * @param aIgnore ignore flag (true/false) * @param aCookie document.cookie string for authentication */ - void IgnoreKeyPress(in boolean aIgnore, in wstring aCookie); + void ignoreKeyPress(in boolean aIgnore, in wstring aCookie); /** Exit browser, closing all windows (not yet implemented) */ - void Exit(); + void exit(); }; diff --git a/mozilla/extensions/xmlterm/base/mozIXMLTerminal.idl b/mozilla/extensions/xmlterm/base/mozIXMLTerminal.idl index bdefa762d53..ae1274de4b6 100644 --- a/mozilla/extensions/xmlterm/base/mozIXMLTerminal.idl +++ b/mozilla/extensions/xmlterm/base/mozIXMLTerminal.idl @@ -131,7 +131,16 @@ interface mozIXMLTerminal : nsISupports */ void resize(); - /** Shows the caret and make it editable. + /** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ + boolean exportHTML(in wstring aFilename, in long permissions, + in wstring style, in unsigned long refreshSeconds, + in boolean forceRefresh); + + /** Shows the caret and make it editable. */ void showCaret(); diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp index 04e7d62d490..ba36fdea823 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermListeners.cpp @@ -624,7 +624,8 @@ mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent) XMLT_LOG(mozXMLTermMouseListener::MouseClick,50, ("buttonCode=%d\n", buttonCode)); -#ifndef NO_WORKAROUND +#if 0 + // NO MORE NEED FOR THIS WORKAROUND! // Without this workaround, clicking on the xmlterm window to give it // focus fails position the cursor at the end of the last line // (For some reason, the MouseDown event causes the cursor to be positioned @@ -646,6 +647,18 @@ mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent) if (NS_FAILED(result) || !selection) return NS_OK; // Do not consume mouse event + PRBool isCollapsed; + result = selection->GetIsCollapsed(&isCollapsed); + if (NS_FAILED(result)) + return NS_OK; // Do not consume mouse event + + XMLT_LOG(mozXMLTermMouseListener::MouseClick,50, ("isCollapsed=%d\n", + isCollapsed)); + + // If non-collapsed selection, do not collapse it + if (!isCollapsed) + return NS_OK; + // Locate selection range nsCOMPtr uiEvent (do_QueryInterface(mouseEvent)); if (!uiEvent) @@ -662,7 +675,7 @@ mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent) return NS_OK; // Do not consume mouse event (void)selection->Collapse(parentNode, offset); -#endif // !NO_WORKAROUND +#endif return NS_OK; // Do not consume mouse event } diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp index c85ae816939..1870b9df222 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp @@ -32,6 +32,9 @@ #include "nsIDocumentViewer.h" +#include "nsILocalFile.h" +#include "nsIFileStreams.h" + #include "nsITextContent.h" #include "nsIDOMElement.h" @@ -64,6 +67,7 @@ // mozXMLTermSession definition ///////////////////////////////////////////////////////////////////////// static const char* kWhitespace=" \b\t\r\n"; +static const PRUnichar kNBSP = 160; const char* const mozXMLTermSession::sessionElementNames[] = { "session", @@ -113,6 +117,7 @@ mozXMLTermSession::mozXMLTermSession() : mXMLTerminal(nsnull), mBodyNode(nsnull), + mMenusNode(nsnull), mSessionNode(nsnull), mCurrentDebugNode(nsnull), @@ -125,7 +130,7 @@ mozXMLTermSession::mozXMLTermSession() : mEntryHasOutput(PR_FALSE), - mPromptSpanNode(nsnull), + mPromptTextNode(nsnull), mCommandSpanNode(nsnull), mInputTextNode(nsnull), @@ -158,6 +163,9 @@ mozXMLTermSession::mozXMLTermSession() : mRestoreInputEcho(PR_FALSE), + mCountExportHTML(0), + mLastExportHTML(nsAutoString()), + mShellPrompt(nsAutoString()), mPromptHTML(nsAutoString()), mFragmentBuffer(nsAutoString()) @@ -224,6 +232,15 @@ NS_IMETHODIMP mozXMLTermSession::Init(mozIXMLTerminal* aXMLTerminal, if (NS_FAILED(result) || !mBodyNode) return NS_ERROR_FAILURE; + nsCOMPtr menusElement; + nsAutoString menusID( NS_LITERAL_STRING("menus") ); + result = vDOMHTMLDocument->GetElementById(menusID, + getter_AddRefs(menusElement)); + + if (NS_SUCCEEDED(result) && menusElement) { + mMenusNode = do_QueryInterface(menusElement); + } + // Use body node as session node by default mSessionNode = mBodyNode; @@ -275,7 +292,7 @@ NS_IMETHODIMP mozXMLTermSession::Finalize(void) mXMLTermStream = nsnull; - mPromptSpanNode = nsnull; + mPromptTextNode = nsnull; mCommandSpanNode = nsnull; mInputTextNode = nsnull; @@ -283,6 +300,7 @@ NS_IMETHODIMP mozXMLTermSession::Finalize(void) mCurrentEntryNode = nsnull; mBodyNode = nsnull; + mMenusNode = nsnull; mSessionNode = nsnull; mCurrentDebugNode = nsnull; @@ -509,9 +527,24 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux, XMLT_LOG(mozXMLTermSession::ReadAll,62, ("Terminating screen mode\n")); + // Uncollapse non-screen stuff + nsAutoString attName(NS_LITERAL_STRING("xmlt-block-collapsed")); + + nsCOMPtr menusElement = do_QueryInterface(mMenusNode); + + if (NS_SUCCEEDED(result) && menusElement) { + menusElement->RemoveAttribute(attName); + } + + nsCOMPtr sessionElement = do_QueryInterface(mSessionNode); + + if (sessionElement) { + sessionElement->RemoveAttribute(attName); + } + // Delete screen element nsCOMPtr resultNode; - mSessionNode->RemoveChild(mScreenNode, getter_AddRefs(resultNode)); + mBodyNode->RemoveChild(mScreenNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) break; mScreenNode = nsnull; @@ -613,7 +646,7 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux, opvals, buf_row)); nsCOMPtr resultNode; - result = mSessionNode->RemoveChild(mScreenNode, + result = mBodyNode->RemoveChild(mScreenNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) break; @@ -1107,6 +1140,7 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux, selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL, nsISelectionController::SELECTION_FOCUS_REGION); + } // Show caret @@ -1119,6 +1153,115 @@ NS_IMETHODIMP mozXMLTermSession::ReadAll(mozILineTermAux* lineTermAux, } +/** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ +NS_IMETHODIMP mozXMLTermSession::ExportHTML(const PRUnichar* aFilename, + PRInt32 permissions, + const PRUnichar* style, + PRUint32 refreshSeconds, + PRBool forceExport, + PRBool* exported) +{ + nsresult result; + + if (!aFilename || !exported) + return NS_ERROR_NULL_POINTER; + + *exported = PR_FALSE; + + if (forceExport) + mLastExportHTML.SetLength(0); + + nsAutoString indentString; indentString.SetLength(0); + nsAutoString htmlString; + result = ToHTMLString(mBodyNode, indentString, htmlString, + PR_TRUE, PR_FALSE ); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + if (htmlString.Equals(mLastExportHTML)) + return NS_OK; + + mLastExportHTML.Assign( htmlString ); + mCountExportHTML++; + + nsAutoString filename( aFilename ); + + if (filename.Length() == 0) { + // Write to STDERR + char* htmlCString = ToNewCString(htmlString); + fprintf(stderr, "mozXMLTermSession::ExportHTML:\n%s\n\n", htmlCString); + nsCRT::free(htmlCString); + + *exported = PR_TRUE; + return NS_OK; + } + + // Copy HTML to local file + nsCOMPtr localFile = do_CreateInstance( NS_LOCAL_FILE_CONTRACTID, &result); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + XMLT_LOG(mozXMLTermSession::ExportHTML,0, + ("Exporting %d\n", mCountExportHTML)); + + result = localFile->InitWithUnicodePath(filename.get()); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + PRInt32 ioFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE; + + nsCOMPtr outStream; + result = NS_NewLocalFileOutputStream(getter_AddRefs(outStream), + localFile, ioFlags, permissions); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + PRUint32 writeCount; + + nsCAutoString cString( "\n\n" ); + + if (refreshSeconds > 0) { + cString.Append(""); + } + + cString.Append("xmlterm page\n"); + cString.Append("\n"); + + if (style) { + cString.Append("\n"); + } + + cString.Append("\n"); + cString.Append("\n"); + + cString.AppendWithConversion(htmlString); + + cString.Append("\n"); + + result = outStream->Write(cString.get(), cString.Length(), + &writeCount); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + result = outStream->Flush(); + + result = outStream->Close(); + + *exported = PR_TRUE; + return NS_OK; +} + + /** Aborts session by closing LineTerm and displays an error message * @param lineTermAux LineTermAux object to be closed * @param abortCode abort code string to dbe displayed @@ -1182,7 +1325,14 @@ NS_IMETHODIMP mozXMLTermSession::DisplayInput(const nsString& aString, XMLT_LOG(mozXMLTermSession::DisplayInput,70,("cursorCol=%d\n", cursorCol)); - result = SetDOMText(mInputTextNode, aString); + // If string terminates in whitespace, append NBSP for cursor positioning + nsAutoString tempString( aString ); + if (aString.Last() == PRUnichar(' ')) + tempString += kNBSP; + + // Display string + result = SetDOMText(mInputTextNode, tempString); + if (NS_FAILED(result)) return NS_ERROR_FAILURE; @@ -1218,20 +1368,15 @@ NS_IMETHODIMP mozXMLTermSession::DisplayInput(const nsString& aString, } else { // Get the last bit of text in the prompt - nsCOMPtr promptTextNode; - result = mPromptSpanNode->GetLastChild(getter_AddRefs(promptTextNode)); + nsCOMPtr domText (do_QueryInterface(mPromptTextNode)); - if (NS_SUCCEEDED(result)) { - nsCOMPtr domText (do_QueryInterface(promptTextNode)); - - if (domText) { - PRUint32 textLength; - result = domText->GetLength(&textLength); - if (NS_SUCCEEDED(result)) { - XMLT_LOG(mozXMLTermSession::DisplayInput,72, - ("textLength=%d\n", textLength)); - result = selection->Collapse(promptTextNode, textLength); - } + if (domText) { + PRUint32 textLength; + result = domText->GetLength(&textLength); + if (NS_SUCCEEDED(result)) { + XMLT_LOG(mozXMLTermSession::DisplayInput,72, + ("textLength=%d\n", textLength)); + result = selection->Collapse(mPromptTextNode, textLength); } } } @@ -1899,8 +2044,13 @@ NS_IMETHODIMP mozXMLTermSession::AppendOutput(const nsString& aString, mOutputTextNode = textNode; mOutputTextOffset = 0; + // If string terminates in whitespace, append NBSP for cursor positioning + nsAutoString tempString( aString ); + if (newline || (aString.Last() == PRUnichar(' '))) + tempString += kNBSP; + // Display incomplete line - result = SetDOMText(mOutputTextNode, aString); + result = SetDOMText(mOutputTextNode, tempString); if (NS_FAILED(result)) return NS_ERROR_FAILURE; @@ -1988,7 +2138,7 @@ NS_IMETHODIMP mozXMLTermSession::AppendOutput(const nsString& aString, currentStyle = strStyle[0]; mOutputTextOffset = 0; - tagName.Assign(NS_LITERAL_STRING("span")); + tagName.Assign(NS_LITERAL_STRING("pre")); PR_ASSERT(strLength > 0); @@ -2857,6 +3007,7 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux) XMLT_LOG(mozXMLTermSession::PositionOutputCursor,80,("\n")); + PRBool dummyOutput = PR_FALSE; if (!mOutputTextNode) { // Append dummy output line nsCOMPtr spanNode, textNode; @@ -2868,6 +3019,12 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux) if (NS_FAILED(result) || !spanNode || !textNode) return; + // Display NBSP for cursor positioning + nsAutoString tempString; + tempString += kNBSP; + SetDOMText(textNode, tempString); + dummyOutput = PR_TRUE; + mOutputDisplayType = SPAN_DUMMY_NODE; mOutputDisplayNode = spanNode; mOutputTextNode = textNode; @@ -2891,6 +3048,8 @@ void mozXMLTermSession::PositionOutputCursor(mozILineTermAux* lineTermAux) domText->GetData(text); PRInt32 textOffset = text.Length(); + if (textOffset && dummyOutput) textOffset--; + if (lineTermAux && (mOutputDisplayType == PRE_STDIN_NODE)) { // Get cursor column PRInt32 cursorCol = 0; @@ -3152,20 +3311,25 @@ NS_IMETHODIMP mozXMLTermSession::NewEntry(const nsString& aPrompt) nsAutoString classAttribute; // Create prompt element - nsCOMPtr newPromptSpanNode; + nsCOMPtr promptSpanNode; tagName.Assign(NS_LITERAL_STRING("span")); name.AssignWithConversion(sessionElementNames[PROMPT_ELEMENT]); result = NewElement(tagName, name, mCurrentEntryNumber, - inputNode, newPromptSpanNode); - if (NS_FAILED(result) || !newPromptSpanNode) { + inputNode, promptSpanNode); + if (NS_FAILED(result) || !promptSpanNode) { return NS_ERROR_FAILURE; } - mPromptSpanNode = newPromptSpanNode; - // Add event attributes to prompt element result = SetEventAttributes(name, mCurrentEntryNumber, - mPromptSpanNode); + promptSpanNode); + + nsCOMPtr domDoc; + result = mXMLTerminal->GetDOMDocument(getter_AddRefs(domDoc)); + if (NS_FAILED(result) || !domDoc) + return NS_ERROR_FAILURE; + + nsCOMPtr resultNode; if (mPromptHTML.Length() == 0) { @@ -3177,19 +3341,23 @@ NS_IMETHODIMP mozXMLTermSession::NewEntry(const nsString& aPrompt) tagName.Assign(NS_LITERAL_STRING("span")); name.Assign(NS_LITERAL_STRING("noicons")); result = NewElementWithText(tagName, name, -1, - mPromptSpanNode, spanNode, textNode); + promptSpanNode, spanNode, textNode); if (NS_FAILED(result) || !spanNode || !textNode) { return NS_ERROR_FAILURE; } - // Set prompt text - result = SetDOMText(textNode, aPrompt); - if (NS_FAILED(result)) - return NS_ERROR_FAILURE; + // Strip single trailing space, if any, from prompt string + int spaceOffset = aPrompt.Length(); - nsCOMPtr domDoc; - result = mXMLTerminal->GetDOMDocument(getter_AddRefs(domDoc)); - if (NS_FAILED(result) || !domDoc) + if ((spaceOffset > 0) && (aPrompt.Last() == ((PRUnichar) ' '))) + spaceOffset--; + + nsAutoString promptStr; + aPrompt.Left(promptStr, spaceOffset); + + // Set prompt text + result = SetDOMText(textNode, promptStr); + if (NS_FAILED(result)) return NS_ERROR_FAILURE; // Create IMG element @@ -3205,31 +3373,16 @@ NS_IMETHODIMP mozXMLTermSession::NewEntry(const nsString& aPrompt) imgElement->SetAttribute(attName, attValue); attName.Assign(NS_LITERAL_STRING("src")); - attValue.Assign(NS_LITERAL_STRING("chrome://xmlterm/content/wheel.gif")); + attValue.Assign(NS_LITERAL_STRING("chrome://xmlterm/skin/wheel.gif")); imgElement->SetAttribute(attName, attValue); attName.Assign(NS_LITERAL_STRING("align")); attValue.Assign(NS_LITERAL_STRING("middle")); imgElement->SetAttribute(attName, attValue); - nsCOMPtr resultNode; - // Append IMG element nsCOMPtr imgNode = do_QueryInterface(imgElement); - result = mPromptSpanNode->AppendChild(imgNode, - getter_AddRefs(resultNode)); - if (NS_FAILED(result)) - return NS_ERROR_FAILURE; - - // Append text node containing single space - nsCOMPtr stubText; - nsAutoString spaceStr(NS_LITERAL_STRING(" ")); - result = domDoc->CreateTextNode(spaceStr, getter_AddRefs(stubText)); - if (NS_FAILED(result) || !stubText) - return NS_ERROR_FAILURE; - - nsCOMPtr stubNode = do_QueryInterface(stubText); - result = mPromptSpanNode->AppendChild(stubNode, + result = promptSpanNode->AppendChild(imgNode, getter_AddRefs(resultNode)); if (NS_FAILED(result)) return NS_ERROR_FAILURE; @@ -3237,7 +3390,7 @@ NS_IMETHODIMP mozXMLTermSession::NewEntry(const nsString& aPrompt) #else // !DEFAULT_ICON_PROMPT // Create text node as child of prompt element nsCOMPtr textNode; - result = NewTextNode(mPromptSpanNode, textNode); + result = NewTextNode(promptSpanNode, textNode); if (NS_FAILED(result) || !textNode) return NS_ERROR_FAILURE; @@ -3250,10 +3403,24 @@ NS_IMETHODIMP mozXMLTermSession::NewEntry(const nsString& aPrompt) } else { // User-specified HTML prompt - result = InsertFragment(mPromptHTML, mPromptSpanNode, + result = InsertFragment(mPromptHTML, promptSpanNode, mCurrentEntryNumber); } + // Append text node containing single NBSP + nsCOMPtr stubText; + nsAutoString spaceStr(kNBSP); + result = domDoc->CreateTextNode(spaceStr, getter_AddRefs(stubText)); + if (NS_FAILED(result) || !stubText) + return NS_ERROR_FAILURE; + + nsCOMPtr stubNode = do_QueryInterface(stubText); + result = inputNode->AppendChild(stubNode, getter_AddRefs(resultNode)); + if (NS_FAILED(result)) + return NS_ERROR_FAILURE; + + mPromptTextNode = stubNode; + // Create command element nsCOMPtr newCommandSpanNode; tagName.Assign(NS_LITERAL_STRING("span")); @@ -3315,13 +3482,29 @@ NS_IMETHODIMP mozXMLTermSession::NewScreen(void) nsAutoString tagName(NS_LITERAL_STRING("div")); nsAutoString name(NS_LITERAL_STRING("screen")); result = NewElement(tagName, name, 0, - mSessionNode, divNode); + mBodyNode, divNode); if (NS_FAILED(result) || !divNode) return NS_ERROR_FAILURE; mScreenNode = divNode; + // Collapse non-screen stuff + nsAutoString attName(NS_LITERAL_STRING("xmlt-block-collapsed")); + nsAutoString attValue(NS_LITERAL_STRING("true")); + + nsCOMPtr menusElement = do_QueryInterface(mMenusNode); + + if (NS_SUCCEEDED(result) && menusElement) { + menusElement->SetAttribute(attName, attValue); + } + + nsCOMPtr sessionElement = do_QueryInterface(mSessionNode); + + if (sessionElement) { + sessionElement->SetAttribute(attName, attValue); + } + // Create individual row elements nsCOMPtr resultNode; PRInt32 row; @@ -4147,6 +4330,8 @@ NS_IMETHODIMP mozXMLTermSession::ToHTMLString(nsIDOMNode* aNode, if (domText) { // Text node domText->GetData(htmlString); + htmlString.ReplaceChar(kNBSP, ' '); + } else { nsCOMPtr domElement = do_QueryInterface(aNode); diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.h b/mozilla/extensions/xmlterm/base/mozXMLTermSession.h index b9435e3f2bb..25a50506a17 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.h +++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.h @@ -86,6 +86,18 @@ class mozXMLTermSession */ NS_IMETHOD ReadAll(mozILineTermAux* lineTermAux, PRBool& processedData); + /** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ + NS_IMETHOD ExportHTML(const PRUnichar* aFilename, + PRInt32 permissions, + const PRUnichar* style, + PRUint32 refreshSeconds, + PRBool forceExport, + PRBool* exported); + /** Aborts session by closing LineTerm and displays an error message * @param lineTermAux LineTermAux object to be closed * @param abortCode abort code string to be displayed @@ -118,8 +130,8 @@ class mozXMLTermSession */ NS_IMETHOD SetPrompt(const PRUnichar* aPrompt); - /** Gets flag denoting whether terminal is in full screen mode - * @param aFlag (output) screen mode flag + /** Gets webcast filename + * @param aFilename (output) webcast filename */ NS_IMETHOD GetScreenMode(PRBool* aFlag); @@ -593,6 +605,9 @@ protected: /** BODY node of document containing XMLterm */ nsCOMPtr mBodyNode; + /** XMLterm menus node */ + nsCOMPtr mMenusNode; + /** XMLterm session node */ nsCOMPtr mSessionNode; @@ -618,13 +633,13 @@ protected: /** flag indicating whether current entry has output data */ PRBool mEntryHasOutput; - /** span node for current command prompt (is this necessary?) */ - nsCOMPtr mPromptSpanNode; + /** text node terminating current command prompt */ + nsCOMPtr mPromptTextNode; - /** span node for current command input (is this necessary?) */ + /** span node for current command input */ nsCOMPtr mCommandSpanNode; - /** text node for current command input (is this necessary?) */ + /** text node for current command input */ nsCOMPtr mInputTextNode; @@ -700,6 +715,14 @@ protected: /** restore input echo flag */ PRBool mRestoreInputEcho; + + /** count of exported HTML */ + PRInt32 mCountExportHTML; + + /** last exported HTML */ + nsString mLastExportHTML; + + /** shell prompt string */ nsString mShellPrompt; diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermShell.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermShell.cpp index 0fb7ec83442..9415f6b5d13 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermShell.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermShell.cpp @@ -82,6 +82,7 @@ mozXMLTermShell::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) debugStr = nsnull; } + tlog_init(stderr); tlog_set_level(XMLT_TLOG_MODULE, messageLevel, debugStr); mLoggingInitialized = PR_TRUE; } @@ -184,6 +185,33 @@ NS_IMETHODIMP mozXMLTermShell::SetPrompt(const PRUnichar* aPrompt, } +/** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ +NS_IMETHODIMP mozXMLTermShell::ExportHTML(const PRUnichar* aFilename, + PRInt32 permissions, + const PRUnichar* style, + PRUint32 refreshSeconds, + PRBool forceExport, + const PRUnichar* aCookie, + PRBool* exported) +{ + if (!mXMLTerminal) + return NS_ERROR_NOT_INITIALIZED; + + nsresult result; + PRBool matchesCookie; + result = mXMLTerminal->MatchesCookie(aCookie, &matchesCookie); + if (NS_FAILED(result) || !matchesCookie) + return NS_ERROR_FAILURE; + + return mXMLTerminal->ExportHTML( aFilename, permissions, style, + refreshSeconds, forceExport, + exported); +} + /** Ignore key press events * (workaround for form input being transmitted to xmlterm) * @param aIgnore ignore flag (PR_TRUE/PR_FALSE) diff --git a/mozilla/extensions/xmlterm/base/mozXMLTerminal.cpp b/mozilla/extensions/xmlterm/base/mozXMLTerminal.cpp index dd4647518ab..e864710ff77 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTerminal.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTerminal.cpp @@ -769,7 +769,7 @@ NS_IMETHODIMP mozXMLTerminal::Paste() return NS_ERROR_FAILURE; // DataFlavors to get out of transferable - trans->AddDataFlavor(kHTMLMime); + // trans->AddDataFlavor(kHTMLMime); // Cannot handle HTML yet trans->AddDataFlavor(kUnicodeMime); // Get data from clipboard @@ -1015,6 +1015,26 @@ NS_IMETHODIMP mozXMLTerminal::Resize(void) return NS_OK; } +/** Exports HTML to file, with META REFRESH, if refreshSeconds is non-zero. + * Nothing is done if display has not changed since last export, unless + * forceExport is true. Returns true if export actually takes place. + * If filename is a null string, HTML is written to STDERR. + */ +NS_IMETHODIMP mozXMLTerminal::ExportHTML(const PRUnichar* aFilename, + PRInt32 permissions, + const PRUnichar* style, + PRUint32 refreshSeconds, + PRBool forceExport, + PRBool* exported) +{ + if (!mXMLTermSession) + return NS_ERROR_FAILURE; + + return mXMLTermSession->ExportHTML( aFilename, permissions, style, + refreshSeconds, forceExport, + exported); +} + // nsIWebProgressListener methods NS_IMETHODIMP mozXMLTerminal::OnStateChange(nsIWebProgress* aWebProgress, diff --git a/mozilla/extensions/xmlterm/config/xmlterm_config.mk b/mozilla/extensions/xmlterm/config/xmlterm_config.mk index 0eb3f19c401..c0318ff74d7 100644 --- a/mozilla/extensions/xmlterm/config/xmlterm_config.mk +++ b/mozilla/extensions/xmlterm/config/xmlterm_config.mk @@ -68,10 +68,6 @@ ifeq ($(OS_ARCH),FreeBSD) DEFINES += -DBSDFAMILY endif -ifeq ($(MOZ_WIDGET_TOOLKIT),gtk) -USE_GTK_WIDGETS = 1 -endif - # # Netscape Portable Runtime options # @@ -79,9 +75,15 @@ ifdef STAND_ALONE ifdef USE_NCURSES DEFINES += -DUSE_NCURSES endif + else # Use NSPR base USE_NSPR_BASE = 1 + +ifeq ($(MOZ_WIDGET_TOOLKIT),gtk) +USE_GTK_WIDGETS = 1 +endif + endif ifdef USE_GTK_WIDGETS diff --git a/mozilla/extensions/xmlterm/jar.mn b/mozilla/extensions/xmlterm/jar.mn index 9493ab1e6af..ede29fcb14c 100644 --- a/mozilla/extensions/xmlterm/jar.mn +++ b/mozilla/extensions/xmlterm/jar.mn @@ -11,6 +11,6 @@ xmlterm.jar: locale/en-US/xmlterm/contents.rdf (ui/locale/en-US/contents.rdf) locale/en-US/xmlterm/xmltermOverlay.dtd (ui/locale/en-US/xmltermOverlay.dtd) skin/modern/xmlterm/contents.rdf (ui/skin/contents.rdf) - content/xmlterm/xmlterm.css (ui/skin/xmlterm.css) - content/xmlterm/xmltpage.css (ui/skin/xmltpage.css) - content/xmlterm/wheel.gif (ui/skin/wheel.gif) + skin/modern/xmlterm/xmlterm.css (ui/skin/xmlterm.css) + skin/modern/xmlterm/xmltpage.css (ui/skin/xmltpage.css) + skin/modern/xmlterm/wheel.gif (ui/skin/wheel.gif) diff --git a/mozilla/extensions/xmlterm/lineterm/ltermEscape.c b/mozilla/extensions/xmlterm/lineterm/ltermEscape.c index a1c6a41537a..2eca9b1544c 100644 --- a/mozilla/extensions/xmlterm/lineterm/ltermEscape.c +++ b/mozilla/extensions/xmlterm/lineterm/ltermEscape.c @@ -1143,18 +1143,49 @@ static int ltermProcessXMLTermSequence(struct lterms *lts, const UNICHAR *buf, param3 = (paramCount > 2) ? paramValues[2] : 0; switch (termChar) { - int streamOpcodes; + int streamOpcodes, nRows, nCols, sprint_len; + char sprint_buf[81]; case U_A_CHAR: /* Send XMLterm device attributes */ + case U_B_CHAR: /* Send XMLterm device attributes (Bourne shell format) */ + case U_C_CHAR: /* Send XMLterm device attributes (C shell format) */ LTERM_LOG(ltermProcessXMLTermSequence,52,("Sending device attributes\n")); - if (ltermSendChar(lts, "\033{?", 3) != 0) - return -1; + + + nRows = lts->nRows; + nCols = lts->nCols; + + if ((nRows >= 0) && (nRows < 10000) && (nCols >= 0) && (nCols < 10000)) { + + if (termChar == U_C_CHAR) { + /* C shell format */ + + sprint_len = sprintf(sprint_buf, "setenv LINES %d;setenv COLUMNS %d;setenv LTERM_COOKIE ", nRows, nCols); + + } else { + + sprint_len = sprintf(sprint_buf, "LINES=%d;COLUMNS=%d;LTERM_COOKIE=", nRows, nCols); + } + + if (sprint_len > 80) { + LTERM_ERROR("ltermProcessXMLTermSequence: Error - sprintf buffer overflow\n"); + } + + if (ltermSendChar(lts, sprint_buf, strlen(sprint_buf)) != 0) + return -1; + } if (strlen(lts->cookie) > 0) { if (ltermSendChar(lts, lts->cookie, strlen(lts->cookie)) != 0) return -1; } + if (termChar == U_B_CHAR) { + const char exportStr[] = ";export LINES COLUMNS LTERM_COOKIE"; + if (ltermSendChar(lts, exportStr, strlen(exportStr)) != 0) + return -1; + } + if (ltermSendChar(lts, "\n", 1) != 0) return -1; return 0; diff --git a/mozilla/extensions/xmlterm/lineterm/tracelog.c b/mozilla/extensions/xmlterm/lineterm/tracelog.c index 404086b0031..a9e28109c0f 100644 --- a/mozilla/extensions/xmlterm/lineterm/tracelog.c +++ b/mozilla/extensions/xmlterm/lineterm/tracelog.c @@ -49,6 +49,8 @@ /* TRACELOG global variable structure */ TlogGlobal tlogGlobal; +static int initGlobal = 0; + /** Initializes all TRACELOG operations and sets filestream for trace/log * output. Setting filestream to NULL suppresses all output. * (documented in tracelog.h) @@ -61,6 +63,12 @@ void tlog_init(FILE* fileStream) fprintf(stderr, "tlog_init:\n"); #endif + /* Do not re-initialize */ + if (initGlobal) + return; + + initGlobal = 1; + /* Error output stream */ tlogGlobal.errorStream = fileStream; @@ -71,6 +79,8 @@ void tlog_init(FILE* fileStream) tlogGlobal.messageLevel[imodule] = 0; tlogGlobal.functionList[imodule] = NULL; } + + return; } @@ -92,11 +102,6 @@ int tlog_set_level(int imodule, int messageLevel, const char *functionList) /* Message level */ tlogGlobal.messageLevel[imodule] = messageLevel; - if (messageLevel > 0) { - tlog_warning("tlog_set_level: module %d, messageLevel=%d\n", - imodule, messageLevel); - } - /* Free function list string */ free(tlogGlobal.functionList[imodule]); @@ -135,6 +140,11 @@ int tlog_set_level(int imodule, int messageLevel, const char *functionList) } } + if (messageLevel > 0) { + tlog_warning("tlog_set_level: module %d, messageLevel=%d\n", + imodule, messageLevel); + } + return 0; } @@ -151,11 +161,10 @@ int tlog_test(int imodule, char *procstr, int level) if ((imodule < 0) || (imodule >= TLOG_MAXMODULES)) return 0; - if ( (level%10 <= tlogGlobal.messageLevel[imodule]%10) && - ( (level <= tlogGlobal.messageLevel[imodule]) || + if ( (level <= tlogGlobal.messageLevel[imodule]) || ((tlogGlobal.functionList[imodule] != NULL) && ( (strstr(tlogGlobal.functionList[imodule],procstr) != NULL) || - (strstr(procstr,tlogGlobal.functionList[imodule]) != NULL)) ) )) { + (strstr(procstr,tlogGlobal.functionList[imodule]) != NULL)) ) ) { /* Display message */ #if defined(USE_NSPR_BASE) && !defined(DEBUG_LTERM) PR_LogPrint("%s%2d: ", procstr, level); diff --git a/mozilla/extensions/xmlterm/linetest/Makefile.in b/mozilla/extensions/xmlterm/linetest/Makefile.in index 6bca9a7acff..b5daf9d2286 100644 --- a/mozilla/extensions/xmlterm/linetest/Makefile.in +++ b/mozilla/extensions/xmlterm/linetest/Makefile.in @@ -55,6 +55,10 @@ SIMPLE_PROGRAMS = lterm ptytest unitest utf8conv # Defines DEFINES = +LOCAL_INCLUDES = \ + -I$(srcdir)/../lineterm \ + $(NULL) + # Libraries to be linked ifeq ($(OS_ARCH),FreeBSD) PTHREADLIBOPT = -pthread diff --git a/mozilla/extensions/xmlterm/scripts/Makefile.in b/mozilla/extensions/xmlterm/scripts/Makefile.in index 5778b496dcc..da5bd2a1cb0 100644 --- a/mozilla/extensions/xmlterm/scripts/Makefile.in +++ b/mozilla/extensions/xmlterm/scripts/Makefile.in @@ -80,6 +80,7 @@ XMLTERM_SCRIPTS = \ $(srcdir)/xmlterm \ $(srcdir)/xls \ $(srcdir)/xcat \ + $(srcdir)/xenv \ $(NULL) libs:: @@ -89,7 +90,8 @@ xpi:: zip $(DIST)/bin/$(XPIFILE) install.js cd $(DIST); zip -g bin/$(XPIFILE) \ bin/xcat \ - bin/xls + bin/xls \ + bin/xenv cd $(DIST)/bin; zip -g $(XPIFILE) \ components/libxmlterm.so \ components/xmlterm.xpt \ diff --git a/mozilla/extensions/xmlterm/scripts/xcat b/mozilla/extensions/xmlterm/scripts/xcat index 74e41191b63..57384ad0295 100755 --- a/mozilla/extensions/xmlterm/scripts/xcat +++ b/mozilla/extensions/xmlterm/scripts/xcat @@ -19,6 +19,11 @@ $height = $opt_height if $opt_height; my $cookie = $ENV{LTERM_COOKIE}; # XMLTerm cookie +if (!$cookie) { + print 'Please use the "eval `xenv`" command to set-up the remote XMLterm environment'."\n"; + exit; +} + my $dir = cwd(); foreach my $url (@ARGV) { # for each argument @@ -114,7 +119,7 @@ foreach my $url (@ARGV) { # for each argument (?::(\d+))? # port )? (/|/[^/\s]\S*?)? # pathname - (?=>|\"|\'|\s|[.,!](?:\s|\Z)|\Z) # URL terminator (look ahead) + (?=>|\)|\"|\'|\s|[.,!](?:\s|\Z)|\Z) # URL terminator (look ahead) %x ) { $urlvals[$nurl] = $&; s%$&%%; @@ -132,9 +137,9 @@ foreach my $url (@ARGV) { # for each argument print "\e{S$cookie\n"; # HTML stream escape sequence if ($nurl >= 2) { - print "
"; + print "
"; } - print ""; + print "$urldesc"; print "\000"; # Terminate HTML stream } @@ -172,8 +177,8 @@ foreach my $url (@ARGV) { # for each argument (?::(\d+))? # port )? (/|/[^/\s]\S*?)? # pathname - (?=>|\"|\'|\s|[.,!](?:\s|\Z)|\Z) # URL terminator (look ahead) - %$&%xg; + (?=>|\)|\"|\'|\s|[.,!](?:\s|\Z)|\Z) # URL terminator (look ahead) + %$&%xg; s/">"/>/g; # Replace ">" with > in the end diff --git a/mozilla/extensions/xmlterm/scripts/xenv b/mozilla/extensions/xmlterm/scripts/xenv new file mode 100755 index 00000000000..e37b8012afc --- /dev/null +++ b/mozilla/extensions/xmlterm/scripts/xenv @@ -0,0 +1,83 @@ +#!/usr/bin/perl +# xenv: defines XMLterm environment variables +# Usage: xenv [-s|--shell] + +use Getopt::Long; + +Getopt::Long::config('bundling'); + +&GetOptions("shell|s=s", "help|h"); + +if ($opt_help) { + print "Usage: xenv [-s ]\n"; + exit; +} + +my $shell = $ENV{SHELL}; +$shell = $opt_shell if $opt_shell; + +my $cshell = 0; + +$cshell = 1 if ($shell =~ /csh$/); + +$| = 1; # Flush output + +cbreak(); # Raw (noecho) mode + +print STDERR "\033{A\n"; # Send escape sequence on STDERR + +my $key = ''; +my $param_str = ""; + +my $bytes = sysread(STDIN, $key, 1); +while ($bytes && ($key ne "\n")) { + $param_str .= $key; + $bytes = sysread(STDIN, $key, 1); +} + +cooked(); # Cooked mode + +my @params = split /;/, $param_str; + +foreach my $param (@params) { + if ( $param =~ /^(\w+)=(.*)$/ ) { + my ($name, $value) = ($1, $2); + + if ($cshell) { + print "setenv $name $value;\n"; + } else { + print "$name=$value; export $name;\n"; + } + } +} + +exit; + +BEGIN { + use POSIX qw(:termios_h); + + my ($term, $oterm, $echo, $noecho, $fd_stdin); + + $fd_stdin = fileno(STDIN); + + $term = POSIX::Termios->new(); + $term->getattr($fd_stdin); + $oterm = $term->getlflag(); + + $echo = ECHO | ECHOK | ICANON; + $noecho = $oterm & ~$echo; + + sub cbreak { + $term->setlflag($noecho); + $term->setcc(VTIME, 1); + $term->setattr($fd_stdin, TCSANOW); + } + + sub cooked { + $term->setlflag($oterm); + $term->setcc(VTIME, 0); + $term->setattr($fd_stdin, TCSANOW); + } +} + +END { cooked() } diff --git a/mozilla/extensions/xmlterm/scripts/xls b/mozilla/extensions/xmlterm/scripts/xls index 84b05fb7f65..85a0d34b65d 100755 --- a/mozilla/extensions/xmlterm/scripts/xls +++ b/mozilla/extensions/xmlterm/scripts/xls @@ -14,6 +14,10 @@ if ($opt_help) { exit; } +my $char_cols = $ENV{COLUMNS}; + +$char_cols = 80 unless $char_cols; + # Icon details #my $imgdir="chrome://xmlterm/skin/default/images" my $imgdir = "file:///usr/share/pixmaps/mc"; @@ -22,9 +26,6 @@ my %img; ($img{'directory'}, $img{'executable'}, $img{'plainfile'}, $img{'urlfile'}) = ('i-directory.png', 'i-executable.png', 'i-regular.png', 'i-regular.png'); -my $ncols = 5; -$ncols = $opt_cols if ($opt_cols); - my $dir = cwd(); my $rowimg = ""; my $rowtxt = ""; @@ -42,10 +43,26 @@ if (@ARGV) { @filelist = glob("*"); # all files in current directory } +my $file; +my $maxlen = 0; +foreach $file (@filelist) { # for each file in the list + $maxlen = length($file) if length($file) > $maxlen; +} + +my $table_cols = $char_cols/($maxlen+1); + +$table_cols = $opt_cols if ($opt_cols); + my $cookie = $ENV{LTERM_COOKIE}; # XMLTerm cookie + +if (!$cookie) { + print 'Please use the "eval `xenv`" command to set-up the remote XMLterm environment'."\n"; + exit; +} + print "\e{S$cookie\012"; # HTML stream escape sequence print ""; -print ""; +print ""; foreach $file (@filelist) { # for each file in the list $file =~ m%\A(.*?) (\.[^/.]*)?\Z%x # Deconstruct file name @@ -147,7 +164,7 @@ foreach $file (@filelist) { # for each file in the list $rowtxt .= "$tail"; $nfile++; - if (($nfile % $ncols) == 0) { # print complete table row + if (($nfile % $table_cols) == 0) { # print complete table row print "$rowimg" unless $opt_text; print "$rowtxt"; $rowimg = ""; diff --git a/mozilla/extensions/xmlterm/ui/content/XMLTermChrome.js b/mozilla/extensions/xmlterm/ui/content/XMLTermChrome.js index 4010a7c82dd..03e623cc0d2 100644 --- a/mozilla/extensions/xmlterm/ui/content/XMLTermChrome.js +++ b/mozilla/extensions/xmlterm/ui/content/XMLTermChrome.js @@ -43,5 +43,5 @@ function StartupXMLTerm() { window.title = "xmlterm: "+window.arguments; // Initialize XMLTerm shell in content window with argvals - window.xmlterm.Init(xmltwin, "", window.arguments); + window.xmlterm.init(xmltwin, "", window.arguments); } diff --git a/mozilla/extensions/xmlterm/ui/content/XMLTermCommands.js b/mozilla/extensions/xmlterm/ui/content/XMLTermCommands.js index 0d85fdb2736..07c77b36f92 100644 --- a/mozilla/extensions/xmlterm/ui/content/XMLTermCommands.js +++ b/mozilla/extensions/xmlterm/ui/content/XMLTermCommands.js @@ -7,9 +7,25 @@ // letter. // Global variables -var AltWin; // Alternate (browser) window +///var gStyleRuleNames; -var gStyleRuleNames; +WRITE_LOG = function (str) {}; +DEBUG_LOG = function (str) {}; + +if (navigator) { + var userAgent = navigator.userAgent; + + if (userAgent && (userAgent.search(/Mozilla\/4\./i) == -1)) { + + if (dump) { + WRITE_LOG = dump; + } + } +} else { + if (dump) { + WRITE_LOG = dump; + } +} var Tips = new Array(); // Usage tip strings var TipNames = new Array(); // Usage tip names @@ -95,7 +111,7 @@ function NewTip() { SelectedTip = Math.floor(ranval * TipCount); if (SelectedTip >= TipCount) SelectedTip = 0; - //dump("xmlterm: NewTip "+SelectedTip+","+ranval+"\n"); + DEBUG_LOG("xmlterm: NewTip "+SelectedTip+","+ranval+"\n"); var tipdata = document.getElementById('tipdata'); tipdata.firstChild.data = Tips[SelectedTip]; @@ -107,7 +123,7 @@ function NewTip() { // Explain tip function ExplainTip(tipName) { - //dump("xmlterm: ExplainTip("+tipName+")\n"); + DEBUG_LOG("xmlterm: ExplainTip("+tipName+")\n"); if (tipName) { var tipdata = document.getElementById('tipdata'); @@ -148,7 +164,7 @@ function F9Key(isShift, isControl) { // Scroll Home key function ScrollHomeKey(isShift, isControl) { - //dump("ScrollHomeKey("+isShift+","+isControl+")\n"); + DEBUG_LOG("ScrollHomeKey("+isShift+","+isControl+")\n"); if (isControl) { return F1Key(isShift, 0); @@ -160,7 +176,7 @@ function ScrollHomeKey(isShift, isControl) { // Scroll End key function ScrollEndKey(isShift, isControl) { - //dump("ScrollEndKey("+isShift+","+isControl+")\n"); + DEBUG_LOG("ScrollEndKey("+isShift+","+isControl+")\n"); if (isControl) { return F2Key(isShift, 0); @@ -172,7 +188,7 @@ function ScrollEndKey(isShift, isControl) { // Scroll PageUp key function ScrollPageUpKey(isShift, isControl) { - //dump("ScrollPageUpKey("+isShift+","+isControl+")\n"); + DEBUG_LOG("ScrollPageUpKey("+isShift+","+isControl+")\n"); ScrollWin(isShift,isControl).scrollBy(0,-120); return false; @@ -180,7 +196,7 @@ function ScrollPageUpKey(isShift, isControl) { // Scroll PageDown key function ScrollPageDownKey(isShift, isControl) { - //dump("ScrollPageDownKey("+isShift+","+isControl+")\n"); + DEBUG_LOG("ScrollPageDownKey("+isShift+","+isControl+")\n"); ScrollWin(isShift,isControl).scrollBy(0,120); return false; @@ -197,16 +213,16 @@ function ScrollWin(isShift, isControl) { // Set history buffer size function SetHistory(value) { - //dump("SetHistory("+value+")\n"); - window.xmlterm.SetHistory(value, document.cookie); - return (false); + DEBUG_LOG("SetHistory("+value+")\n"); + window.xmlterm.setHistory(value, document.cookie); + return false; } // Set prompt function SetPrompt(value) { - //dump("SetPrompt("+value+")\n"); - window.xmlterm.SetPrompt(value, document.cookie); - return (false); + DEBUG_LOG("SetPrompt("+value+")\n"); + window.xmlterm.setPrompt(value, document.cookie); + return false; } // Create new XMLTerm window @@ -214,40 +230,40 @@ function NewXMLTerm(firstcommand) { newwin = window.openDialog( "chrome://xmlterm/content/xmlterm.xul", "xmlterm", "chrome,dialog=no,resizable", firstcommand); - dump("NewXMLTerm: "+newwin+"\n") - return (false); + WRITE_LOG("NewXMLTerm: "+newwin+"\n") + return false; } // Handle resize events function Resize(event) { - //dump("Resize()\n"); - window.xmlterm.Resize(); - return (false); + DEBUG_LOG("Resize()\n"); + window.xmlterm.resize(); + return false; } // Form Focus (workaround for form input being transmitted to xmlterm) function FormFocus() { - //dump("FormFocus()\n"); - window.xmlterm.IgnoreKeyPress(true, document.cookie); + DEBUG_LOG("FormFocus()\n"); + window.xmlterm.ignoreKeyPress(true, document.cookie); return false; } // Form Blur (workaround for form input being transmitted to xmlterm) function FormBlur() { - //dump("FormBlur()\n"); - window.xmlterm.IgnoreKeyPress(false, document.cookie); + DEBUG_LOG("FormBlur()\n"); + window.xmlterm.ignoreKeyPress(false, document.cookie); return false; } // Set user level, icons mode etc. function UpdateSettings(selectName) { - //dump("UpdateSettings: "+selectName+"\n"); + DEBUG_LOG("UpdateSettings: "+selectName+"\n"); var selectedIndex = document.xmltform1[selectName].selectedIndex; var selectedOption = document.xmltform1[selectName].options[selectedIndex].value; - //dump("UpdateSettings: selectedOption=="+selectedOption+"\n"); + DEBUG_LOG("UpdateSettings: selectedOption=="+selectedOption+"\n"); switch(selectName) { case "userLevel": @@ -288,37 +304,40 @@ function UpdateSettings(selectName) { break; default: - //dump("UpdateSettings: Unknown selectName "+selectName+"\n"); + DEBUG_LOG("UpdateSettings: Unknown selectName "+selectName+"\n"); break; } window.xmltform1Index[selectName] = selectedIndex; window.xmltform1Option[selectName] = selectedOption; + Webcast(); + return false; } // Alter style in stylesheet of specified document doc, or current document // if doc is omitted. -// ****CSS DOM IS BROKEN****; selectorText seems to be null for all rules function AlterStyle(ruleName, propertyName, propertyValue, doc) { - //dump("AlterStyle("+ruleName+"{"+propertyName+":"+propertyValue+"})\n"); + DEBUG_LOG("AlterStyle("+ruleName+"{"+propertyName+":"+propertyValue+"})\n"); if (!doc) doc = window.document; var sheet = doc.styleSheets[0]; var r; for (r = 0; r < sheet.cssRules.length; r++) { - //dump("selectorText["+r+"]="+sheet.cssRules[r].selectorText+"\n"); + DEBUG_LOG("selectorText["+r+"]="+sheet.cssRules[r].selectorText+"\n"); + + if (sheet.cssRules[r].selectorText.toLowerCase() == ruleName.toLowerCase()) { - //if (sheet.cssRules[r].selectorText == ruleName) { // Ugly workaround for accessing rules until bug 53448 is fixed - if (gStyleRuleNames[r] == ruleName) { + // (****CSS DOM IS BROKEN****; selectorText seems to be null for all rules) + ///if (gStyleRuleNames[r] == ruleName) { - //dump("cssText["+r+"]="+sheet.cssRules[r].cssText+"\n"); + DEBUG_LOG("cssText["+r+"]="+sheet.cssRules[r].cssText+"\n"); var style = sheet.cssRules[r].style; - //dump("style="+style.getPropertyValue(propertyName)+"\n"); + DEBUG_LOG("style="+style.getPropertyValue(propertyName)+"\n"); style.setProperty(propertyName,propertyValue,""); } @@ -333,22 +352,10 @@ function MetaDefault(arg1) { // Load URL in XMLTermBrowser window function Load(url) { - var succeeded = false; - if (window.xmltbrowser) { - //dump("Load:xmltbrowser.location.href="+window.xmltbrowser.location.href+"\n"); - if (window.xmltbrowser.location.href.length) { - window.xmltbrowser.location = url; - succeeded = true; - } - } - if (!succeeded) { - window.xmltbrowser = window.open(url, "xmltbrowser"); - } + DEBUG_LOG("Load:url="+url+"\n"); + window.open(url); - // Save browser window object in global variable - AltWin = window.xmltbrowser; - - return (false); + return false; } // Control display of all output elements @@ -356,14 +363,24 @@ function DisplayAllOutput(flag) { var outputElements = document.getElementsByName("output"); for (i=0; i= 0) && (window.xmlterm.currentEntryNumber != entryNumber)) { - //dump("NOT CURRENT COMMAND\n"); - return (false); + DEBUG_LOG("NOT CURRENT COMMAND\n"); + return false; } var action, sendStr; @@ -537,21 +565,23 @@ function HandleEvent(eventObj, eventType, targetType, entryNumber, // Primitive actions if (action === "send") { - //dump("send = "+sendStr+"\n"); - window.xmlterm.SendText(sendStr, document.cookie); + DEBUG_LOG("send = "+sendStr+"\n"); + window.xmlterm.sendText(sendStr, document.cookie); } else if (action === "sendln") { - //dump("sendln = "+sendStr+"\n\n"); - window.xmlterm.SendText("\025"+sendStr+"\n", document.cookie); + DEBUG_LOG("sendln = "+sendStr+"\n\n"); + window.xmlterm.sendText("\025"+sendStr+"\n", document.cookie); } else if (action === "createln") { - //dump("createln = "+sendStr+"\n\n"); + DEBUG_LOG("createln = "+sendStr+"\n\n"); newwin = NewXMLTerm(sendStr+"\n"); } } } - return (false); + Webcast(); + + return false; } // Set history buffer count using form entry @@ -566,6 +596,54 @@ function SetPromptValue() { return SetPrompt(field.value); } +function Webcast() { + if (!window.webcastIntervalId) + return; + + DEBUG_LOG("XMLTermCommands.js: Webcast: "+window.webcastFile+"\n"); + + var style = ""; + + if (window.xmltform1Option.showIcons == "on") { + style += "SPAN.noicons {display: none}\n"; + style += "SPAN.icons {display: inline}\n"; + style += "IMG.icons {display: inline}\n"; + style += "TR.icons {display: table-row}\n"; + } + + var exported = window.xmlterm.exportHTML(window.webcastFile, 0644, style, + 0, false, document.cookie); + DEBUG_LOG("XMLTermCommands.js: exported="+exported+"\n"); +} + +function InitiateWebcast() { + var field = document.getElementById('inputvalue'); + + window.webcastFile = field.value ? field.value : ""; + window.webcastFile = "/var/www/html/users/xmlt.html"; + + WRITE_LOG("XMLTermCommands.js: InitiateWebcast: "+window.webcastFile+"\n"); + + Webcast(); + window.webcastIntervalId = window.setInterval(Webcast, 2000); +} + +function TerminateWebcast() { + window.webcastFile = null; + + if (window.webcastIntervalId) { + window.clearInterval(window.webcastIntervalId); + window.webcastIntervalId = null; + } +} + +function ToggleWebcast() { + if (window.webcastIntervalId) + TerminateWebcast(); + else + InitiateWebcast(); +} + // Insert help element displaying URL in an IFRAME before output element // of entryNumber, or before the SESSION element if entryNumber is zero. // Height is the height of the IFRAME in pixels. @@ -575,7 +653,7 @@ function ShowHelp(url, entryNumber, height) { if (!height) height = 120; - //dump("xmlterm: ShowHelp("+url+","+entryNumber+","+height+")\n"); + DEBUG_LOG("xmlterm: ShowHelp("+url+","+entryNumber+","+height+")\n"); if (entryNumber) { beforeID = "output"+entryNumber; @@ -588,7 +666,7 @@ function ShowHelp(url, entryNumber, height) { var beforeElement = document.getElementById(beforeID); if (!beforeElement) { - //dump("InsertIFrame: beforeElement ID="+beforeID+"not found\n"); + DEBUG_LOG("InsertIFrame: beforeElement ID="+beforeID+"not found\n"); return false; } @@ -611,7 +689,7 @@ function ShowHelp(url, entryNumber, height) { var closeElement = document.createElement("span"); closeElement.setAttribute('class', 'helplink'); closeElement.appendChild(document.createTextNode("Close help frame")); - //closeElement.appendChild(document.createElement("p")); + closeElement.appendChild(document.createElement("p")); var iframe = document.createElement("iframe"); iframe.setAttribute('id', helpID+'frame'); @@ -624,7 +702,7 @@ function ShowHelp(url, entryNumber, height) { helpElement.appendChild(iframe); helpElement.appendChild(closeElement); - //dump(helpElement); + DEBUG_LOG(helpElement); // Insert help element parentNode.insertBefore(helpElement, beforeElement); @@ -639,7 +717,7 @@ function ShowHelp(url, entryNumber, height) { // About XMLTerm function AboutXMLTerm() { - //dump("xmlterm: AboutXMLTerm\n"); + DEBUG_LOG("xmlterm: AboutXMLTerm\n"); var tipdata = document.getElementById('tipdata'); tipdata.firstChild.data = ""; @@ -649,19 +727,39 @@ function AboutXMLTerm() { return false; } +function Redirect() { + window.location = window.redirectURL; +} + + +function GetQueryParam(paramName) { + var url = document.location.href; + + var paramExp = new RegExp("[?&]"+paramName+"=([^&]*)"); + + var matches = url.match(paramExp); + + var paramVal = ""; + if (matches && (matches.length > 1)) { + paramVal = matches[1]; + } + + return paramVal; +} + // onLoad event handler function LoadHandler() { - //dump("xmlterm: LoadHandler ... "+window.xmlterm+"\n"); + WRITE_LOG("xmlterm: LoadHandler ... "+window.xmlterm+"\n"); // Ugly workaround for accessing rules in stylesheet until bug 53448 is fixed - var sheet = document.styleSheets[0]; - //dump("sheet.cssRules.length="+sheet.cssRules.length+"\n"); + ///var sheet = document.styleSheets[0]; + //WRITE_LOG("sheet.cssRules.length="+sheet.cssRules.length+"\n"); - var styleElement = (document.getElementsByTagName("style"))[0]; - var styleText = styleElement.firstChild.data; + ///var styleElement = (document.getElementsByTagName("style"))[0]; + ///var styleText = styleElement.firstChild.data; - gStyleRuleNames = styleText.match(/\b[\w-.]+(?=\s*\{)/g); - //dump("gStyleRuleNames.length="+gStyleRuleNames.length+"\n"); + ///gStyleRuleNames = styleText.match(/\b[\w-.]+(?=\s*\{)/g); + //WRITE_LOG("gStyleRuleNames.length="+gStyleRuleNames.length+"\n"); //NewTip(); @@ -669,8 +767,8 @@ function LoadHandler() { window.xmltform1Index = new Object(); window.xmltform1Option = new Object(); - window.xmltform1Index.userLevel = 1; - window.xmltform1Option.userLevel = "intermediate"; + window.xmltform1Index.userLevel = 2; + window.xmltform1Option.userLevel = "advanced"; window.xmltform1Index.showIcons = 0; window.xmltform1Option.showIcons = "off"; @@ -678,6 +776,44 @@ function LoadHandler() { window.xmltform1Index.windowsMode = 0; window.xmltform1Option.windowsMode = "off"; + if (!window.xmlterm && exportCount) { + var redirectURL = document.location.href; + var urlLen = redirectURL.indexOf("?"); + + if (urlLen > 0) redirectURL = redirectURL.substr(0,urlLen); + + DEBUG_LOG("exportCount="+exportCount+"\n"); + + var minrefresh = GetQueryParam("minrefresh"); + var maxrefresh = GetQueryParam("maxrefresh"); + var refresh = GetQueryParam("refresh"); + var id = GetQueryParam("id"); + + if (minrefresh) { + if (!maxrefresh) maxrefresh = 10*minrefresh; + if (!refresh) refresh = minrefresh; + if (!id) id = 0; + + if (exportCount > id*1) + refresh = minrefresh; + else + refresh = 2*refresh; + + if (refresh > maxrefresh) refresh=maxrefresh; + + var refreshTime = refresh*1000; + + redirectURL += "?minrefresh="+minrefresh + "&maxrefresh="+maxrefresh +"&refresh="+refresh + "&id="+exportCount; + + DEBUG_LOG("redirectURL="+redirectURL+"\n"); + + window.redirectURL = redirectURL; + window.timeoutId = window.setTimeout(Redirect, refreshTime); + } + + window.scrollTo(0,4000); // Scroll to bottom of page + } + return false; // The following code fragment is skipped because the chrome takes care of @@ -687,17 +823,17 @@ function LoadHandler() { return false; } - //dump("LoadHandler: WINDOW.ARGUMENTS="+window.arguments+"\n"); + DEBUG_LOG("LoadHandler: WINDOW.ARGUMENTS="+window.arguments+"\n"); - dump("Trying to make an XMLTerm Shell through the component manager...\n"); + WRITE_LOG("Trying to make an XMLTerm Shell through the component manager...\n"); var xmltshell = Components.classes["@mozilla.org/xmlterm/xmltermshell;1"].createInstance(); xmltshell = xmltshell.QueryInterface(Components.interfaces.mozIXMLTermShell); - //dump("Interface xmltshell2 = " + xmltshell + "\n"); + DEBUG_LOG("Interface xmltshell2 = " + xmltshell + "\n"); if (!xmltshell) { - dump("Failed to create XMLTerm shell\n"); + WRITE_LOG("Failed to create XMLTerm shell\n"); window.close(); return; } @@ -709,13 +845,13 @@ function LoadHandler() { var contentWindow = window; // Initialize XMLTerm shell in content window with argvals - window.xmlterm.Init(contentWindow, "", ""); + window.xmlterm.init(contentWindow, "", ""); - //dump("LoadHandler:"+document.cookie+"\n"); + DEBUG_LOG("LoadHandler:"+document.cookie+"\n"); - //dump("contentWindow="+contentWindow+"\n"); - //dump("document="+document+"\n"); - //dump("documentElement="+document.documentElement+"\n"); + DEBUG_LOG("contentWindow="+contentWindow+"\n"); + DEBUG_LOG("document="+document+"\n"); + DEBUG_LOG("documentElement="+document.documentElement+"\n"); // Handle resize events //contentWindow.addEventListener("onresize", Resize); @@ -726,37 +862,37 @@ function LoadHandler() { //contentWindow.xmlterm = xmlterm; - //dump(contentWindow.xmlterm); + DEBUG_LOG(contentWindow.xmlterm); // The following code is for testing IFRAMEs only - //dump("[Main] "+window+"\n"); - //dump(window.screenX+", "+window.screenY+"\n"); - //dump(window.scrollX+", "+window.scrollY+"\n"); - //dump(window.pageXOffset+", "+window.pageYOffset+"\n"); + DEBUG_LOG("[Main] "+window+"\n"); + DEBUG_LOG(window.screenX+", "+window.screenY+"\n"); + DEBUG_LOG(window.scrollX+", "+window.scrollY+"\n"); + DEBUG_LOG(window.pageXOffset+", "+window.pageYOffset+"\n"); - //dump("IFRAME checks\n"); + DEBUG_LOG("IFRAME checks\n"); var iframe = document.getElementById('iframe1'); - //dump("iframe="+iframe+"\n"); + DEBUG_LOG("iframe="+iframe+"\n"); frames=document.frames; - //dump("frames="+frames+"\n"); - //dump("frames.length="+frames.length+"\n"); + DEBUG_LOG("frames="+frames+"\n"); + DEBUG_LOG("frames.length="+frames.length+"\n"); framewin = frames[0]; - //dump("framewin="+framewin+"\n"); - //dump("framewin.document="+framewin.document+"\n"); + DEBUG_LOG("framewin="+framewin+"\n"); + DEBUG_LOG("framewin.document="+framewin.document+"\n"); - //dump(framewin.screenX+", "+framewin.screenY+"\n"); - //dump(framewin.scrollX+", "+framewin.scrollY+"\n"); - //dump(framewin.pageXOffset+", "+framewin.pageYOffset+"\n"); + DEBUG_LOG(framewin.screenX+", "+framewin.screenY+"\n"); + DEBUG_LOG(framewin.scrollX+", "+framewin.scrollY+"\n"); + DEBUG_LOG(framewin.pageXOffset+", "+framewin.pageYOffset+"\n"); var body = framewin.document.getElementsByTagName("BODY")[0]; - //dump("body="+body+"\n"); + DEBUG_LOG("body="+body+"\n"); var height= body.scrollHeight; - //dump("height="+height+"\n"); + DEBUG_LOG("height="+height+"\n"); // iframe.height = 800; // iframe.width = 700; @@ -764,9 +900,9 @@ function LoadHandler() { // framewin.sizeToContent(); framewin.xmltshell = xmltshell; - //dump(framewin.xmltshell+"\n"); + DEBUG_LOG(framewin.xmltshell+"\n"); - //dump("xmlterm: LoadHandler completed\n"); - return (false); + DEBUG_LOG("xmlterm: LoadHandler completed\n"); + return false; } diff --git a/mozilla/extensions/xmlterm/ui/content/xmlterm.html b/mozilla/extensions/xmlterm/ui/content/xmlterm.html index 5a8ed5072a4..ebda8183666 100644 --- a/mozilla/extensions/xmlterm/ui/content/xmlterm.html +++ b/mozilla/extensions/xmlterm/ui/content/xmlterm.html @@ -3,14 +3,11 @@ xmlterm page - + href="chrome://xmlterm/skin/xmltpage.css"> +--> @@ -92,33 +90,40 @@ TR.icons {display: none} +
+ + + +
F1 + F2 + F7 + F8 + F9 +
ctl-Home + ctl-End +
+ + + + +
+
+ -
- -
Keyboard shortcuts
- - - - -
F1 - F2 - F7 - F8 - F9 -
ctl-Home - ctl-End -
- - - - -
-
- - - Value: - - -
+ + +
+ Value: + + + + +
+
+ + +
+ + New Tip: + + + +   + + + + Explain Tip + +
+ - -
- - New Tip: - - - -   - - - - Explain Tip - -
- +
-
- + diff --git a/mozilla/extensions/xmlterm/ui/skin/xmltpage.css b/mozilla/extensions/xmlterm/ui/skin/xmltpage.css index 2fe115e4b96..d1631928029 100644 --- a/mozilla/extensions/xmlterm/ui/skin/xmltpage.css +++ b/mozilla/extensions/xmlterm/ui/skin/xmltpage.css @@ -1,5 +1,14 @@ /* xmltpage.css: default style sheet for xmlterm.html */ +*[xmlt-block-collapsed="true"], +*[xmlt-inline-collapsed="true"] { + display: none; +} + +*[xmlt-underline="true"] { + text-decoration: underline +} + BODY { font-family: monaco, courier, elite, monospace; background-color: #FFFFFF; } @@ -56,7 +65,7 @@ SPAN.helplink { font-family: sans-serif; color: blue; cursor: hand; text-decoration: underline } /* Level style */ -DIV.intermediate {display: block} +DIV.intermediate {display: none} DIV.beginner {display: none} /* Icons style */