1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Fix for 194196: No syntax highlighting when comparing assembly files

This commit is contained in:
Anton Leherbauer 2007-07-13 11:21:57 +00:00
parent 8fc042bfd7
commit 268346e7e6
6 changed files with 286 additions and 115 deletions

View file

@ -342,7 +342,9 @@ Folding.label= F&olding
# Merge fonts
cCompareFontDefiniton.label= C/C++ compare text font
cCompareFontDefiniton.description= The C/C++ compare text font is used by C/C++ compare/merge tools.
cCompareFontDefiniton.description= The C/C++ compare text font is used by Assembly compare/merge tools.
asmCompareFontDefiniton.label= Assembly compare text font
asmCompareFontDefiniton.description= The Asembly compare text font is used by Assembly compare/merge tools.
# External Search Editor

View file

@ -593,6 +593,15 @@
<description>
%cCompareFontDefiniton.description
</description>
</fontDefinition>
<fontDefinition
label="%asmCompareFontDefiniton.label"
defaultsTo="org.eclipse.cdt.ui.editors.textfont"
categoryId="org.eclipse.compare.contentmergeviewer.TextMergeViewer"
id="org.eclipse.cdt.internal.ui.compare.AsmMergeViewer">
<description>
%asmCompareFontDefiniton.description
</description>
</fontDefinition>
</extension>
@ -978,6 +987,13 @@
contentTypeId="org.eclipse.cdt.core.cxxHeader"
contentMergeViewerId="org.eclipse.cdt.ui.compare.CContentViewerCreator">
</contentTypeBinding>
<viewer
class="org.eclipse.cdt.internal.ui.compare.AsmContentViewerCreator"
extensions="asm"
id="org.eclipse.cdt.ui.compare.AsmContentViewerCreator"/>
<contentTypeBinding
contentTypeId="org.eclipse.cdt.core.asmSource"
contentMergeViewerId="org.eclipse.cdt.ui.compare.AsmContentViewerCreator"/>
</extension>
<extension
point="org.eclipse.ui.actionSets">

View file

