InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ISnpRunnableContext Class Referenceabstract

#include <ISnpRunnableContext.h>

Inheritance diagram for ISnpRunnableContext:
IPMUnknownCPMUnknown< ISnpRunnableContext >SnpRunnableContextSuiteCSB

Public Types

enum  { kDefaultIID = IID_ISNPRUNNABLECONTEXT }
 

Public Member Functions

virtual IActiveContextGetActiveContext () const =0
 
- Public Member Functions inherited from IPMUnknown
virtual IPMUnknownQueryInterface (PMIID interfaceID) const =0
 
virtual void AddRef () const =0
 
virtual void Release () const =0
 

Detailed Description

From SDK sample; interface that provides a code snippet with the context in which it is to run and can 

used to get the selection target, the active document and other

contextual information. 



Code snippet's SnpRunnable::CanRun and SnpRunnable::Run methods get passed

the ISnpRunnableContext interface in a parameter called runnableContext.

ISnpRunnableContext is aggregated onto each concrete selection boss class

in the application and can be queried for the selection target and for 

suites on a concrete selection.



The code below queries runnableContext for the layout selection target:

<pre>

InterfacePtr<ILayoutTarget> layoutTarget(runnableContext, UseDefaultIID());

if (layoutTarget) {

a layout selection exists, do something. } else { a layout selection is not available, do nothing. } To get the selection target (ILayoutTarget, ITextTarget, ITableTarget, IXMLNodeTarget etc.) query the runnableContext parameter for the target you want to work with. Note that it is recommended that your snippet only targets one selection format.

Note the access to the selection's target lets you prototype code for a custom suite quickly and efficiently using the SnippetRunner framework. Remember though that it is a prototyping tool and you must move your code into a custom suite when it is ready.

The code below shows how to use ISnpRunnableContext to discover the a suite, the active document, workspace, view and more:

How do I get a suite from ISnpRunnableContext?

    InterfacePtr<IFooSuite> fooSuite(runnableContext, UsedefaultIID());

    if (fooSuite) {

you can use the suite.

    }
How do I get the active document from ISnpRunnableContext?

    IDocument* document = runnableContext->GetActiveContext()->GetContextDocument();
How do I get the active workspace from ISnpRunnableContext?

    IWorkspace* workspace = runnableContext->GetActiveContext()->GetContextWorkspace();
How do I get the active view from ISnpRunnableContext

    IControlView* controlView = runnableContext->GetActiveContext()->GetContextView();
How do I get the active layout control data from ISnpRunnableContext?

    InterfacePtr<ILayoutControlData> layoutControlData(runnableContext->GetActiveContext()->GetContextView(), UseDefaultIID());
How do I get the active selection manager from ISnpRunnableContext?

    ISelectionManager* selectionManager = runnableContext->GetActiveContext()->GetContextSelection();
How do I get a suite via the active selection manager from ISnpRunnableContext?

    InterfacePtr<IBarSuite> barSuite(runnableContext->GetActiveContext->GetContextSelection(), UseDefaultIID()); 

Note that this call is different from the IFooSuite code described previously. The call

shown here queries the suite via the active ISelectionManager. 

  

The code below shows how your SnpRunnable::CanRun method can check which product or language feature set your snippet is running under. Normally you won't need to check but if you do:


    #include "FeatureSets.h"

    #include "LocaleSetting.h"
    bool16 isInCopyProductFS = LocaleSetting::GetLocale().IsProductFS(kInCopyProductFS);

    bool16 isInDesignProductFS = LocaleSetting::GetLocale().IsProductFS(kInDesignProductFS);

    bool16 isRomanLanguageFS = LocaleSetting::GetLocale().IsLanguageFS(kRomanLanguageFS);

    bool16 isJapaneseLanguageFS = LocaleSetting::GetLocale().IsLanguageFS(kJapaneseLanguageFS);

    

Member Enumeration Documentation

anonymous enum

kDefaultIID

Member Function Documentation

virtual IActiveContext* ISnpRunnableContext::GetActiveContext () const
pure virtual

Return the active context from which the active document, view, workspace and selection manager can be obtained.

Returns
the active context.

Implemented in SnpRunnableContextSuiteCSB.