aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-28 17:56:48 (EDT)
committerChris Aniszczyk2011-04-29 08:37:01 (EDT)
commit2c09a303f7158429b843b63e5557528390ed71d6 (patch)
treec37cec20dacb53f231fe8f8f28eabb6d45074a21
parentc57c20ab5e53963065a66ca2fd77786d2c27c5bd (diff)
downloadegit-2c09a303f7158429b843b63e5557528390ed71d6.zip
egit-2c09a303f7158429b843b63e5557528390ed71d6.tar.gz
egit-2c09a303f7158429b843b63e5557528390ed71d6.tar.bz2
Add form editor with commit and diff pagesrefs/changes/90/3290/2
Bug: 343000 Change-Id: I81f1d0e814e7ad7998a268ea9fbe0140a737c573 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/plugin.properties3
-rw-r--r--org.eclipse.egit.ui/plugin.xml17
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java124
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java25
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties1
6 files changed, 170 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 77fd6da..abe97fc 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -265,4 +265,5 @@ DeleteBranchCommand.name = Delete Branch
RenameBranchCommand.name = Rename Branch
CompareInTreeCommand.name = Compare in Tree
CompareWithPreviousCommand.name = Compare with Previous Revision
-CompareWithPreviousAction.label = Previous Revision \ No newline at end of file
+CompareWithPreviousAction.label = Previous Revision
+CommitEditor.name = Git Commit Editor \ No newline at end of file
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 01551fe..ae1f2bc 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3407,4 +3407,21 @@
<extension
point="org.eclipse.core.expressions.propertyTesters">
</extension>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ class="org.eclipse.egit.ui.internal.commit.CommitEditor"
+ default="false"
+ icon="icons/obj16/changelog_obj.gif"
+ id="org.eclipse.egit.ui.commitEditor"
+ name="%CommitEditor.name">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ class="org.eclipse.egit.ui.internal.commit.CommitEditorInputFactory"
+ id="org.eclipse.egit.ui.internal.commit.CommitEditorInputFactory">
+ </factory>
+ </extension>
</plugin>
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 72d170c..a85f29f 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
@@ -2915,6 +2915,9 @@ public class UIText extends NLS {
public static String CommitActionHandler_repository;
/** */
+ public static String CommitEditor_TitleHeader;
+
+ /** */
public static String CommitEditorInput_Name;
/** */
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
new file mode 100644
index 0000000..67dabb0
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditor.java
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commit;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Editor class to view a commit in a form editor.
+ */
+public class CommitEditor extends SharedHeaderFormEditor {
+
+ /**
+ * ID - editor id
+ */
+ public static final String ID = "org.eclipse.egit.ui.commitEditor"; //$NON-NLS-1$
+
+ /**
+ * Open commit in editor
+ *
+ * @param commit
+ * @throws PartInitException
+ */
+ public static final void open(RepositoryCommit commit)
+ throws PartInitException {
+ CommitEditorInput input = new CommitEditorInput(commit);
+ IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage(), input, ID);
+ }
+
+ /**
+ * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+ */
+ protected void addPages() {
+ try {
+ addPage(new CommitEditorPage(this));
+ addPage(new DiffEditorPage(this));
+ } catch (PartInitException e) {
+ Activator.error("Error adding page", e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @see org.eclipse.ui.forms.editor.SharedHeaderFormEditor#createHeaderContents(org.eclipse.ui.forms.IManagedForm)
+ */
+ protected void createHeaderContents(IManagedForm headerForm) {
+ RepositoryCommit commit = getCommit();
+ ScrolledForm form = headerForm.getForm();
+ form.setText(MessageFormat.format(UIText.CommitEditor_TitleHeader,
+ commit.getRepositoryName(), commit.abbreviate()));
+ form.setToolTipText(commit.getRevCommit().name());
+ getToolkit().decorateFormHeading(form.getForm());
+ }
+
+ private RepositoryCommit getCommit() {
+ return (RepositoryCommit) getAdapter(RepositoryCommit.class);
+ }
+
+ /**
+ * @see org.eclipse.ui.part.MultiPageEditorPart#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (RepositoryCommit.class == adapter)
+ return getEditorInput().getAdapter(adapter);
+
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * @see org.eclipse.ui.forms.editor.FormEditor#init(org.eclipse.ui.IEditorSite,
+ * org.eclipse.ui.IEditorInput)
+ */
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ if (input.getAdapter(RepositoryCommit.class) == null) {
+ throw new PartInitException(
+ "Input could not be adapted to commit object"); //$NON-NLS-1$
+ }
+ super.init(site, input);
+ setPartName(input.getName());
+ setTitleToolTip(input.getToolTipText());
+ }
+
+ /**
+ * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void doSave(IProgressMonitor monitor) {
+ // Save not supported
+ }
+
+ /**
+ * @see org.eclipse.ui.part.EditorPart#doSaveAs()
+ */
+ public void doSaveAs() {
+ // Save as not supported
+ }
+
+ /**
+ * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
+ */
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
index 9fe7221..4458b6c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/CommitEditorPage.java
@@ -15,6 +15,7 @@ import java.text.MessageFormat;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea;
import org.eclipse.egit.ui.internal.history.FileDiff;
@@ -29,14 +30,18 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.events.ExpansionAdapter;
import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.Section;
/**
@@ -119,8 +124,24 @@ public class CommitEditorPage extends FormPage {
toolkit.createLabel(parents,
UIText.CommitEditorPage_LabelParent).setForeground(
toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
- toolkit.createHyperlink(parents,
- parentCommit.abbreviate(PARENT_LENGTH).name(), SWT.NONE);
+ final Hyperlink link = toolkit
+ .createHyperlink(parents,
+ parentCommit.abbreviate(PARENT_LENGTH).name(),
+ SWT.NONE);
+ link.addHyperlinkListener(new HyperlinkAdapter() {
+
+ public void linkActivated(HyperlinkEvent e) {
+ try {
+ CommitEditor.open(new RepositoryCommit(getCommit()
+ .getRepository(), parentCommit));
+ if ((e.getStateMask() & SWT.MOD1) != 0)
+ getEditor().close(false);
+ } catch (PartInitException e1) {
+ Activator.logError(
+ "Error opening commit editor", e1);//$NON-NLS-1$
+ }
+ }
+ });
}
}
}
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 0b5ba74..1cb7961 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
@@ -997,6 +997,7 @@ CommitAction_MergeHeadErrorMessage=The file .git/MERGE_MSG was not found althoug
CommitAction_MergeHeadErrorTitle=Inconsistent Merge state
CommitActionHandler_calculatingChanges=Calculating changes in selected repositories
CommitActionHandler_repository=Repository: {0}
+CommitEditor_TitleHeader={0} commit {1}...
CommitEditorInput_Name={0} [{1}]
CommitEditorInput_ToolTip=Commit {0} in repository {1}
CommitEditorPage_LabelAuthor={0} (author) on {1}