@@ -295,49 +295,58 @@ public final boolean executeCommand(final ParameterizedCommand parameterizedComm
295295 final EHandlerService handlerService = getHandlerService ();
296296 final Command command = parameterizedCommand .getCommand ();
297297
298- final IEclipseContext staticContext = createContext (trigger );
299-
300298 final boolean commandDefined = command .isDefined ();
301299 // boolean commandEnabled;
302300 boolean commandHandled = false ;
303301
304- try {
305- // commandEnabled = handlerService.canExecute(parameterizedCommand, staticContext);
306- Object obj = HandlerServiceImpl .lookUpHandler (context , command .getId ());
307- if (obj != null ) {
308- if (obj instanceof IHandler ) {
309- commandHandled = ((IHandler ) obj ).isHandled ();
310- } else {
311- commandHandled = true ;
312- }
302+ // commandEnabled = handlerService.canExecute(parameterizedCommand,
303+ // staticContext);
304+ Object obj = HandlerServiceImpl .lookUpHandler (context , command .getId ());
305+ if (obj != null ) {
306+ if (obj instanceof IHandler handler ) {
307+ commandHandled = command .isEnabled () && handler .isHandled ();
308+ } else {
309+ commandHandled = true ;
313310 }
311+ }
314312
315- if (isTracingEnabled ()) {
316- logger .trace ("Command " + parameterizedCommand + ", defined: " + commandDefined + ", handled: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
317- + commandHandled + " in " + describe (context )); //$NON-NLS-1$
318- }
313+ if (isTracingEnabled ()) {
314+ logger .trace ("Command " + parameterizedCommand + ", defined: " + commandDefined + ", handled: " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
315+ + commandHandled + " in " + describe (context )); //$NON-NLS-1$
316+ }
319317
318+ final IEclipseContext staticContext = createContext (trigger );
319+ if (trigger .widget instanceof Browser ) {
320+ getDisplay ()
321+ .asyncExec (() -> handleCommandExecution (parameterizedCommand , handlerService , staticContext , obj ));
322+ } else {
323+ handleCommandExecution (parameterizedCommand , handlerService , staticContext , obj );
324+ }
325+ return (commandDefined && commandHandled );
326+ }
327+
328+ private void handleCommandExecution (final ParameterizedCommand parameterizedCommand ,
329+ final EHandlerService handlerService , final IEclipseContext staticContext , Object handler ) {
330+ try {
320331 handlerService .executeHandler (parameterizedCommand , staticContext );
321332 final Object commandException = staticContext .get (HandlerServiceImpl .HANDLER_EXCEPTION );
322333 if (commandException instanceof CommandException ) {
323- commandHandled = false ;
324334 if (commandException instanceof ExecutionException ) {
325335 if (logger != null ) {
326336 logger .error ((Throwable ) commandException ,
327337 "Execution exception for: " + parameterizedCommand + " in " //$NON-NLS-1$//$NON-NLS-2$
328338 + describe (context ));
329339 }
330340 } else if (isTracingEnabled ()) {
331- logger .trace ((Throwable ) commandException ,
332- "Command exception for: " + parameterizedCommand + " in " //$NON-NLS-1$ //$NON-NLS-2$
341+ logger .trace ((Throwable ) commandException , "Command exception for: " + parameterizedCommand + " in " //$NON-NLS-1$ //$NON-NLS-2$
333342 + describe (context ));
334343 if (handlerService instanceof HandlerServiceImpl serviceImpl ) {
335344 IEclipseContext serviceContext = serviceImpl .getContext ();
336345 if (serviceContext != null ) {
337346 StringBuilder sb = new StringBuilder ("\n \t Execution context: " ); //$NON-NLS-1$
338347 sb .append (describe (serviceContext ));
339348 sb .append ("\n \t Handler: " ); //$NON-NLS-1$
340- sb .append (obj );
349+ sb .append (handler );
341350 logger .trace (sb .toString ());
342351 }
343352 }
@@ -352,17 +361,16 @@ public final boolean executeCommand(final ParameterizedCommand parameterizedComm
352361 }
353362 }
354363 }
355- /*
356- * Now that the command has executed (and had the opportunity to use the remembered
357- * state of the dialog), it is safe to delete that information.
358- */
359- if (keyAssistDialog != null ) {
360- keyAssistDialog .clearRememberedState ();
361- }
362364 } finally {
363365 staticContext .dispose ();
364366 }
365- return (commandDefined && commandHandled );
367+ /*
368+ * Now that the command has executed (and had the opportunity to use the
369+ * remembered state of the dialog), it is safe to delete that information.
370+ */
371+ if (keyAssistDialog != null ) {
372+ keyAssistDialog .clearRememberedState ();
373+ }
366374 }
367375
368376 private boolean isTracingEnabled () {
0 commit comments