Added support for prefs and string bundles for editor, various bug fixes, preliminary Horizontal Line dialog work

git-svn-id: svn://10.0.0.236/trunk@34343 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cmanske%netscape.com
1999-06-09 01:27:08 +00:00
parent 9ee8cd5583
commit 5cc87fa56e
27 changed files with 500 additions and 222 deletions

View File

@@ -67,8 +67,6 @@ CPPSRCS = \
MODULE = editor
REQUIRES = xpcom raptor dom base netlib
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -102,18 +102,6 @@ CPP_OBJS = \
MODULE=editor
REQUIRES=xpcom raptor dom base netlib pref
LINCS=-I$(PUBLIC)\editor \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\txmgr \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\dom
MAKE_OBJ_TYPE = DLL
DLLNAME = ender
DLL=.\$(OBJDIR)\$(DLLNAME).dll
@@ -129,6 +117,7 @@ LLIBS= \
$(DIST)\lib\plc3.lib \
$(DIST)\lib\raptorhtmlpars.lib \
$(DIST)\lib\raptorwidget_s.lib \
$(DIST)\lib\netlib.lib \
$(LIBNSPR)
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib

View File

@@ -18,6 +18,8 @@
#include "nsIDOMDocument.h"
#include "nsIPref.h"
#include "nsILocale.h"
#include "nsEditor.h"
#include "nsIEditProperty.h" // to be removed XXX
#include "nsIDOMText.h"
@@ -46,7 +48,6 @@
#include "nsISupportsArray.h"
#include "nsICaret.h"
#include "nsIStyleContext.h"
#include "nsIEditActionListener.h"
#include "nsIContent.h"
@@ -111,13 +112,14 @@ static NS_DEFINE_IID(kJoinElementTxnIID, JOIN_ELEMENT_TXN_IID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
// factory classes
static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID);
static NS_DEFINE_IID(kIHTMLEditFactoryIID, NS_IHTMLEDITORFACTORY_IID);
static NS_DEFINE_IID(kITextEditFactoryIID, NS_ITEXTEDITORFACTORY_IID);
#ifdef XP_PC
#define TRANSACTION_MANAGER_DLL "txmgr.dll"
#else
@@ -131,6 +133,8 @@ static NS_DEFINE_IID(kITextEditFactoryIID, NS_ITEXTEDITORFACTORY_IID);
#define NS_ERROR_EDITOR_NO_SELECTION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_EDITOR,1)
#define NS_ERROR_EDITOR_NO_TEXTNODE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_EDITOR,2)
#define EDITOR_BUNDLE_URL "resource:/res/editor.properties"
const char* nsEditor::kMOZEditorBogusNodeAttr="MOZ_EDITOR_BOGUS_NODE";
const char* nsEditor::kMOZEditorBogusNodeValue="TRUE";
@@ -294,7 +298,7 @@ nsEditor::nsEditor()
gInstanceCount++;
mActionListeners = 0;
PR_ExitMonitor(getEditorMonitor());
mPrefs = 0;
}
@@ -315,6 +319,10 @@ nsEditor::~nsEditor()
delete mActionListeners;
mActionListeners = 0;
}
// Release service pointers
if (mPrefs)
nsServiceManager::ReleaseService(kPrefCID, mPrefs);
}
@@ -456,6 +464,51 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell)
caret->SetCaretVisible(PR_TRUE);
caret->SetCaretReadOnly(PR_FALSE);
}
// NOTE: We don't fail if we can't get prefs or string bundles
// since we could still be used as the text edit widget without prefs
// Get the prefs service (Note: can't use nsCOMPtr for service pointers)
nsresult result = nsServiceManager::GetService(kPrefCID,
nsIPref::GetIID(),
(nsISupports**)&mPrefs);
if (NS_FAILED(result) || !mPrefs)
{
printf("ERROR: Failed to get Prefs Service instance.\n");
}
// TODO: Cache basic preferences?
// Register callbacks for preferences that we need to
// respond to while running
nsIStringBundleService* service;
result = nsServiceManager::GetService(kStringBundleServiceCID,
nsIStringBundleService::GetIID(),
(nsISupports**)&service);
if (NS_SUCCEEDED(result) && service)
{
nsCOMPtr<nsIURL> url;
result = NS_NewURL(getter_AddRefs(url), nsString(EDITOR_BUNDLE_URL));
if (NS_SUCCEEDED(result) && url)
{
nsILocale* locale = nsnull;
result = service->CreateBundle(url, locale, getter_AddRefs(mStringBundle));
if (NS_FAILED(result))
printf("ERROR: Failed to get Create StringBundle\n");
} else {
printf("ERROR: Failed to get create URL for StringBundle\n");
}
// We don't need to keep service around once we created the bundle
nsServiceManager::ReleaseService(kStringBundleServiceCID, service);
} else {
printf("ERROR: Failed to get StringBundle Service instance.\n");
}
/*
Example of getting a string:
nsString value;
ret = mStringBundle->GetStringFromName("editor.foo", value);
*/
mPresShell->SetCaretEnabled(PR_TRUE);
@@ -3748,6 +3801,18 @@ nsEditor::JoinNodeDeep(nsIDOMNode *aLeftNode,
return res;
}
// Get a string from the localized string resources
nsresult nsEditor::GetString(const nsString& name, nsString& value)
{
nsresult result = NS_ERROR_NOT_INITIALIZED;
value = "";
if (mStringBundle && (name != ""))
{
result = mStringBundle->GetStringFromName(name, value);
}
return result;
}
/******************************************************************************
* nsAutoSelectionReset
*****************************************************************************/
@@ -3776,6 +3841,3 @@ nsAutoSelectionReset::~nsAutoSelectionReset()
}
}

