1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

2005-02-016 Alain Magloire

PR 84423, Patch from :  Tomaszewski Przemek
	Added keybinding next/previous(CTRL-SHIFT-UP/DOWN) to from
	member to member in the CEditor(PR 84423).

	* NEWS
	* plugin.properties
	* plugin.xml
	* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
	* src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties
	* src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java
	* src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
This commit is contained in:
Alain Magloire 2005-02-06 20:33:25 +00:00
parent 401c7a5866
commit b941f8c76f
9 changed files with 316 additions and 25 deletions

View file

@ -1,3 +1,16 @@
2005-02-016 Alain Magloire
PR 84423, Patch from : Tomaszewski Przemek
Added keybinding next/previous(CTRL-SHIFT-UP/DOWN) to from
member to member in the CEditor(PR 84423).
* NEWS
* plugin.properties
* plugin.xml
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
* src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties
* src/org/eclipse/cdt/internal/ui/editor/CSourceViewer.java
* src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java
2005-02-02 Bogdan Gheorghe
Added a delete IProblem Markers action to context menu to allow users to manually
remove problems reported by the parser during an index.

View file

@ -1,5 +1,8 @@
Release CDT-3.0
* Added keybinding next/previous(CTRL-SHIFT-UP/DOWN) to move from
member to member in the CEditor(PR 84423).
* Drag && Drop support
for ICElement classes , in the C/C++ project view and C Outliner.

View file

@ -170,6 +170,11 @@ CEditorFontDefinition.description = The C/C++ editor text font is used by C/C++
BuildConsoleFontDefinition.description= The C-Build console font is used by the C-Build console
BuildConsoleFontDefinition.label= C-Build Console Text Font
ActionDefinition.GotoNextMember.name = Go to next C/C++ member
ActionDefinition.GotoNextMember.description = Goes to the next C/C++ member
ActionDefinition.GotoPrevMember.name = Go to previous C/C++ member
ActionDefinition.GotoPrevMember.description = Goes to the previous C/C++ member
##########################################################################
# Filter Support
##########################################################################

View file

@ -969,6 +969,30 @@
command="org.eclipse.cdt.ui.edit.open.outline"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</keyBinding>
<command
name="%ActionDefinition.GotoNextMember.name"
description="%ActionDefinition.GotoNextMember.description"
category="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.goto.next.member">
</command>
<keyBinding
string="Ctrl+Shift+ARROW_DOWN"
scope="org.eclipse.cdt.ui.cEditorScope"
command="org.eclipse.cdt.ui.edit.text.c.goto.next.member"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</keyBinding>
<command
name="%ActionDefinition.GotoPrevMember.name"
description="%ActionDefinition.GotoPrevMember.description"
category="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.goto.prev.member">
</command>
<keyBinding
string="Ctrl+Shift+ARROW_UP"
scope="org.eclipse.cdt.ui.cEditorScope"
command="org.eclipse.cdt.ui.edit.text.c.goto.prev.member"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</keyBinding>
</extension>
<extension
id="org.eclipse.cdt.ui.CSearchPage"

View file

