1 11 package org.eclipse.jdt.internal.ui.javaeditor.selectionactions; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.jface.action.Action; 16 17 import org.eclipse.ui.PlatformUI; 18 import org.eclipse.ui.texteditor.IUpdate; 19 20 import org.eclipse.jdt.core.ISourceRange; 21 22 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 23 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 24 25 public class StructureSelectHistoryAction extends Action implements IUpdate { 26 private JavaEditor fEditor; 27 private SelectionHistory fHistory; 28 29 public StructureSelectHistoryAction(JavaEditor editor, SelectionHistory history) { 30 super(SelectionActionMessages.StructureSelectHistory_label); 31 setToolTipText(SelectionActionMessages.StructureSelectHistory_tooltip); 32 setDescription(SelectionActionMessages.StructureSelectHistory_description); 33 Assert.isNotNull(history); 34 Assert.isNotNull(editor); 35 fHistory= history; 36 fEditor= editor; 37 update(); 38 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.STRUCTURED_SELECTION_HISTORY_ACTION); 39 } 40 41 public void update() { 42 setEnabled(!fHistory.isEmpty()); 43 } 44 45 public void run() { 46 ISourceRange old= fHistory.getLast(); 47 if (old != null) { 48 try { 49 fHistory.ignoreSelectionChanges(); 50 fEditor.selectAndReveal(old.getOffset(), old.getLength()); 51 } finally { 52 fHistory.listenToSelectionChanges(); 53 } 54 } 55 } 56 } 57 | Popular Tags |