diff options
| author | Daniel Megert | 2012-01-21 00:26:07 +0000 |
|---|---|---|
| committer | Matthias Sohn | 2012-01-21 00:26:07 +0000 |
| commit | 5922341006cdaffcf83f034cb6bbb063ae499ee6 (patch) | |
| tree | f048ef6c3812ebe845e0650b099d190ae6cfbed1 | |
| parent | 20d1d972a5db3caca0036b7bddeb8c3df8e70496 (diff) | |
| download | egit-5922341006cdaffcf83f034cb6bbb063ae499ee6.tar.gz egit-5922341006cdaffcf83f034cb6bbb063ae499ee6.tar.xz egit-5922341006cdaffcf83f034cb6bbb063ae499ee6.zip | |
Added context menu to the Commit Editor's header text
Added a context menu with 'Copy SHA-1' and 'Copy' to the header of the
Commit Editor.
Bug 359038
Change-Id: I418fe61db9e6cd9b52d67cefdf14555b5190e5ae
Signed-off-by: Daniel Megert <daniel_megert@ch.ibm.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
4 files changed, 93 insertions, 10 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index 0aa000f0a8..e4a557ddfb 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -2,7 +2,7 @@ * Copyright (C) 2008, Roger C. Soares <rogersoares@intelinet.com.br> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2010, Matthias Sohn <matthias.sohn@sap.com> - * + * Copyright (C) 2011, Daniel Megert <daniel_megert@ch.ibm.com> * 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 @@ -3374,6 +3374,18 @@ public class UIText extends NLS { public static String CommitEditorPage_TooltipSignedOffByCommitter; /** */ + public static String Header_contextMenu_copy; + + /** */ + public static String Header_contextMenu_copy_SHA1; + /** */ + + public static String Header_copy_SHA1_error_title; + + /** */ + public static String Header_copy_SHA1_error_message; + + /** */ public static String CommitFileDiffViewer_CanNotOpenCompareEditorTitle; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java index 802ea2ecfc..2cdd937999 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 GitHub Inc. + * Copyright (c) 2011 GitHub Inc. 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 @@ -7,11 +7,10 @@ * * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation + * Daniel Megert <daniel_megert@ch.ibm.com> - Added context menu to the Commit Editor's header text *******************************************************************************/ package org.eclipse.egit.ui.internal.commit; -import java.text.MessageFormat; - import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -143,8 +142,7 @@ public class CommitEditor extends SharedHeaderFormEditor implements protected void createHeaderContents(IManagedForm headerForm) { RepositoryCommit commit = getCommit(); ScrolledForm form = headerForm.getForm(); - new HeaderText(form.getForm(), MessageFormat.format( - UIText.CommitEditor_TitleHeader, commit.getRevCommit().name())); + new HeaderText(form.getForm(), commit.getRevCommit().name()); form.setToolTipText(commit.getRevCommit().name()); getToolkit().decorateFormHeading(form.getForm()); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/HeaderText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/HeaderText.java index 0fcb989775..3155f52ce9 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/HeaderText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/HeaderText.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2011 GitHub Inc. + * Copyright (c) 2011 GitHub Inc. 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 @@ -7,23 +7,38 @@ * * Contributors: * Kevin Sawicki (GitHub Inc.) - initial API and implementation + * Daniel Megert <daniel_megert@ch.ibm.com> - Added context menu to the Commit Editor's header text *****************************************************************************/ package org.eclipse.egit.ui.internal.commit; import java.lang.reflect.Field; +import java.text.MessageFormat; +import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.UIUtils; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.TextViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.forms.widgets.Form; import org.eclipse.ui.internal.forms.widgets.BusyIndicator; import org.eclipse.ui.internal.forms.widgets.FormHeading; @@ -45,9 +60,10 @@ public class HeaderText { /** * @param form - * @param text + * @param sha1String string form of the SHA-1, in lower case hexadecimal */ - public HeaderText(Form form, String text) { + public HeaderText(Form form, String sha1String) { + String text= MessageFormat.format(UIText.CommitEditor_TitleHeader, sha1String); try { FormHeading heading = (FormHeading) form.getHead(); heading.setBusy(true); @@ -65,7 +81,7 @@ public class HeaderText { if (busyLabel == null) throw new IllegalArgumentException(); - TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY); + final TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY); titleViewer.setDocument(new Document(text)); titleLabel = titleViewer.getTextWidget(); @@ -74,8 +90,13 @@ public class HeaderText { titleLabel.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { titleLabel.setSelection(0); + Event selectionEvent= new Event(); + selectionEvent.x = 0; + selectionEvent.y = 0; + titleLabel.notifyListeners(SWT.Selection, selectionEvent); } }); + createContextMenu(titleLabel, sha1String); Point size = titleLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT); Image emptyImage = new Image(heading.getDisplay(), size.x, size.y); @@ -112,4 +133,50 @@ public class HeaderText { int y = (titleLabel.getParent().getSize().y - size.y) / 2; titleLabel.setBounds(busyLabel.getLocation().x, y, size.x, size.y); } + + private static void createContextMenu(final StyledText styledText, final String sha1String) { + Menu menu = new Menu(styledText); + + final MenuItem copySHA1MenuItem = new MenuItem(menu, SWT.PUSH); + copySHA1MenuItem.setText(UIText.Header_contextMenu_copy_SHA1); + final Shell shell = styledText.getShell(); + copySHA1MenuItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + copyToClipboard(sha1String, shell); + } + }); + + final MenuItem copyMenuItem = new MenuItem(menu, SWT.PUSH); + copyMenuItem.setText(UIText.Header_contextMenu_copy); + copyMenuItem.setEnabled(false); + copyMenuItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + styledText.copy(); + } + }); + styledText.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + copyMenuItem.setEnabled(styledText.getSelectionCount() > 0); + } + }); + + styledText.setMenu(menu); + } + + private static void copyToClipboard(String str, Shell shell) { + Clipboard clipboard= new Clipboard(shell.getDisplay()); + try { + clipboard.setContents(new String[] { str }, new Transfer[] { TextTransfer.getInstance() }); + } catch (SWTError ex) { + if (ex.code != DND.ERROR_CANNOT_SET_CLIPBOARD) + throw ex; + String title= UIText.Header_copy_SHA1_error_title; + String message= UIText.Header_copy_SHA1_error_message; + if (MessageDialog.openQuestion(shell, title, message)) + copyToClipboard(str, shell); + } finally { + clipboard.dispose(); + } + } + } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 05c59e9e4b..61f04c11e0 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -9,6 +9,7 @@ # Shawn Pearce - initial implementation # Daniel Megert <daniel_megert@ch.ibm.com> - Escaped single quotes where needed # - Removed unused entry +# - Added context menu to the Commit Editor's header text ############################################################################### AbortRebaseCommand_CancelDialogMessage=The abort operation was canceled AbortRebaseCommand_JobName=Aborting Rebase @@ -1165,6 +1166,11 @@ CommitEditorPage_TooltipCommitter=Committer CommitEditorPage_TooltipSignedOffByAuthor=Signed off by author CommitEditorPage_TooltipSignedOffByCommitter=Signed off by committer +Header_contextMenu_copy=&Copy +Header_contextMenu_copy_SHA1=Copy &SHA-1 +Header_copy_SHA1_error_title= Problem Copying SHA-1 to Clipboard +Header_copy_SHA1_error_message= There was a problem when accessing the system clipboard. Retry? + MergeHandler_SelectBranchMessage=There is more than one ref for this commit. Please select the ref you want to merge. MergeHandler_SelectBranchTitle=Select a Ref for Merge MultiPullResultDialog_DetailsButton=&Details |
