1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added MSVS key binding. New commands from bug 209218.

This commit is contained in:
Ken Ryall 2008-03-28 19:39:19 +00:00
parent bb469b32ee
commit c3e795c6d0
8 changed files with 422 additions and 1 deletions

View file

@ -117,6 +117,12 @@ ActionDefinition.format.description=Format Source Code
ActionDefinition.gotoMatchingBracket.name= Go to Matching Bracket
ActionDefinition.gotoMatchingBracket.description= Moves the cursor to the matching bracket
ActionDefinition.gotoNextBookmark.name= Next Bookmark
ActionDefinition.gotoNextBookmark.description= Goto next bookmark of the selected file
ActionDefinition.FindWord.name= Find Word
ActionDefinition.FindWord.description= Select a word and find the next occurrence
ActionDefinition.toggleSourceHeader.name= Toggle Source/Header
ActionDefinition.toggleSourceHeader.description= Toggles between corresponding source and header files
@ -480,3 +486,5 @@ indexedFilesDecorator.label = C/C++ Indexed Files
# Hyperlinking
cEditorHyperlinkTarget= C/C++ Editor
cElementHyperlinkDetector= C/C++ Elements
keybinding.MSVS= Microsoft Visual Studio

View file

@ -1411,6 +1411,7 @@
</extension>
<extension point="org.eclipse.ui.bindings">
<!-- win32: M1=CTRL, M2=SHIFT, M3=ALT, M4=-
carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL -->
<key
@ -1609,6 +1610,173 @@
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
contextId="org.eclipse.cdt.ui.cEditorScope"
commandId="org.eclipse.cdt.ui.refactor.extract.constant"/>
<scheme
id="org.eclipse.cdt.ui.visualstudio"
parentId="org.eclipse.ui.defaultAcceleratorConfiguration"
name="%keybinding.MSVS"/>
<!-- =================================================================================== -->
<!-- MICROSOFT VISUAL STUDIO KEY SHORTCUTS -->
<!-- =================================================================================== -->
<!-- C/C++ Source Keys -->
<!-- MSVS Edit.GoToDefinition -->
<key
sequence="F12"
commandId="org.eclipse.cdt.ui.edit.opendef"
contextId="org.eclipse.cdt.ui.cEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- Edit Keys -->
<key
sequence="F3"
commandId="org.eclipse.ui.edit.findNext"
contextId="org.eclipse.ui.textEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M2+F3"
commandId="org.eclipse.ui.edit.findPrevious"
contextId="org.eclipse.ui.textEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M1+F3"
commandId="org.eclipse.cdt.ui.edit.text.c.find.word"
contextId="org.eclipse.cdt.ui.cEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M1+M2+F"
commandId="org.eclipse.search.ui.openSearchDialog"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- File Keys -->
<!-- Help Keys -->
<!-- MakeFile Source Keys -->
<!-- Navigate Keys -->
<key
sequence="M1+F2"
commandId="org.eclipse.ui.edit.addBookmark"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M2+F2"
commandId="org.eclipse.cdt.ui.edit.text.c.goto.next.bookmark"
contextId="org.eclipse.cdt.ui.cEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M1+G"
commandId="org.eclipse.ui.edit.text.goto.line"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- Project Keys -->
<!-- MSVS RebuildSolution -->
<!-- THERE IS CURRENTLY NO REBUILD
<key
sequence="M1+M2+B"
commandId="org.eclipse.ui.project.rebuildProject"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
-->
<!-- MSVS NewProject -->
<key
sequence="M1+M2+N"
commandId="org.eclipse.ui.newWizard"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- Run/Debug Keys -->
<!-- MSVS Start -->
<key
sequence="M1+F5"
commandId="org.eclipse.debug.ui.commands.RunLast"
contextId="org.eclipse.ui.globalScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS StartWithoutDebugging -->
<key
sequence="F5"
commandId="org.eclipse.debug.ui.commands.DebugLast"
contextId="org.eclipse.ui.globalScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS StepInto -->
<key
sequence="F11"
commandId="org.eclipse.debug.ui.commands.StepInto"
contextId="org.eclipse.debug.ui.debugging"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS StepOver -->
<key
sequence="F10"
commandId="org.eclipse.debug.ui.commands.StepOver"
contextId="org.eclipse.debug.ui.debugging"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS StepReturn -->
<key
sequence="M2+F11"
commandId="org.eclipse.debug.ui.commands.StepReturn"
contextId="org.eclipse.debug.ui.debugging"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS ToggleBreakpoint -->
<key
sequence="F9"
commandId="org.eclipse.debug.ui.commands.ToggleBreakpoint"
contextId="org.eclipse.ui.globalScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS RunToCursor -->
<key
sequence="M1+F10"
commandId="org.eclipse.debug.ui.commands.RunToLine"
contextId="org.eclipse.ui.globalScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVS Breakpoints -->
<key
sequence="M1+M3+B"
commandId="org.eclipse.debug.ui.BreakpointView"
contextId="org.eclipse.ui.globalScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- Search Keys -->
<!-- Text Editing Keys -->
<key
sequence="M1+ARROW_LEFT"
commandId="org.eclipse.ui.edit.text.goto.wordPrevious"
contextId="org.eclipse.ui.textEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<key
sequence="M1+ARROW_RIGHT"
commandId="org.eclipse.ui.edit.text.goto.wordNext"
contextId="org.eclipse.ui.textEditorScope"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- View Keys -->
<!-- Views Keys -->
<!-- Window Keys -->
<!-- MSVC Window NextDocumentWindow -->
<key
sequence="M1+TAB"
commandId="org.eclipse.ui.window.nextEditor"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
<!-- MSVC Window.PreviousDocumentWindow -->
<key
sequence="M1+M2+TAB"
commandId="org.eclipse.ui.window.previousEditor"
schemeId="org.eclipse.cdt.ui.visualstudio"/>
</extension>
<extension
point="org.eclipse.ui.commands">
@ -1746,6 +1914,18 @@
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.goto.matching.bracket">
</command>
<command
name="%ActionDefinition.gotoNextBookmark.name"
description="%ActionDefinition.gotoNextBookmark.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.goto.next.bookmark">
</command>
<command
name="%ActionDefinition.FindWord.name"
description="%ActionDefinition.FindWord.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.text.c.find.word">
</command>
<command
name="%ActionDefinition.toggleSourceHeader.name"
description="%ActionDefinition.toggleSourceHeader.description"

