1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix a few things for the QML editor.

Fixed up content type warning. Hooked up colors for the QMLEditor to
the CEditor preferences. Fixed up tabbing in the main.qml template.
Fixed the GCC toolchain to find compiler on path on windows.

Change-Id: I66a013666d1ab99bfe94a2a558486cc81681c67c
This commit is contained in:
Doug Schaefer 2016-05-16 10:39:02 -04:00 committed by Gerrit Code Review @ Eclipse.org
parent 022e9428fd
commit 1cd5ff5169
5 changed files with 136 additions and 42 deletions

View file

@ -289,6 +289,12 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
return command;
}
if (Platform.getOS().equals(Platform.OS_WIN32)) {
if (!command.toString().endsWith(".exe")) { //$NON-NLS-1$
command = Paths.get(command.toString() + ".exe"); //$NON-NLS-1$
}
}
if (path != null) {
for (Path p : path) {
Path c = p.resolve(command);

View file

@ -2,17 +2,17 @@ import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
visible: true
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
}

View file

@ -68,7 +68,7 @@
point="org.eclipse.core.filebuffers.documentSetup">
<participant
class="org.eclipse.cdt.internal.qt.ui.editor.QMLDocumentSetupParticipant"
contentTypeId="qmlFile"
contentTypeId="org.eclipse.cdt.qt.core.qmlFile"
extensions="qml">
</participant>
</extension>

View file

@ -17,6 +17,7 @@ import javax.script.ScriptException;
import org.eclipse.cdt.internal.qt.ui.Activator;
import org.eclipse.cdt.internal.qt.ui.actions.OpenDeclarationsAction;
import org.eclipse.cdt.qt.core.IQMLAnalyzer;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceStore;
@ -27,8 +28,11 @@ import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
/**
@ -39,14 +43,36 @@ public class QMLEditor extends TextEditor {
public static final String BRACKET_MATCHING_COLOR_PREFERENCE = "org.eclipse.cdt.qt.ui.qmlMatchingBracketsColor"; //$NON-NLS-1$
private static final String BRACKET_MATCHING_PREFERENCE = "org.eclipse.cdt.qt.ui.qmlMatchingBrackets"; //$NON-NLS-1$
private static final char[] BRACKETS = { '{', '}', '(', ')', '[', ']' };
private final IQMLAnalyzer analyzer = Activator.getService(IQMLAnalyzer.class);
@Override
protected void initializeEditor() {
super.initializeEditor();
setSourceViewerConfiguration(new QMLSourceViewerConfiguration(this, getPreferenceStore()));
IPreferenceStore prefStore = new ChainedPreferenceStore(new IPreferenceStore[] {
Activator.getDefault().getPreferenceStore(),
CUIPlugin.getDefault().getPreferenceStore(),
CUIPlugin.getDefault().getCorePreferenceStore(),
EditorsUI.getPreferenceStore()
});
setPreferenceStore(prefStore);
setSourceViewerConfiguration(new QMLSourceViewerConfiguration(this, prefStore));
}
@Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
((QMLSourceViewerConfiguration) getSourceViewerConfiguration()).handlePreferenceStoreChanged(event);
super.handlePreferenceStoreChanged(event);
}
@Override
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
if (((QMLSourceViewerConfiguration) getSourceViewerConfiguration()).affectsTextPresentation(event)) {
return true;
} else {
return super.affectsTextPresentation(event);
}
}
@Override
@ -77,7 +103,7 @@ public class QMLEditor extends TextEditor {
support.setMatchingCharacterPainterPreferenceKeys(BRACKET_MATCHING_PREFERENCE,
BRACKET_MATCHING_COLOR_PREFERENCE);
IPreferenceStore store = getPreferenceStore();
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(BRACKET_MATCHING_PREFERENCE, true);
store.setDefault(BRACKET_MATCHING_COLOR_PREFERENCE, "155,155,155"); //$NON-NLS-1$
}

View file

@ -12,8 +12,13 @@ package org.eclipse.cdt.internal.qt.ui.editor;
import java.util.Map;
import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.ui.text.ICColorConstants;
import org.eclipse.cdt.ui.text.IColorManager;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
@ -30,37 +35,29 @@ import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
/**
* Performs syntax highlighting for the {@link QMLEditor}.
*/
public class QMLSourceViewerConfiguration extends TextSourceViewerConfiguration {
private static final int TOKEN_DEFAULT = 0;
private static final int TOKEN_MULTI_LINE_COMMENT = 1;
private static final int TOKEN_SINGLE_LINE_COMMENT = 2;
private static final int TOKEN_KEYWORD = 3;
private static final int TOKEN_STRING = 4;
private static final int TOKEN_TASK_TAG = 5;
// Just using Qt Creator defaults-ish for now
// TODO: Add preference page for syntax highlighting
private static final IToken[] allTokens = new IToken[] { new Token(null),
new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 155, 200)))),
new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 155, 200)))),
new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(155, 155, 0)), null, SWT.BOLD)),
new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 155, 0)), null, SWT.ITALIC)),
new Token(new TextAttribute(new Color(Display.getCurrent(), new RGB(0, 100, 155)), null, SWT.BOLD)) };
private Token defaultToken;
private Token multiLineCommentToken;
private Token singleLineCommentToken;
private Token keywordToken;
private Token stringToken;
private Token taskTagToken;
private final QMLEditor editor;
public QMLSourceViewerConfiguration(QMLEditor editor, IPreferenceStore prefs) {
super(prefs);
this.editor = editor;
initTokens(prefs);
}
@Override
@ -89,21 +86,21 @@ public class QMLSourceViewerConfiguration extends TextSourceViewerConfiguration
private ITokenScanner createMultiLineCommentTokenScanner() {
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setDefaultReturnToken(allTokens[TOKEN_MULTI_LINE_COMMENT]);
scanner.setRules(new IRule[] { createTaskTagRule(allTokens[TOKEN_MULTI_LINE_COMMENT]) });
scanner.setDefaultReturnToken(multiLineCommentToken);
scanner.setRules(new IRule[] { createTaskTagRule(multiLineCommentToken) });
return scanner;
}
private ITokenScanner createSingleLineCommentTokenScanner() {
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setDefaultReturnToken(allTokens[TOKEN_SINGLE_LINE_COMMENT]);
scanner.setRules(new IRule[] { createTaskTagRule(allTokens[TOKEN_SINGLE_LINE_COMMENT]) });
scanner.setDefaultReturnToken(singleLineCommentToken);
scanner.setRules(new IRule[] { createTaskTagRule(singleLineCommentToken) });
return scanner;
}
private ITokenScanner createStringTokenScanner() {
RuleBasedScanner scanner = new RuleBasedScanner();
scanner.setDefaultReturnToken(allTokens[TOKEN_STRING]);
scanner.setDefaultReturnToken(stringToken);
return scanner;
}
@ -120,13 +117,13 @@ public class QMLSourceViewerConfiguration extends TextSourceViewerConfiguration
public boolean isWordPart(char c) {
return Character.isJavaIdentifierPart(c);
}
}, allTokens[TOKEN_DEFAULT]);
}, defaultToken);
// Works decently well for now. However, some keywords like 'color' can
// also be used as identifiers. Can only fix this with
// semantic highlighting after the parser is completed.
for (String keyword : QMLKeywords.getKeywords(true)) {
wordRule.addWord(keyword, allTokens[TOKEN_KEYWORD]);
wordRule.addWord(keyword, keywordToken);
}
scanner.setRules(new IRule[] { wordRule });
@ -147,9 +144,9 @@ public class QMLSourceViewerConfiguration extends TextSourceViewerConfiguration
}, defaultToken);
// TODO: Add preference page for task tags
wordRule.addWord("TODO", allTokens[TOKEN_TASK_TAG]); //$NON-NLS-1$
wordRule.addWord("FIXME", allTokens[TOKEN_TASK_TAG]); //$NON-NLS-1$
wordRule.addWord("XXX", allTokens[TOKEN_TASK_TAG]); //$NON-NLS-1$
wordRule.addWord("TODO", taskTagToken); //$NON-NLS-1$
wordRule.addWord("FIXME", taskTagToken); //$NON-NLS-1$
wordRule.addWord("XXX", taskTagToken); //$NON-NLS-1$
return wordRule;
}
@ -165,10 +162,75 @@ public class QMLSourceViewerConfiguration extends TextSourceViewerConfiguration
@Override
protected Map<String, IAdaptable> getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
@SuppressWarnings("unchecked")
Map<String, IAdaptable> targets = super.getHyperlinkDetectorTargets(sourceViewer);
targets.put("org.eclipse.cdt.qt.ui.qml", editor); //$NON-NLS-1$
return targets;
}
private void initTokens(IPreferenceStore prefStore) {
IColorManager colorManager = CDTUITools.getColorManager();
defaultToken = new Token(null);
multiLineCommentToken = new Token(createTextAttribute(colorManager, ICColorConstants.C_MULTI_LINE_COMMENT));
singleLineCommentToken = new Token(createTextAttribute(colorManager, ICColorConstants.C_SINGLE_LINE_COMMENT));
keywordToken = new Token(createTextAttribute(colorManager, ICColorConstants.C_KEYWORD));
stringToken = new Token(createTextAttribute(colorManager, ICColorConstants.C_STRING));
taskTagToken = new Token(createTextAttribute(colorManager, ICColorConstants.TASK_TAG));
}
private TextAttribute createTextAttribute(IColorManager colorManager, String colorKey) {
Color color = colorManager.getColor(colorKey);
if (color == null) {
RGB rgb= PreferenceConverter.getColor(fPreferenceStore, colorKey);
colorManager.unbindColor(colorKey);
colorManager.bindColor(colorKey, rgb);
color = colorManager.getColor(colorKey);
}
String boldKey= colorKey + PreferenceConstants.EDITOR_BOLD_SUFFIX;
String italicKey= colorKey + PreferenceConstants.EDITOR_ITALIC_SUFFIX;
String strikethroughKey= colorKey + PreferenceConstants.EDITOR_STRIKETHROUGH_SUFFIX;
String underlineKey= colorKey + PreferenceConstants.EDITOR_UNDERLINE_SUFFIX;
int style= fPreferenceStore.getBoolean(boldKey) ? SWT.BOLD : SWT.NORMAL;
if (fPreferenceStore.getBoolean(italicKey))
style |= SWT.ITALIC;
if (fPreferenceStore.getBoolean(strikethroughKey))
style |= TextAttribute.STRIKETHROUGH;
if (fPreferenceStore.getBoolean(underlineKey))
style |= TextAttribute.UNDERLINE;
return new TextAttribute(color, null, style);
}
public void handlePreferenceStoreChanged(PropertyChangeEvent event) {
IColorManager colorManager = CDTUITools.getColorManager();
String property = event.getProperty();
if (property.startsWith(ICColorConstants.C_MULTI_LINE_COMMENT)) {
multiLineCommentToken.setData(createTextAttribute(colorManager, ICColorConstants.C_MULTI_LINE_COMMENT));
}
if (property.startsWith(ICColorConstants.C_SINGLE_LINE_COMMENT)) {
singleLineCommentToken.setData(createTextAttribute(colorManager, ICColorConstants.C_SINGLE_LINE_COMMENT));
}
if (property.startsWith(ICColorConstants.C_KEYWORD)) {
keywordToken.setData(createTextAttribute(colorManager, ICColorConstants.C_KEYWORD));
}
if (property.startsWith(ICColorConstants.C_STRING)) {
stringToken.setData(createTextAttribute(colorManager, ICColorConstants.C_STRING));
}
if (property.startsWith(ICColorConstants.TASK_TAG)) {
taskTagToken.setData(createTextAttribute(colorManager, ICColorConstants.TASK_TAG));
}
}
protected boolean affectsTextPresentation(PropertyChangeEvent event) {
String property = event.getProperty();
return property.startsWith(ICColorConstants.C_MULTI_LINE_COMMENT)
|| property.startsWith(ICColorConstants.C_SINGLE_LINE_COMMENT)
|| property.startsWith(ICColorConstants.C_KEYWORD)
|| property.startsWith(ICColorConstants.C_STRING)
|| property.startsWith(ICColorConstants.TASK_TAG);
}
}