Skip to content

Commit c41b487

Browse files
committed
Add "Advanced Text Editor" strategy to the list of possible strategies
Extend the options provided in "Open unassociated files with:" selection box to "Advanced Text Editor" (and "System Editor, if none: Advanced Text Editor"), which offer more functionality as "Text" by default. Hint: "Advanced" is just a user visible name for the existing "Generic" text editor behind. Fixes #1380
1 parent 1251165 commit c41b487

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

bundles/org.eclipse.ui.genericeditor/plugin.properties

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ command.toggle.highlight.name = Toggle Highlight
3737
menu.source.label = Source
3838
gotoMatchingBracketCommand_name = Go to Matching Bracket
3939
gotoMatchingBracketCommand_description = Moves the cursor to the matching bracket
40+
systemEditorOrGenericEditorStrategy=System Editor; if none: Advanced Text Editor
41+
genericEditorStrategy=Advanced Text Editor

bundles/org.eclipse.ui.genericeditor/plugin.xml

+15
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,19 @@
260260
contentType="org.eclipse.core.runtime.text">
261261
</reconciler>
262262
</extension>
263+
<extension
264+
point="org.eclipse.ui.ide.unassociatedEditorStrategy">
265+
<strategy
266+
class="org.eclipse.ui.internal.genericeditor.SystemEditorOrGenericTextEditorStrategy"
267+
id="org.eclipse.ui.internal.genericeditor.systemEditorOrGenericEditor"
268+
interactive="false"
269+
label="%systemEditorOrGenericEditorStrategy">
270+
</strategy>
271+
<strategy
272+
class="org.eclipse.ui.internal.genericeditor.GenericTextEditorStrategy"
273+
id="org.eclipse.ui.internal.genericeditor.genericTextEditor"
274+
interactive="false"
275+
label="%genericEditorStrategy">
276+
</strategy>
277+
</extension>
263278
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Andrey Loskutov ([email protected]) and others
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Andrey Loskutov ([email protected])
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.genericeditor;
15+
16+
import org.eclipse.ui.IEditorDescriptor;
17+
import org.eclipse.ui.IEditorRegistry;
18+
import org.eclipse.ui.ide.IUnassociatedEditorStrategy;
19+
20+
/**
21+
* Use generic text editor for unassociated text files.
22+
* <p>
23+
* This allows to see syntax highlighting in all editors opened on "not
24+
* associated" file extensions, if there is a tm4e support for that syntax
25+
* available - for example with python, css, html, xml files.
26+
* </p>
27+
*/
28+
public final class GenericTextEditorStrategy implements IUnassociatedEditorStrategy {
29+
30+
@Override
31+
public IEditorDescriptor getEditorDescriptor(String name, IEditorRegistry editorReg) {
32+
// don't care about file name and always return generic editor id
33+
// No files from "registered" editors will appear here
34+
return editorReg.findEditor(ExtensionBasedTextEditor.GENERIC_EDITOR_ID);
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Andrey Loskutov ([email protected]) and others
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Andrey Loskutov ([email protected])
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.genericeditor;
15+
16+
import org.eclipse.ui.IEditorDescriptor;
17+
import org.eclipse.ui.IEditorRegistry;
18+
import org.eclipse.ui.ide.IUnassociatedEditorStrategy;
19+
20+
/**
21+
* Strategy for unassociated file types:
22+
* <ol>
23+
* <li>The operating system is consulted to determine if an in-place component
24+
* editor is available (e.g. OLE editor on Win32 platforms).</li>
25+
* <li>The operating system is consulted to determine if an external editor is
26+
* available.</li>
27+
* <li>The workbench editor registry is consulted to determine if the generic
28+
* text editor is available.</li>
29+
* </ol>
30+
*/
31+
public final class SystemEditorOrGenericTextEditorStrategy implements IUnassociatedEditorStrategy {
32+
33+
@Override
34+
public IEditorDescriptor getEditorDescriptor(String name, IEditorRegistry editorReg) {
35+
IEditorDescriptor editorDesc = null;
36+
// next check the OS for in-place editor (OLE on Win32)
37+
if (editorReg.isSystemInPlaceEditorAvailable(name)) {
38+
editorDesc = editorReg.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
39+
}
40+
41+
// next check with the OS for an external editor
42+
if (editorDesc == null && editorReg.isSystemExternalEditorAvailable(name)) {
43+
editorDesc = editorReg.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
44+
}
45+
46+
// next lookup the default text editor
47+
if (editorDesc == null) {
48+
editorDesc = editorReg.findEditor(ExtensionBasedTextEditor.GENERIC_EDITOR_ID);
49+
}
50+
return editorDesc;
51+
}
52+
}

0 commit comments

Comments
 (0)