Gadgets > Creating GUI Applications with Rogue Wave Views Studio > Extending Rogue Wave Views Studio > Extending Rogue Wave Views Studio: An Example > Defining a New Command
 
Defining a New Command
The editor now recognizes what MyManager has generated. But a new buffer instance must be created.
To do so, provide a new command to create an instance of MyBuffer. Make a subclass of IlvStCommand, redefining the virtual member function doIt. The following is an example:
const char* NameNewBuffer = “MyNewBuffer”;
 
class MyNewBuffer: public IlvStCommand {
public:
virtual IlvStError* doIt(IlvStudio*, IlvAny);
};
 
IlvStError*
MyNewBuffer::doIt(IlvStudio* editor, IlvAny arg)
{
if (arg) {
editor->buffers().setCurrent((IlvStBuffer*)arg);
return 0;
}
const char* name = editor->options().getDefaultBufferName();
IlvStBuffer* buffer = new MyGadgetBuffer(editor, name);
if (editor->buffers().get(name))
buffer->newName(name); // uniq name
return editor->execute(IlvNmNewBuffer, 0, 0, buffer);
}
Now the command must be integrated into the editor. To do so:
1. Add the registration of the new command to your initialize function, providing a function to build it.
2. Describe the new command in a new command declaration file named mystudio.cmd. You have to specify this command declaration file in your option file using the commandFile option.
The following is an example of the initialize function:
static IlvStCommand*
MkMyNewBuffer(IlvStudio*)
{
return new MyNewBuffer;
}
 
IlBoolean
MyStudioExtension::initializeCommandDescriptors()
{
IlvStudio* editor = getEditor();
// ...
editor->registerCommand("MyNewBuffer", MkMyNewBuffer);
// ...
return IlTrue;
}
The following is a command declaration example:
command MyNewBuffer {
label "MyBuffer";
prompt "Open my buffer";
category buffer;
}

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.