Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Dmitriev2014-09-22 22:10:36 +0000
committerVadim Dmitriev2014-10-22 20:48:18 +0000
commit52c6fc2726b033f665019add601fd354dc9eecfa (patch)
treed02930aaf8b6b61e5f585b8ac1ff253281e3d15e
parent41dae8a01f5fbfa4d4d31c30a0a564bf7e0ec736 (diff)
downloadegit-52c6fc2726b033f665019add601fd354dc9eecfa.tar.gz
egit-52c6fc2726b033f665019add601fd354dc9eecfa.tar.xz
egit-52c6fc2726b033f665019add601fd354dc9eecfa.zip
Link Interactive Rebase view with selected repository
Now rebase interactive view has a button in the toolbar to enable and disable linking view content with repository or resource selection. Bug: 444660 Change-Id: I417f53fc12af34d5843a14b205ceaac1a741de79 Signed-off-by: Vadim Dmitriev <dmgloss@mail.ru>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractivePreferences.java19
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java98
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties1
6 files changed, 113 insertions, 12 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
index 1b3d58bf93..e202ab3b18 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java
@@ -113,6 +113,8 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer {
store.setDefault(UIPreferences.CLONE_WIZARD_SHOW_DETAILED_FAILURE_DIALOG, true);
store.setDefault(UIPreferences.MERGE_MODE, "2"); //$NON-NLS-1$
store.setDefault(UIPreferences.USE_LOGICAL_MODEL, true);
+
+ store.setDefault(UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, true);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index 469ce50da6..9d182dcf1d 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -217,6 +217,8 @@ public class UIPreferences {
public static final String CLONE_WIZARD_SHOW_DETAILED_FAILURE_DIALOG = "CloneWizard_ShowDetailedFailureDialog"; //$NON-NLS-1$
/** */
public final static String REBASE_INTERACTIVE_ORDER_REVERSE = "rebase_interactive_order_reverse"; //$NON-NLS-1$
+ /** */
+ public static final String REBASE_INTERACTIVE_SYNC_SELECTION = "RebaseInteractive_SyncWithSelection"; //$NON-NLS-1$
/**
* Converts a persisted String separated with commas to an integer array
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index f80504b862..1e90561470 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -4216,6 +4216,9 @@ public class UIText extends NLS {
public static String InteractiveRebaseView_continueItem_text;
/** */
+ public static String InteractiveRebaseView_LinkSelection;
+
+ /** */
public static String InteractiveRebaseView_refreshItem_text;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractivePreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractivePreferences.java
index f079fe0eb8..3a09204766 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractivePreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractivePreferences.java
@@ -42,4 +42,23 @@ public class RebaseInteractivePreferences {
getPreferencesStore().setValue(
UIPreferences.REBASE_INTERACTIVE_ORDER_REVERSE, reversed);
}
+
+ /**
+ * @return if the view should react on selection changes.
+ */
+ public static boolean isReactOnSelection() {
+ return getPreferencesStore().getBoolean(
+ UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION);
+ }
+
+ /**
+ * Sets if the view should react on selection changes.
+ *
+ * @param react
+ * {@code true} - should react, {@code false} - should ignore.
+ */
+ public static void setReactOnSelection(boolean react) {
+ getPreferencesStore().setValue(
+ UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION, react);
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java
index d8c8b3a078..fa5e92ae71 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java
@@ -18,7 +18,11 @@ import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.egit.core.AdapterUtils;
+import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan;
import org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementAction;
import org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.ElementType;
@@ -30,6 +34,7 @@ import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.actions.BooleanPrefAction;
import org.eclipse.egit.ui.internal.commands.shared.AbortRebaseCommand;
import org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler;
import org.eclipse.egit.ui.internal.commands.shared.ContinueRebaseCommand;
@@ -39,11 +44,14 @@ import org.eclipse.egit.ui.internal.commit.CommitEditor;
import org.eclipse.egit.ui.internal.commit.RepositoryCommit;
import org.eclipse.egit.ui.internal.repository.RepositoriesView;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
+import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.util.LocalSelectionTransfer;
@@ -79,11 +87,13 @@ import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
@@ -147,6 +157,8 @@ public class RebaseInteractiveView extends ViewPart implements
private RebasePlanIndexer planIndexer;
+ private IPreferenceChangeListener prefListener;
+
/**
* View for handling interactive rebase
*/
@@ -181,6 +193,9 @@ public class RebaseInteractiveView extends ViewPart implements
if (resource != null) {
RepositoryMapping mapping = RepositoryMapping
.getMapping(resource);
+ if (mapping == null)
+ return;
+
repo = mapping.getRepository();
}
}
@@ -214,6 +229,10 @@ public class RebaseInteractiveView extends ViewPart implements
if (planIndexer != null)
planIndexer.dispose();
+
+ InstanceScope.INSTANCE.getNode(
+ org.eclipse.egit.core.Activator.getPluginId())
+ .removePreferenceChangeListener(prefListener);
}
@Override
@@ -278,6 +297,52 @@ public class RebaseInteractiveView extends ViewPart implements
return null;
}
});
+
+ prefListener = new IPreferenceChangeListener() {
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (!RepositoryUtil.PREFS_DIRECTORIES.equals(event.getKey()))
+ return;
+
+ final Repository repo = currentRepository;
+ if (repo == null)
+ return;
+
+ if (Activator.getDefault().getRepositoryUtil().contains(repo))
+ return;
+
+ // Unselect repository as it has been removed
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ currentRepository = null;
+ showRepository(null);
+ }
+ });
+ }
+ };
+
+ InstanceScope.INSTANCE.getNode(
+ org.eclipse.egit.core.Activator.getPluginId())
+ .addPreferenceChangeListener(prefListener);
+
+ IActionBars actionBars = getViewSite().getActionBars();
+ IToolBarManager toolbar = actionBars.getToolBarManager();
+
+ listenOnRepositoryViewSelection = RebaseInteractivePreferences
+ .isReactOnSelection();
+
+ // link with selection
+ Action linkSelectionAction = new BooleanPrefAction(
+ (IPersistentPreferenceStore) Activator.getDefault()
+ .getPreferenceStore(),
+ UIPreferences.REBASE_INTERACTIVE_SYNC_SELECTION,
+ UIText.InteractiveRebaseView_LinkSelection) {
+ @Override
+ public void apply(boolean value) {
+ listenOnRepositoryViewSelection = value;
+ }
+ };
+ linkSelectionAction.setImageDescriptor(UIIcons.ELCL16_SYNCED);
+ toolbar.add(linkSelectionAction);
}
private void createCommandToolBar(Form theForm, FormToolkit toolkit) {
@@ -424,8 +489,7 @@ public class RebaseInteractiveView extends ViewPart implements
};
ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
- srv.addPostSelectionListener(RepositoriesView.VIEW_ID,
- selectionChangedListener);
+ srv.addPostSelectionListener(selectionChangedListener);
}
private class RebaseCommandItemSelectionListener extends SelectionAdapter {
@@ -752,10 +816,6 @@ public class RebaseInteractiveView extends ViewPart implements
private void showRepository(final Repository repository) {
if (form.isDisposed())
return;
- if (repository == null) {
- form.setText(UIText.RebaseInteractiveView_NoSelection);
- return;
- }
if (currentPlan != null)
currentPlan.removeRebaseInteractivePlanChangeListener(this);
@@ -763,13 +823,24 @@ public class RebaseInteractiveView extends ViewPart implements
if (planIndexer != null)
planIndexer.dispose();
- currentPlan = RebaseInteractivePlan.getPlan(repository);
- planIndexer = new RebasePlanIndexer(currentPlan);
- currentPlan.addRebaseInteractivePlanChangeListener(this);
- form.setText(getRepositoryName(repository));
+ if (isValidRepo(repository)) {
+ currentPlan = RebaseInteractivePlan.getPlan(repository);
+ planIndexer = new RebasePlanIndexer(currentPlan);
+ currentPlan.addRebaseInteractivePlanChangeListener(this);
+ form.setText(getRepositoryName(repository));
+ } else {
+ currentPlan = null;
+ planIndexer = null;
+ form.setText(UIText.RebaseInteractiveView_NoSelection);
+ }
refresh();
}
+ private boolean isValidRepo(final Repository repository) {
+ return repository != null && !repository.isBare()
+ && repository.getWorkTree().exists();
+ }
+
void refresh() {
if (!isReady())
return;
@@ -836,8 +907,11 @@ public class RebaseInteractiveView extends ViewPart implements
if (RebaseInteractivePreferences.isOrderReversed()) {
Tree tree = planTreeViewer.getTree();
- TreeItem bottomItem = tree.getItem(tree.getItemCount() - 1);
- tree.showItem(bottomItem);
+ int itemCount = tree.getItemCount();
+ if (itemCount > 0) {
+ TreeItem bottomItem = tree.getItem(itemCount - 1);
+ tree.showItem(bottomItem);
+ }
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index bb01525b8c..c18ffc6b9f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1529,6 +1529,7 @@ ImportProjectsWrongSelection = Wrong selection
ImportProjectsSelectionInRepositoryRequired = A folder selection in the Repository View is required
InteractiveRebaseView_abortItem_text= Abort
InteractiveRebaseView_continueItem_text= Continue
+InteractiveRebaseView_LinkSelection=Link with Editor and Selection
InteractiveRebaseView_refreshItem_text= Refresh
InteractiveRebaseView_skipItem_text= Skip
InteractiveRebaseView_startItem_text= Start

Back to the top