1 11 12 package org.eclipse.ui.internal.keys; 13 14 import org.eclipse.jface.action.IContributionItem; 15 import org.eclipse.jface.action.IStatusLineManager; 16 import org.eclipse.jface.bindings.keys.KeySequence; 17 import org.eclipse.ui.IWorkbench; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.internal.WorkbenchWindow; 20 import org.eclipse.ui.internal.util.StatusLineContributionItem; 21 22 38 class KeyBindingState { 39 40 45 private IWorkbenchWindow associatedWindow; 46 47 54 private KeySequence currentSequence; 55 56 61 private final IWorkbench workbench; 62 63 71 KeyBindingState(IWorkbench workbenchToNotify) { 72 currentSequence = KeySequence.getInstance(); 73 workbench = workbenchToNotify; 74 associatedWindow = workbench.getActiveWorkbenchWindow(); 75 } 76 77 85 IWorkbenchWindow getAssociatedWindow() { 86 return associatedWindow; 87 } 88 89 95 KeySequence getCurrentSequence() { 96 return currentSequence; 97 } 98 99 106 StatusLineContributionItem getStatusLine() { 107 if (associatedWindow instanceof WorkbenchWindow) { 108 WorkbenchWindow window = (WorkbenchWindow) associatedWindow; 109 IStatusLineManager statusLine = window.getStatusLineManager(); 110 if (statusLine != null) { IContributionItem item = statusLine 114 .find("ModeContributionItem"); if (item instanceof StatusLineContributionItem) { 116 return ((StatusLineContributionItem) item); 117 } 118 } 119 } 120 121 return null; 122 } 123 124 135 void reset() { 136 currentSequence = KeySequence.getInstance(); 137 updateStatusLines(); 138 } 139 140 146 void setAssociatedWindow(IWorkbenchWindow window) { 147 associatedWindow = window; 148 } 149 150 157 void setCurrentSequence(KeySequence sequence) { 158 currentSequence = sequence; 159 updateStatusLines(); 160 } 161 162 166 private void updateStatusLines() { 167 StatusLineContributionItem statusLine = getStatusLine(); 168 if (statusLine != null) { 169 statusLine.setText(getCurrentSequence().format()); 170 } 171 } 172 } 173 | Popular Tags |