| Summary: | Cancel button in "Ask via popup" strategy opens the selected editor | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Kaloyan Raev <kaloyan> |
| Component: | UI | Assignee: | Patrik Suzzi <psuzzi> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | gautier.desaintmartinlacaze, Lars.Vogel, loskutov, mistria, psuzzi |
| Version: | 4.6 | ||
| Target Milestone: | 4.6 M5 | ||
| Hardware: | All | ||
| OS: | All | ||
| See Also: |
https://git.eclipse.org/r/63820 https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=fed29d30e755af1480939dc62a117c13073ab4c8 https://bugs.eclipse.org/bugs/show_bug.cgi?id=486665 |
||
| Whiteboard: | |||
|
Description
Kaloyan Raev
The problem here is AskUserViaPopupUnknownEditorStrategy#getEditorDescriptor always return an editor:
dialog.open();
// <1>
return dialog.getSelectedEditor();
the caller is IDE#getEditorDescriptor.
It always expects an editor, and when the editor it is null,
it shows the user an Exception
IEditorDescriptor editorDesc = strategy.getEditorDescriptor(name, editorReg);
// if no valid editor found, bail out
if (editorDesc == null) {
throw new PartInitException(
IDEWorkbenchMessages.IDE_noFileEditorFound);
}
So, if in <1> we return null on dialog.cancel
The IDE#getEditorDescriptor will throw an exception
This is not aceptable.
Any suggestion before I start working on this ?
Because of how the underlying open action in the IDE class is implemented, we cannot return null as editor here, because the openEditor() operations do not support cancel. So the strategy cannot really support cancel neither. Some possibilities: * Hide/Remove Cancel button * Fallback to the SystemEditor or TextEditor strategy in case Cancel is hit Codewise, it could be simple to throw a different exception telling the user he didn't choose an editor New Gerrit change created: https://git.eclipse.org/r/63820 Indeed, but that would have to be propagated to IDE class (where about everything is an immutable API) and to UI then. Because of our concern in backward compatibility, it makes the addition of Exception not such a trivial task. But if you manage to implement that as you suggest without breaking compatibility, then it's most likely the best implementation. Another possibility is to stop assuming that openEditor returning null is an error and to simply not pop-up an error when this happens. As suggested in Gerrit reviews, I added the strategy a method to return IStatus. Now IDE can discriminate the state based on IStatus and, in case of error, it shows a specific exception message when the user cancels. The exception is the same type of exception used in case the Editor is null, but the descriptive text explains that the user is responsible for mis-selection Note the bug applies to two cases, and the solution works for both: - when user opens a file with unknown extension, and cancels the selection - when the user creates a new file with unknown extension Gerrit change https://git.eclipse.org/r/63820 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=fed29d30e755af1480939dc62a117c13073ab4c8 I've updated interface to document that the implementers can throw either Core or OperationCancelled exceptions. The merged fix respects user cancellation in the editor selection dialog: no editor is opened on cancel. |