Gadgets > Creating GUI Applications with Rogue Wave Views Studio > Extending Rogue Wave Views Studio > Extending Rogue Wave Views Studio Components > The Class IlvStExtension
 
The Class IlvStExtension
To initialize a new extension and add it to Rogue Wave® Views Studio, you have to derive a class from IlvStExtension defining a set of methods that will be invoked in a predefined sequence. The constructor of IlvStExtension takes the following two parameters:
*name is the name of the extension.
*editor is the instance of the editor that is being extended.
The constructor of the IlvStExtension class adds the new instance to the extension list of the editor. You must create an instance of your extension before initializing the IlvStudio instance. When the editor is deleted, this instance is also deleted. An extension must not be explicitly deleted.
Here is an example:
#include <ivstudio/studext.h>
 
class MyStudioExtension
: public IlvStExtension {
public:
MyStudioExtension(IlvStudio* editor);
virtual IlBoolean preInitialize();
virtual IlBoolean initializePanels();
virtual IlBoolean initializeCommandDescriptors();
virtual IlBoolean initializeBuffers();
virtual IlBoolean initializeInspectors();
};
 
int
main(int argc, char* argv[])
{
IlvSetLanguage();
// --- Display ---
IlvDisplay* display = new IlvDisplay("ivstudio", "", argc, argv);
if (display->isBad()) {
IlvFatalError("Couldn't open display");
delete display;
return 1;
}
 
// ---- Create and initialize the editor ---
IlvStudio* editor = new IlvStudio(display, argc, argv);
if (editor->isBad()) {
IlvFatalError("Could not initialize the editor");
delete display;
return 2;
}
new MyStudioExtension(editor); // added line
editor->initialize();
editor->parseArguments();
editor->mainLoop();
return 0;
}
First Initialization Step
The preInitialize method is the first one to be invoked when the editor is initialized. At this stage, configuration files have not yet been read.
What you should do in this method:
*Complete the display path so that it contains the directories where your configuration and data files are located.
*Add a configuration file.
*If you define a buffer type and want it to be the default buffer when the editor is initialized, you have to set the default constructor in this method.
For example:
// A buffer constructor.
static IlvStBuffer* ILVCALLBACK
MakeMyBuffer(IlvStudio* editor, const char* name, const char*)
{
return new MyGadgetBuffer(editor, name);
}
 
static const char* UserData = "../data";
 
IlBoolean
MyStudioExtension::preInitialize()
{
IlvStudio* editor = getEditor();
// Add the path.
editor->getDisplay()->prependToPath(UserData);
// Add an option file.
editor->addOptionFile("mystudio.opt");
// Must be done here so
// the first default buffer will be a MyGadgetBuffer.
editor->buffers().setDefaultConstructor(MakeMyBuffer);
return IlTrue;
}
Initializing Buffers
The initializeBuffers method is called after the predefined buffers are initialized. You can complete the buffer initialization and the related initializations in this method.
For example:
IlBoolean
MyStudioExtension::initializeBuffers()
{
IlvStudio* editor = getEditor();
editor->buffers().registerType("MyGadgetManagerOutput", MakeMyBuffer);
return IlTrue;
}
Initializing Command Descriptors
The initializeCommandDescriptors method is called after the command descriptors are read and after the predefined command constructors are registered. You can register your command constructors in this method.
For example:
static IlvStCommand*
MkMyShowPanel(IlvStudio* editor)
{
return new IlvStShowPanel(editor->getPanel("MyPanel"));
}
 
static IlvStCommand*
MkMyAddClass(IlvStudio*)
{
return new MyAddClass;
}
 
static IlvStCommand*
MkMyNewBuffer(IlvStudio*)
{
return new MyNewBuffer;
}
 
IlBoolean
MyStudioExtension::initializeCommandDescriptors()
{
// Register my commands.
IlvStudio* editor = getEditor();
editor->registerCommand("MyShowPanel", MkMyShowPanel);
editor->registerCommand("AddMyClass", MkMyAddClass);
editor->registerCommand("MyNewBuffer", MkMyNewBuffer);
return IlTrue;
}
Initializing Panels
When the initializePanels method is called, the panel properties are loaded and the predefined panels are created, but the panel properties are not yet applied to the panels. Create your own panels in this method as follows:
IlBoolean
MyStudioExtension::initializePanels()
{
IlvStudio* editor = getEditor();
// Create MyGadgetPalette.
MyGadgetPalette* pal = new MyGadgetPalette(editor);
pal->connect();
// Create MyPanel.
MyPanelHandler* pan = new MyPanelHandler(editor, "MyPanel");
pan->connect();
return IlTrue;
}
Registering Inspectors
To register an inspector panel, you have to map an object that is able to create the inspector panel to the class name of the inspected object. The inspector panel builder must derive from the class IlvStInspectorPanelBuilder. To declare an inspector panel builder class, you must use the macro IlvStDefineInspectorPanelBuilder, as follows:
IlvStDefineInspectorPanelBuilder(MyClassInspector,\
MyClassInspectorBuilder)
The mapping used to register an inspector panel is done inside the initializeInspectors method, which is called after the predefined inspectors are initialized.
Here is how you add an inspector panel builder:
IlBoolean
MyStudioExtension::initializeInspectors()
{
IlvStudio* editor = getEditor();
editor->inspector().registerBuilder("MyClass",
new MyClassInspectorBuilder);
return IlTrue;
}
Initializing Editing Modes
The initializeModes method is called after the predefined editing modes are initialized. If you provide an editing mode, you can initialize it here.
Last Initialization Step
The postInitialize method is the last method to be called.

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.