Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deepika-u
Copy link
Contributor

@deepika-u deepika-u commented Mar 11, 2025

Make ContentTypes->default text editor as Generic Code Editor.

Fixes #2527

Before the pr
When i come to Content Types page ->
1st screen
image

2nd screen when i select Text
image

3rd screen when i open a text file
image

After the pr changes
When i come to Content Types page ->
1st screen
image

2nd screen when i select Text
image

3rd screen when i open a text file
image

Copy link
Contributor

@BeckerWdf BeckerWdf left a 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?

@deepika-u
Copy link
Contributor Author

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.

Copy link
Contributor

github-actions bot commented Mar 11, 2025

Test Results

 1 824 files  +  1   1 824 suites  +1   1h 33m 8s ⏱️ + 2m 33s
 7 918 tests ±  0   7 689 ✅ ±  0  228 💤 ±0  1 ❌ ±0 
23 841 runs  +121  23 092 ✅ +121  748 💤 ±0  1 ❌ ±0 

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.

@iloveeclipse
Copy link
Member

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).

@deepika-u
Copy link
Contributor Author

deepika-u commented Mar 11, 2025

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.

@deepika-u deepika-u force-pushed the ContentType_defaultTextEditor branch 3 times, most recently from e1eb5d8 to c1517a3 Compare March 17, 2025 12:05
Fixes eclipse-platform#2527
Make ContentTypes->default text editor as Generic Code Editor.

Fixes eclipse-platform#2527
@deepika-u deepika-u force-pushed the ContentType_defaultTextEditor branch from c1517a3 to 18ee998 Compare March 17, 2025 12:06
@deepika-u deepika-u marked this pull request as ready for review March 18, 2025 05:32
@deepika-u
Copy link
Contributor Author

@BeckerWdf
org.eclipse.ui.tests.dialogs.ResourceInitialSelectionTest.testSingleSelectionAndTwoInitialSelectionsWithInitialPattern is locally passing with the pr on mac
image (3)

I have tested this issue completely and also tried with xml, html files. They are not impacted.
Can you review now please?

@deepika-u
Copy link
Contributor Author

@vogella @BeckerWdf
Can you review this pr please when you get some time?

Copy link
Contributor

@mickaelistria mickaelistria left a 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$
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@iloveeclipse iloveeclipse left a 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$
Copy link
Member

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...

Copy link
Contributor Author

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?

Copy link
Contributor

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...).

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Generic Code Editor default for text files
4 participants