Commit 361a02a5 authored by Marko Luukkainen's avatar Marko Luukkainen Committed by Tuukka Lehtonen

Modified OpenWith for further customization.

gitlab #624

Change-Id: I186c49de0590f4832e7f6337505001db81c057bf
(cherry picked from commit acf5a3bf)
parent fd757177
......@@ -38,4 +38,9 @@ public class GraphDebuggerEditorAdapter extends AbstractResourceEditorAdapter {
openEditorWithId(GraphDebuggerEditor.EDITOR_ID, new ResourceEditorInput(GraphDebuggerEditor.EDITOR_ID,r));
}
@Override
public String getEditorId() {
return GraphDebuggerEditor.EDITOR_ID;
}
}
......@@ -36,4 +36,9 @@ public class GraphicalDebuggerEditorAdapter extends AbstractResourceEditorAdapte
openEditorWithId(GraphicalDebuggerEditor.EDITOR_ID, new ResourceEditorInput(GraphicalDebuggerEditor.EDITOR_ID,r));
}
@Override
public String getEditorId() {
return GraphicalDebuggerEditor.EDITOR_ID;
}
}
......@@ -49,7 +49,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements
private static final boolean DEBUG_ADAPTERS = false;
private ResourceManager resourceManager;
protected ResourceManager resourceManager;
private String editorId = null;
public OpenWithMenuContribution() {
......@@ -73,6 +73,10 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements
}
}
public String getEditorId() {
return editorId;
}
public void setEditorId(String editorId) {
this.editorId = editorId;
}
......@@ -123,18 +127,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements
if (editorAdapters.length > 0) {
// Sort the open with actions in descending priority order.
Adapter[] adapters = new Adapter[editorAdapters.length];
for (int i = 0; i < editorAdapters.length; i++)
adapters[i] = new Adapter(editorAdapters[i], r, true);
Arrays.sort(adapters, new Comparator<Adapter>() {
@Override
public int compare(Adapter o1, Adapter o2) {
int delta = o2.getPriority() - o1.getPriority();
if (delta != 0)
return delta;
return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getText(), o2.getText());
}
});
Adapter[] adapters = toAdapters(editorAdapters, r);
for (Adapter a : adapters)
addMenuItem(subMenu, a, r);
......@@ -144,6 +137,22 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements
};
}
protected Adapter[] toAdapters(EditorAdapter[] editorAdapters, Object r) {
Adapter[] adapters = new Adapter[editorAdapters.length];
for (int i = 0; i < editorAdapters.length; i++)
adapters[i] = new Adapter(editorAdapters[i], r, true);
Arrays.sort(adapters, new Comparator<Adapter>() {
@Override
public int compare(Adapter o1, Adapter o2) {
int delta = o2.getPriority() - o1.getPriority();
if (delta != 0)
return delta;
return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.getText(), o2.getText());
}
});
return adapters;
}
protected EditorAdapter[] filter(EditorAdapter[] adapters, String id) {
if (id == null)
return adapters;
......@@ -170,7 +179,7 @@ public class OpenWithMenuContribution extends DynamicMenuContribution implements
item.addSelectionListener(adapter);
}
static class Adapter extends ResourceEditorAdapterAction implements SelectionListener {
protected static class Adapter extends ResourceEditorAdapterAction implements SelectionListener {
boolean remember;
public Adapter(EditorAdapter adapter, Object r, boolean remember) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment