Skip to content

Commit

Permalink
TEIIDDES-1724: Stops active editor selection if object is a descendent
Browse files Browse the repository at this point in the history
* When opening an editor, the default behaviour is to find the file that
  is the input of the editor. This file is then selected in the model
  explorer if 'link with editor' is enabled.

* Behaviour changed to check whether the file being selected in the model
  explorer is the container of the currently selected object. If it is
  then do not change the selection.
  • Loading branch information
Paul Richardson committed Sep 16, 2013
1 parent 15b1f10 commit d35e012
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Set;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -70,6 +71,7 @@
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.ISelectionListener;
Expand All @@ -92,6 +94,7 @@
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.IGotoMarker;
import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.ui.operations.UndoActionHandler;
import org.eclipse.ui.part.IShowInTarget;
import org.eclipse.ui.part.PluginTransfer;
Expand Down Expand Up @@ -1621,6 +1624,41 @@ else if (renameAction != null && renameAction.isEnabled()) {
}
}

@Override
protected void editorActivated(IEditorPart editor) {
if (!isLinkingEnabled()) {
return;
}

IFile file = ResourceUtil.getFile(editor.getEditorInput());
if (file == null)
return;

ISelection newSelection = new StructuredSelection(file);
TreeViewer treeViewer = getTreeViewer();
ISelection oldSelection = treeViewer.getSelection();

if (oldSelection.equals(newSelection)) {
treeViewer.getTree().showSelection();
return;
}

if (oldSelection instanceof IStructuredSelection && !oldSelection.isEmpty()) {
IStructuredSelection sSelection = (IStructuredSelection) oldSelection;
/*
* If the current selection is in any way a sub-compoment of the new selected file,
* eg. a table or transformation diagram, then don't select the file as this is just
* an annoying waste of time.
*/
for (Object element : sSelection.toArray()) {
if (file.equals(ResourceUtil.getFile(element)))
return;
}
}

treeViewer.setSelection(newSelection, true);
}

protected class ShowImportsAction extends Action {
public ShowImportsAction() {
super(Util.getString(I18N_PREFIX + "showImportsAction"), IAction.AS_CHECK_BOX); //$NON-NLS-1$
Expand Down

0 comments on commit d35e012

Please sign in to comment.