Ejemplo n.º 1
0
/*---------------------------------------------------------------------------

  ~nsDocShellEditorData

----------------------------------------------------------------------------*/
nsDocShellEditorData::~nsDocShellEditorData()
{
  TearDownEditor();
}
Ejemplo n.º 2
0
REEditor*
RESession::GetEditorForResource(
	ResType		inResType,
	ResIDT		inResID,
	Boolean		inCreateIfNeeded,
	Boolean		inSuppressErrors)
{

	// Validate pointers.

	ValidateThis_();
	ValidateObject_(mContainer);
	ValidateObject_(mMap);

	// First find the data model resource.
	
	PDResource* thePDRsrc = mContainer->FindResource(
					RMIdentifier(inResType), RMIdentifier(inResID), false);

	if (thePDRsrc == nil)
		return nil;
	ValidateObject_(thePDRsrc);
	
	// Find the low-level resource.
	
	RMResource* theRMRsrc = mMap->FindResource(
					RMIdentifier(inResType), RMIdentifier(inResID), false);
	if (theRMRsrc == nil)
		return nil;
	ValidateObject_(theRMRsrc);

	// Okay, we have both. Ask the data model if it has an editor already.
	
	REEditor* theEditor = (REEditor*) thePDRsrc->FindUserInterfaceObject('edit');
	if (theEditor != nil) {
		ValidateObject_(theEditor);
		return theEditor;
	}
	
	// No editor exists. See if user wanted us to create one.
	
	if (inCreateIfNeeded) {
	
		ExceptionCode error = 0;
	
		try {
	
			// The document object knows the ResType->editor type mapping.
			// Let it create the editor object.
	
			theEditor = mDocument->CreateEditorForResource(inResType, inResID);
	
			// If an editor was created, configure it for this resource.
	
			if (theEditor != nil) {
				ValidateObject_(theEditor);
				if (thePDRsrc->IsEnabled())
					theEditor->EnableSelf();
				else
					theEditor->DisableSelf();
				theEditor->mSuppressErrors = inSuppressErrors;
				theEditor->FinishCreateSelf();
				theEditor->SetPrimaryResource(theRMRsrc);
				theEditor->ReadResourceData();
				AcquireResourceForEditing(theEditor, inResType, inResID, false);
			}
		}
		catch (const LException& inError) {
			error = inError.GetErrorCode();
		}
		catch(...) {
			error = err_CantOpen;
		}

		if (error != 0) {

			// Show editor failed dialog.
			
			if ((!inSuppressErrors) && (error != err_CantOpenSilent))
				ShowCantOpenDialog();
			
			// Destroy the editor.
			
			if (theEditor != nil) {
				ValidateObject_(theEditor);
				TearDownEditor(theEditor);
			}
			theEditor = nil;
		}
	}
	
	// Return the editor that we created.
	
	return theEditor;
	
}