View file

@ -0,0 +1,80 @@
package org.eclipse.cdt.internal.ui.actions;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.FindNextAction;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.cdt.internal.ui.text.CWordFinder;
/**
* Select the word at current cursor location and find the next occurrence.
*/
public class FindWordAction extends TextEditorAction {
public static final String FIND_WORD = "FindWord"; //$NON-NLS-1$
private ITextViewer fViewer;
private FindNextAction fFindNext;
/**
* Creates new action.
*/
public FindWordAction(ResourceBundle bundle, String prefix, ITextEditor editor, ITextViewer viewer) {
super(bundle, prefix, editor);
fViewer = viewer;
fFindNext = new FindNextAction(bundle, prefix, editor, true);
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null )
return;
ISelectionProvider selectionProvider = editor.getSelectionProvider();
if (selectionProvider == null)
return;
ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
if (selection == null || selection.isEmpty())
return;
IDocumentProvider docProvider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
if (docProvider == null || input == null)
return;
IDocument document = docProvider.getDocument(input);
if (document == null)
return;
IResource resource = (IResource)(input).getAdapter(IResource.class);
if (resource == null || !(resource instanceof IFile))
return;
// find the word at current cursor location
int offset = selection.getOffset();
IRegion region = CWordFinder.findWord(document, offset);
if (region == null || region.getLength() == 0)
return;
// select the word and find next occurrence
fViewer.setSelectedRange(region.getOffset(), region.getLength());
fFindNext.run();
}
}

View file

