|
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 521-528
Link Here
|
| 521 |
* DO NOT CALL THIS METHOD. |
523 |
* DO NOT CALL THIS METHOD. |
| 522 |
* </p> |
524 |
* </p> |
| 523 |
* |
525 |
* |
| 524 |
* @param commandId the command id to check |
526 |
* @param commandId |
| 525 |
* @param the context to use for activations |
527 |
* the command id to check |
|
|
528 |
* @param the |
| 529 |
* context to use for activations |
| 526 |
* @since 3.3 |
530 |
* @since 3.3 |
| 527 |
*/ |
531 |
*/ |
| 528 |
public final IHandler findHandler(String commandId, |
532 |
public final IHandler findHandler(String commandId, |
|
Lines 531-537
Link Here
|
| 531 |
if (o instanceof IHandlerActivation) { |
535 |
if (o instanceof IHandlerActivation) { |
| 532 |
IHandlerActivation activation = (IHandlerActivation) o; |
536 |
IHandlerActivation activation = (IHandlerActivation) o; |
| 533 |
try { |
537 |
try { |
| 534 |
if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { |
538 |
if (eval(context, activation)) { |
| 535 |
return activation.getHandler(); |
539 |
return activation.getHandler(); |
| 536 |
} |
540 |
} |
| 537 |
} catch (CoreException e) { |
541 |
} catch (CoreException e) { |
|
Lines 545-551
Link Here
|
| 545 |
while (i.hasNext()) { |
549 |
while (i.hasNext()) { |
| 546 |
IHandlerActivation activation = (IHandlerActivation) i.next(); |
550 |
IHandlerActivation activation = (IHandlerActivation) i.next(); |
| 547 |
try { |
551 |
try { |
| 548 |
if (activation.getExpression().evaluate(context) == EvaluationResult.TRUE) { |
552 |
if (eval(context, activation)) { |
| 549 |
lastActivation = currentActivation; |
553 |
lastActivation = currentActivation; |
| 550 |
currentActivation = activation; |
554 |
currentActivation = activation; |
| 551 |
} |
555 |
} |
|
Lines 553-567
Link Here
|
| 553 |
// OK, this one is out of the running |
557 |
// OK, this one is out of the running |
| 554 |
} |
558 |
} |
| 555 |
} |
559 |
} |
| 556 |
if (currentActivation!=null) { |
560 |
if (currentActivation != null) { |
| 557 |
if (lastActivation==null) { |
561 |
if (lastActivation == null) { |
| 558 |
return currentActivation.getHandler(); |
562 |
return currentActivation.getHandler(); |
| 559 |
} |
563 |
} |
| 560 |
if (lastActivation.getSourcePriority()!=currentActivation.getSourcePriority()) { |
564 |
if (lastActivation.getSourcePriority() != currentActivation |
|
|
565 |
.getSourcePriority()) { |
| 561 |
return currentActivation.getHandler(); |
566 |
return currentActivation.getHandler(); |
| 562 |
} |
567 |
} |
| 563 |
} |
568 |
} |
| 564 |
} |
569 |
} |
| 565 |
return null; |
570 |
return null; |
| 566 |
} |
571 |
} |
|
|
572 |
|
| 573 |
/** |
| 574 |
* @param context |
| 575 |
* @param activation |
| 576 |
* @return |
| 577 |
* @throws CoreException |
| 578 |
*/ |
| 579 |
private boolean eval(IEvaluationContext context, |
| 580 |
IHandlerActivation activation) throws CoreException { |
| 581 |
Expression expression = activation.getExpression(); |
| 582 |
if (expression==null) { |
| 583 |
return true; |
| 584 |
} |
| 585 |
return expression.evaluate(context) == EvaluationResult.TRUE; |
| 586 |
} |
| 587 |
|
| 588 |
public IEvaluationContext getContextSnapshot() { |
| 589 |
EvaluationContext context = new EvaluationContext(null, |
| 590 |
Collections.EMPTY_LIST); |
| 591 |
IEvaluationContext tmpContext = getCurrentState(); |
| 592 |
context.addVariable(ISources.ACTIVE_ACTION_SETS_NAME, tmpContext |
| 593 |
.getVariable(ISources.ACTIVE_ACTION_SETS_NAME)); |
| 594 |
context.addVariable(ISources.ACTIVE_CONTEXT_NAME, tmpContext |
| 595 |
.getVariable(ISources.ACTIVE_CONTEXT_NAME)); |
| 596 |
context.addVariable(ISources.ACTIVE_EDITOR_ID_NAME, tmpContext |
| 597 |
.getVariable(ISources.ACTIVE_EDITOR_ID_NAME)); |
| 598 |
context.addVariable(ISources.ACTIVE_EDITOR_NAME, tmpContext |
| 599 |
.getVariable(ISources.ACTIVE_EDITOR_NAME)); |
| 600 |
context.addVariable(ISources.ACTIVE_PART_ID_NAME, tmpContext |
| 601 |
.getVariable(ISources.ACTIVE_PART_ID_NAME)); |
| 602 |
context.addVariable(ISources.ACTIVE_PART_NAME, tmpContext |
| 603 |
.getVariable(ISources.ACTIVE_PART_NAME)); |
| 604 |
context.addVariable(ISources.ACTIVE_SITE_NAME, tmpContext |
| 605 |
.getVariable(ISources.ACTIVE_SITE_NAME)); |
| 606 |
context |
| 607 |
.addVariable( |
| 608 |
ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME, |
| 609 |
tmpContext |
| 610 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_COOLBAR_VISIBLE_NAME)); |
| 611 |
context |
| 612 |
.addVariable( |
| 613 |
ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME, |
| 614 |
tmpContext |
| 615 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_IS_PERSPECTIVEBAR_VISIBLE_NAME)); |
| 616 |
context.addVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME, tmpContext |
| 617 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME)); |
| 618 |
context |
| 619 |
.addVariable( |
| 620 |
ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME, |
| 621 |
tmpContext |
| 622 |
.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_SHELL_NAME)); |
| 623 |
return context; |
| 624 |
} |
| 567 |
} |
625 |
} |