mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
[173730] [terminal] Provide an optional input line editing field for dumb remote systems
- created an interface ICommandInputField with 3 methods: createControl,dispose and setFont. - concrete class CommandInputFieldWithHistory creates a Text widget and keeps a history - ITerminalViewControl has [sg]etCommandInputField. If null no input field is shown. - TerminalView got new action TooggleCommandInputField - TerminalView uses concrete class CommandInputFieldWithHistory and saves history in memento. The idea is that all handling and widget creating is done in ICommandInputField. New fancy implementations with incremental search, history pop-up, history manager etc just have to implement ICommandInputField. Or enhance CommandInputFieldWithHistory...
This commit is contained in:
parent
6cfb4e0fba
commit
572bf57a40
15 changed files with 361 additions and 23 deletions
Binary file not shown.
After Width: | Height: | Size: 385 B |
Binary file not shown.
After Width: | Height: | Size: 239 B |
Binary file not shown.
After Width: | Height: | Size: 239 B |
|
@ -24,6 +24,7 @@ public class ActionMessages extends NLS {
|
|||
}
|
||||
public static String NEW_TERMINAL;
|
||||
public static String CONNECT;
|
||||
public static String TOGGLE_COMMAND_INPUT_FIELD;
|
||||
public static String DISCONNECT;
|
||||
public static String SETTINGS_ELLIPSE;
|
||||
public static String COPY;
|
||||
|
|
|
@ -24,3 +24,4 @@ PASTE = Paste
|
|||
SELECTALL = Select All
|
||||
CLEARALL = Clear All
|
||||
SETTINGS = Settings
|
||||
TOGGLE_COMMAND_INPUT_FIELD= Toggle Command Input Field
|
||||
|
|
|
@ -25,7 +25,10 @@ import org.eclipse.tm.internal.terminal.view.TerminalViewPlugin;
|
|||
abstract public class TerminalAction extends Action {
|
||||
protected final ITerminalView fTarget;
|
||||
public TerminalAction(ITerminalView target, String strId) {
|
||||
super(""); //$NON-NLS-1$
|
||||
this(target,strId,0);
|
||||
}
|
||||
public TerminalAction(ITerminalView target, String strId, int style) {
|
||||
super("",style); //$NON-NLS-1$
|
||||
|
||||
fTarget = target;
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.actions;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.tm.internal.terminal.view.ITerminalView;
|
||||
import org.eclipse.tm.internal.terminal.view.ImageConsts;
|
||||
|
||||
public class TerminalActionToggleCommandInputField extends TerminalAction
|
||||
{
|
||||
public TerminalActionToggleCommandInputField(ITerminalView target)
|
||||
{
|
||||
super(target,
|
||||
TerminalActionToggleCommandInputField.class.getName(),IAction.AS_RADIO_BUTTON);
|
||||
|
||||
setupAction(ActionMessages.TOGGLE_COMMAND_INPUT_FIELD,
|
||||
ActionMessages.TOGGLE_COMMAND_INPUT_FIELD,
|
||||
ImageConsts.IMAGE_CLCL_COMMAND_INPUT_FIELD,
|
||||
ImageConsts.IMAGE_ELCL_COMMAND_INPUT_FIELD,
|
||||
ImageConsts.IMAGE_DLCL_COMMAND_INPUT_FIELD,
|
||||
true);
|
||||
setChecked(fTarget.hasCommandInputField());
|
||||
}
|
||||
public void run() {
|
||||
fTarget.setCommandInputField(!fTarget.hasCommandInputField());
|
||||
setChecked(fTarget.hasCommandInputField());
|
||||
}
|
||||
}
|
|
@ -26,4 +26,6 @@ public interface ITerminalView {
|
|||
public void onEditPaste();
|
||||
public void onEditClearAll();
|
||||
public void onEditSelectAll();
|
||||
public boolean hasCommandInputField();
|
||||
public void setCommandInputField(boolean on);
|
||||
}
|
||||
|
|
|
@ -41,4 +41,7 @@ public interface ImageConsts
|
|||
public static final String IMAGE_ELCL_CONNECT = "ImageElclConnect"; //$NON-NLS-1$
|
||||
public static final String IMAGE_ELCL_DISCONNECT = "ImageElclDisconnect"; //$NON-NLS-1$
|
||||
public static final String IMAGE_ELCL_SETTINGS = "ImageElclSettings"; //$NON-NLS-1$
|
||||
public static final String IMAGE_CLCL_COMMAND_INPUT_FIELD = "ImageClclCommandInputField";//$NON-NLS-1$
|
||||
public static final String IMAGE_ELCL_COMMAND_INPUT_FIELD = "ImageDlclCommandInputField";//$NON-NLS-1$
|
||||
public static final String IMAGE_DLCL_COMMAND_INPUT_FIELD = "ImageDlclCommandInputField";//$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ import org.eclipse.tm.internal.terminal.actions.TerminalActionNewTerminal;
|
|||
import org.eclipse.tm.internal.terminal.actions.TerminalActionPaste;
|
||||
import org.eclipse.tm.internal.terminal.actions.TerminalActionSelectAll;
|
||||
import org.eclipse.tm.internal.terminal.actions.TerminalActionSettings;
|
||||
import org.eclipse.tm.internal.terminal.actions.TerminalActionToggleCommandInputField;
|
||||
import org.eclipse.tm.internal.terminal.control.CommandInputFieldWithHistory;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
|
||||
import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory;
|
||||
|
@ -63,7 +65,13 @@ import org.eclipse.ui.actions.RetargetAction;
|
|||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
|
||||
public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$
|
||||
private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$
|
||||
|
||||
private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$NON-NLS-1$
|
||||
|
||||
private static final String STORE_COMMAND_INPUT_FIELD_HISTORY = "CommandInputFieldHistory"; //$NON-NLS-1$
|
||||
|
||||
public static final String FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$
|
||||
|
||||
protected ITerminalViewControl fCtlTerminal;
|
||||
|
||||
|
@ -85,6 +93,8 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
|
||||
protected TerminalAction fActionEditSelectAll;
|
||||
|
||||
protected TerminalAction fActionToggleCommandInputField;
|
||||
|
||||
protected TerminalMenuHandlerEdit fMenuHandlerEdit;
|
||||
|
||||
protected TerminalPropertyChangeHandler fPropertyChangeHandler;
|
||||
|
@ -93,6 +103,8 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
|
||||
private SettingsStore fStore;
|
||||
|
||||
private CommandInputFieldWithHistory fCommandInputField;
|
||||
|
||||
public TerminalView() {
|
||||
Logger
|
||||
.log("==============================================================="); //$NON-NLS-1$
|
||||
|
@ -265,11 +277,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
}
|
||||
|
||||
public void onTerminalFontChanged() {
|
||||
fCtlTerminal.getCtlText().setFont(JFaceResources.getFont(FONT_DEFINITION));
|
||||
|
||||
// Tell the TerminalControl singleton that the font has changed.
|
||||
|
||||
fCtlTerminal.onFontChanged();
|
||||
fCtlTerminal.setFont(JFaceResources.getFont(FONT_DEFINITION));
|
||||
}
|
||||
|
||||
public void onEditCopy() {
|
||||
|
@ -379,20 +387,22 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
protected void setupControls(Composite wndParent) {
|
||||
ITerminalConnector[] connectors=TerminalConnectorExtension.getTerminalConnectors();
|
||||
fCtlTerminal = TerminalViewControlFactory.makeControl(this, wndParent, connectors);
|
||||
String connectionType=fStore.get("ConnectionType"); //$NON-NLS-1$
|
||||
String connectionType=fStore.get(STORE_CONNECTION_TYPE);
|
||||
for (int i = 0; i < connectors.length; i++) {
|
||||
connectors[i].load(getStore(connectors[i]));
|
||||
if(connectors[i].getId().equals(connectionType))
|
||||
fCtlTerminal.setConnector(connectors[i]);
|
||||
}
|
||||
setCommandInputField("true".equals(fStore.get(STORE_HAS_COMMAND_INPUT_FIELD))); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private void saveSettings(ITerminalConnector connector) {
|
||||
ITerminalConnector[] connectors=fCtlTerminal.getConnectors();
|
||||
for (int i = 0; i < connectors.length; i++) {
|
||||
connectors[i].save(getStore(connectors[i]));
|
||||
}
|
||||
if(connector!=null) {
|
||||
fStore.put("ConnectionType",connector.getId()); //$NON-NLS-1$
|
||||
fStore.put(STORE_CONNECTION_TYPE,connector.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -403,6 +413,9 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
|
||||
public void saveState(IMemento memento) {
|
||||
super.saveState(memento);
|
||||
if(fCommandInputField!=null)
|
||||
fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory());
|
||||
fStore.put(STORE_HAS_COMMAND_INPUT_FIELD,hasCommandInputField()?"true":"false"); //$NON-NLS-1$//$NON-NLS-2$
|
||||
fStore.saveState(memento);
|
||||
}
|
||||
private ISettingsStore getStore(ITerminalConnector connector) {
|
||||
|
@ -419,6 +432,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
fActionEditPaste = new TerminalActionPaste(this);
|
||||
fActionEditClearAll = new TerminalActionClearAll(this);
|
||||
fActionEditSelectAll = new TerminalActionSelectAll(this);
|
||||
fActionToggleCommandInputField = new TerminalActionToggleCommandInputField(this);
|
||||
|
||||
IActionBars actionBars = getViewSite().getActionBars();
|
||||
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fActionEditCopy);
|
||||
|
@ -456,6 +470,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
toolBarMgr.add(fActionTerminalConnect);
|
||||
toolBarMgr.add(fActionTerminalDisconnect);
|
||||
toolBarMgr.add(fActionTerminalSettings);
|
||||
toolBarMgr.add(fActionToggleCommandInputField);
|
||||
}
|
||||
|
||||
protected void setupContextMenus() {
|
||||
|
@ -481,6 +496,7 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
menuMgr.add(new Separator());
|
||||
menuMgr.add(fActionEditClearAll);
|
||||
menuMgr.add(fActionEditSelectAll);
|
||||
menuMgr.add(fActionToggleCommandInputField);
|
||||
|
||||
// Other plug-ins can contribute there actions here
|
||||
menuMgr.add(new Separator("Additions")); //$NON-NLS-1$
|
||||
|
@ -625,4 +641,21 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCommandInputField() {
|
||||
return fCommandInputField!=null;
|
||||
}
|
||||
public void setCommandInputField(boolean on) {
|
||||
// save the old history
|
||||
if(fCommandInputField!=null) {
|
||||
fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory());
|
||||
fCommandInputField=null;
|
||||
}
|
||||
if(on) {
|
||||
// TODO make history size configurable
|
||||
fCommandInputField=new CommandInputFieldWithHistory(100);
|
||||
fCommandInputField.setHistory(fStore.get(STORE_COMMAND_INPUT_FIELD_HISTORY));
|
||||
}
|
||||
fCtlTerminal.setCommandInputField(fCommandInputField);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class TerminalViewPlugin extends AbstractUIPlugin {
|
|||
map.put(ImageConsts.IMAGE_CLCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_CLCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_CLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_CLCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$
|
||||
|
||||
loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_LOCALTOOL, map);
|
||||
|
||||
|
@ -59,6 +60,7 @@ public class TerminalViewPlugin extends AbstractUIPlugin {
|
|||
map.put(ImageConsts.IMAGE_ELCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_ELCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_ELCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_ELCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$
|
||||
|
||||
loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_ELCL, map);
|
||||
|
||||
|
@ -69,6 +71,7 @@ public class TerminalViewPlugin extends AbstractUIPlugin {
|
|||
map.put(ImageConsts.IMAGE_DLCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_DLCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_DLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
|
||||
map.put(ImageConsts.IMAGE_DLCL_COMMAND_INPUT_FIELD, "command_input_field.gif"); //$NON-NLS-1$
|
||||
|
||||
loadImageRegistry(imageRegistry, ImageConsts.IMAGE_DIR_DLCL, map);
|
||||
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.control;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.eclipse.swt.events.KeyListener;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
|
||||
/**
|
||||
* Manages the Command History for the command line input
|
||||
* of the terminal control.
|
||||
*
|
||||
*/
|
||||
public class CommandInputFieldWithHistory implements ICommandInputField {
|
||||
final List fHistory=new ArrayList();
|
||||
private int fHistoryPos=0;
|
||||
private final int fMaxSize;
|
||||
private boolean fInHistory=false;
|
||||
private Text fInputField;
|
||||
public CommandInputFieldWithHistory(int maxHistorySize) {
|
||||
fMaxSize=maxHistorySize;
|
||||
}
|
||||
/**
|
||||
* Add a line to the history.
|
||||
* @param line
|
||||
*/
|
||||
protected void pushLine(String line) {
|
||||
// if we used the history. therefore we added the current as 0th item
|
||||
if(fInHistory)
|
||||
fHistory.remove(0);
|
||||
fInHistory=false;
|
||||
fHistoryPos=0;
|
||||
// anything to remember?
|
||||
if(line==null || line.trim().length()==0)
|
||||
return;
|
||||
fHistory.add(0,line);
|
||||
// ignore if the same as last
|
||||
if(fHistory.size()>1 && line.equals(fHistory.get(1)))
|
||||
fHistory.remove(0);
|
||||
// limit the history size.
|
||||
if(fHistory.size()>=fMaxSize)
|
||||
fHistory.remove(fHistory.size()-1);
|
||||
}
|
||||
/**
|
||||
* Sets the history
|
||||
* @param history or null
|
||||
*/
|
||||
public void setHistory(String history) {
|
||||
fHistory.clear();
|
||||
if(history==null)
|
||||
return;
|
||||
fHistory.addAll(Arrays.asList(history.split("\n"))); //$NON-NLS-1$
|
||||
}
|
||||
/**
|
||||
* @return the current content of the history buffer and new line separated list
|
||||
*/
|
||||
public String getHistory() {
|
||||
StringBuffer buff=new StringBuffer();
|
||||
boolean sep=false;
|
||||
for (Iterator iterator = fHistory.iterator(); iterator.hasNext();) {
|
||||
String line=(String) iterator.next();
|
||||
if(line.length()>0) {
|
||||
if(sep)
|
||||
buff.append("\n"); //$NON-NLS-1$
|
||||
else
|
||||
sep=true;
|
||||
buff.append(line);
|
||||
}
|
||||
}
|
||||
return buff.toString();
|
||||
}
|
||||
/**
|
||||
* @param currLine
|
||||
* @param count (+1 or -1) for forward and backward movement. -1 goes back
|
||||
* @return the new string to be displayed in the command line or null,
|
||||
* if the limit is reached.
|
||||
*/
|
||||
public String move(String currLine, int count) {
|
||||
if(!fInHistory) {
|
||||
fInHistory=true;
|
||||
fHistory.add(0,currLine);
|
||||
} else {
|
||||
fHistory.set(fHistoryPos,currLine);
|
||||
}
|
||||
if(fHistoryPos+count>=fHistory.size())
|
||||
return null;
|
||||
if(fHistoryPos+count<0)
|
||||
return null;
|
||||
fHistoryPos+=count;
|
||||
return (String) fHistory.get(fHistoryPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit the history movements and go to position 0;
|
||||
* @return the string to be shown in the command line
|
||||
*/
|
||||
protected String escape() {
|
||||
if(!fInHistory)
|
||||
return null;
|
||||
fHistoryPos=0;
|
||||
return (String) fHistory.get(fHistoryPos);
|
||||
}
|
||||
public void createControl(Composite parent,final ITerminalViewControl terminal) {
|
||||
fInputField=new Text(parent, SWT.SINGLE|SWT.BORDER);
|
||||
fInputField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||
fInputField.setFont(terminal.getCtlText().getFont());
|
||||
fInputField.addKeyListener(new KeyListener(){
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.keyCode=='\n' || e.keyCode=='\r') {
|
||||
e.doit=false;
|
||||
String line=fInputField.getText();
|
||||
if(!terminal.pasteString(line+"\n")) //$NON-NLS-1$
|
||||
return;
|
||||
pushLine(line);
|
||||
setCommand("");//$NON-NLS-1$
|
||||
} else if(e.keyCode==SWT.ARROW_UP || e.keyCode==SWT.PAGE_UP) {
|
||||
e.doit=false;
|
||||
setCommand(move(fInputField.getText(),1));
|
||||
} else if(e.keyCode==SWT.ARROW_DOWN || e.keyCode==SWT.PAGE_DOWN) {
|
||||
e.doit=false;
|
||||
setCommand(move(fInputField.getText(),-1));
|
||||
} else if(e.keyCode==SWT.ESC) {
|
||||
e.doit=false;
|
||||
setCommand(escape());
|
||||
}
|
||||
}
|
||||
private void setCommand(String line) {
|
||||
if(line==null)
|
||||
return;
|
||||
fInputField.setText(line);
|
||||
fInputField.setSelection(fInputField.getCharCount());
|
||||
}
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
}
|
||||
public void setFont(Font font) {
|
||||
fInputField.setFont(font);
|
||||
fInputField.getParent().layout(true);
|
||||
}
|
||||
public void dispose() {
|
||||
fInputField.dispose();
|
||||
fInputField=null;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.control;
|
||||
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
/**
|
||||
* Interface to create a command input control.
|
||||
*
|
||||
*/
|
||||
public interface ICommandInputField {
|
||||
/**
|
||||
* @param parent
|
||||
* @param terminal
|
||||
*/
|
||||
void createControl(Composite parent, ITerminalViewControl terminal);
|
||||
|
||||
void dispose();
|
||||
/**
|
||||
* Sets the font of a control created with {@link #createControl(Composite, ITerminalViewControl)}
|
||||
* @param control
|
||||
* @param font the new text font
|
||||
*/
|
||||
void setFont(Font font);
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.control;
|
|||
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.tm.terminal.ITerminalConnector;
|
||||
import org.eclipse.tm.terminal.TerminalState;
|
||||
|
||||
|
@ -22,7 +23,7 @@ import org.eclipse.tm.terminal.TerminalState;
|
|||
*/
|
||||
public interface ITerminalViewControl {
|
||||
boolean isEmpty();
|
||||
void onFontChanged();
|
||||
void setFont(Font font);
|
||||
StyledText getCtlText();
|
||||
boolean isDisposed();
|
||||
void selectAll();
|
||||
|
@ -40,7 +41,23 @@ public interface ITerminalViewControl {
|
|||
ITerminalConnector getTerminalConnection();
|
||||
void setConnector(ITerminalConnector connector);
|
||||
void connectTerminal();
|
||||
/**
|
||||
* @param write a single character to terminal
|
||||
*/
|
||||
void sendKey(char arg0);
|
||||
/**
|
||||
* @param string write string to terminal
|
||||
*/
|
||||
public boolean pasteString(String string);
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
/**
|
||||
* @param inputField null means no input field is shown
|
||||
*/
|
||||
void setCommandInputField(ICommandInputField inputField);
|
||||
/**
|
||||
* @return null or the current input field
|
||||
*/
|
||||
ICommandInputField getCommandInputField();
|
||||
}
|
|
@ -35,11 +35,15 @@ import org.eclipse.swt.events.KeyListener;
|
|||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.VerifyEvent;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
|
||||
import org.eclipse.tm.terminal.ITerminalConnector;
|
||||
|
@ -85,16 +89,16 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
private ITerminalConnector fConnector;
|
||||
private final ITerminalConnector[] fConnectors;
|
||||
|
||||
private ICommandInputField fCommandInputField;
|
||||
|
||||
private volatile TerminalState fState;
|
||||
|
||||
public TerminalControl(ITerminalListener target, Composite wndParent, ITerminalConnector[] connectors) {
|
||||
fConnectors=connectors;
|
||||
fTerminalListener=target;
|
||||
fWndParent = wndParent;
|
||||
|
||||
setTerminalText(new TerminalText(this));
|
||||
|
||||
setupTerminal();
|
||||
setupTerminal(wndParent);
|
||||
}
|
||||
|
||||
public ITerminalConnector[] getConnectors() {
|
||||
|
@ -114,11 +118,7 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
public void paste() {
|
||||
TextTransfer textTransfer = TextTransfer.getInstance();
|
||||
String strText = (String) fClipboard.getContents(textTransfer);
|
||||
if (strText == null)
|
||||
return;
|
||||
for (int i = 0; i < strText.length(); i++) {
|
||||
sendChar(strText.charAt(i), false);
|
||||
}
|
||||
pasteString(strText);
|
||||
// TODO paste in another thread.... to avoid blocking
|
||||
// new Thread() {
|
||||
// public void run() {
|
||||
|
@ -130,6 +130,20 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
// }.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strText
|
||||
*/
|
||||
public boolean pasteString(String strText) {
|
||||
if(!isConnected())
|
||||
return false;
|
||||
if (strText == null)
|
||||
return false;
|
||||
for (int i = 0; i < strText.length(); i++) {
|
||||
sendChar(strText.charAt(i), false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.ITerminalControl#selectAll()
|
||||
*/
|
||||
|
@ -358,9 +372,9 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.ITerminalControl#setupTerminal()
|
||||
*/
|
||||
public void setupTerminal() {
|
||||
public void setupTerminal(Composite parent) {
|
||||
fState=TerminalState.CLOSED;
|
||||
setupControls();
|
||||
setupControls(parent);
|
||||
setupListeners();
|
||||
setupHelp(fWndParent, TerminalPlugin.HELP_VIEW);
|
||||
}
|
||||
|
@ -368,11 +382,18 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.tm.terminal.ITerminalControl#onFontChanged()
|
||||
*/
|
||||
public void onFontChanged() {
|
||||
public void setFont(Font font) {
|
||||
getCtlText().setFont(font);
|
||||
if(fCommandInputField!=null) {
|
||||
fCommandInputField.setFont(font);
|
||||
}
|
||||
|
||||
// Tell the TerminalControl singleton that the font has changed.
|
||||
|
||||
getTerminalText().fontChanged();
|
||||
}
|
||||
|
||||
protected void setupControls() {
|
||||
protected void setupControls(Composite parent) {
|
||||
// The Terminal view now aims to be an ANSI-conforming terminal emulator, so it
|
||||
// can't have a horizontal scroll bar (but a vertical one is ok). Also, do
|
||||
// _not_ make the TextViewer read-only, because that prevents it from seeing a
|
||||
|
@ -380,8 +401,15 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
// switch to another Workbench control). We prevent local keyboard input from
|
||||
// modifying the text in method TerminalVerifyKeyListener.verifyKey().
|
||||
|
||||
// fViewer = new TextViewer(fWndParent, SWT.V_SCROLL);
|
||||
fWndParent=new Composite(parent,SWT.NONE);
|
||||
GridLayout layout=new GridLayout();
|
||||
layout.marginWidth=0;
|
||||
layout.marginHeight=0;
|
||||
|
||||
fWndParent.setLayout(layout);
|
||||
setCtlText(new StyledText(fWndParent, SWT.V_SCROLL));
|
||||
fCtlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
|
||||
|
||||
fDisplay = getCtlText().getDisplay();
|
||||
fClipboard = new Clipboard(fDisplay);
|
||||
|
@ -791,4 +819,16 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
fConnector=connector;
|
||||
|
||||
}
|
||||
public ICommandInputField getCommandInputField() {
|
||||
return fCommandInputField;
|
||||
}
|
||||
|
||||
public void setCommandInputField(ICommandInputField inputField) {
|
||||
if(fCommandInputField!=null)
|
||||
fCommandInputField.dispose();
|
||||
fCommandInputField=inputField;
|
||||
if(fCommandInputField!=null)
|
||||
fCommandInputField.createControl(fWndParent, this);
|
||||
fWndParent.layout(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue