[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Another editor patch
|
Hi all,
commiting the following code into org.eclipse.cdt.ui.
It fixes a problem where the status line number/insert
were not being updated properly with the move to 2.0.
Also removes the duplicate status line contributions.
Sebastien
Index: CEditor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEdito
r.java,v
retrieving revision 1.3
diff -c -r1.3 CEditor.java
*** CEditor.java 9 Aug 2002 02:31:24 -0000 1.3
--- CEditor.java 9 Aug 2002 21:07:27 -0000
***************
*** 805,842 ****
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());
--- 805,810 ----
***************
*** 852,942 ****
startBracketHighlighting();
- }
-
- /*
- * @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) {
--- 820,825 ----
Index: CEditorActionContributor.java
===================================================================
RCS file:
/home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEdito
rActionContributor.java,v
retrieving revision 1.1
diff -c -r1.1 CEditorActionContributor.java
*** CEditorActionContributor.java 26 Jun 2002 20:55:44 -0000 1.1
--- CEditorActionContributor.java 9 Aug 2002 21:07:27 -0000
***************
*** 24,29 ****
--- 24,30 ----
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,106 ****
//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() {
--- 96,101 ----
***************
*** 124,133 ****
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]));
}
--- 119,124 ----
***************
*** 181,191 ****
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);
--- 172,178 ----
ITextEditor textEditor= null;
if (part instanceof ITextEditor)
textEditor= (ITextEditor) part;
!
fShiftRight.setEditor(textEditor);
fShiftLeft.setEditor(textEditor);
***************
*** 197,208 ****
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]);
- }
}
/*
--- 184,189 ----
***************
*** 210,218 ****
*
* More code here only until we move to 2.0...
*/
! public void contributeToStatusLine(IStatusLineManager
statusLineManager) {
super.contributeToStatusLine(statusLineManager);
! for (int i= 0; i < STATUSFIELDS.length; i++)
! statusLineManager.add((IContributionItem)
fStatusFields.get(STATUSFIELDS[i]));
}
}
--- 191,198 ----
*
* More code here only until we move to 2.0...
*/
! public void contributeeToStatusLine(IStatusLineManager
statusLineManager) {
super.contributeToStatusLine(statusLineManager);
!
}
}
Index: StatusLineContributionItem.java
===================================================================
RCS file: StatusLineContributionItem.java
diff -N StatusLineContributionItem.java
*** StatusLineContributionItem.java 26 Jun 2002 20:55:44 -0000 1.1
--- /dev/null 1 Jan 1970 00:00:00 -0000
***************
*** 1,98 ****
- 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);
- }
- }
-
-
--- 0 ----