void CommandContributionItem::CreateCommand(const QString &commandId,
    const QHash<QString,Object::Pointer> &parameters)
{
  if (commandId.isEmpty())
  {
//    StatusManager.getManager().handle(StatusUtil.newStatus(IStatus.ERROR,
//                                                           "Unable to create menu item \"" + getId()
//                                                           + "\", no command id", null));
    BERRY_ERROR << "Unable to create menu item \"" << this->GetId().toStdString()
                << "\", no command id";
    return;
  }
  Command::Pointer cmd = commandService->GetCommand(commandId);
  if (!cmd->IsDefined())
  {
//    StatusManager.getManager().handle(StatusUtil.newStatus(
//                                        IStatus.ERROR, "Unable to create menu item \"" + getId()
//                                        + "\", command \"" + commandId + "\" not defined", null));
    BERRY_ERROR << "Unable to create menu item \"" << this->GetId().toStdString()
                << "\", command \"" << commandId.toStdString() << "\" not defined";
    return;
  }

  command = ParameterizedCommand::GenerateCommand(cmd, parameters);
}
Example #2
0
  void CommandManager::CommandListener::CommandChanged(const SmartPointer<const CommandEvent> commandEvent) {
    if (commandEvent->IsDefinedChanged()) {
      const Command::Pointer command(commandEvent->GetCommand());
      const std::string commandId = command->GetId();
      const bool commandIdAdded = command->IsDefined();
      if (commandIdAdded) {
        commandManager->definedHandleObjects.insert(command);
      } else {
        commandManager->definedHandleObjects.erase(command);
      }
      CommandManagerEvent::Pointer event(new CommandManagerEvent(*commandManager,
            commandId, commandIdAdded, true, "", false, false));
        commandManager->FireCommandManagerChanged(event);

    }
  }
Example #3
0
void CommandService::RegisterElement(const SmartPointer<IElementReference>& elementReference)
{
  QList<IElementReference::Pointer>& parameterizedCommands = commandCallbacks[elementReference->GetCommandId()];
  parameterizedCommands.push_back(elementReference);

  // If the active handler wants to update the callback, it can do
  // so now
  Command::Pointer command = GetCommand(elementReference->GetCommandId());
  if (command->IsDefined())
  {
    if (IElementUpdater::Pointer updater = command->GetHandler().Cast<IElementUpdater>())
    {
      updater->UpdateElement(elementReference->GetElement().GetPointer(),
                             elementReference->GetParameters());
    }
  }
}
Example #4
0
void CommandService::RefreshElements(const QString& commandId,
                     const QHash<QString, Object::Pointer>&  filter)
{
  Command::Pointer cmd = GetCommand(commandId);

  if (!cmd->IsDefined() || !(cmd->GetHandler().Cast<IElementUpdater>()))
  {
    return;
  }
  IElementUpdater::Pointer updater = cmd->GetHandler().Cast<IElementUpdater>();

  if (commandCallbacks.isEmpty())
  {
    return;
  }

  if(!commandCallbacks.contains(commandId))
  {
    return;
  }

  foreach (IElementReference::Pointer callbackRef, commandCallbacks[commandId])
  {
    struct _SafeRunnable : public ISafeRunnable
    {
      IElementUpdater* updater;
      IElementReference* callbackRef;

      _SafeRunnable(IElementUpdater* updater, IElementReference* callbackRef)
        : updater(updater), callbackRef(callbackRef)
      {}

      void HandleException(const std::exception& exc)
      {
        WorkbenchPlugin::Log(QString("Failed to update callback: ") +
                             callbackRef->GetCommandId() + exc.what());
      }

      void Run()
      {
        updater->UpdateElement(callbackRef->GetElement().GetPointer(), callbackRef->GetParameters());
      }
    };

    QHash<QString,Object::Pointer> parms = callbackRef->GetParameters();

    ISafeRunnable::Pointer run(new _SafeRunnable(updater.GetPointer(), callbackRef.GetPointer()));
    if (filter.isEmpty())
    {
      SafeRunner::Run(run);
    }
    else
    {
      bool match = true;
      QHashIterator<QString, Object::Pointer> i(filter);
      while (i.hasNext())
      {
        i.next();
        Object::Pointer value = parms[i.key()];
        if (i.value() != value)
        {
          match = false;
          break;
        }
      }
      if (match)
      {
        SafeRunner::Run(run);
      }
    }
  }
}