summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRemy Suen2010-04-26 18:35:34 (EDT)
committer Chris Aniszczyk2010-04-26 18:39:55 (EDT)
commit70353242991531860eb1ac930caeea00d02d4697 (patch)
treeca21ed7aa1328b11578221f29276dd3eb8245c3b
parent974c5c47687dccbed6b0fe88b7025c8e1363bc42 (diff)
downloadegit-70353242991531860eb1ac930caeea00d02d4697.zip
egit-70353242991531860eb1ac930caeea00d02d4697.tar.gz
egit-70353242991531860eb1ac930caeea00d02d4697.tar.bz2
'Repositories' view should use IOpenListenerrefs/changes/90/590/4
Using open events to expand/collapse tree nodes or to open the current selection is very common in the Eclipse workbench. An IOpenListener has been attached to the 'Repositories' view so that it will react in the same way as other Eclipse views. Change-Id: I2e6d622fc96ca4a0f52ac0b462f1320f754dbc1b Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java67
1 files changed, 53 insertions, 14 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
index ed3fc59..d78044f 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java
@@ -55,10 +55,13 @@ import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode.RepositoryTree
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
@@ -252,6 +255,39 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
}
});
+ tv.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ if (selection.isEmpty()) {
+ // nothing selected, ignore
+ return;
+ }
+
+ Object element = selection.getFirstElement();
+ ITreeContentProvider contentProvider = (ITreeContentProvider) tv
+ .getContentProvider();
+ if (contentProvider.hasChildren(element)) {
+ // this element has children, expand/collapse it
+ tv.setExpandedState(element, !tv.getExpandedState(element));
+ } else {
+ Object[] selectionArray = selection.toArray();
+ for (Object selectedElement : selectionArray) {
+ RepositoryTreeNode node = (RepositoryTreeNode) selectedElement;
+ // if any of the selected elements are not files, ignore the open request
+ if (node.getType() != RepositoryTreeNodeType.FILE) {
+ return;
+ }
+ }
+
+ // open the files the user has selected
+ for (Object selectedElement : selectionArray) {
+ RepositoryTreeNode node = (RepositoryTreeNode) selectedElement;
+ openFile((File) node.getObject());
+ }
+ }
+ }
+ });
addContextMenu();
@@ -793,20 +829,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
@Override
public void widgetSelected(SelectionEvent e) {
- IFileStore store = EFS.getLocalFileSystem().getStore(
- new Path(file.getAbsolutePath()));
- try {
- // TODO do we need a read-only editor here?
- IDE.openEditor(getSite().getPage(),
- new FileStoreEditorInput(store),
- EditorsUI.DEFAULT_TEXT_EDITOR_ID);
-
- } catch (PartInitException e1) {
- MessageDialog.openError(getSite().getShell(),
- UIText.RepositoriesView_Error_WindowTitle, e1
- .getMessage());
- }
-
+ openFile(file);
}
});
@@ -824,6 +847,22 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider {
}
+ private void openFile(File file) {
+ IFileStore store = EFS.getLocalFileSystem().getStore(
+ new Path(file.getAbsolutePath()));
+ try {
+ // TODO do we need a read-only editor here?
+ IDE.openEditor(getSite().getPage(),
+ new FileStoreEditorInput(store),
+ EditorsUI.DEFAULT_TEXT_EDITOR_ID);
+ } catch (PartInitException e) {
+ MessageDialog.openError(getSite().getShell(),
+ UIText.RepositoriesView_Error_WindowTitle, e.getMessage());
+ Activator.getDefault().getLog().log(
+ Activator.error("Failed to open editor on external file", e)); //$NON-NLS-1$
+ }
+ }
+
private void createImportProjectItem(Menu men, final Repository repo,
final String path) {
MenuItem importProjects;