-
Notifications
You must be signed in to change notification settings - Fork 209
Make ContentTypes->default text editor as Generic Code Editor. #2832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Make ContentTypes->default text editor as Generic Code Editor. #2832
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why reversing the list fixes the issue?
Could you hold on the review please, i found another bug with my fix. So once that is fixed may be you can review it please. |
Test Results 1 824 files + 1 1 824 suites +1 1h 33m 8s ⏱️ + 2m 33s For more details on these failures, see this check. Results for commit 18ee998. ± Comparison against base commit 7f9ec57. ♻️ This comment has been updated with latest results. |
Change on the preference page alone doesn't change default associations. Note, there will be most likely lot of tests failing which expect default test editor be opened if you switch defaults (depending on where and how you will do that). |
Thanks for the feedback and headsup, even i was expecting some failures because default behavior is changing with the fix. That was the primary reason i have made it a draft than a normal pr. |
e1eb5d8
to
c1517a3
Compare
Fixes eclipse-platform#2527 Make ContentTypes->default text editor as Generic Code Editor. Fixes eclipse-platform#2527
c1517a3
to
18ee998
Compare
@BeckerWdf I have tested this issue completely and also tried with xml, html files. They are not impacted. |
@vogella @BeckerWdf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is addressed at the wrong layer. The default editor is not something to be hardcoded but to be configured.
@@ -1358,6 +1358,13 @@ private IEditorDescriptor selectDefaultEditor(List<IEditorDescriptor> descriptor | |||
String key = IPreferenceConstants.DEFAULT_EDITOR_FOR_CONTENT_TYPE + contentType.getId(); | |||
String defaultEditorId = store.getString(key); | |||
IEditorDescriptor descriptor = null; | |||
if (defaultEditorId.isEmpty() && contentType.getId().contentEquals("org.eclipse.core.runtime.text")) { //$NON-NLS-1$ | |||
IEditorDescriptor genericEditor = descriptors.stream() | |||
.filter(e -> "org.eclipse.ui.genericeditor.GenericEditor".equals(e.getId())) //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, org.eclipse.ui.workbench does not depend on the genericeditor plugin, so this would be possibly incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, org.eclipse.ui.workbench plugin does have neither org.eclipse.workbench.texteditor or org.eclipse.ui.genericeditor in its plugin dependencies.
@@ -1358,6 +1358,13 @@ private IEditorDescriptor selectDefaultEditor(List<IEditorDescriptor> descriptor | |||
String key = IPreferenceConstants.DEFAULT_EDITOR_FOR_CONTENT_TYPE + contentType.getId(); | |||
String defaultEditorId = store.getString(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to change the defaultEditorId for this key, this is probably something to define the preferences; through a preference initializing or some plugin_customization.ini in the product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am back from my vacation. Let me check on this. Thanks for your inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
through a preference initializing or some plugin_customization.ini in the product.
Correct. It would be
org.eclipse.ui.workbench/defaultEditorForContentType_org.eclipse.core.runtime.text=org.eclipse.ui.genericeditor.GenericEditor
and it would belong to the products
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right way to unconditionally change user preferences in a getter method.
There are two different other, less hacky solutions proposed in comments, please consider them as the path forward.
@@ -1358,6 +1358,13 @@ private IEditorDescriptor selectDefaultEditor(List<IEditorDescriptor> descriptor | |||
String key = IPreferenceConstants.DEFAULT_EDITOR_FOR_CONTENT_TYPE + contentType.getId(); | |||
String defaultEditorId = store.getString(key); | |||
IEditorDescriptor descriptor = null; | |||
if (defaultEditorId.isEmpty() && contentType.getId().contentEquals("org.eclipse.core.runtime.text")) { //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As author of this lines I've played with the idea to pick up the generic editor and make it default, but that could potentially break behavior of existing tests or products who depend on plain text editor usage.
Same effect can be achieved by a simple change of the generic editor contribution
diff --git a/bundles/org.eclipse.ui.genericeditor/plugin.xml b/bundles/org.eclipse.ui.genericeditor/plugin.xml
index 107f075..1711b4d 100644
--- a/bundles/org.eclipse.ui.genericeditor/plugin.xml
+++ b/bundles/org.eclipse.ui.genericeditor/plugin.xml
@@ -34,3 +34,3 @@
contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
- default="false"
+ default="true"
icon="icons/full/obj16/generic_editor.png"
But guess why it wasn't done by default...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But guess why it wasn't done by default...
@iloveeclipse
I think this is the simplest ever possible solution. It works so awesome. But why it should not be used this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if another editor also decides to declares itself as "default" ? Overall, this "default" flag is a mistake from the beginning: in an extensible environment (may it be the IDE, the OS...), nothing can pretend to be the default for task X as other competitive, and maybe better, solutions can be provided at any point of time. Setting default=true here isn't much better than harcoding it in the code, as it makes extensibility more complex.
The choice of the "best" or "recommended" default becomes more a choice of packaging (set in .product) or preference (set in preference page).
That was my dogmatic answer (which I still think is the only correct one). That said, I don't care that much and if most people want to change the flag here, I wouldn't see it as a big harm; as long as people who make the change are ready to face the criticism from the people who have set default=true
in their RCP and might now see a different behavior (but maybe pushing them to use the Generic Editor is likely to help them on the longer run...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works so awesome. But why it should not be used this way?
See above: that could potentially break behavior of existing tests or products who depend on plain text editor usage.
However, thinking once more about it while answering here, now with #1659 fixed via #1665 one could argue that customers expecting "old classic" text editor to be opened by default could simply customize their products by adding this line in product customization file:
org.eclipse.ui.workbench/defaultEditorForContentType_org.eclipse.core.runtime.text=org.eclipse.ui.DefaultTextEditor
Given that, the change would be not breaking because we would have a viable workaround. I've pushed #2881, let see what tests say.
Make ContentTypes->default text editor as Generic Code Editor.
Fixes #2527
Before the pr

When i come to Content Types page ->
1st screen
2nd screen when i select Text

3rd screen when i open a text file

After the pr changes

When i come to Content Types page ->
1st screen
2nd screen when i select Text

3rd screen when i open a text file
