|
Lines 12-17
Link Here
|
| 12 |
package org.eclipse.ui.internal.handlers; |
12 |
package org.eclipse.ui.internal.handlers; |
| 13 |
|
13 |
|
| 14 |
import java.util.Collection; |
14 |
import java.util.Collection; |
|
|
15 |
import java.util.Collections; |
| 15 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
| 16 |
import java.util.HashSet; |
17 |
import java.util.HashSet; |
| 17 |
import java.util.Iterator; |
18 |
import java.util.Iterator; |
|
Lines 23-28
Link Here
|
| 23 |
import org.eclipse.core.commands.Command; |
24 |
import org.eclipse.core.commands.Command; |
| 24 |
import org.eclipse.core.commands.IHandler; |
25 |
import org.eclipse.core.commands.IHandler; |
| 25 |
import org.eclipse.core.commands.util.Tracing; |
26 |
import org.eclipse.core.commands.util.Tracing; |
|
|
27 |
import org.eclipse.core.expressions.EvaluationContext; |
| 26 |
import org.eclipse.core.expressions.EvaluationResult; |
28 |
import org.eclipse.core.expressions.EvaluationResult; |
| 27 |
import org.eclipse.core.expressions.Expression; |
29 |
import org.eclipse.core.expressions.Expression; |
| 28 |
import org.eclipse.core.expressions.IEvaluationContext; |
30 |
import org.eclipse.core.expressions.IEvaluationContext; |
|
Lines 517-529
Link Here
|
| 517 |
} |
519 |
} |
| 518 |
|
520 |
|
| 519 |
/** |
521 |
/** |
| 520 |
* Currently this is a kludge. |
522 |
* Currently this is a an internal method to help locate a handler. |
| 521 |
* <p> |
523 |
* <p> |
| 522 |
* DO NOT CALL THIS METHOD. |
524 |
* DO NOT CALL THIS METHOD. |
| 523 |
* </p> |
525 |
* </p> |
| 524 |
* |
526 |
* |
| 525 |
* @param commandId the command id to check |
527 |
* @param commandId |
| 526 |
* @param the context to use for activations |
528 |
* the command id to check |
|
|
529 |
* @param context |
| 530 |
* the context to use for activations |
| 527 |
* @since 3.3 |
531 |
* @since 3.3 |
| 528 |
*/ |
532 |
*/ |
| 529 |
public final IHandler findHandler(String commandId, |
533 |
public final IHandler findHandler(String commandId, |
|
Lines 532-538
Link Here
|
| 532 |
if (o instanceof IHandlerActivation) { |
536 |
if (o instanceof IHandlerActivation) { |
| 533 |
IHandlerActivation activation = (IHandlerActivation) o; |
537 |
IHandlerActivation activation = (IHandlerActivation) o; |
| 534 |
try { |
538 |
try { |
| 535 |
if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { |
539 |
if (eval(context, activation)) { |
| 536 |
return activation.getHandler(); |
540 |
return activation.getHandler(); |
| 537 |
} |
541 |
} |
| 538 |
} catch (CoreException e) { |
542 |
} catch (CoreException e) { |
|
Lines 543-552
Link Here
|
| 543 |
IHandlerActivation lastActivation = null; |
547 |
IHandlerActivation lastActivation = null; |
| 544 |
IHandlerActivation currentActivation = null; |
548 |
IHandlerActivation currentActivation = null; |
| 545 |
Iterator i = activations.iterator(); |
549 |
Iterator i = activations.iterator(); |
| 546 |
while (i.hasNext()) { |
550 |
while (i.hasNext() && lastActivation==null) { |
| 547 |
IHandlerActivation activation = (IHandlerActivation) i.next(); |
551 |
IHandlerActivation activation = (IHandlerActivation) i.next(); |
| 548 |
try { |
552 |
try { |
| 549 |
if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { |
553 |
if (eval(context, activation)) { |
| 550 |
lastActivation = currentActivation; |
554 |
lastActivation = currentActivation; |
| 551 |
currentActivation = activation; |
555 |
currentActivation = activation; |
| 552 |
} |
556 |
} |
|
Lines 554-568
Link Here
|
| 554 |
// OK, this one is out of the running |
558 |
// OK, this one is out of the running |
| 555 |
} |
559 |
} |
| 556 |
} |
560 |
} |
| 557 |
if (currentActivation!=null) { |
561 |
if (currentActivation != null) { |
| 558 |
if (lastActivation==null) { |
562 |
if (lastActivation == null) { |
| 559 |
return currentActivation.getHandler(); |
563 |
return currentActivation.getHandler(); |
| 560 |
} |
564 |
} |
| 561 |
if (lastActivation.getSourcePriority()!=currentActivation.getSourcePriority()) { |
565 |
if (lastActivation.getSourcePriority() != currentActivation |
| 562 |
return currentActivation.getHandler(); |
566 |
.getSourcePriority()) { |
|
|
567 |
return lastActivation.getHandler(); |
| 563 |
} |
568 |
} |
| 564 |
} |
569 |
} |
| 565 |
} |
570 |
} |
| 566 |
return null; |
571 |
return null; |
| 567 |
} |
572 |
} |
|
|
573 |
|
| 574 |
/** |
| 575 |
* Evaluate the expression for the handler and bypass the result cache. |
| 576 |
* <p> |
| 577 |
* DO NOT CALL THIS METHOD. |
| 578 |
* </p> |
| 579 |
* |
| 580 |
* @param context |
| 581 |
* @param activation |
| 582 |
* @return <code>true</code> if the handler expression can evaluate to |
| 583 |
* true. |
| 584 |
* @throws CoreException |
| 585 |
* @since 3.3 |
| 586 |
*/ |
| 587 |
private boolean eval(IEvaluationContext context, |
| 588 |
IHandlerActivation activation) throws CoreException { |
| 589 |
Expression expression = activation.getExpression(); |
| 590 |
if (expression == null) { |
| 591 |
return true; |
| 592 |
} |
| 593 |
return expression.evaluate(context) == EvaluationResult.TRUE; |
| 594 |
} |
| 595 |
|
| 596 |
/** |
| 597 |
* Normally the context returned from getCurrentState() still tracks the |
| 598 |
* application state. This method creates a copy and fills it in with the |
| 599 |
* variables that we know about. Currently it does not fill in the active |
| 600 |
* selection. |
| 601 |
* <p> |
| 602 |
* DO NOT CALL THIS METHOD. It is experimental in 3.3. |
| 603 |
* </p> |
| 604 |
* |
| 605 |
* @return an evaluation context with no parent. |
| 606 |
* @since 3.3 |
| 607 |
*/ |
| 608 |
public IEvaluationContext getContextSnapshot() { |
| 609 |
EvaluationContext context = new EvaluationContext(null, |
| 610 |
Collections.EMPTY_LIST); |
| 611 |
IEvaluationContext tmpContext = getCurrentState(); |
| 612 |
context.addVariable(ISources.ACTIVE_ACTION_SETS_NAME, tmpContext |
| 613 |
.getVariable(ISources.ACTIVE_ACTION_SETS_NAME)); |
| 614 |
context.addVariable(ISources.ACTIVE_CONTEXT_NAME, tmpContext |
| 615 |
.getVariable(ISources.ACTIVE_CONTEXT_NAME)); |
| 616 |
context.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, tmpContext |
| 617 |
.getVariable(ISources.ACTIVE_EDITOR_ID_NAME)); |
| 618 |
context.addVariable(ISources.ACTIVE_EDITOR_NAME, tmpContext |
| 619 |
.getVariable(ISources.ACTIVE_EDITOR_NAME)); |
| 620 |
context.addVariable(ISources.ACTIVE_PART_ID_NAME, tmpContext |
| 621 |
.getVariable(ISources.ACTIVE_PART_ID_NAME)); |
| 622 |
context.addVariable(ISources.ACTIVE_PART_NAME, tmpContext |
| 623 |
.getVariable(ISources.ACTIVE_PART_NAME)); |
| 624 |
context.addVariable(ISources.ACTIVE_SITE_NAME, tmpContext |
| 625 |
.getVariable(ISources.ACTIVE_SITE_NAME)); |
| 626 |
context |
| 627 |
.addVariable( |
| 628 |
ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME, |
| 629 |
tmpContext |
| 630 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME)); |
| 631 |
context |
| 632 |
.addVariable( |
| 633 |
ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME, |
| 634 |
tmpContext |
| 635 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME)); |
| 636 |
context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, tmpContext |
| 637 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME)); |
| 638 |
context |
| 639 |
.addVariable( |
| 640 |
ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, |
| 641 |
tmpContext |
| 642 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME)); |
| 643 |
return context; |
| 644 |
} |
| 568 |
} |
645 |
} |