public MergeSourceViewer( SourceViewer sourceViewer, ResourceBundle bundle, ICompareContainer container) { Assert.isNotNull(sourceViewer); fSourceViewer = sourceViewer; fResourceBundle = bundle; fContainer = container; MenuManager menu = new MenuManager(); menu.setRemoveAllWhenShown(true); menu.addMenuListener(this); StyledText te = getSourceViewer().getTextWidget(); te.setMenu(menu.createContextMenu(te)); fContainer.registerContextMenu(menu, getSourceViewer()); // for listening to editor show/hide line number preference value fPreferenceChangeListener = new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { MergeSourceViewer.this.handlePropertyChangeEvent(event); } }; EditorsUI.getPreferenceStore().addPropertyChangeListener(fPreferenceChangeListener); fShowLineNumber = EditorsUI.getPreferenceStore() .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER); if (fShowLineNumber) { updateLineNumberRuler(); } IOperationHistory history = getHistory(); if (history != null) history.addOperationHistoryListener(this); // don't add save when in a dialog, IWorkbenchPart is null in dialog containers fAddSaveAction = fContainer.getWorkbenchPart() != null; }
private void addSave(IMenuManager menu) { ICommandService commandService = (ICommandService) fContainer.getWorkbenchPart().getSite().getService(ICommandService.class); final Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_SAVE); final IHandler handler = command.getHandler(); if (handler != null) { if (fSaveContributionItem == null) { fSaveContributionItem = new CommandContributionItem( new CommandContributionItemParameter( fContainer.getWorkbenchPart().getSite(), null, command.getId(), CommandContributionItem.STYLE_PUSH)); } // save is an editable dependent action, ie add only when edit // is possible if (handler.isHandled() && getSourceViewer().isEditable()) menu.add(fSaveContributionItem); } }
public static CompareHandlerService createFor(ICompareContainer container, Shell shell) { IServiceLocator serviceLocator = container.getServiceLocator(); if (serviceLocator != null) { IHandlerService service = (IHandlerService) serviceLocator.getService(IHandlerService.class); if (service != null) return new CompareHandlerService(container, null); } if (container.getWorkbenchPart() == null && shell != null) { // We're in a dialog so we can use an active shell expression IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); if (service != null) { Expression e = new ActiveShellExpression(shell); return new CompareHandlerService(container, e); } } return new CompareHandlerService(null, null); }
private void initialize() { if (fHandlerService == null) { IServiceLocator serviceLocator = fContainer.getServiceLocator(); if (serviceLocator != null) { IHandlerService service = (IHandlerService) serviceLocator.getService(IHandlerService.class); if (service != null) fHandlerService = service; } if (fHandlerService == null && fContainer.getWorkbenchPart() == null && fExpression != null) { // We're in a dialog so we can use an active shell expression IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); if (service != null) { fHandlerService = service; } } } }