@ -0,0 +1,156 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.compare;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
/**
* Abstract implementation of a merge viewer.
*/
abstract class AbstractMergeViewer extends TextMergeViewer {
private IPropertyChangeListener fPreferenceChangeListener;
private IPreferenceStore fPreferenceStore;
protected boolean fUseSystemColors;
/**
* Creates a color from the information stored in the given preference store.
* Returns <code>null</code> if there is no such information available.
*/
protected static RGB createColor(IPreferenceStore store, String key) {
if (!store.contains(key))
return null;
if (store.isDefault(key))
return PreferenceConverter.getDefaultColor(store, key);
return PreferenceConverter.getColor(store, key);
}
/**
* Create a new merge viewer.
*
* @param parent
* @param style
* @param configuration
*/
public AbstractMergeViewer(Composite parent, int style, CompareConfiguration configuration) {
super(parent, style | SWT.LEFT_TO_RIGHT, configuration);
IPreferenceStore store = getPreferenceStore();
fUseSystemColors= store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
if (! fUseSystemColors) {
RGB bg= createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
RGB fg= createColor(store, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
}
protected IPreferenceStore getPreferenceStore() {
if (fPreferenceStore == null) {
fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore();
fPreferenceChangeListener= new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
handlePropertyChange(event);
}
};
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
}
return fPreferenceStore;
}
protected void handleDispose(DisposeEvent event) {
if (fPreferenceChangeListener != null) {
fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
fPreferenceChangeListener= null;
}
super.handleDispose(event);
}
protected void handlePropertyChange(PropertyChangeEvent event) {
String key= event.getProperty();
if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)) {
if (!fUseSystemColors) {
RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
}
} else if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
if (fUseSystemColors) {
setBackgroundColor(null);
setForegroundColor(null);
} else {
RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
} else if (key.equals(ICColorConstants.C_DEFAULT)) {
if (!fUseSystemColors) {
RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
}
}
protected String getDocumentPartitioning() {
return ICPartitions.C_PARTITIONING;
}
protected IDocumentPartitioner getDocumentPartitioner() {
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
}
protected void configureTextViewer(TextViewer textViewer) {
if (textViewer instanceof SourceViewer) {
((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
}
}
/*
* @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getTitle()
*/
public abstract String getTitle();
/**
* @return a source configuration for the viewer
*/
protected abstract SourceViewerConfiguration getSourceViewerConfiguration();
}

View file

@ -0,0 +1,20 @@
package org.eclipse.cdt.internal.ui.compare;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.IViewerCreator;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
/**
* Creates a merge viewer for assembly code.
*/
public class AsmContentViewerCreator implements IViewerCreator {
/*
* @see org.eclipse.compare.IViewerCreator#createViewer(org.eclipse.swt.widgets.Composite, org.eclipse.compare.CompareConfiguration)
*/
public Viewer createViewer(Composite parent, CompareConfiguration config) {
return new AsmMergeViewer(parent, SWT.NULL, config);
}
}

View file

@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Anton Leherbauer (Wind River Systems) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.compare;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.asm.AsmSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.editor.asm.AsmTextTools;
/**
* A merge viewer for assembly code.
*/
public class AsmMergeViewer extends AbstractMergeViewer {
private static final String TITLE= "AsmMergeViewer.title"; //$NON-NLS-1$
AsmSourceViewerConfiguration fSourceViewerConfiguration;
/**
* Create a new assembly merge viewer.
*
* @param parent
* @param style
* @param configuration
*/
public AsmMergeViewer(Composite parent, int style, CompareConfiguration configuration) {
super(parent, style, configuration);
}
/*
* @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#getSourceViewerConfiguration()
*/
protected SourceViewerConfiguration getSourceViewerConfiguration() {
if (fSourceViewerConfiguration == null) {
AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
IPreferenceStore store = getPreferenceStore();
fSourceViewerConfiguration = new AsmSourceViewerConfiguration(tools, store);
}
return fSourceViewerConfiguration;
}
/*
* @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#getTitle()
*/
public String getTitle() {
return CUIPlugin.getResourceString(TITLE);
}
/*
* @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#handlePropertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/
protected void handlePropertyChange(PropertyChangeEvent event) {
super.handlePropertyChange(event);
if (fSourceViewerConfiguration != null) {
AsmTextTools tools= CUIPlugin.getDefault().getAsmTextTools();
if (tools.affectsBehavior(event)) {
invalidateTextPresentation();
}
}
}
}

View file

@ -13,122 +13,31 @@
package org.eclipse.cdt.internal.ui.compare;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.text.ICPartitions;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.cdt.internal.ui.text.CTextTools;
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
public class CMergeViewer extends TextMergeViewer {
/**
* A merge viewer for C/C++ code.
*/
public class CMergeViewer extends AbstractMergeViewer {
private static final String TITLE= "CMergeViewer.title"; //$NON-NLS-1$
private IPropertyChangeListener fPreferenceChangeListener;
private IPreferenceStore fPreferenceStore;
private boolean fUseSystemColors;
private CSourceViewerConfiguration fSourceViewerConfiguration;
CSourceViewerConfiguration fSourceViewerConfiguration;
public CMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
super(parent, styles | SWT.LEFT_TO_RIGHT, mp);
IPreferenceStore store = getPreferenceStore();
fUseSystemColors= store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
if (! fUseSystemColors) {
RGB bg= createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
RGB fg= createColor(store, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
super(parent, styles, mp);
}
private IPreferenceStore getPreferenceStore() {
if (fPreferenceStore == null) {
fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore();
fPreferenceChangeListener= new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
handlePropertyChange(event);
}
};
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
}
return fPreferenceStore;
}
protected void handleDispose(DisposeEvent event) {
if (fPreferenceChangeListener != null) {
fPreferenceStore.removePropertyChangeListener(fPreferenceChangeListener);
fPreferenceChangeListener= null;
}
super.handleDispose(event);
}
protected void handlePropertyChange(PropertyChangeEvent event) {
String key= event.getProperty();
if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)) {
if (!fUseSystemColors) {
RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
}
} else if (key.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
if (fUseSystemColors) {
setBackgroundColor(null);
setForegroundColor(null);
} else {
RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
setBackgroundColor(bg);
RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
} else if (key.equals(ICColorConstants.C_DEFAULT)) {
if (!fUseSystemColors) {
RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT);
setForegroundColor(fg);
}
}
if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) {
getSourceViewerConfiguration().handlePropertyChangeEvent(event);
invalidateTextPresentation();
}
}
/**
* Creates a color from the information stored in the given preference store.
* Returns <code>null</code> if there is no such information available.
*/
private static RGB createColor(IPreferenceStore store, String key) {
if (!store.contains(key))
return null;
if (store.isDefault(key))
return PreferenceConverter.getDefaultColor(store, key);
return PreferenceConverter.getColor(store, key);
}
private CSourceViewerConfiguration getSourceViewerConfiguration() {
protected SourceViewerConfiguration getSourceViewerConfiguration() {
if (fSourceViewerConfiguration == null) {
CTextTools tools= CUIPlugin.getDefault().getTextTools();
IPreferenceStore store = getPreferenceStore();
@ -140,25 +49,16 @@ public class CMergeViewer extends TextMergeViewer {
public String getTitle() {
return CUIPlugin.getResourceString(TITLE);
}
/*
* @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioning()
*/
protected String getDocumentPartitioning() {
return ICPartitions.C_PARTITIONING;
}
/*
* @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioner()
* @see org.eclipse.cdt.internal.ui.compare.AbstractMergeViewer#handlePropertyChange(org.eclipse.jface.util.PropertyChangeEvent)
*/
protected IDocumentPartitioner getDocumentPartitioner() {
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
}
protected void handlePropertyChange(PropertyChangeEvent event) {
super.handlePropertyChange(event);
protected void configureTextViewer(TextViewer textViewer) {
if (textViewer instanceof SourceViewer) {
((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
if (fSourceViewerConfiguration != null && fSourceViewerConfiguration.affectsTextPresentation(event)) {
fSourceViewerConfiguration.handlePropertyChangeEvent(event);
invalidateTextPresentation();
}
}
}