mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix up the status line contributions so they work with the 2.0
AbstractTextEditor
This commit is contained in:
parent
547d7800c0
commit
9089dd4dcc
3 changed files with 4 additions and 239 deletions
|
@ -805,38 +805,6 @@ public class CEditor extends AbstractTextEditor implements ISelectionChangedList
|
|||
|
||||
getSelectionProvider().addSelectionChangedListener(sListener);
|
||||
|
||||
ICursorListener fCursorListener = new ICursorListener() {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.keyCode != 0) {
|
||||
StyledText styledText= (StyledText) e.widget;
|
||||
int action = styledText.getKeyBinding(e.keyCode | e.stateMask);
|
||||
if (ST.TOGGLE_OVERWRITE == action) {
|
||||
fInserting= !fInserting;
|
||||
updateStatusField(CTextEditorActionConstants.STATUS_INPUT_MODE);
|
||||
} else { //if(action == ST.LINE_UP || action == ST.LINE_DOWN || action == ST.COLUMN_NEXT || action == ST.COLUMN_PREVIOUS) {
|
||||
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyReleased(KeyEvent e) {
|
||||
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
|
||||
}
|
||||
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseDown(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseUp(MouseEvent e) {
|
||||
updateStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
|
||||
}
|
||||
};
|
||||
|
||||
StyledText styledText= getSourceViewer().getTextWidget();
|
||||
styledText.addMouseListener(fCursorListener);
|
||||
styledText.addKeyListener(fCursorListener);
|
||||
|
||||
initializeViewerColors(getSourceViewer());
|
||||
|
||||
|
@ -854,91 +822,6 @@ public class CEditor extends AbstractTextEditor implements ISelectionChangedList
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
* @see ITextEditorExtension#setStatusField(IStatusField, String)
|
||||
*/
|
||||
public void setStatusField(IStatusField field, String category) {
|
||||
//Assert.isNotNull(category);
|
||||
if (field != null) {
|
||||
|
||||
if (fStatusFields == null)
|
||||
fStatusFields= new HashMap(3);
|
||||
|
||||
fStatusFields.put(category, field);
|
||||
updateStatusField(category);
|
||||
|
||||
} else if (fStatusFields != null)
|
||||
fStatusFields.remove(category);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the status fields for the given category.
|
||||
*
|
||||
* @param category
|
||||
*/
|
||||
protected void updateStatusField(String category) {
|
||||
if (CTextEditorActionConstants.STATUS_CURSOR_POS.equals(category)) {
|
||||
|
||||
IStatusField field= getStatusField(CTextEditorActionConstants.STATUS_CURSOR_POS);
|
||||
if (field != null)
|
||||
field.setText(getCursorPosition());
|
||||
|
||||
} else if (CTextEditorActionConstants.STATUS_INPUT_MODE.equals(category)) {
|
||||
|
||||
IStatusField field= getStatusField(CTextEditorActionConstants.STATUS_INPUT_MODE);
|
||||
if (field != null)
|
||||
field.setText(isInInsertMode() ? "Insert" : "Overwrite");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this editor is in overwrite or insert mode.
|
||||
*
|
||||
* @return <code>true</code> if in insert mode,
|
||||
* <code>false</code> for overwrite mode
|
||||
*/
|
||||
protected boolean isInInsertMode() {
|
||||
return fInserting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a description of the cursor position.
|
||||
*
|
||||
* @return a description of the cursor position
|
||||
*/
|
||||
protected String getCursorPosition() {
|
||||
ISourceViewer viewer = getSourceViewer();
|
||||
if(viewer == null)
|
||||
return "";
|
||||
StyledText styledText= viewer.getTextWidget();
|
||||
|
||||
int offset= viewer.getVisibleRegion().getOffset();
|
||||
int caret= offset + styledText.getCaretOffset();
|
||||
IDocument document= viewer.getDocument();
|
||||
|
||||
try {
|
||||
|
||||
int line=document.getLineOfOffset(caret);
|
||||
|
||||
int lineOffset= document.getLineOffset(line);
|
||||
int occurrences= 0;
|
||||
for (int i= lineOffset; i < caret; i++)
|
||||
if ('\t' == document.getChar(i))
|
||||
++ occurrences;
|
||||
|
||||
int tabWidth= styledText.getTabs();
|
||||
int column= caret - lineOffset + (tabWidth -1) * occurrences;
|
||||
|
||||
return ((line + 1) + " : " + (column + 1));
|
||||
|
||||
} catch (BadLocationException x) {
|
||||
return "??";
|
||||
}
|
||||
}
|
||||
|
||||
private Color getColor(String key) {
|
||||
RGB rgb= PreferenceConverter.getColor(getPreferenceStore(), key);
|
||||
return getColor(rgb);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
|
|||
import org.eclipse.ui.texteditor.IStatusField;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
|
||||
import org.eclipse.ui.texteditor.StatusLineContributionItem;
|
||||
import org.eclipse.ui.texteditor.TextEditorAction;
|
||||
import org.eclipse.ui.texteditor.TextOperationAction;
|
||||
|
||||
|
@ -95,12 +96,6 @@ public class CEditorActionContributor extends BasicTextEditorActionContributor {
|
|||
//private ToggleTextHoverAction fToggleTextHover;
|
||||
private GotoErrorAction fPreviousError;
|
||||
private GotoErrorAction fNextError;
|
||||
private Map fStatusFields;
|
||||
|
||||
private final static String[] STATUSFIELDS= {
|
||||
CTextEditorActionConstants.STATUS_INPUT_MODE,
|
||||
CTextEditorActionConstants.STATUS_CURSOR_POS,
|
||||
};
|
||||
|
||||
|
||||
public CEditorActionContributor() {
|
||||
|
@ -124,10 +119,6 @@ public class CEditorActionContributor extends BasicTextEditorActionContributor {
|
|||
CPluginImages.setImageDescriptors(fPreviousError, CPluginImages.T_TOOL, CPluginImages.IMG_TOOL_GOTO_PREV_ERROR);
|
||||
fNextError= new GotoErrorAction("Editor.NextError.", true); //$NON-NLS-1$
|
||||
CPluginImages.setImageDescriptors(fNextError, CPluginImages.T_TOOL, CPluginImages.IMG_TOOL_GOTO_NEXT_ERROR);
|
||||
|
||||
fStatusFields= new HashMap(3);
|
||||
for (int i= 0; i < STATUSFIELDS.length; i++)
|
||||
fStatusFields.put(STATUSFIELDS[i], new StatusLineContributionItem(STATUSFIELDS[i]));
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,11 +172,7 @@ public class CEditorActionContributor extends BasicTextEditorActionContributor {
|
|||
ITextEditor textEditor= null;
|
||||
if (part instanceof ITextEditor)
|
||||
textEditor= (ITextEditor) part;
|
||||
|
||||
if (part instanceof CEditor) {
|
||||
for (int i= 0; i < STATUSFIELDS.length; i++)
|
||||
((CEditor)part).setStatusField(null, STATUSFIELDS[i]);
|
||||
}
|
||||
|
||||
|
||||
fShiftRight.setEditor(textEditor);
|
||||
fShiftLeft.setEditor(textEditor);
|
||||
|
@ -197,12 +184,6 @@ public class CEditorActionContributor extends BasicTextEditorActionContributor {
|
|||
fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
|
||||
fOpenOnSelection.setAction(getAction(textEditor, "OpenOnSelection")); //$NON-NLS-1$
|
||||
|
||||
|
||||
if (part instanceof CEditor) {
|
||||
CEditor ed = (CEditor) part;
|
||||
for (int i= 0; i < STATUSFIELDS.length; i++)
|
||||
ed.setStatusField((IStatusField) fStatusFields.get(STATUSFIELDS[i]), STATUSFIELDS[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -210,9 +191,8 @@ public class CEditorActionContributor extends BasicTextEditorActionContributor {
|
|||
*
|
||||
* More code here only until we move to 2.0...
|
||||
*/
|
||||
public void contributeToStatusLine(IStatusLineManager statusLineManager) {
|
||||
public void contributeeToStatusLine(IStatusLineManager statusLineManager) {
|
||||
super.contributeToStatusLine(statusLineManager);
|
||||
for (int i= 0; i < STATUSFIELDS.length; i++)
|
||||
statusLineManager.add((IContributionItem) fStatusFields.get(STATUSFIELDS[i]));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
/*
|
||||
* (c) Copyright IBM Corp. 2000, 2001.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is temporarily here to provide some editor line/column numbers.
|
||||
* This is all in Eclipse 2.0, so we remove it when we move forward to that version.
|
||||
*/
|
||||
|
||||
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.texteditor.IStatusField;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Contribution item for the status line.
|
||||
*/
|
||||
public class StatusLineContributionItem extends ContributionItem implements IStatusField {
|
||||
|
||||
|
||||
static class StatusLineLabel extends CLabel {
|
||||
|
||||
private static int INDENT= 3; // left and right margin used in CLabel
|
||||
|
||||
private Point fFixedSize;
|
||||
|
||||
public StatusLineLabel(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
|
||||
GC gc= new GC(parent);
|
||||
gc.setFont(parent.getFont());
|
||||
Point extent= gc.textExtent("MMMMMMMMM");
|
||||
gc.dispose();
|
||||
|
||||
fFixedSize= new Point(extent.x + INDENT * 2, 10);
|
||||
}
|
||||
|
||||
public Point computeSize(int wHint, int hHint, boolean changed) {
|
||||
return fFixedSize;
|
||||
}
|
||||
};
|
||||
|
||||
private String fText;
|
||||
private Image fImage;
|
||||
private StatusLineLabel fLabel;
|
||||
|
||||
/**
|
||||
* Creates a new item with the given id.
|
||||
*
|
||||
* @param id the item's id
|
||||
*/
|
||||
StatusLineContributionItem(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IStatusField#setText
|
||||
*/
|
||||
public void setText(String text) {
|
||||
fText= text;
|
||||
if (fLabel != null && !fLabel.isDisposed()) {
|
||||
fLabel.setText(fText);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IStatusField#setImage(Image)
|
||||
*/
|
||||
public void setImage(Image image) {
|
||||
fImage= image;
|
||||
if (fLabel != null && !fLabel.isDisposed()) {
|
||||
fLabel.setImage(fImage);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IContributionItem#fill(Composite)
|
||||
*/
|
||||
public void fill(Composite parent) {
|
||||
fLabel= new StatusLineLabel(parent, SWT.SHADOW_IN);
|
||||
fLabel.setData(this);
|
||||
|
||||
if (fText != null)
|
||||
fLabel.setText(fText);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue