OpenASIP  2.0
Public Member Functions | Private Attributes | List of all members
CommandRegistry Class Reference

#include <CommandRegistry.hh>

Collaboration diagram for CommandRegistry:
Collaboration graph

Public Member Functions

 CommandRegistry ()
 
 ~CommandRegistry ()
 
void addCommand (GUICommand *command)
 
GUICommandcreateCommand (const int id)
 
GUICommandcreateCommand (const std::string name)
 
GUICommandfirstCommand ()
 
GUICommandnextCommand ()
 
std::string commandName (int id) const
 
std::string commandShortName (const std::string name) const
 
int commandId (const std::string name) const
 
std::string commandIcon (const std::string name) const
 
bool isEnabled (const std::string command)
 

Private Attributes

std::vector< GUICommand * > commands_
 Commands in the registry. More...
 
std::vector< GUICommand * >::iterator iterator_
 The position of the iteration. Used by the firstCommand() and nextCommand(). More...
 

Detailed Description

List of editor commands which can be added to the toolbar or executed using a keyboard shortcut.

Definition at line 47 of file CommandRegistry.hh.

Constructor & Destructor Documentation

◆ CommandRegistry()

CommandRegistry::CommandRegistry ( )

The Constructor.

Definition at line 44 of file CommandRegistry.cc.

44  {
45 }

◆ ~CommandRegistry()

CommandRegistry::~CommandRegistry ( )

The Destructor.

Definition at line 51 of file CommandRegistry.cc.

51  {
52  // delete commands in registry
53  vector<GUICommand*>::iterator i = commands_.begin();
54  for (; i != commands_.end(); i++) {
55  delete *i;
56  }
57  commands_.clear();
58 }

References commands_.

Member Function Documentation

◆ addCommand()

void CommandRegistry::addCommand ( GUICommand command)

Referenced by EVT_MENU_RANGE().

◆ commandIcon()

std::string CommandRegistry::commandIcon ( const std::string  name) const

Returns icon for the GUICommand.

Parameters
nameName of the GUICommand.
Returns
Icon for the GUICommand.

Definition at line 155 of file CommandRegistry.cc.

155  {
156  vector<GUICommand*>::const_iterator i = commands_.begin();
157  for (; i != commands_.end(); i++) {
158  if ((*i)->name() == name) {
159  return (*i)->icon();
160  }
161  }
162  throw InstanceNotFound(__FILE__, __LINE__, __func__, "");
163  return "";
164 }

References __func__, and commands_.

Referenced by GUIOptions::createToolbar().

◆ commandId()

int CommandRegistry::commandId ( const std::string  name) const

Returns enumerated ID of the command.

Parameters
nameName of the GUICommand.
Returns
Enumerated ID of the GUICommand, or -1 if no command was found.

Definition at line 137 of file CommandRegistry.cc.

137  {
138 
139  vector<GUICommand*>::const_iterator i = commands_.begin();
140  for (; i != commands_.end(); i++) {
141  if ((*i)->name() == name) {
142  return (*i)->id();
143  }
144  }
145  return -1;
146 }

References commands_.

Referenced by GUIOptions::createToolbar(), and MainFrame::updateUI().

◆ commandName()

std::string CommandRegistry::commandName ( int  id) const

Returns name of the GUICommand.

Parameters
idID of the GUICommand.
Returns
Command name.

Definition at line 173 of file CommandRegistry.cc.

173  {
174  vector<GUICommand*>::const_iterator i = commands_.begin();
175  for (; i != commands_.end(); i++) {
176  if ((*i)->id() == id) {
177  return (*i)->name();
178  }
179  }
180  throw InstanceNotFound(__FILE__, __LINE__, __func__, "");
181  return "";
182 }

References __func__, and commands_.

Referenced by MainFrame::menuAccelerator(), and ProximMainFrame::menuAccelerator().

◆ commandShortName()

std::string CommandRegistry::commandShortName ( const std::string  name) const

Returns short name of the GUICommand.

Parameters
nameName of the GUICommand.
Returns
Short version of the command name.

Definition at line 191 of file CommandRegistry.cc.

191  {
192  vector<GUICommand*>::const_iterator i = commands_.begin();
193  for (; i != commands_.end(); i++) {
194  if ((*i)->name() == name) {
195  return (*i)->shortName();
196  }
197  }
198  throw InstanceNotFound(__FILE__, __LINE__, __func__, "");
199  return "";
200 }

