🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.indesign.sdk
Article #522

Re: Im- and export of InDesign Snippet (*.inds)

#522
From: Detlef Vorl�nder
Date: Thu, 15 Jan 2009 12:28
149 lines
4790 bytes
I had a look at the sample files - it doesn't look that good...while writing this sample code Adobe should have recognized that there is something missing (getting a UIDList of all imported page items).

So I coded a solution using an IObserver which works fine for me:
---------------------------------------------------------------------
observer.cpp
------------
#include "VCPlugInHeaders.h"
#include "observer.h"

CREATE_PMINTERFACE(IRserverDocObserver, kIRserverDocObserverImpl)

IRserverDocObserver::IRserverDocObserver(IPMUnknown* boss) : CObserver(boss, IID_IIRSERVEROBSERVER)
{
}
IRserverDocObserver::~IRserverDocObserver()	
{
}
void IRserverDocObserver::AutoAttach()
{
}
void IRserverDocObserver::AutoDetach()
{
}
void IRserverDocObserver::Update(const ClassID& theChange, ISubject* theSubject, const PMIID& protocol, void* changedBy)
{
	if (theChange == kAddToHierarchyCmdBoss)
	{
		ICommand* iCommand = (ICommand*)changedBy;
		const UIDList* itemList = iCommand->GetItemList();
		IDataBase* database = ::GetUIDRef(theSubject).GetDataBase();
		for (int i = 0; i < itemList->Length(); i++)
		{
			if (database->GetClass(itemList->At(i)) == kSplineItemBoss)
			{
				if (!this->newPageitemsUIDs.Contains(itemList->At(i)))
				{
					if (this->newPageitemsUIDs.Length() == 0)
					{
						this->newPageitemsUIDs = UIDList(database, itemList->At(i));
					}
					else
					{
						this->newPageitemsUIDs.Append(itemList->At(i));
					}
				}
			}
		}
	}
}
bool IRserverDocObserver::AttachDocument()
{
	bool retval = false;
	this->newPageitemsUIDs.Clear();
	InterfacePtr<IDocument> document(this, UseDefaultIID());
	if (document)
	{
		InterfacePtr<ISubject> docSubject(document, UseDefaultIID());
		if (docSubject && !docSubject->IsAttached(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER))
		{
			docSubject->AttachObserver(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER);
			retval = true;
		}
	}
	return retval;
}
bool IRserverDocObserver::DetachDocument()
{
	bool retval = false;
	InterfacePtr<IDocument> document(this, UseDefaultIID());
	if (document)
	{
		InterfacePtr<ISubject> docSubject(document, UseDefaultIID());
		if (docSubject && docSubject->IsAttached(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER))
		{
			docSubject->DetachObserver(this, IID_IHIERARCHY_DOCUMENT, IID_IIRSERVEROBSERVER);
			retval = true;
		}
	}
	return retval;
}
PMString IRserverDocObserver::GetNewPageitemsUIDs()
{
	PMString UIDs;
	for (int i = 0; i < this->newPageitemsUIDs.Length(); i++)
	{
		if (!UIDs.IsEmpty())
		{
			UIDs.Append(",");
		}
		UIDs.AppendNumber(this->newPageitemsUIDs.At(i).Get());
	}
	return UIDs;
}
---------------------------------------------------------------------
observer.h
----------
#include "IDocument.h"
#include "IHierarchy.h"
#include "ISubject.h"
#include "CObserver.h"
#include "UIDList.h"
#include "SplineID.h"
#include "IRserverID.h"

class IRserverDocObserver : public CObserver
{
public:
	IRserverDocObserver(IPMUnknown* boss);
	virtual ~IRserverDocObserver();

	void AutoAttach();
	void AutoDetach();
	bool AttachDocument();
	bool DetachDocument();
	virtual void Update(const ClassID& theChange, ISubject* theSubject, const PMIID& protocol, void* changedBy);
	PMString GetNewPageitemsUIDs();

protected:
	UIDList newPageitemsUIDs;
};
---------------------------------------------------------------------
* .fr file ---------
AddIn
{
   kDocBoss,
   kInvalidClass,
   {
      IID_IIRSERVEROBSERVER, kIRserverDocObserverImpl
   }
},
---------------------------------------------------------------------

Then I use this code around the import:

InterfacePtr<IRserverDocObserver> docObserver(documentUIDRef, IID_IIRSERVEROBSERVER);
if (!docObserver->AttachDocument())
{
   return;		
}
if (Utils<ISnippetImport>()->ImportFromStream(stream, documentElement, kInvalidClass, kSuppressUI) != kSuccess)
{
   return;
}
PMString importedItems = docObserver->GetNewPageitemsUIDs();
docObserver->DetachDocument();

Maybe this is useful for anyone having the same problem.
Thanks for your help
Detlef
Technical Details
Message-ID: <59b780a3.5@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
References: <59b780a3.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f63e9,d03e0f8dac97cdac
X-Google-Attributes: gidf63e9,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Detlef Vorl�nder" <indesign@interred.de>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.indesign.sdk
Subject: Re: Im- and export of InDesign Snippet (*.inds)
Message-ID: <59b780a3.5@webcrossing.la2eafNXanI>
Date: Thu, 15 Jan 2009 04:28:38 -0800
References: <59b780a3.-1@webcrossing.la2eafNXanI>
Lines: 161
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit