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 2622 Details for
Bug 13360
[Bookmarks] bookmark: cannot edit in the vertical ruler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
change name via dialog or inline editing
13360.txt (text/plain), 14.65 KB, created by
Sebastian Davids
on 2002-12-03 08:50:06 EST
(
hide
)
Description:
change name via dialog or inline editing
Filename:
MIME Type:
Creator:
Sebastian Davids
Created:
2002-12-03 08:50:06 EST
Size:
14.65 KB
patch
obsolete
>Index: BookmarkNavigator.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/bookmarkexplorer/BookmarkNavigator.java,v >retrieving revision 1.1 >diff -u -r1.1 BookmarkNavigator.java >--- BookmarkNavigator.java 24 Sep 2002 16:40:06 -0000 1.1 >+++ BookmarkNavigator.java 3 Dec 2002 13:48:22 -0000 >@@ -1,9 +1,17 @@ > package org.eclipse.ui.views.bookmarkexplorer; > >-/* >- * (c) Copyright IBM Corp. 2000, 2001. >- * All Rights Reserved. >- */ >+/********************************************************************** >+Copyright (c) 2000, 2002 IBM Corp. 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: >+ IBM Corp. - initial version >+ Sebastian Davids <sdavids@gmx.de> - fixes for bug 13360 >+********************************************************************/ >+ > import java.net.MalformedURLException; > import java.net.URL; > import java.util.ArrayList; >@@ -41,10 +49,11 @@ > * </p> > */ > public class BookmarkNavigator extends ViewPart { >- private StructuredViewer viewer; >+ private TreeViewer viewer; > private OpenBookmarkAction openAction; > private CopyBookmarkAction copyAction; > private RemoveBookmarkAction removeAction; >+ private RenameBookmarkAction renameAction; > private SelectAllAction selectAllAction; > private ShowInNavigatorAction showInNavigatorAction; > private IMemento memento; >@@ -79,7 +88,9 @@ > removeAction.setHoverImageDescriptor(getImageDescriptor("clcl16/remtsk_tsk.gif"));//$NON-NLS-1$ > removeAction.setImageDescriptor(getImageDescriptor("elcl16/remtsk_tsk.gif"));//$NON-NLS-1$ > removeAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/remtsk_tsk.gif"));//$NON-NLS-1$ >- >+ >+ renameAction = new RenameBookmarkAction(this, viewer.getTree()); >+ > selectAllAction = new SelectAllAction(this); > showInNavigatorAction = new ShowInNavigatorAction(getViewSite().getPage(), viewer); > >@@ -156,6 +167,7 @@ > manager.add(removeAction); > manager.add(selectAllAction); > manager.add(showInNavigatorAction); >+ manager.add(renameAction); > manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); > } > /** >@@ -217,6 +229,7 @@ > //update the actions > openAction.selectionChanged(selection); > removeAction.selectionChanged(selection); >+ renameAction.selectionChanged(selection); > selectAllAction.selectionChanged(selection); > showInNavigatorAction.selectionChanged(selection); > } >Index: IBookmarkHelpContextIds.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/bookmarkexplorer/IBookmarkHelpContextIds.java,v >retrieving revision 1.1 >diff -u -r1.1 IBookmarkHelpContextIds.java >--- IBookmarkHelpContextIds.java 24 Sep 2002 16:40:06 -0000 1.1 >+++ IBookmarkHelpContextIds.java 3 Dec 2002 13:48:22 -0000 >@@ -20,6 +20,7 @@ > // Actions > public static final String COPY_BOOKMARK_ACTION = PREFIX + "copy_bookmark_action_context"; //$NON-NLS-1$ > public static final String REMOVE_BOOKMARK_ACTION = PREFIX + "remove_bookmark_action_context"; //$NON-NLS-1$ >+ public static final String RENAME_BOOKMARK_ACTION = PREFIX + "rename_bookmark_action_context"; //$NON-NLS-1$ > public static final String OPEN_BOOKMARK_ACTION = PREFIX + "open_bookmark_action_context"; //$NON-NLS-1$ > public static final String SELECT_ALL_BOOKMARK_ACTION = PREFIX + "select_all_bookmark_action_context"; //$NON-NLS-1$ > >Index: RenameBookmarkAction.java >=================================================================== >RCS file: RenameBookmarkAction.java >diff -N RenameBookmarkAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ RenameBookmarkAction.java 3 Dec 2002 13:48:22 -0000 >@@ -0,0 +1,309 @@ >+package org.eclipse.ui.views.bookmarkexplorer; >+ >+/********************************************************************** >+Copyright (c) 2000, 2002 IBM Corp. 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: >+ Sebastian Davids <sdavids@gmx.de> - initial version >+*********************************************************************/ >+ >+import org.eclipse.core.resources.IMarker; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jface.dialogs.ErrorDialog; >+import org.eclipse.jface.dialogs.IInputValidator; >+import org.eclipse.jface.dialogs.InputDialog; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.TreeViewer; >+import org.eclipse.jface.window.Window; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.custom.TreeEditor; >+import org.eclipse.swt.events.FocusAdapter; >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Text; >+import org.eclipse.swt.widgets.Tree; >+import org.eclipse.ui.help.WorkbenchHelp; >+ >+/** >+ * Action to rename the selected bookmarks. >+ */ >+/* package */ class RenameBookmarkAction extends BookmarkAction { >+ >+ /* The tree editing widgets. If treeEditor is null then edit using the >+ dialog. We keep the editorText around so that we can close it if >+ a new selection is made. */ >+ private TreeEditor fTreeEditor; >+ private Text fTextEditor; >+ private Composite fTextEditorParent; >+ >+ //The bookmark being edited if this is being done inline >+ private IMarker fInlinedBookmark; >+ >+ /** >+ * Create a new action for the given view. Using this constructor will >+ * rename using a dialog rather than the inline editor of a >+ * BookmarkNavigator. >+ * >+ * @param view the view showing bookmarks >+ * @since 2.1 >+ */ >+ public RenameBookmarkAction(BookmarkNavigator view) { >+ this(view, null); >+ } >+ >+ /** >+ * Create a new action for the given view; an inline editor will be used to >+ * change the bookmarks name. >+ * >+ * @param view the view showing bookmarks >+ * @param tree the tree we want to use an inline editor on. >+ * >+ * @since 2.1 >+ */ >+ public RenameBookmarkAction(BookmarkNavigator view, Tree tree) { >+ super(view, BookmarkMessages.getString("RenameBookmark.text")); //$NON-NLS-1$ >+ >+ setToolTipText(BookmarkMessages.getString("RenameBookmark.toolTip")); //$NON-NLS-1$ >+ WorkbenchHelp.setHelp(this, IBookmarkHelpContextIds.REMOVE_BOOKMARK_ACTION); >+ setEnabled(false); >+ >+ if (tree != null) >+ fTreeEditor = new TreeEditor(tree); >+ } >+ >+ /** >+ * Rename the marker selection. >+ */ >+ public void run() { >+ IStructuredSelection sel = getStructuredSelection(); >+ >+ if (sel.isEmpty()) >+ return; >+ >+ Object o = sel.getFirstElement(); >+ >+ if (!(o instanceof IMarker)) >+ return; >+ >+ IMarker marker = (IMarker) o; >+ >+ try { >+ if (!IMarker.BOOKMARK.equals(marker.getType())) >+ return; >+ >+ String oldName = getOldName(marker); >+ >+ if (oldName == null) >+ return; >+ >+ if (fTreeEditor == null) { >+ String newName = queryNewBookmarkNameDialog(oldName); >+ >+ if (newName != null) >+ marker.setAttribute(IMarker.MESSAGE, newName); >+ } else >+ queryNewBookmarkNameInline(marker, oldName); >+ } catch (CoreException e) { >+ ErrorDialog.openError(getView().getShell(), BookmarkMessages.getString("RenameBookmark.errorTitle"), null, e.getStatus()); //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * Disables this action if the selection is empty. >+ */ >+ public void selectionChanged(IStructuredSelection selection) { >+ disposeTextWidget(); >+ >+ setEnabled(!selection.isEmpty()); >+ } >+ >+ private Composite createParent() { >+ Tree tree = ((TreeViewer) getView().getViewer()).getTree(); >+ >+ Composite result = new Composite(tree, SWT.NONE); >+ >+ fTreeEditor.horizontalAlignment = SWT.LEFT; >+ fTreeEditor.grabHorizontal = true; >+ fTreeEditor.setEditor(result, tree.getSelection()[0]); >+ >+ return result; >+ } >+ >+ /** >+ * Create the text editor widget. >+ * >+ * @param bookmark the bookmark to rename >+ */ >+ private void createTextEditor(final IMarker bookmark) { >+ // Create text editor parent. This draws a nice bounding rect. >+ fTextEditorParent = createParent(); >+ fTextEditorParent.setVisible(false); >+ fTextEditorParent.addListener(SWT.Paint, new Listener() { >+ public void handleEvent (Event e) { >+ Point textSize = fTextEditor.getSize(); >+ Point parentSize = fTextEditorParent.getSize(); >+ e.gc.drawRectangle(0, 0, Math.min(textSize.x + 4, parentSize.x - 1), parentSize.y - 1); >+ } >+ }); >+ >+ // Create inner text editor. >+ fTextEditor = new Text(fTextEditorParent, SWT.NONE); >+ fTextEditorParent.setBackground(fTextEditor.getBackground()); >+ fTextEditor.addListener(SWT.Modify, new Listener() { >+ public void handleEvent (Event e) { >+ Point textSize = fTextEditor.computeSize(SWT.DEFAULT, SWT.DEFAULT); >+ textSize.x += textSize.y; // Add extra space for new characters. >+ Point parentSize = fTextEditorParent.getSize(); >+ fTextEditor.setBounds(2, 1, Math.min(textSize.x, parentSize.x - 4), parentSize.y - 2); >+ fTextEditorParent.redraw(); >+ } >+ }); >+ >+ fTextEditor.addListener(SWT.Traverse, new Listener() { >+ public void handleEvent(Event event) { >+ //Workaround for Bug 20214 due to extra >+ //traverse events >+ switch (event.detail) { >+ case SWT.TRAVERSE_ESCAPE: >+ //Do nothing in this case >+ disposeTextWidget(); >+ event.doit = true; >+ event.detail = SWT.TRAVERSE_NONE; >+ break; >+ case SWT.TRAVERSE_RETURN: >+ saveChangesAndDispose(bookmark); >+ event.doit = true; >+ event.detail = SWT.TRAVERSE_NONE; >+ break; >+ } >+ } >+ }); >+ >+ fTextEditor.addFocusListener(new FocusAdapter() { >+ public void focusLost(FocusEvent fe) { >+ saveChangesAndDispose(bookmark); >+ } >+ }); >+ } >+ >+ /** >+ * Close the text widget and reset the editorText field. >+ */ >+ private void disposeTextWidget() { >+ if (fTextEditorParent == null) >+ return; >+ >+ fTextEditorParent.dispose(); >+ fTextEditorParent = null; >+ fTextEditor = null; >+ fTreeEditor.setEditor(null,null); >+ } >+ /** >+ * Return the old name of the target bookmark or <code>null</code> if an >+ * error occurred. >+ */ >+ private String getOldName(IMarker bookmark) { >+ try { >+ return (String) bookmark.getAttribute(IMarker.MESSAGE); >+ } catch (CoreException e) { >+ ErrorDialog.openError(getView().getShell(), BookmarkMessages.getString("RenameBookmark.errorTitle"), null, e.getStatus()); //$NON-NLS-1$ >+ return null; >+ } >+ } >+ >+ /** >+ * Return the new name to be given to the target bookmarkor >+ * <code>null</code> if an error occurred; uses an Dialog. >+ */ >+ private String queryNewBookmarkNameDialog(String oldName) { >+ String title = BookmarkMessages.getString("RenameBookmarkDialog.title"); //$NON-NLS-1$ >+ String message = BookmarkMessages.getString("RenameBookmarkDialog.message"); //$NON-NLS-1$ >+ >+ IInputValidator inputValidator = new IInputValidator() { >+ public String isValid(String newText) { >+ return (newText == null || newText.length() == 0) ? " " : null; //$NON-NLS-1$ >+ } >+ }; >+ >+ InputDialog dialog = new InputDialog(getView().getShell(), title, message, oldName, inputValidator); >+ >+ if (dialog.open() != Window.CANCEL) { >+ String name = dialog.getValue(); >+ >+ if (name == null) >+ return null; >+ >+ name = name.trim(); >+ >+ return (name.length() == 0) ? null : name; >+ } else >+ return null; >+ } >+ >+ /** >+ * Inline editing of the bookmarks name. >+ */ >+ private void queryNewBookmarkNameInline(IMarker bookmark, String oldName) { >+ // Make sure text editor is created only once. Simply reset text >+ // editor when action is executed more than once. Fixes bug 22269. >+ if (fTextEditorParent == null) >+ createTextEditor(bookmark); >+ >+ fTextEditor.setText(oldName); >+ >+ // Open text editor with initial size. >+ fTextEditorParent.setVisible(true); >+ >+ Point textSize = fTextEditor.computeSize(SWT.DEFAULT, SWT.DEFAULT); >+ textSize.x += textSize.y; // Add extra space for new characters. >+ Point parentSize = fTextEditorParent.getSize(); >+ >+ fTextEditor.setBounds(2, 1, Math.min(textSize.x, parentSize.x - 4), parentSize.y - 2); >+ fTextEditorParent.redraw(); >+ fTextEditor.selectAll (); >+ fTextEditor.setFocus (); >+ } >+ >+ /** >+ * Save the changes and dispose of the text widget. >+ * @param bookmark the bookmark to be renamed. >+ */ >+ private void saveChangesAndDispose(IMarker bookmark) { >+ // Cache the bookmark to avoid selection loss since a selection of >+ // another item can trigger this method >+ fInlinedBookmark = bookmark; >+ >+ final String newLabel = fTextEditor.getText().trim(); >+ >+ // Run this in an async to make sure that the operation that triggered >+ // this action is completed. Otherwise this leads to problems when the >+ // icon of the item being renamed is clicked (i.e., which causes the rename >+ // text widget to lose focus and trigger this method). >+ Runnable query = new Runnable() { >+ public void run() { >+ //Dispose the text widget regardless >+ disposeTextWidget(); >+ >+ try { >+ if ("".equals(newLabel)) //$NON-NLS-1$ >+ return; >+ >+ fInlinedBookmark.setAttribute(IMarker.MESSAGE, newLabel); >+ } catch (CoreException e) { >+ ErrorDialog.openError(getView().getShell(), BookmarkMessages.getString("RenameBookmark.errorTitle"), null, e.getStatus()); //$NON-NLS-1$ >+ } >+ >+ fInlinedBookmark = null; >+ } >+ }; >+ >+ getView().getShell().getDisplay().asyncExec(query); >+ } >+} >Index: messages.properties >=================================================================== >RCS file: /home/eclipse/org.eclipse.ui.views/src/org/eclipse/ui/views/bookmarkexplorer/messages.properties,v >retrieving revision 1.1 >diff -u -r1.1 messages.properties >--- messages.properties 24 Sep 2002 16:40:06 -0000 1.1 >+++ messages.properties 3 Dec 2002 13:48:22 -0000 >@@ -22,5 +22,12 @@ > RemoveBookmark.toolTip = Delete > RemoveBookmark.errorTitle = Error deleting bookmarks > >+RenameBookmark.text = &Rename Bookmark >+RenameBookmark.toolTip = Rename Bookmark >+RenameBookmark.errorTitle = Could not rename bookmark >+ >+RenameBookmarkDialog.title = Rename Bookmark >+RenameBookmarkDialog.message = Enter the new name for this Bookmark: >+ > SelectAll.text = Select A&ll > SelectAll.toolTip = Select All
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 13360
: 2622