mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Todd
This commit is contained in:
parent
7c13219552
commit
a17df8ba39
6 changed files with 251 additions and 23 deletions
|
@ -27,6 +27,8 @@ AddBlockCommentAction.label= Add &Block Comment
|
|||
|
||||
RemoveBlockCommentAction.label= Remove Bloc&k Comment
|
||||
|
||||
JoinLinesAction.label= Join Lines
|
||||
|
||||
# The Wizards
|
||||
# C
|
||||
newCWizardsCategory.name=C
|
||||
|
@ -102,6 +104,9 @@ ActionDefinition.addBlockComment.description= Enclose the selection with a block
|
|||
ActionDefinition.removeBlockComment.name= Remove Block Comment
|
||||
ActionDefinition.removeBlockComment.description= Remove the block comment enclosing the selection
|
||||
|
||||
ActionDefinition.joinLines.name= Join Lines
|
||||
ActionDefinition.joinLines.description= Join the current and next line together
|
||||
|
||||
ActionDefinition.format.name=Format
|
||||
ActionDefinition.format.description=Format Source Code
|
||||
|
||||
|
|
|
@ -948,6 +948,11 @@
|
|||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.goto.matching.bracket"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.join.lines"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
sequence="M1+M2+J"/>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
|
@ -986,6 +991,12 @@
|
|||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.remove.block.comment">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.joinLines.name"
|
||||
description="%ActionDefinition.joinLines.description"
|
||||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.join.lines">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.opendef.name"
|
||||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 Todd Papaioannou
|
||||
* 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:
|
||||
* Todd Papaioannou - initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.TextEditorAction;
|
||||
|
||||
/**
|
||||
* Join Lines Action is a relatively simple extension of TextEditorAction
|
||||
* that, when invoked, will join the current and next line together.
|
||||
*
|
||||
* @author Todd Papaioannou (toddp@acm.org)
|
||||
* @version $Date$
|
||||
* @see org.eclipse.ui.texteditor.TextEditorAction
|
||||
*/
|
||||
public class JoinLinesAction extends TextEditorAction {
|
||||
|
||||
// This is the editor component that we will work on
|
||||
ITextEditor theEditor;
|
||||
|
||||
/**
|
||||
* Create a new instance of JoinLinesAction. We basically just call
|
||||
* our parent's constructor.
|
||||
*
|
||||
* @param bundle The resource bundle
|
||||
* @param prefix A prefix to be prepended to the various resource keys
|
||||
* (described in <code>ResourceAction</code> constructor),
|
||||
* or <code>null</code> if none
|
||||
* @param editor The text editor component on which this Action will work.
|
||||
*/
|
||||
public JoinLinesAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
|
||||
|
||||
super(bundle, prefix, editor);
|
||||
|
||||
} // end of constructor
|
||||
|
||||
|
||||
/**
|
||||
* Run is where all the action (sic!) happens. This is a pretty simple
|
||||
* action that basically joins the current line and next line together.
|
||||
* It achieves this by determining which line of the editor's document
|
||||
* we are on, and then replacing the delimiter at the end of the line
|
||||
* with nothing.
|
||||
*
|
||||
* TODO: Currently, we don't bother to remove any excess whitespace.
|
||||
* Doing so in the future might be a nice touch.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
// Make sure we can proceed.
|
||||
if ((theEditor != null) && isEnabled() && canModifyEditor()) {
|
||||
|
||||
// Retrieve the current editor's document
|
||||
IDocument theDocument = getDocument(theEditor);
|
||||
|
||||
if (theDocument != null) {
|
||||
|
||||
try {
|
||||
|
||||
// First, retrieve the current selection
|
||||
ITextSelection theSelection = getSelection(theEditor);
|
||||
|
||||
if (theSelection != null) {
|
||||
|
||||
// Now, figure out the end line of the selection
|
||||
int currentLine = theSelection.getEndLine();
|
||||
|
||||
// What's the offset of this line in the document?
|
||||
int lineOffset = theDocument.getLineOffset(currentLine);
|
||||
|
||||
// And the length of the line?
|
||||
int lineLength = theDocument.getLineLength(currentLine);
|
||||
|
||||
// What delimeter do we have?
|
||||
String delim = theDocument.getLineDelimiter(currentLine);
|
||||
|
||||
// How long is it?
|
||||
int delimLength = delim.length();
|
||||
|
||||
// Now back track to the last real char in the line
|
||||
int newLineEnd = lineOffset + lineLength - delimLength;
|
||||
|
||||
// Replace the delimter char(s) with nothing
|
||||
theDocument.replace(newLineEnd, delimLength, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (BadLocationException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} // end of if (document)
|
||||
|
||||
} // end of isEnabled()
|
||||
|
||||
} // end of run
|
||||
|
||||
|
||||
/**
|
||||
* Check that we can actually modify the document of the current editor.
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
super.update();
|
||||
|
||||
// Make sure we can proceed.
|
||||
if (isEnabled() && canModifyEditor()) {
|
||||
|
||||
// Retrieve the text editor and store it for later
|
||||
theEditor = getTextEditor();
|
||||
}
|
||||
|
||||
} // end of update
|
||||
|
||||
|
||||
/**
|
||||
* Get Document attempts to retrieve 'editor's document.
|
||||
*
|
||||
* @param editor The editor whose document we want to retrieve.
|
||||
*
|
||||
* @return An IDocument if there is one, or null.
|
||||
*/
|
||||
private IDocument getDocument(ITextEditor editor) {
|
||||
|
||||
// What we will return
|
||||
IDocument theDocument = null;
|
||||
|
||||
// Retrieve the document provider
|
||||
IDocumentProvider documentProvider = editor.getDocumentProvider();
|
||||
|
||||
if (documentProvider != null) {
|
||||
|
||||
// Retrieve the actual document
|
||||
theDocument = documentProvider.getDocument(editor.getEditorInput());
|
||||
}
|
||||
|
||||
return theDocument;
|
||||
|
||||
} // end of getDocument
|
||||
|
||||
|
||||
/**
|
||||
* Get selection attempts to retrieve 'editor's current selection.
|
||||
*
|
||||
* @param editor The editor whose selection we want to retrieve.
|
||||
*
|
||||
* @return An ITextSelection if there is one, or null.
|
||||
*/
|
||||
private ITextSelection getSelection(ITextEditor editor) {
|
||||
|
||||
// What we will return
|
||||
ITextSelection theSelection = null;
|
||||
|
||||
// First try to retrieve the editor's selection provider
|
||||
ISelectionProvider selectionProvider = editor.getSelectionProvider();
|
||||
|
||||
if (selectionProvider != null) {
|
||||
|
||||
// Now try to retrieve the selection
|
||||
ISelection selection = selectionProvider.getSelection();
|
||||
|
||||
// Is this of the correct type?
|
||||
if (selection instanceof ITextSelection) {
|
||||
|
||||
// Ok, cast it and assign it
|
||||
theSelection = (ITextSelection) selection;
|
||||
}
|
||||
}
|
||||
|
||||
return theSelection;
|
||||
|
||||
} // end of getSelection
|
||||
|
||||
} // end of JoinLinesAction
|
|
@ -29,6 +29,7 @@ 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.JoinLinesAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
|
||||
import org.eclipse.cdt.internal.ui.browser.typehierarchy.OpenTypeHierarchyAction;
|
||||
import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction;
|
||||
|
@ -666,6 +667,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
|
||||
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
|
||||
|
||||
action = new JoinLinesAction(CEditorMessages.getResourceBundle(), "JoinLines.", this); //$NON-NLS-1$
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.JOIN_LINES);
|
||||
setAction("Join Lines", action); //$NON-NLS-1$
|
||||
|
||||
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.COMMENT);
|
||||
setAction("Comment", action); //$NON-NLS-1$
|
||||
|
|
|
@ -144,6 +144,10 @@ RemoveBlockComment.label=Remove Bloc&k Comment
|
|||
RemoveBlockComment.tooltip=Remove Block Comment Markers Enclosing the Caret
|
||||
RemoveBlockComment.description=Removes any block comment markers enclosing the caret
|
||||
|
||||
JoinLines.label=Join Lines
|
||||
JoinLines.tooltip=Join Lines
|
||||
JoinLines.description=Join the current and next line together
|
||||
|
||||
Format.label=F&ormat
|
||||
Format.tooltip=Format the Selected Text
|
||||
Format.description=Format the selected text
|
||||
|
|
|
@ -50,6 +50,12 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
*/
|
||||
public static final String REMOVE_BLOCK_COMMENT= "org.eclipse.cdt.ui.edit.text.c.remove.block.comment"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the source -> join lines action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.join.lines"</code>).
|
||||
* @since 3.0.2
|
||||
*/
|
||||
public static final String JOIN_LINES= "org.eclipse.cdt.ui.edit.text.c.join.lines"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the source -> format action
|
||||
|
@ -69,27 +75,30 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
*/
|
||||
public static final String OPEN_DECL= "org.eclipse.cdt.ui.edit.opendecl"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the open definition action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.opendef"</code>).
|
||||
*/
|
||||
public static final String OPEN_DEF= "org.eclipse.cdt.ui.edit.opendef"; //$NON-NLS-1$
|
||||
/**
|
||||
* Action definition ID of the open definition action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.opendef"</code>).
|
||||
*/
|
||||
public static final String OPEN_DEF= "org.eclipse.cdt.ui.edit.opendef"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the show in C/C++ Projects View action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.opencview"</code>).
|
||||
*/
|
||||
public static final String OPEN_CVIEW= "org.eclipse.cdt.ui.edit.opencview"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> rename element action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.rename.element"</code>).
|
||||
*/
|
||||
public static final String RENAME_ELEMENT= "org.eclipse.cdt.ui.edit.text.rename.element"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> undo action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.undo.action"</code>).
|
||||
*/
|
||||
public static final String UNDO_ACTION= "org.eclipse.cdt.ui.edit.text.undo.action"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the refactor -> redo action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.redo.action"</code>).
|
||||
|
@ -101,6 +110,7 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
* (value <code>"org.eclipse.cdt.ui.search.findrefs"</code>).
|
||||
*/
|
||||
public static final String FIND_REFS= "org.eclipse.cdt.ui.search.findrefs"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the find declarations in workspace action
|
||||
* (value <code>"org.eclipse.cdt.ui.search.finddecl"</code>).
|
||||
|
@ -119,23 +129,23 @@ 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 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 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 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$
|
||||
/**
|
||||
* 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$
|
||||
|
||||
/**
|
||||
* Action definition ID of the edit -> go to matching bracket action
|
||||
|
|
Loading…
Add table
Reference in a new issue