diff --git a/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationDescriptor.cpp b/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationDescriptor.cpp index f15f2dffbd..4bde4b4807 100644 --- a/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationDescriptor.cpp +++ b/Plugins/org.blueberry.core.runtime/src/internal/berryApplicationDescriptor.cpp @@ -1,267 +1,267 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryApplicationDescriptor.h" #include "berryApplicationHandle.h" #include "berryApplicationContainer.h" #include "berryIRuntimeConstants.h" #include namespace berry { const QString ApplicationDescriptor::APP_TYPE = "blueberry.application.type"; const QString ApplicationDescriptor::APP_DEFAULT = "blueberry.application.default"; const QString ApplicationDescriptor::APP_TYPE_MAIN_THREAD = "main.thread"; const QString ApplicationDescriptor::APP_TYPE_ANY_THREAD = "any.thread"; ApplicationDescriptor::ApplicationDescriptor(const QSharedPointer& contributor, const QString& pid, const QString& name, const QString& iconPath, const Flags& flags, int cardinality, ApplicationContainer* appContainer) : pid(pid) , name(name) , contributor(contributor) , appContainer(appContainer) , flags(flags) , cardinality(cardinality) , iconPath(iconPath) , instanceId(0) , locked(false) { if (pid.isEmpty()) { throw std::invalid_argument("Application ID must not be empty!"); } } ApplicationDescriptor::~ApplicationDescriptor() { } QString ApplicationDescriptor::getApplicationId() const { return pid; } QHash ApplicationDescriptor::getProperties(const QLocale& /*locale*/) const { return this->getProperties(); } QHash berry::ApplicationDescriptor::getProperties() const { // just use the service properties; for now we do not localize any properties return GetServiceProperties(); } ctkApplicationHandle* ApplicationDescriptor::launch(const QHash& arguments) { CheckArgs(arguments); try { // if this application is locked throw an exception. /* if (GetLocked()) { throw ctkIllegalStateException("Cannot launch a locked application."); } */ // initialize the appHandle ApplicationHandle* appHandle = CreateAppHandle(arguments); try { // use the appContainer to launch the application on the main thread. appContainer->Launch(appHandle); } catch (const std::exception& t) { // be sure to destroy the appHandle if an error occurs try { appHandle->destroy(); } catch (...) { // ignore and clean up } throw t; } return appHandle; } catch (const ctkIllegalStateException& ise) { throw ise; } catch (const ctkApplicationException& ae) { throw ae; } catch (const ctkException& e) { throw ctkApplicationException(ctkApplicationException::APPLICATION_INTERNAL_ERROR, e); } catch (const std::exception& e) { throw ctkApplicationException(ctkApplicationException::APPLICATION_INTERNAL_ERROR, QString(e.what())); } catch (...) { throw ctkApplicationException(ctkApplicationException::APPLICATION_INTERNAL_ERROR); } } void ApplicationDescriptor::CheckArgs(const QHash arguments) { foreach(QString key, arguments.keys()) { if (key.isEmpty()) { throw std::invalid_argument("Empty string is an invalid key"); } } } ctkProperties ApplicationDescriptor::GetServiceProperties() const { ctkProperties props; props[ctkApplicationDescriptor::APPLICATION_PID] = getApplicationId(); if (!name.isEmpty()) { props[ctkApplicationDescriptor::APPLICATION_NAME] = name; } props[ctkApplicationDescriptor::APPLICATION_CONTAINER] = IRuntimeConstants::PI_RUNTIME(); props[ctkApplicationDescriptor::APPLICATION_LOCATION] = GetLocation(); bool launchable = appContainer->IsLocked(this) == 0 ? true : false; props[ctkApplicationDescriptor::APPLICATION_LAUNCHABLE] = launchable; props[ctkApplicationDescriptor::APPLICATION_LOCKED] = GetLocked(); bool visible = flags.testFlag(FLAG_VISIBLE); props[ctkApplicationDescriptor::APPLICATION_VISIBLE] = visible; props[APP_TYPE] = GetThreadTypeString(); if (flags.testFlag(FLAG_DEFAULT_APP)) { props[APP_DEFAULT] = true; } if (!iconPath.isEmpty()) { props[ctkApplicationDescriptor::APPLICATION_ICON] = iconPath; } return props; } ApplicationHandle* ApplicationDescriptor::CreateAppHandle(const QHash& arguments) { ApplicationHandle* newAppHandle = new ApplicationHandle(GetInstanceID(), arguments, this); //appContainer.lock(newAppHandle); QStringList clazzes; clazzes.push_back(qobject_interface_iid()); clazzes.push_back(qobject_interface_iid()); ctkServiceRegistration appHandleReg = appContainer->GetContext()->registerService(clazzes, newAppHandle, newAppHandle->GetServiceProperties()); newAppHandle->SetServiceRegistration(appHandleReg); return newAppHandle; } QString ApplicationDescriptor::GetInstanceID() const { QMutexLocker l(&mutex); // make sure the instanceID has not reached the max if (instanceId == std::numeric_limits::max()) { instanceId = 0; } // create a unique instance id - return getApplicationId() + "." + instanceId++; + return QString("%1.%2").arg(getApplicationId()).arg(instanceId++); } QString ApplicationDescriptor::GetLocation() const { if (!contributor) { return QString(); } return contributor->getLocation(); } bool ApplicationDescriptor::GetLocked() const { QMutexLocker l(&mutex); return locked; } QString ApplicationDescriptor::GetThreadTypeString() const { if (flags.testFlag(FLAG_TYPE_ANY_THREAD)) { return APP_TYPE_ANY_THREAD; } return APP_TYPE_MAIN_THREAD; } ApplicationContainer* ApplicationDescriptor::GetContainerManager() const { return appContainer; } void ApplicationDescriptor::RefreshProperties() { ctkServiceRegistration reg = GetServiceRegistration(); if (reg) { try { reg.setProperties(GetServiceProperties()); } catch (const ctkIllegalStateException&) { // this must mean the service was unregistered // just ignore } } } void ApplicationDescriptor::SetServiceRegistration(const ctkServiceRegistration& sr) { QMutexLocker l(®istrationMutex); this->sr = sr; registrationValidOrWaiting = sr; registrationMutexCondition.wakeAll(); } ctkServiceRegistration ApplicationDescriptor::GetServiceRegistration() const { QMutexLocker l(®istrationMutex); if (!sr && registrationValidOrWaiting) { registrationMutexCondition.wait(®istrationMutex, 1000); // timeout after 1 second } return sr; } void ApplicationDescriptor::Unregister() { ctkServiceRegistration temp = GetServiceRegistration(); if (temp) { SetServiceRegistration(ctkServiceRegistration()); temp.unregister(); } } int ApplicationDescriptor::GetThreadType() const { return flags & (FLAG_TYPE_ANY_THREAD | FLAG_TYPE_MAIN_THREAD); } } diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryCommandParameter.cpp b/Plugins/org.blueberry.ui.qt/src/internal/berryCommandParameter.cpp index a5d0823254..860397be92 100644 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryCommandParameter.cpp +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryCommandParameter.cpp @@ -1,143 +1,143 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryCommandParameter.h" #include "berryIConfigurationElement.h" #include "berryIParameterValues.h" #include "berryCoreException.h" #include "berryCommandExceptions.h" #include "berryParameterType.h" namespace berry { const QString CommandParameter::ATTRIBUTE_VALUES = "values"; const int CommandParameter::HASH_CODE_NOT_COMPUTED = 0; const int CommandParameter::HASH_FACTOR = 89; const int CommandParameter::HASH_INITIAL = qHash(CommandParameter::GetStaticClassName()); CommandParameter::CommandParameter(const QString& id, const QString& name, const SmartPointer& values, const SmartPointer& parameterType, const bool optional) : name(name) , optional(optional) , parameterType(parameterType) , valuesConfigurationElement(values) , id(id) { if (id.isNull()) { throw ctkInvalidArgumentException("Cannot create a parameter with a null id"); } if (name.isNull()) { throw ctkInvalidArgumentException("The name of a parameter cannot be null."); } if (values.IsNull()) { throw ctkInvalidArgumentException("The values for a parameter cannot be null."); } } bool CommandParameter::operator==(const Object* object) const { if (this == object) { return true; } if (const CommandParameter* parameter = dynamic_cast(object)) { if (id != parameter->id) { return false; } if (name != parameter->name) { return false; } if (values != parameter->values) { return false; } return optional == parameter->optional; } else { return false; } } QString CommandParameter::GetId() const { return id; } QString CommandParameter::GetName() const { return name; } SmartPointer CommandParameter::GetParameterType() const { return parameterType; } IParameterValues* CommandParameter::GetValues() const { if (values.isNull()) { try { values.reset(valuesConfigurationElement->CreateExecutableExtension(ATTRIBUTE_VALUES)); } catch (const CoreException& e) { throw ParameterValuesException("Problem creating parameter values", e); } if (values.isNull()) { throw ParameterValuesException( "Parameter values were not an instance of IParameterValues"); } } return values.data(); } bool CommandParameter::IsOptional() const { return optional; } QString CommandParameter::ToString() const { if (str.isNull()) { QString paramValuesStr; if (!values.isNull()) { QDebug dbg(¶mValuesStr); dbg << values->GetParameterValues(); } - str = "Parameter(" + id + ',' + name + ',' + paramValuesStr + ',' + optional +')'; + str = QString("Parameter(%1,%2,%3,%4)").arg(id).arg(name).arg(paramValuesStr).arg(optional); } return str; } } diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryContainerPlaceholder.cpp b/Plugins/org.blueberry.ui.qt/src/internal/berryContainerPlaceholder.cpp index dcad3f95a6..0d3bcc3c7b 100644 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryContainerPlaceholder.cpp +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryContainerPlaceholder.cpp @@ -1,128 +1,128 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryContainerPlaceholder.h" #include "berryPartPlaceholder.h" #include "berryILayoutContainer.h" namespace berry { int ContainerPlaceholder::nextId = 0; ContainerPlaceholder::ContainerPlaceholder(const QString& id) : - PartPlaceholder(id == "" ? QString("Container Placeholder ") + nextId++ : id) + PartPlaceholder(id == "" ? QString("Container Placeholder %1").arg(nextId++) : id) { } void ContainerPlaceholder::Add(LayoutPart::Pointer child) { if (child.Cast() == 0) { return; } realContainer->Add(child); } bool ContainerPlaceholder::AllowsAdd(LayoutPart::Pointer /*toAdd*/) { return false; } QList ContainerPlaceholder::GetChildren() const { return realContainer->GetChildren(); } QString ContainerPlaceholder::GetID() const { return LayoutPart::GetID(); } LayoutPart::Pointer ContainerPlaceholder::GetRealContainer() { return realContainer.Cast(); } void ContainerPlaceholder::Remove(LayoutPart::Pointer child) { if (child.Cast () == 0) { return; } realContainer->Remove(child); } void ContainerPlaceholder::Replace(LayoutPart::Pointer oldChild, LayoutPart::Pointer newChild) { if (oldChild.Cast() == 0 && newChild.Cast() == 0) { return; } realContainer->Replace(oldChild, newChild); } void ContainerPlaceholder::SetRealContainer( ILayoutContainer::Pointer container) { if (container == 0) { // set the parent container of the children back to the real container if (realContainer != 0) { QList children = realContainer->GetChildren(); for (QList::iterator iter = children.begin(); iter != children.end(); ++iter) { (*iter)->SetContainer(realContainer); } } } else { // replace the real container with this place holder QList children = container->GetChildren(); for (QList::iterator iter = children.begin(); iter != children.end(); ++iter) { (*iter)->SetContainer(ILayoutContainer::Pointer(this)); } } this->realContainer = container; } void ContainerPlaceholder::FindSashes(LayoutPart::Pointer /*part*/, PartPane::Sashes& sashes) { ILayoutContainer::Pointer container = this->GetContainer(); if (container != 0) { container->FindSashes(LayoutPart::Pointer(this), sashes); } } void ContainerPlaceholder::ResizeChild(LayoutPart::Pointer /*childThatChanged*/) { } bool ContainerPlaceholder::AllowsAutoFocus() { return false; } } diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryHandlerAuthority.cpp b/Plugins/org.blueberry.ui.qt/src/internal/berryHandlerAuthority.cpp index 8fbbb5b273..92f357e9aa 100644 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryHandlerAuthority.cpp +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryHandlerAuthority.cpp @@ -1,505 +1,505 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryHandlerAuthority.h" #include "berryISources.h" #include "berryIServiceLocator.h" #include "berryIEvaluationService.h" #include "berryIEvaluationContext.h" #include "berryIEvaluationReference.h" #include "berryICommandService.h" #include "berryIHandler.h" #include "berryISourceProvider.h" #include "services/berryISourceProviderService.h" #include "berryObjects.h" #include "berryHandlerActivation.h" #include "berryMultiStatus.h" #include "berryPlatformUI.h" #include "berryWorkbenchPlugin.h" #include "berryCommandTracing.h" #include "berryCommand.h" #include "berryEvaluationContext.h" #include "berryExpression.h" #include namespace berry { bool HandlerAuthority::DEBUG = false; // = Policy.DEBUG_HANDLERS; bool HandlerAuthority::DEBUG_PERFORMANCE = false; // = Policy.DEBUG_HANDLERS_PERFORMANCE; bool HandlerAuthority::DEBUG_VERBOSE = false; // = Policy.DEBUG_HANDLERS && Policy.DEBUG_HANDLERS_VERBOSE; QString HandlerAuthority::DEBUG_VERBOSE_COMMAND_ID; // = Policy.DEBUG_HANDLERS_VERBOSE_COMMAND_ID; const QString HandlerAuthority::TRACING_COMPONENT = "HANDLERS"; const QList HandlerAuthority::SELECTION_VARIABLES = QList() << ISources::ACTIVE_CURRENT_SELECTION_NAME() << ISources::ACTIVE_FOCUS_CONTROL_ID_NAME() << ISources::ACTIVE_FOCUS_CONTROL_NAME() << ISources::ACTIVE_MENU_EDITOR_INPUT_NAME() << ISources::ACTIVE_MENU_NAME() << ISources::ACTIVE_MENU_SELECTION_NAME(); class HandlerAuthority::HandlerPropertyListener : public IPropertyChangeListener { private: HandlerAuthority* authority; HandlerActivation::Pointer handler; public: HandlerPropertyListener(HandlerAuthority* authority, const HandlerActivation::Pointer& activation) : authority(authority) , handler(activation) { handler->SetListener(this); } using IPropertyChangeListener::PropertyChange; void PropertyChange(const PropertyChangeEvent::Pointer& event) override { if (handler->GetCommandId() == event->GetProperty()) { bool val = false; if (ObjectBool::Pointer boolObj = event->GetNewValue().Cast()) { val = boolObj->GetValue(); } handler->SetResult(val); authority->changedCommandIds.insert(handler->GetCommandId()); } } }; IEvaluationService* HandlerAuthority::GetEvaluationService() const { if (evalService == nullptr) { evalService = locator->GetService(); evalService->AddServiceListener(GetServiceListener()); } return evalService; } IPropertyChangeListener* HandlerAuthority::GetServiceListener() const { return const_cast(this); } void HandlerAuthority::PropertyChange(const PropertyChangeEvent::Pointer& event) { if (IEvaluationService::PROP_NOTIFYING == event->GetProperty()) { if (ObjectBool::Pointer boolObj = event->GetNewValue().Cast()) { bool startNotifying = boolObj->GetValue(); if (startNotifying) { changedCommandIds.clear(); } else { ProcessChangedCommands(); } } } } HandlerAuthority::HandlerAuthority(ICommandService* commandService, IServiceLocator* locator) : commandService(commandService) , locator(locator) , evalService(nullptr) { if (commandService == nullptr) { throw ctkInvalidArgumentException("The handler authority needs a command service"); } } HandlerAuthority::~HandlerAuthority() { GetEvaluationService()->RemoveServiceListener(GetServiceListener()); } void HandlerAuthority::ActivateHandler(const SmartPointer& activation) { const HandlerActivation::Pointer handler = activation.Cast(); // First we update the handlerActivationsByCommandId map. const QString commandId = handler->GetCommandId(); MultiStatus::Pointer conflicts( new MultiStatus(PlatformUI::PLUGIN_ID(), 0, "A handler conflict occurred. This may disable some commands.", BERRY_STATUS_LOC) ); IdToHandlerActivationMap::mapped_type& handlerActivations = handlerActivationsByCommandId[commandId]; handlerActivations.insert(handler, Empty()); if (handler->GetExpression().IsNotNull()) { auto l = new HandlerPropertyListener(this, handler); handler->SetReference(GetEvaluationService()->AddEvaluationListener( handler->GetExpression(), l, handler->GetCommandId())); } if (handlerActivations.size() > 1) { UpdateCommand(commandId, ResolveConflicts(commandId, handlerActivations, conflicts)); } else { UpdateCommand(commandId, (Evaluate(handler) ? handler : HandlerActivation::Pointer(nullptr))); } if (conflicts->GetSeverity() != IStatus::OK_TYPE) { WorkbenchPlugin::Log(conflicts); } } void HandlerAuthority::DeactivateHandler(const SmartPointer& activation) { const HandlerActivation::Pointer handler = activation.Cast(); // First we update the handlerActivationsByCommandId map. const QString commandId = handler->GetCommandId(); MultiStatus::Pointer conflicts( new MultiStatus("org.blueberry.ui", 0, "A handler conflict occurred. This may disable some commands.", BERRY_STATUS_LOC)); IdToHandlerActivationMap::iterator value = handlerActivationsByCommandId.find(commandId); if (value != handlerActivationsByCommandId.end()) { IdToHandlerActivationMap::mapped_type& handlerActivations = value.value(); if (handlerActivations.remove(handler) > 0) { if (handler->GetReference().IsNotNull()) { GetEvaluationService()->RemoveEvaluationListener(handler->GetReference()); handler->SetReference(IEvaluationReference::Pointer(nullptr)); handler->SetListener(nullptr); } if (handlerActivations.isEmpty()) { handlerActivationsByCommandId.remove(commandId); UpdateCommand(commandId, IHandlerActivation::Pointer(nullptr)); } else if (handlerActivations.size() == 1) { IHandlerActivation::Pointer remainingActivation = handlerActivations.begin().key(); UpdateCommand(commandId, (Evaluate(remainingActivation) ? remainingActivation : IHandlerActivation::Pointer(nullptr))); } else { UpdateCommand(commandId, ResolveConflicts(commandId, handlerActivations, conflicts)); } } } if (conflicts->GetSeverity() != IStatus::OK_TYPE) { WorkbenchPlugin::Log(conflicts); } } SmartPointer HandlerAuthority::ResolveConflicts( const QString& commandId, const QMap,Empty>& activations, SmartPointer conflicts) { // If we don't have any, then there is no match. if (activations.isEmpty()) { return IHandlerActivation::Pointer(nullptr); } // Cycle over the activations, remembered the current best. QMapIterator activationItr(activations); HandlerActivation::Pointer bestActivation; HandlerActivation::Pointer currentActivation; bool conflict = false; while (activationItr.hasNext()) { currentActivation = activationItr.next().key(); if (!Evaluate(currentActivation)) { continue; // only consider potentially active handlers } // Check to see if we haven't found a potentially active handler yet if ((DEBUG_VERBOSE) && ((DEBUG_VERBOSE_COMMAND_ID.isNull()) || (DEBUG_VERBOSE_COMMAND_ID == commandId))) { CommandTracing::PrintTrace(TRACING_COMPONENT, " resolveConflicts: eval: " + currentActivation->ToString()); } if (bestActivation.IsNull()) { bestActivation = currentActivation; conflict = false; continue; } // Compare the two handlers. int comparison = bestActivation->CompareTo(currentActivation.GetPointer()); if (comparison < 0) { bestActivation = currentActivation; conflict = false; } else if (comparison == 0) { if (currentActivation->GetHandler() != bestActivation->GetHandler()) { conflict = true; break; } } else { break; } } // If we are logging information, now is the time to do it. if (DEBUG) { if (conflict) { CommandTracing::PrintTrace(TRACING_COMPONENT, "Unresolved conflict detected for '" + commandId + '\''); } else if ((bestActivation.IsNotNull()) && (DEBUG_VERBOSE) && ((DEBUG_VERBOSE_COMMAND_ID.isNull()) || (DEBUG_VERBOSE_COMMAND_ID == commandId))) { CommandTracing::PrintTrace(TRACING_COMPONENT, "Resolved conflict detected. The following activation won: "); CommandTracing::PrintTrace(TRACING_COMPONENT, " " + bestActivation->ToString()); } } // Return the current best. if (conflict) { if (!previousLogs.contains(commandId)) { previousLogs.insert(commandId); QString str; QDebug dbg(&str); dbg << "Conflict for" << commandId << ":"; dbg << bestActivation->ToString(); dbg << currentActivation->ToString(); IStatus::Pointer s(new Status(IStatus::WARNING_TYPE, "org.blueberry.ui", str, BERRY_STATUS_LOC)); conflicts->Add(s); } return IHandlerActivation::Pointer(nullptr); } return bestActivation; } void HandlerAuthority::UpdateCommand(const QString& commandId, const SmartPointer& activation) { const Command::Pointer command = commandService->GetCommand(commandId); if (activation.IsNull()) { command->SetHandler(IHandler::Pointer(nullptr)); } else { command->SetHandler(activation->GetHandler()); commandService->RefreshElements(commandId, QHash()); } } SmartPointer HandlerAuthority::FindHandler(const QString& commandId, IEvaluationContext* context) { IdToHandlerActivationMap::mapped_type activations = handlerActivationsByCommandId.value(commandId); IHandlerActivation::Pointer lastActivation; IHandlerActivation::Pointer currentActivation; QMapIterator i(activations); while (i.hasNext() && lastActivation.IsNull()) { HandlerActivation::Pointer activation = i.next().key(); try { if (Eval(context, activation)) { lastActivation = currentActivation; currentActivation = activation; } } catch (const CoreException&) { // OK, this one is out of the running } } if (currentActivation.IsNotNull()) { if (lastActivation.IsNull()) { return currentActivation->GetHandler(); } if (lastActivation->GetSourcePriority() != currentActivation->GetSourcePriority()) { return lastActivation->GetHandler(); } } return IHandler::Pointer(nullptr); } IEvaluationContext::Pointer HandlerAuthority::CreateContextSnapshot(bool includeSelection) { IEvaluationContext::Pointer tmpContext = GetCurrentState(); EvaluationContext::Pointer context; if (includeSelection) { context = new EvaluationContext(nullptr, tmpContext->GetDefaultVariable()); for (int i = 0; i < SELECTION_VARIABLES.size(); i++) { CopyVariable(context.GetPointer(), tmpContext.GetPointer(), SELECTION_VARIABLES[i]); } } else { context = new EvaluationContext(nullptr, Object::Pointer(nullptr)); } ISourceProviderService* sp = locator->GetService(); QList providers = sp->GetSourceProviders(); for (int i = 0; i < providers.size(); i++) { QList names = providers[i]->GetProvidedSourceNames(); for (int j = 0; j < names.size(); j++) { if (!IsSelectionVariable(names[j])) { CopyVariable(context.GetPointer(), tmpContext.GetPointer(), names[j]); } } } return context; } bool HandlerAuthority::Eval(IEvaluationContext* context, const SmartPointer& activation) { Expression::Pointer expression = activation->GetExpression(); if (expression.IsNull()) { return true; } return expression->Evaluate(context) == EvaluationResult::TRUE_EVAL; } bool HandlerAuthority::IsSelectionVariable(const QString& name) { for (int i = 0; i < SELECTION_VARIABLES.size(); i++) { if (SELECTION_VARIABLES[i] == name) { return true; } } return false; } void HandlerAuthority::CopyVariable(IEvaluationContext* context, IEvaluationContext* tmpContext, const QString& var) { Object::ConstPointer o = tmpContext->GetVariable(var); if (o.IsNotNull()) { context->AddVariable(var, o); } } void HandlerAuthority::ProcessChangedCommands() { // If tracing, then track how long it takes to process the activations. QElapsedTimer timer; if (DEBUG_PERFORMANCE) { timer.start(); } MultiStatus::Pointer conflicts( new MultiStatus("org.blueberry.ui", 0, "A handler conflict occurred. This may disable some commands.", BERRY_STATUS_LOC)); /* * For every command identifier with a changed activation, we resolve * conflicts and trigger an update. */ const QSet changedIds = changedCommandIds; changedCommandIds.clear(); foreach(const QString& commandId, changedIds) { IdToHandlerActivationMap::mapped_type activations = handlerActivationsByCommandId.value(commandId); if (activations.size() == 1) { const IHandlerActivation::Pointer activation = activations.begin().key(); UpdateCommand(commandId, (Evaluate(activation) ? activation : IHandlerActivation::Pointer(nullptr))); } else { const IHandlerActivation::Pointer activation = ResolveConflicts( commandId, activations, conflicts); UpdateCommand(commandId, activation); } } if (conflicts->GetSeverity() != IStatus::OK_TYPE) { WorkbenchPlugin::Log(conflicts); } // If tracing performance, then print the results. if (DEBUG_PERFORMANCE) { const int elapsedTime = timer.elapsed(); const int size = changedCommandIds.size(); if (size > 0) { - CommandTracing::PrintTrace(TRACING_COMPONENT, QString::number(size) + " command ids changed in " + elapsedTime + "ms"); + CommandTracing::PrintTrace(TRACING_COMPONENT, QString("%1 command ids changed in %2 ms").arg(size).arg(elapsedTime)); } } } bool HandlerAuthority::Evaluate(const SmartPointer& expression) { IEvaluationContext::Pointer contextWithDefaultVariable = GetCurrentState(); return expression->Evaluate(contextWithDefaultVariable.GetPointer()); } SmartPointer HandlerAuthority::GetCurrentState() const { return GetEvaluationService()->GetCurrentState(); } //void HandlerAuthority::UpdateShellKludge() //{ // ((EvaluationService) getEvaluationService()).updateShellKludge(); //} //void HandlerAuthority::UpdateShellKludge(const SmartPointer& shell) //{ // ((EvaluationService) getEvaluationService()).updateShellKludge(shell); //} }