@ -0,0 +1,158 @@
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* P.Tomaszewski
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
import java.util.LinkedList;
import java.util.List;
import java.util.ResourceBundle;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.internal.core.model.WorkingCopy;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;
/**
* Gives possibility to move fast between member elements of the c/c++ source.
*
* @author P.Tomaszewski
*/
public class GoToNextPreviousMemberAction extends TextEditorAction {
/** Determines should action take user to the next member or to the previous one. */
private boolean fGotoNext;
/**
* Creates new action.
* @param bundle Resource bundle.
* @param prefix Prefix.
* @param editor Editor.
* @param gotoNext Is it go to next or previous action.
*/
public GoToNextPreviousMemberAction(ResourceBundle bundle, String prefix, ITextEditor editor, boolean gotoNext) {
super(bundle, prefix, editor);
fGotoNext = gotoNext;
}
/**
* Creates new action.
* @param bundle Resource bundle.
* @param prefix Prefix.
* @param editor Editor.
* @param style UI style.
* @param gotoNext Is it go to next or previous action.
*/
public GoToNextPreviousMemberAction(ResourceBundle bundle, String prefix, ITextEditor editor, int style, boolean gotoNext) {
super(bundle, prefix, editor, style);
fGotoNext = gotoNext;
}
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
final CEditor editor = (CEditor) getTextEditor();
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
final IEditorInput editorInput = editor.getEditorInput();
final WorkingCopy workingCopy = (WorkingCopy) CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
try {
final ICElement[] elements = workingCopy.getChildren();
final Integer[] elementOffsets = createSourceIndexes(elements);
final ICElement selectedElement = workingCopy.getElementAtOffset(selection.getOffset());
if (selectedElement != null && selectedElement instanceof ISourceReference) {
final int offset = ((ISourceReference) selectedElement).getSourceRange().getStartPos();
final int offsetToSelect = fGotoNext ? getNextOffset(elementOffsets, offset) : getPreviousOffset(elementOffsets, offset);
editor.selectAndReveal(offsetToSelect, 0);
} else if (selectedElement == null) {
final int offset = selection.getOffset();
final int offsetToSelect = fGotoNext ? getNextOffset(elementOffsets, offset) : getPreviousOffset(elementOffsets, offset);
editor.selectAndReveal(offsetToSelect, 0);
} else {
//System.out.println("Selected element class:" + selectedElement.getClass()); //$NON-NLS-1$
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
//System.out.println("Exception:" + e.getMessage()); //$NON-NLS-1$
}
}
/**
* Searches for next offset within array of offsets.
* @param offsets Offsets to search.
* @param actualOffset Actual offsets.
* @return Found offset or actual.
*/
private static int getNextOffset(Integer[] offsets, int actualOffset) {
if (actualOffset < offsets[0].intValue())
{
return offsets[0].intValue();
}
for (int i = 0; i < offsets.length - 1; i++) {
if (offsets[i].intValue() == actualOffset) {
return offsets[i + 1].intValue();
} else if ((actualOffset > offsets[i].intValue())
&& (actualOffset < offsets[i + 1].intValue())) {
return offsets[i + 1].intValue();
}
}
return actualOffset;
}
/**
* Searches for previous offset within array of offsets.
* @param offsets Offsets to search.
* @param actualOffset Actual offset.
* @return Found offset or actual.
*/
private static int getPreviousOffset(Integer[] offsets, int actualOffset) {
if (actualOffset > offsets[offsets.length - 1].intValue())
{
return offsets[offsets.length - 1].intValue();
}
for (int i = 1; i < offsets.length; i++) {
if (offsets[i].intValue() == actualOffset) {
return offsets[i - 1].intValue();
} else if ((actualOffset > offsets[i - 1].intValue())
&& (actualOffset < offsets[i].intValue())) {
return offsets[i - 1].intValue();
}
}
return actualOffset;
}
/**
* Creates array in indexes from ICElements.
* @param elements Elements to retrieve needed data.
* @return indexes.
* @throws CModelException Thrown if source range not found.
*/
private static Integer[] createSourceIndexes(ICElement[] elements) throws CModelException
{
final List indexesList = new LinkedList();
for (int i = 0; i < elements.length; i++) {
if (elements[i] instanceof ISourceReference) {
indexesList.add(new Integer(((ISourceReference) elements[i]).getSourceRange().getStartPos()));
}
}
//System.out.println("Indexes list:" + indexesList); //$NON-NLS-1$
final Integer[] indexes = new Integer[indexesList.size()];
indexesList.toArray(indexes);
return indexes;
}
}

View file

