diff --git a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java index 710a8c952e0..f2117a113f8 100644 --- a/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java +++ b/build/org.eclipse.cdt.build.gcc.core/src/org/eclipse/cdt/build/gcc/core/GCCToolChain.java @@ -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); diff --git a/qt/org.eclipse.cdt.qt.core/templates/project2/appProject/main.qml b/qt/org.eclipse.cdt.qt.core/templates/project2/appProject/main.qml index 603cd9461d2..ff717c4659f 100644 --- a/qt/org.eclipse.cdt.qt.core/templates/project2/appProject/main.qml +++ b/qt/org.eclipse.cdt.qt.core/templates/project2/appProject/main.qml @@ -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 + } } diff --git a/qt/org.eclipse.cdt.qt.ui/plugin.xml b/qt/org.eclipse.cdt.qt.ui/plugin.xml index 240ebb106a4..de058a0092e 100644 --- a/qt/org.eclipse.cdt.qt.ui/plugin.xml +++ b/qt/org.eclipse.cdt.qt.ui/plugin.xml @@ -68,7 +68,7 @@ point="org.eclipse.core.filebuffers.documentSetup"> diff --git a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java index 1be6776a615..e327f9733da 100644 --- a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java +++ b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLEditor.java @@ -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$ } diff --git a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLSourceViewerConfiguration.java b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLSourceViewerConfiguration.java index 7b84c8efbf5..1786f2f5343 100644 --- a/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLSourceViewerConfiguration.java +++ b/qt/org.eclipse.cdt.qt.ui/src/org/eclipse/cdt/internal/qt/ui/editor/QMLSourceViewerConfiguration.java @@ -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 getHyperlinkDetectorTargets(ISourceViewer sourceViewer) { - @SuppressWarnings("unchecked") Map 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); + } + }