Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 114438 Details for
Bug 6823
[Edit] Add Goto Line (CTRL-L) to Compare Editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch v01
clipboard.txt (text/plain), 13.67 KB, created by
Tomasz Zarna
on 2008-10-07 11:31:19 EDT
(
hide
)
Description:
Patch v01
Filename:
MIME Type:
Creator:
Tomasz Zarna
Created:
2008-10-07 11:31:19 EDT
Size:
13.67 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.compare >Index: compare/org/eclipse/compare/internal/MergeSourceViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/MergeSourceViewer.java,v >retrieving revision 1.44 >diff -u -r1.44 MergeSourceViewer.java >--- compare/org/eclipse/compare/internal/MergeSourceViewer.java 22 May 2007 20:19:52 -0000 1.44 >+++ compare/org/eclipse/compare/internal/MergeSourceViewer.java 7 Oct 2008 15:23:38 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2007 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 IBM Corporation and others. > * 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 >@@ -50,6 +50,7 @@ > public static final String SELECT_ALL_ID= "selectAll"; //$NON-NLS-1$ > public static final String SAVE_ID= "save"; //$NON-NLS-1$ > public static final String FIND_ID= "find"; //$NON-NLS-1$ >+ public static final String GOTO_LINE_ID= "gotoLine"; //$NON-NLS-1$ > > class TextOperationAction extends MergeViewerAction { > >@@ -453,6 +454,7 @@ > menu.add(new Separator("edit")); //$NON-NLS-1$ > menu.add(new Separator("find")); //$NON-NLS-1$ > addMenu(menu, FIND_ID); >+ addMenu(menu, GOTO_LINE_ID); > > menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); > >Index: compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties,v >retrieving revision 1.31 >diff -u -r1.31 TextMergeViewerResources.properties >--- compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties 20 Apr 2007 18:33:08 -0000 1.31 >+++ compare/org/eclipse/compare/contentmergeviewer/TextMergeViewerResources.properties 7 Oct 2008 15:23:37 -0000 >@@ -1,5 +1,5 @@ > ############################################################################### >-# Copyright (c) 2000, 2007 IBM Corporation and others. >+# Copyright (c) 2000, 2008 IBM Corporation and others. > # 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 >@@ -112,5 +112,15 @@ > Editor.FindReplace.image= > Editor.FindReplace.description=Find/Replace > >+Editor.GotoLine.label=&Go to Line... >+Editor.GotoLine.tooltip=Go to Line >+Editor.GotoLine.image= >+Editor.GotoLine.description=Go to Line >+ >+Editor.GotoLine.dialog.title=Go to Line >+Editor.GotoLine.dialog.message=Enter line number (1..{0}): >+Editor.GotoLine.dialog.invalid_input=Not a number >+Editor.GotoLine.dialog.invalid_range=Line number out of range >+ > action.IgnoreWhiteSpace.label=&Ignore White Space > action.IgnoreWhiteSpace.tooltip=Ignore White Space Where Applicable >Index: compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java,v >retrieving revision 1.232 >diff -u -r1.232 TextMergeViewer.java >--- compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java 5 Aug 2008 08:50:50 -0000 1.232 >+++ compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java 7 Oct 2008 15:23:37 -0000 >@@ -22,6 +22,7 @@ > > import org.eclipse.compare.*; > import org.eclipse.compare.internal.*; >+import org.eclipse.compare.internal.GotoLineAction; > import org.eclipse.compare.internal.merge.DocumentMerger; > import org.eclipse.compare.internal.merge.DocumentMerger.Diff; > import org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput; >@@ -2124,6 +2125,8 @@ > // Add the find action to the popup menu of the viewer > contributeFindAction(part); > >+ contributeGotoLineAction(part); >+ > configureTextViewer(part); > > return part; >@@ -2140,6 +2143,12 @@ > viewer.addAction(MergeSourceViewer.FIND_ID, action); > } > >+ private void contributeGotoLineAction(MergeSourceViewer viewer) { >+ IAction action = new GotoLineAction(getResourceBundle(), "Editor.GotoLine.", viewer); //$NON-NLS-1$ >+ action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_GOTO); >+ viewer.addAction(MergeSourceViewer.GOTO_LINE_ID, action); >+ } >+ > private void connectGlobalActions(final MergeSourceViewer part) { > if (fHandlerService != null) { > if (part != null) >Index: compare/org/eclipse/compare/internal/GotoLineAction.java >=================================================================== >RCS file: compare/org/eclipse/compare/internal/GotoLineAction.java >diff -N compare/org/eclipse/compare/internal/GotoLineAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ compare/org/eclipse/compare/internal/GotoLineAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,255 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.compare.internal; >+ >+import java.util.ResourceBundle; >+ >+import org.eclipse.jface.dialogs.IDialogSettings; >+import org.eclipse.jface.dialogs.IInputValidator; >+import org.eclipse.jface.dialogs.InputDialog; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.ITextViewerExtension5; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.window.Window; >+import org.eclipse.swt.custom.StyledText; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.texteditor.ResourceAction; >+ >+import com.ibm.icu.text.MessageFormat; >+ >+ >+/** >+ * Action for jumping to a particular line in the text viewer. >+ * The user is requested to enter the line number into an input dialog. >+ * The action is initially associated with a text viewer via the constructor. >+ * <p> >+ * The following keys, prepended by the given option prefix, >+ * are used for retrieving resources from the given bundle: >+ * <ul> >+ * <li><code>"dialog.invalid_range"</code> - to indicate an invalid line number</li> >+ * <li><code>"dialog.invalid_input"</code> - to indicate an invalid line number format</li> >+ * <li><code>"dialog.title"</code> - the input dialog's title</li> >+ * <li><code>"dialog.message"</code> - the input dialog's message</li> >+ * </ul></p> >+ * >+ * @see org.eclipse.ui.texteditor.GotoLineAction >+ */ >+public class GotoLineAction extends ResourceAction { >+ >+ /** >+ * Validates whether the text found in the input field of the >+ * dialog forms a valid line number. A number is valid if it is >+ * one to which can be jumped. >+ */ >+ class NumberValidator implements IInputValidator { >+ >+ /* >+ * @see IInputValidator#isValid(String) >+ */ >+ public String isValid(String input) { >+ >+ if (input == null || input.length() == 0) >+ return " "; //$NON-NLS-1$ >+ >+ try { >+ int i= Integer.parseInt(input); >+ if (i <= 0 || fLastLine < i) >+ return fBundle.getString(fPrefix + "dialog.invalid_range"); //$NON-NLS-1$ >+ >+ } catch (NumberFormatException x) { >+ return fBundle.getString(fPrefix + "dialog.invalid_input"); //$NON-NLS-1$ >+ } >+ >+ return null; >+ } >+ } >+ >+ /** >+ * Standard input dialog with custom dialog bounds >+ * strategy and settings. >+ * >+ * @since 2.0 >+ */ >+ static class GotoLineDialog extends InputDialog { >+ >+ /* >+ * @see InputDialog#InputDialog(org.eclipse.swt.widgets.Shell, java.lang.String, java.lang.String, java.lang.String, org.eclipse.jface.dialogs.IInputValidator) >+ */ >+ public GotoLineDialog(Shell parent, String title, String message, String initialValue, IInputValidator validator) { >+ super(parent, title, message, initialValue, validator); >+ } >+ >+ /* >+ * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings() >+ * @since 3.2 >+ */ >+ protected IDialogSettings getDialogBoundsSettings() { >+ String sectionName= getClass().getName() + "_dialogBounds"; //$NON-NLS-1$ >+ IDialogSettings settings= CompareUIPlugin.getDefault().getDialogSettings(); >+ IDialogSettings section= settings.getSection(sectionName); >+ if (section == null) >+ section= settings.addNewSection(sectionName); >+ return section; >+ } >+ >+ /* >+ * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsStrategy() >+ * @since 3.2 >+ */ >+ protected int getDialogBoundsStrategy() { >+ return DIALOG_PERSISTLOCATION; >+ } >+ } >+ >+ /** The biggest valid line number of the presented document */ >+ private int fLastLine; >+ /** This action's ITextViewer */ >+ private ITextViewer fTextViewer; >+ /** This action's resource bundle */ >+ private ResourceBundle fBundle; >+ /** This action's prefix used for accessing the resource bundle */ >+ private String fPrefix; >+ >+ /** >+ * Creates a new action for the given text viewer. The action configures its >+ * visual representation from the given resource bundle. >+ * >+ * @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 textViewer the text viewer >+ */ >+ public GotoLineAction(ResourceBundle bundle, String prefix, ITextViewer textViewer) { >+ super(bundle, prefix); >+ fTextViewer = textViewer; >+ fBundle= bundle; >+ fPrefix= prefix; >+ } >+ >+ /** >+ * Jumps to the given line. >+ * >+ * @param line the line to jump to >+ */ >+ private void gotoLine(int line) { >+ IDocument document=fTextViewer.getDocument(); >+ try { >+ int start= document.getLineOffset(line); >+ selectAndReveal(start, 0); >+ // TODO: >+ // IWorkbenchPage page= editor.getSite().getPage(); >+ // page.activate(editor); >+ } catch (BadLocationException x) { >+ // ignore >+ } >+ } >+ >+ /* >+ * @see Action#run() >+ */ >+ public void run() { >+ try { >+ >+ if (fTextViewer == null) >+ return; >+ >+ IDocument document = fTextViewer.getDocument(); >+ if (document == null) >+ return; >+ >+ fLastLine= document.getLineOfOffset(document.getLength()) + 1; >+ >+ String title= fBundle.getString(fPrefix + "dialog.title"); //$NON-NLS-1$ >+ String message = MessageFormat.format(fBundle.getString(fPrefix + "dialog.message"), new Object[] {new Integer(fLastLine)}); //$NON-NLS-1$ >+ >+ GotoLineDialog d= new GotoLineDialog(Display.getCurrent().getActiveShell(), title, message, "", new NumberValidator()); //$NON-NLS-1$ >+ if (d.open() == Window.OK) { >+ try { >+ int line= Integer.parseInt(d.getValue()); >+ gotoLine(line - 1); >+ } catch (NumberFormatException x) { >+ // ignore >+ } >+ } >+ >+ } catch (BadLocationException x) { >+ // ignore >+ } >+ } >+ >+ // methods copied from AbstractTextEditor >+ >+ /* >+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#selectAndReveal(int, int) >+ */ >+ private void selectAndReveal(int start, int length) { >+ selectAndReveal(start, length, start, length); >+ } >+ >+ /* >+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#selectAndReveal(int, int, int, int) >+ */ >+ private void selectAndReveal(int selectionStart, int selectionLength, int revealStart, int revealLength) { >+ // TODO: >+// ISelection selection= getSelectionProvider().getSelection(); >+// if (selection instanceof ITextSelection) { >+// ITextSelection textSelection= (ITextSelection) selection; >+// if (textSelection.getOffset() != 0 || textSelection.getLength() != 0) >+// markInNavigationHistory(); >+// } >+ >+ StyledText widget= fTextViewer.getTextWidget(); >+ widget.setRedraw(false); >+ { >+ adjustHighlightRange(revealStart, revealLength); >+ fTextViewer.revealRange(revealStart, revealLength); >+ >+ fTextViewer.setSelectedRange(selectionStart, selectionLength); >+ >+// markInNavigationHistory(); >+ } >+ widget.setRedraw(true); >+ } >+ >+ /* >+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#adjustHighlightRange(int, int) >+ */ >+ private void adjustHighlightRange(int offset, int length) { >+ if (fTextViewer == null) >+ return; >+ >+ if (fTextViewer instanceof ITextViewerExtension5) { >+ ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; >+ extension.exposeModelRange(new Region(offset, length)); >+ } else if (!isVisible(fTextViewer, offset, length)) { >+ fTextViewer.resetVisibleRegion(); >+ } >+ } >+ >+ /* >+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#isVisible(ISourceViewer, int, int) >+ */ >+ private static final boolean isVisible(ITextViewer viewer, int offset, int length) { >+ if (viewer instanceof ITextViewerExtension5) { >+ ITextViewerExtension5 extension= (ITextViewerExtension5) viewer; >+ IRegion overlap= extension.modelRange2WidgetRange(new Region(offset, length)); >+ return overlap != null; >+ } >+ return viewer.overlapsWithVisibleRegion(offset, length); >+ } >+ >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 6823
:
114438
|
114439
|
114533
|
114680
|
114934
|
114935