References __func__, and commands_.

Referenced by GUIOptions::createToolbar().

◆ createCommand() [1/2]

GUICommand * CommandRegistry::createCommand ( const int  id)

Creates a new command corresponding to the id.

Parameters
idEnumerated ID of the GUICommand.
Returns
Created GUICommand, or NULL, if no GUICommand was found with the ID.

Definition at line 69 of file CommandRegistry.cc.

69  {
70  vector<GUICommand*>::iterator i = commands_.begin();
71  for (; i != commands_.end(); i++) {
72  if ((*i)->id() == id) {
73  return (*i)->create();
74  }
75  }
76  return NULL;
77 }

References commands_.

Referenced by OSEdMainFrame::onCommandEvent(), HDBEditorMainFrame::onCommandEvent(), OSEdTreeView::onItemClicked(), HDBEditorMainFrame::onUpdateUI(), and MainFrame::onUpdateUI().

◆ createCommand() [2/2]

GUICommand * CommandRegistry::createCommand ( const std::string  name)

Creates a new command corresponding to the command name.

Parameters
nameName of the GUICommand.
Returns
Created GUICommand, or NULL, if no GUICommand was found with the name.

Definition at line 87 of file CommandRegistry.cc.

87  {
88  vector<GUICommand*>::iterator i = commands_.begin();
89  for (; i != commands_.end(); i++) {
90  if ((*i)->name() == name) {
91  return (*i)->create();
92  }
93  }
94  return NULL;
95 }

References commands_.

◆ firstCommand()

GUICommand * CommandRegistry::firstCommand ( )

Returns first command in the registry.

Returns
Pointer to the first command in the registry.

Definition at line 104 of file CommandRegistry.cc.

104  {
105  iterator_ = commands_.begin();
106  if (iterator_ == commands_.end()) {
107  return NULL;
108  }
109  return (*iterator_);
110 }

References commands_, and iterator_.

Referenced by OptionsDialog::readCommands(), DropDownMenu::updateMenu(), and OSEdMainFrame::updateMenuBar().

◆ isEnabled()

bool CommandRegistry::isEnabled ( const std::string  command)

Returns true, if command is executable and should be enabled, false if not.

Parameters
commandThe command which is checked for enabled/disabled state.
Returns
true, if the command is executable.

Definition at line 210 of file CommandRegistry.cc.

210  {
211  vector<GUICommand*>::iterator i = commands_.begin();
212  for (; i != commands_.end(); i++) {
213  if ((*i)->name() == command) {
214  return (*i)->isEnabled();
215  }
216  }
217  throw InstanceNotFound(__FILE__, __LINE__, __func__, "");
218  return false;
219 }

References __func__, and commands_.

Referenced by SelectTool::createDefaultMenu(), GUIOptions::createToolbar(), SelectTool::popContextMenu(), ConnectTool::rightClick(), and MainFrame::updateUI().

◆ nextCommand()

GUICommand * CommandRegistry::nextCommand ( )

Returns next command in the registry.

Returns
Pointer to the next command in the registry.

Definition at line 120 of file CommandRegistry.cc.

120  {
121  iterator_++;
122  if (iterator_ == commands_.end()) {
123  return NULL;
124  }
125  return (*iterator_);
126 }

References commands_, and iterator_.

Referenced by OptionsDialog::readCommands(), DropDownMenu::updateMenu(), and OSEdMainFrame::updateMenuBar().

Member Data Documentation

◆ commands_

std::vector<GUICommand*> CommandRegistry::commands_
private

◆ iterator_

std::vector<GUICommand*>::iterator CommandRegistry::iterator_
private

The position of the iteration. Used by the firstCommand() and nextCommand().

Definition at line 68 of file CommandRegistry.hh.

Referenced by firstCommand(), and nextCommand().


The documentation for this class was generated from the following files:
CommandRegistry::commands_
std::vector< GUICommand * > commands_
Commands in the registry.
Definition: CommandRegistry.hh:65
__func__
#define __func__
Definition: Application.hh:67
CommandRegistry::iterator_
std::vector< GUICommand * >::iterator iterator_
The position of the iteration. Used by the firstCommand() and nextCommand().
Definition: CommandRegistry.hh:68
InstanceNotFound
Definition: Exception.hh:304