@ -0,0 +1,107 @@
package org.eclipse.cdt.internal.ui.actions;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.ui.texteditor.TextEditorAction;
/**
* Find and goto the next bookmark in the currently selected file.
*/
public class GotoNextBookmarkAction extends TextEditorAction {
public static final String NEXT_BOOKMARK = "GotoNextBookmark"; //$NON-NLS-1$
/**
* Private class to handle comparison of markers using their line numbers.
*/
private class CompareMarker implements Comparator {
public int compare(Object o1, Object o2) {
IMarker m1 = (IMarker) o1;
IMarker m2 = (IMarker) o2;
int l1 = MarkerUtilities.getLineNumber(m1);
int l2 = MarkerUtilities.getLineNumber(m2);
if (l1 > l2) return 1;
if (l1 < l2) return -1;
return 0;
}
}
/**
* Creates new action.
*/
public GotoNextBookmarkAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
super(bundle, prefix, editor);
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@SuppressWarnings("unchecked")
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null )
return;
ISelectionProvider provider = editor.getSelectionProvider();
if (provider == null)
return;
ITextSelection selection = (ITextSelection) provider.getSelection();
if (selection == null || selection.isEmpty())
return;
IEditorInput input= editor.getEditorInput();
if (input == null)
return;
IResource resource = (IResource)(input).getAdapter(IResource.class);
if (resource == null || !(resource instanceof IFile))
return;
try {
IMarker[] bookmarks = resource.findMarkers(IMarker.BOOKMARK, true, IResource.DEPTH_ONE);
if (bookmarks.length == 0)
return;
// sort bookmarks by line number
CompareMarker comparator = new CompareMarker();
Arrays.sort(bookmarks, comparator);
// marker line numbers are 1-based
int line = selection.getStartLine() + 1;
IMarker lastBookmark = bookmarks[bookmarks.length - 1];
// start from the beginning of file if reached or went beyond last bookmark
if (line >= MarkerUtilities.getLineNumber(lastBookmark)) {
line = 1;
}
// find the next bookmark and goto it
for (int i = 0; i < bookmarks.length; i++) {
IMarker bookmark = bookmarks[i];
if (MarkerUtilities.getLineNumber(bookmark) > line) {
IDE.openEditor(getTextEditor().getSite().getPage(), bookmark, OpenStrategy.activateOnOpen());
break;
}
}
}
catch (CoreException e) {
e.printStackTrace();
}
}
}

View file

@ -190,8 +190,10 @@ 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.GotoNextBookmarkAction;
import org.eclipse.cdt.internal.ui.actions.IndentAction;
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.cdt.internal.ui.dnd.TextEditorDropAdapter;
import org.eclipse.cdt.internal.ui.dnd.TextViewerDragAdapter;
@ -2012,6 +2014,16 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
IAction action= new GotoMatchingBracketAction(this);
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
action = new GotoNextBookmarkAction(CEditorMessages.getResourceBundle(), "GotoNextBookmark.", this); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_BOOKMARK);
setAction(GotoNextBookmarkAction.NEXT_BOOKMARK, action);
action = new FindWordAction(CEditorMessages.getResourceBundle(), "FindWord.", this, getSourceViewer()); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.FIND_WORD);
setAction(FindWordAction.FIND_WORD, action);
markAsStateDependentAction(FindWordAction.FIND_WORD, true);
markAsSelectionDependentAction(FindWordAction.FIND_WORD, true);
action = new ToggleCommentAction(CEditorMessages.getResourceBundle(), "ToggleComment.", this); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_COMMENT);

View file