View File

@@ -27,10 +27,10 @@
#include "nsIDOMEventListener.h"
#include "nsIDOMRange.h"
#include "nsCOMPtr.h"
#include "nsIStringBundle.h"
#include "nsITransactionManager.h"
#include "TransactionFactory.h"
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
class nsIEditActionListener;
class nsIDOMCharacterData;
@@ -48,6 +48,10 @@ class JoinElementTxn;
class EditAggregateTxn;
class nsVoidArray;
class nsISupportsArray;
class nsIPref;
class nsIStringBundleService;
class nsIStringBundle;
class nsILocale;
//This is the monitor for the editor.
PRMonitor *getEditorMonitor();
@@ -72,9 +76,12 @@ private:
static PRInt32 gInstanceCount;
nsVoidArray *mActionListeners;
nsCOMPtr<nsIStringBundle> mStringBundle;
protected:
nsIDOMDocument * mDoc;
// Services are not nsCOMPtr friendly
nsIPref* mPrefs;
public:
@@ -494,7 +501,7 @@ public:
static nsCOMPtr<nsIDOMNode> NextNodeInBlock(nsIDOMNode *aNode, IterDirection aDir);
static nsresult GetStartNodeAndOffset(nsIDOMSelection *aSelection, nsCOMPtr<nsIDOMNode> *outStartNode, PRInt32 *outStartOffset);
static nsresult GetEndNodeAndOffset(nsIDOMSelection *aSelection, nsCOMPtr<nsIDOMNode> *outEndNode, PRInt32 *outEndOffset);
nsresult IsPreformatted(nsIDOMNode *aNode, PRBool *aResult);
nsresult IsNextCharWhitespace(nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool *aResult);
nsresult IsPrevCharWhitespace(nsIDOMNode *aParentNode, PRInt32 aOffset, PRBool *aResult);
@@ -502,6 +509,7 @@ public:
nsresult SplitNodeDeep(nsIDOMNode *aNode, nsIDOMNode *aSplitPointParent, PRInt32 aSplitPointOffset);
nsresult JoinNodeDeep(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMSelection *aSelection);
nsresult GetString(const nsString& name, nsString& value);
};

View File

@@ -1809,13 +1809,13 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
if (aTagName == "" || !aReturn)
return NS_ERROR_NULL_POINTER;
nsAutoString TagName = aTagName;
TagName.ToLowerCase();
nsAutoString realTagName;
PRBool isHREF = (TagName == "href");
PRBool isAnchor = (TagName == "anchor");
PRBool isHREF = (TagName.Equals("href"));
PRBool isAnchor = (TagName.Equals("anchor"));
if (isHREF || isAnchor)
{
realTagName = "a";
@@ -1836,16 +1836,20 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement*
// ATTRIBUTES SAVED IN PREFS?
if (isAnchor)
{
// TODO: Get the text of the selection and build a suggested Name
// Replace spaces with "_"
} else if (TagName.Equals("hr"))
{
}
// ADD OTHER DEFAULT ATTRIBUTES HERE
if (NS_SUCCEEDED(res))
{
*aReturn = newElement;
}
return res;
}
@@ -1876,15 +1880,12 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection, ns
}
}
DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode);
res = DeleteSelectionAndPrepareToCreateNode(parentSelectedNode, offsetOfNewNode);
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(aElement);
res = InsertNode(aElement, parentSelectedNode, offsetOfNewNode);
}
return res;
}
@@ -2164,8 +2165,19 @@ NS_IMETHODIMP nsHTMLEditor::GetLocalFileURL(nsIDOMWindow* aParent, const nsStrin
nsCOMPtr<nsIFileWidget> fileWidget;
// TODO: WHERE TO WE PUT GLOBAL STRINGS TO BE LOCALIZED?
nsString title(htmlFilter ? "Open HTML file" : "Select Image File");
nsAutoString title("");
// Get strings from editor resource bundle
nsString name;
if (htmlFilter)
{
name = "OpenHTMLFile";
} else if (imgFilter)
{
name = "SelectImageFile";
}
GetString(name, title);
nsFileSpec fileSpec;
// TODO: GET THE DEFAULT DIRECTORY FOR DIFFERENT TYPES FROM PREFERENCES
nsFileSpec aDisplayDirectory;