Hello, I am trying to create a plugin for CS6, and I wanted it to be accessed through a panel, so I created a new project with the panel setting on. I was able to get the button I wanted on there, but I can't seem to get the observer to work. I was able to get CMyProjectBtnObs::Update to run, but not anything in the action component I have been lurking around the forums trying to find what I was doing wrong, and when I added :
InterfacePtr<IPanelControlData> panelControlData(this, UseDefaultIID());
to my auto-attach function, my program was crashing, saying panelControlData is nil. What could cause this to be nil? Is it looking for a member variable in my CMyProjectBtnObs file that I didn't create (There are no member variable in my implementation)? I have been running into a ton of errors with InterfacePtr with many objects not being successfully created, but until now I have always been able to find a way around it by using different functions. Thanks a lot for the help!
--Jacob
this is the full code for my observer function:
#include <CObserver.h>
#include <ISubject.h>
#include <IBooleanControlData.h>
#include <MyProjectID.h>
#include "ISubject.h"
#include <CDialogObserver.h>
#include <fstream>
#include <IControlView.h>
#include <CObserver.h>
#include <IObserver.h>
#include <ITextControlData.h>
#include <IPanelControlData.h>
class CMyProjectBtnObs : public CObserver
{
public:
/** Constructor. @param boss interface ptr from boss object on which this interface is aggregated. */ CMyProjectBtnObs( IPMUnknown* boss ); /** Destructor */ virtual ~CMyProjectBtnObs() ; /** Initialises widgets and attaches widget observers. */ void AutoAttach(); /** Detaches widget observers. */ void AutoDetach(); /** Update is called for all registered observers, and is the method through which changes are broadcast. @param theChange this is specified by the agent of change; it can be the class ID of the agent, or it may be some specialised message ID. @param theSubject this provides a reference to the object which has changed; in this case, the widget boss objects that are being observed. @param protocol the protocol along which the change occurred. @param changedBy this can be used to provide additional information about the change or a reference to the boss object that caused the change. */ void Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy);
private:
/** Attach this observer to the given widget. @param panelControlData refers to the panel that contains the widget @param widgetID gives the subject to be observed @param interfaceID gives the protocol to be observed */ void AttachWidget(const InterfacePtr<IPanelControlData>& panelControlData, const WidgetID& widgetID, const PMIID& interfaceID); /** Attach this observer from the given widget. @param panelControlData refers to the panel that contains the widget @param widgetID gives the subject being observed @param interfaceID gives the protocol being observed */ void DetachWidget(const InterfacePtr<IPanelControlData>& panelControlData, const WidgetID& widgetID, const PMIID& interfaceID); /** Initialise the dropdown that displays the names of code snippets that are registered with the framework and available to be run. @param panelControlData refers to the panel that contains the widget */ void InitialiseSnippetNames(const InterfacePtr<IPanelControlData>& panelControlData); /** Initialise the Trace checkbox. @param panelControlData refers to the panel that contains the widget */ void InitialiseTrace(const InterfacePtr<IPanelControlData>& panelControlData); /** Handle the snippet selected in the dropdown widget being changed. */ void ChangeSnippet(); /** Handle the Trace checkbox widget being checked. */ void TraceOn(); /** Handle the Trace checkbox widget being unchecked. */ void TraceOff(); /** Handle the save log button widget being clicked. */ void SaveLog(); /** Handle the clear log button widget being clicked. */ void ClearLog(); /** Handle the parameter widget update by saving snippet parameters to the snippet parameter dictionary (SnipRunParameterDictionary). */ void SaveParameters(); /** Synchronise the Go button with the name of the snippet to be run. @param snippetName */ void UpdateGoButton(const PMString& snippetName); /** Query the text control data interface of the given widget. @param widgetID gives the which whose text control data is desired @return interface pointer to the widget's text control data. */ InterfacePtr<ITextControlData> QueryTextControlData(const WidgetID& widgetID); // Snippet parameter dictionary helper.
private: /** Dictionary helper class that stores key value pairs where the key is a snippet name and the value is the snippet's parameters. The dictionary is not persistent. */
};
CREATE_PMINTERFACE(CMyProjectBtnObs, kMyProjectBtnObsImpl)
CMyProjectBtnObs::CMyProjectBtnObs(IPMUnknown* boss):CObserver(boss)
{
}
CMyProjectBtnObs::~CMyProjectBtnObs()
{
}
void CMyProjectBtnObs::AttachWidget(const InterfacePtr<IPanelControlData>& panelContgrolData, const WidgetID& widgetID, const PMIID& interfaceID)
{ do { InterfacePtr<IPanelControlData> ay(this,UseDefaultIID()); IControlView* controlView = ay->FindWidget(widgetID); if (controlView == nil) { ASSERT_FAIL("controlView invalid"); break; } InterfacePtr<ISubject> subject(controlView, UseDefaultIID()); if (subject == nil) { ASSERT_FAIL("subject invalid"); break; } subject->AttachObserver(this, interfaceID); } while (false);
}
void CMyProjectBtnObs::AutoAttach()
{ do{ InterfacePtr<IPanelControlData> panelControlData(this, UseDefaultIID()); if (panelControlData == nil) { break; } this->AttachWidget(panelControlData, kMyProjectBtnObsImpl, ITextControlData::kDefaultIID); }while(false);
}
void CMyProjectBtnObs::AutoDetach()
{
CObserver::AutoDetach(); InterfacePtr<ISubject> theSubject(this, UseDefaultIID()); if(theSubject != nil) theSubject->DetachObserver(this, IID_IBOOLEANCONTROLDATA);
}
void CMyProjectBtnObs::Update(const ClassID& theChange, ISubject* theSubject, const PMIID &protocol, void* changedBy)
{ //CObserver::Update(theChange, theSubject, protocol, changedBy); do{ if(theChange != kTrueStateMessage) break; InterfacePtr<IControlView> controlView(theSubject, UseDefaultIID()); WidgetID theSelectedWidget = controlView->GetWidgetID(); printf("\n Update"); } while(kFalse);
}