@ -30,7 +30,9 @@ import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
public class CEditorActionContributor extends TextEditorActionContributor {
@ -44,12 +46,14 @@ public class CEditorActionContributor extends TextEditorActionContributor {
private GotoAnnotationAction fPreviousAnnotation;
private GotoAnnotationAction fNextAnnotation;
private RetargetTextEditorAction fGotoMatchingBracket;
private RetargetTextEditorAction fGotoNextBookmark;
private RetargetTextEditorAction fGotoNextMemberAction;
private RetargetTextEditorAction fGotoPreviousMemberAction;
private RetargetTextEditorAction fToggleInsertModeAction;
private RetargetTextEditorAction fShowOutline;
private RetargetTextEditorAction fToggleSourceHeader;
private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
private RetargetTextEditorAction fFindWord;
public CEditorActionContributor() {
super();
@ -87,6 +91,9 @@ public class CEditorActionContributor extends TextEditorActionContributor {
fGotoMatchingBracket= new RetargetTextEditorAction(bundle, "GotoMatchingBracket."); //$NON-NLS-1$
fGotoMatchingBracket.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
fGotoNextBookmark = new RetargetTextEditorAction(bundle, "GotoNextBookmark."); //$NON-NLS-1$
fGotoNextBookmark.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_BOOKMARK);
fGotoNextMemberAction= new RetargetTextEditorAction(bundle, "GotoNextMember."); //$NON-NLS-1$
fGotoNextMemberAction.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
fGotoPreviousMemberAction= new RetargetTextEditorAction(bundle, "GotoPreviousMember."); //$NON-NLS-1$
@ -101,7 +108,9 @@ public class CEditorActionContributor extends TextEditorActionContributor {
fToggleSourceHeader= new RetargetTextEditorAction(bundle, "ToggleSourceHeader."); //$NON-NLS-1$
fToggleSourceHeader.setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_SOURCE_HEADER);
}
fFindWord = new RetargetTextEditorAction(bundle, "FindWord."); //$NON-NLS-1$
fFindWord.setActionDefinitionId(ICEditorActionDefinitionIds.FIND_WORD);
}
/*
* @see org.eclipse.ui.texteditor.BasicTextEditorActionContributor#contributeToMenu(org.eclipse.jface.action.IMenuManager)
@ -116,6 +125,8 @@ public class CEditorActionContributor extends TextEditorActionContributor {
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContentAssist);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_ASSIST, fContextInformation);
editMenu.prependToGroup(IWorkbenchActionConstants.FIND_EXT, fFindWord);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftRight);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fShiftLeft);
editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, fFormatter);
@ -138,6 +149,7 @@ public class CEditorActionContributor extends TextEditorActionContributor {
gotoMenu.appendToGroup("additions2", fGotoPreviousMemberAction); //$NON-NLS-1$
gotoMenu.appendToGroup("additions2", fGotoNextMemberAction); //$NON-NLS-1$
gotoMenu.appendToGroup("additions2", fGotoMatchingBracket); //$NON-NLS-1$
gotoMenu.appendToGroup("additions2", fGotoNextBookmark); //$NON-NLS-1$
}
}
@ -185,12 +197,14 @@ public class CEditorActionContributor extends TextEditorActionContributor {
fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$
fGotoMatchingBracket.setAction(getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET));
fGotoNextBookmark.setAction(getAction(textEditor, GotoNextBookmarkAction.NEXT_BOOKMARK));
fGotoNextMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER));
fGotoPreviousMemberAction.setAction(getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER));
fShowOutline.setAction(getAction(textEditor, "OpenOutline")); //$NON-NLS-1$
fToggleSourceHeader.setAction(getAction(textEditor, "ToggleSourceHeader")); //$NON-NLS-1$
fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
fFindWord.setAction(getAction(textEditor, FindWordAction.FIND_WORD));
if (part instanceof CEditor) {
CEditor cEditor= (CEditor) part;

View file

@ -118,6 +118,14 @@ GotoMatchingBracket.description=Go to Matching Bracket
GotoMatchingBracket.error.invalidSelection=No bracket selected
GotoMatchingBracket.error.noMatchingBracket=No matching bracket found
GotoNextBookmark.description=Goto next bookmark of the selected file
GotoNextBookmark.label=Next Bookmark
GotoNextBookmark.tooltip=Goto Next Bookmark of the Selected File
FindWord.description=Select a word and find the next occurrence
FindWord.label=Find Word
FindWord.tooltip=Select a Word and Find the Next Occurrence
ToggleComment_error_title=Comment/Uncomment
ToggleComment_error_message=An error occurred while commenting/uncommenting.

View file

@ -178,6 +178,18 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
*/
public static final String GOTO_MATCHING_BRACKET= "org.eclipse.cdt.ui.edit.text.c.goto.matching.bracket"; //$NON-NLS-1$
/**
* Action definition ID for goto next bookmark action
* (value <code>"org.eclipse.cdt.ui.edit.text.c.goto.next.bookmark"</code>).
*/
public static final String GOTO_NEXT_BOOKMARK = "org.eclipse.cdt.ui.edit.text.c.goto.next.bookmark"; //$NON-NLS-1$
/**
* Action definition ID for find word action
* (value <code>"org.eclipse.cdt.ui.edit.text.c.find.word"</code>).
*/
public static final String FIND_WORD = "org.eclipse.cdt.ui.edit.text.c.find.word"; //$NON-NLS-1$
/**
* Action definition ID for toggle source/header action.
* (value <code>"org.eclipse.cdt.ui.edit.text.c.toggle.source.header"</code>)