blob: d558b3c084b94ecb79f2576eeeea4a2ca3ff38f9 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2002, 2005 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM - Initial API and implementation
*******************************************************************************/
package org.eclipse.core.tools;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.part.ViewPart;
public class BaseTextView extends ViewPart {
protected TextViewer viewer;
public BaseTextView() {
super();
}
@Override
public void createPartControl(Composite parent) {
viewer = new TextViewer(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
viewer.setDocument(new Document());
IActionBars bars = getViewSite().getActionBars();
GlobalAction selectAllAction = new SelectAllAction(viewer);
selectAllAction.registerAsGlobalAction(bars);
GlobalAction copyAction = new CopyTextSelectionAction(viewer);
copyAction.registerAsGlobalAction(bars);
bars.updateActionBars();
// creates a context menu with actions and adds it to the viewer control
MenuManager menuMgr = new MenuManager();
menuMgr.add(copyAction);
menuMgr.add(selectAllAction);
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
}
@Override
public void setFocus() {
// do nothing
}
}