@ -1,9 +1,9 @@
package org.eclipse.cdt.internal.ui.editor;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
package org.eclipse.cdt.internal.ui.editor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -22,6 +22,7 @@ import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.actions.AddBlockCommentAction;
import org.eclipse.cdt.internal.ui.actions.FoldingActionGroup;
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
import org.eclipse.cdt.internal.ui.browser.typehierarchy.OpenTypeHierarchyAction;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
@ -119,7 +120,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
*/
private class EditorSelectionChangedListener extends AbstractSelectionChangedListener {
/*
/**
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/
public void selectionChanged(SelectionChangedEvent event) {
@ -141,7 +142,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
/** Search actions **/
private ActionGroup fSelectionSearchGroup;
/** Groups refactoring actions. */
private ActionGroup fRefactoringActionGroup;
/** Action which shows selected element in CView. */
private ShowInCViewAction fShowInCViewAction;
/** Activity Listeners **/
@ -153,9 +156,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
/** The mouse listener */
private MouseClickListener fMouseListener;
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']', '<', '>' };
/** Pairs of brackets, used to match. */
protected final static char[] BRACKETS = { '{', '}', '(', ')', '[', ']', '<', '>' };
protected CPairMatcher fBracketMatcher = new CPairMatcher(BRACKETS);
/** Matches the brackets. */
protected CPairMatcher fBracketMatcher = new CPairMatcher(BRACKETS);
/** The editor's tab converter */
private TabConverter fTabConverter;
@ -163,9 +168,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
/** Listener to annotation model changes that updates the error tick in the tab image */
private CEditorErrorTickUpdater fCEditorErrorTickUpdater;
/* Preference key for matching brackets */
/** Preference key for matching brackets */
public final static String MATCHING_BRACKETS = "matchingBrackets"; //$NON-NLS-1$
/* Preference key for matching brackets color */
/** Preference key for matching brackets color */
public final static String MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; //$NON-NLS-1$
/** Preference key for inserting spaces rather than tabs */
public final static String SPACES_FOR_TABS = "spacesForTabs"; //$NON-NLS-1$
@ -204,13 +209,19 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
*/
private IMarker fLastMarkerTarget= null;
/**
* Handles property changes.
*/
private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener, org.eclipse.jface.util.IPropertyChangeListener {
/*
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
/**
* @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/
public void propertyChange(org.eclipse.jface.util.PropertyChangeEvent event) {
handlePreferencePropertyChanged(event);
}
/**
* @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
*/
public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
handlePreferencePropertyChanged(new org.eclipse.jface.util.PropertyChangeEvent(event.getSource(), event.getProperty(), event.getOldValue(), event.getNewValue()));
}
@ -223,7 +234,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
super();
}
/* (non-Javadoc)
/**
* @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#initializeEditor()
*/
protected void initializeEditor() {
@ -244,7 +255,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
fCEditorErrorTickUpdater = new CEditorErrorTickUpdater(this);
}
/* (non-Javadoc)
/**
* @see org.eclipse.ui.texteditor.AbstractTextEditor#doSetInput(org.eclipse.ui.IEditorInput)
*/
protected void doSetInput(IEditorInput input) throws CoreException {
@ -257,7 +268,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
}
/**
* Update the title image
* Update the title image.
* @param image Title image.
*/
public void updatedTitleImage(Image image) {
setTitleImage(image);
@ -265,6 +277,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
/**
* Gets the current input
* @return IFile Input file.
*/
public IFile getInputFile() {
IEditorInput editorInput = getEditorInput();
@ -276,11 +289,15 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
return null;
}
public boolean isSaveAsAllowed() {
/**
* @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
*/
public boolean isSaveAsAllowed() {
return true;
}
/**
* Gets the outline page of the c-editor
* Gets the outline page of the c-editor.
* @return Outline page.
*/
public CContentOutlinePage getOutlinePage() {
if (fOutlinePage == null) {
@ -291,7 +308,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
return fOutlinePage;
}
/* (non-Javadoc)
/**
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
public Object getAdapter(Class required) {
@ -402,7 +419,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
updateStatusLine();
}
/* (non-Javadoc)
/**
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/
public void selectionChanged(SelectionChangedEvent event) {
@ -417,12 +434,17 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
setSelection(range, !isActivePart());
}
} catch (CModelException e) {
// Selection change not applied.
}
}
}
}
public void setSelection(ICElement element) {
/**
* Sets selection for C element.
* @param element Element to select.
*/
public void setSelection(ICElement element) {
if (element == null || element instanceof ITranslationUnit) {
/*
@ -445,7 +467,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
}
}
public void setSelection(ISourceReference element, boolean moveCursor) {
/**
* Sets selection for source reference.
* @param element Source reference to set.
* @param moveCursor Should cursor be moved.
*/
public void setSelection(ISourceReference element, boolean moveCursor) {
if (element != null) {
StyledText textWidget= null;
@ -459,6 +486,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
try {
setSelection(element.getSourceRange(), moveCursor);
} catch (CModelException e) {
// Selection not applied.
}
}
}
@ -524,20 +552,29 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
}
return;
} catch (IllegalArgumentException x) {
// No information to the user
} catch (BadLocationException e) {
// No information to the user
}
if (moveCursor)
resetHighlightRange();
}
private boolean isActivePart() {
/**
* Checks is the editor active part.
* @return <code>true</code> if editor is the active part of the workbench.
*/
private boolean isActivePart() {
IWorkbenchWindow window = getSite().getWorkbenchWindow();
IPartService service = window.getPartService();
return (this == service.getActivePart());
}
public void dispose() {
/**
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
public void dispose() {
if (fProjectionModelUpdater != null) {
fProjectionModelUpdater.uninstall();
@ -610,7 +647,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
super.dispose();
}
/* (non-Javadoc)
/**
* @see org.eclipse.ui.texteditor.AbstractTextEditor#canHandleMove(org.eclipse.ui.IEditorInput, org.eclipse.ui.IEditorInput)
*/
protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) {
@ -640,6 +677,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
return oldLanguage.equals(newLanguage);
}
/**
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
*/
protected void createActions() {
super.createActions();
@ -706,7 +746,15 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
setAction("OpenOutline", action); //$NON-NLS-1$*/
//Assorted action groupings
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoNextMemeber.", this, true);
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
setAction("GotoNextMember", action); //$NON-NLS-1$*/
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoPrevMemeber.", this, false);
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_PREVIOUS_MEMBER);
setAction("GotoPrevMember", action); //$NON-NLS-1$*/
//Assorted action groupings
fSelectionSearchGroup = new SelectionSearchGroup(this);
fRefactoringActionGroup = new RefactoringActionGroup(this, null);
@ -716,6 +764,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
}
/**
* @see org.eclipse.ui.texteditor.AbstractTextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
*/
public void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
@ -732,6 +783,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenDeclarations"); //$NON-NLS-1$
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "OpenTypeHierarchy"); //$NON-NLS-1$
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoNextMember"); //$NON-NLS-1$
addAction(menu, ITextEditorActionConstants.GROUP_FIND, "GotoPrevMember"); //$NON-NLS-1$
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "ContentAssistProposal"); //$NON-NLS-1$
addAction(menu, IContextMenuConstants.GROUP_GENERATE, "AddIncludeOnSelection"); //$NON-NLS-1$
@ -744,13 +797,22 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
}
public void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) {
/**
* Sets an input for the outline page.
* @param page Page to set the input.
* @param input Input to set.
*/
public static void setOutlinePageInput(CContentOutlinePage page, IEditorInput input) {
if (page != null) {
IWorkingCopyManager manager = CUIPlugin.getDefault().getWorkingCopyManager();
page.setInput(manager.getWorkingCopy(input));
}
}
/**
* Determines is folding enabled.
* @return <code>true</code> if folding is enabled, <code>false</code> otherwise.
*/
boolean isFoldingEnabled() {
return CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED);
}
@ -764,6 +826,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
* We attach our own mouseDown listener on the menu bar,
* and our own listener for cursor/key/selection events to update cursor position in
* status bar.
* @param parent Parent composite of the control.
*/
public void createPartControl(Composite parent) {
super.createPartControl(parent);
@ -804,6 +868,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
preferences.addPropertyChangeListener(fPropertyChangeListener);
}
/**
* Returns a next error in the editor.
* @param offset Offset to start check.
* @param forward Do check forward.
* @return Found error marker or <code>null</code>.
*/
private IMarker getNextError(int offset, boolean forward) {
IMarker nextError = null;

View file

@ -170,3 +170,10 @@ CEditor.menu.search=Search
EditorUtility.concatModifierStrings= {0} + {1}
OpenOnSelection.label=Open On Selection
GotoNextMemeber.description=Goes to next member
GotoNextMemeber.label=Go to &next member
GotoNextMemeber.tooltip=Goes to next member
GotoPrevMemeber.description=Goes to previous member
GotoPrevMemeber.label=Go to &previous member
GotoPrevMemeber.tooltip=Goes to previous member.

View file

@ -101,7 +101,6 @@ public class CSourceViewer extends ProjectionViewer implements ITextViewerExtens
}
case SHOW_OUTLINE:
{
System.out.println("Show outline operation called.");
fOutlinePresenter.showInformation();
return;
}

View file

@ -114,8 +114,20 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
public static final String OPEN_EDITOR= "org.eclipse.cdt.ui.edit.text.c.open.editor"; //$NON-NLS-1$
/**
* Action definition ID of the open outline dialog.
* Action definition ID of the open quick outline.
* (value <code>"org.eclipse.cdt.ui.edit.open.outline"</code>).
*/
public static final String OPEN_OUTLINE= "org.eclipse.cdt.ui.edit.open.outline"; //$NON-NLS-1$
/**
* Action definition ID for go to next c member.
* (value <code>"org.eclipse.cdt.ui.edit.text.c.goto.next.memeber"</code>)
*/
public static final String GOTO_NEXT_MEMBER = "org.eclipse.cdt.ui.edit.text.c.goto.next.member"; //$NON-NLS-1$
/**
* Action definition ID for go to previous c member.
* (value <code>"org.eclipse.cdt.ui.edit.text.c.goto.prev.memeber"</code>)
*/
public static final String GOTO_PREVIOUS_MEMBER = "org.eclipse.cdt.ui.edit.text.c.goto.prev.member"; //$NON-NLS-1$
}