mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
2005-03-30 Alain Magloire
Fix PR 87334 * src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java
This commit is contained in:
parent
3097c2f126
commit
61da45c653
2 changed files with 109 additions and 3 deletions
|
@ -1,3 +1,7 @@
|
|||
2005-03-30 Alain Magloire
|
||||
Fix PR 87334
|
||||
* src/org/eclipse/cdt/internal/ui/compare/CMergeViewer.java
|
||||
|
||||
2005-03-29 Chris Wiebe
|
||||
prevent duplicate #includes
|
||||
* src/org/eclipse/cdt/internal/ui/wizards/NewClassCodeGenerator.java
|
||||
|
|
|
@ -7,10 +7,14 @@ package org.eclipse.cdt.internal.ui.compare;
|
|||
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
|
||||
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.compare.CompareConfiguration;
|
||||
import org.eclipse.compare.contentmergeviewer.ITokenComparator;
|
||||
|
@ -18,24 +22,121 @@ import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
|
|||
import org.eclipse.compare.internal.TokenComparator;
|
||||
|
||||
|
||||
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.util.PropertyChangeEvent;
|
||||
|
||||
public class CMergeViewer extends TextMergeViewer {
|
||||
|
||||
private static final String TITLE= "CMergeViewer.title"; //$NON-NLS-1$
|
||||
|
||||
|
||||
private IPropertyChangeListener fPreferenceChangeListener;
|
||||
private IPreferenceStore fPreferenceStore;
|
||||
private boolean fUseSystemColors;
|
||||
private CSourceViewerConfiguration fSourceViewerConfiguration;
|
||||
private CTextTools fCTextTools;
|
||||
|
||||
public CMergeViewer(Composite parent, int styles, CompareConfiguration mp) {
|
||||
super(parent, styles, mp);
|
||||
fPreferenceStore= CUIPlugin.getDefault().getCombinedPreferenceStore();
|
||||
if (fPreferenceStore != null) {
|
||||
fPreferenceChangeListener= new IPropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
handlePropertyChange(event);
|
||||
}
|
||||
};
|
||||
fPreferenceStore.addPropertyChangeListener(fPreferenceChangeListener);
|
||||
}
|
||||
|
||||
fUseSystemColors= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
|
||||
if (! fUseSystemColors) {
|
||||
RGB bg= createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
|
||||
setBackgroundColor(bg);
|
||||
RGB fg= createColor(fPreferenceStore, ICColorConstants.C_DEFAULT);
|
||||
setForegroundColor(fg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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 (getTextTools().affectsBehavior(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 CTextTools getTextTools() {
|
||||
if (fCTextTools == null) {
|
||||
fCTextTools = CUIPlugin.getDefault().getTextTools();
|
||||
}
|
||||
return fCTextTools;
|
||||
}
|
||||
|
||||
private CSourceViewerConfiguration getSourceViewerConfiguration() {
|
||||
if (fSourceViewerConfiguration == null) {
|
||||
CTextTools tools= getTextTools();
|
||||
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools, null);
|
||||
}
|
||||
return fSourceViewerConfiguration;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return CUIPlugin.getResourceString(TITLE);
|
||||
}
|
||||
|
||||
|
||||
protected ITokenComparator createTokenComparator(String s) {
|
||||
return new TokenComparator(s);
|
||||
}
|
||||
|
@ -47,7 +148,8 @@ public class CMergeViewer extends TextMergeViewer {
|
|||
protected void configureTextViewer(TextViewer textViewer) {
|
||||
if (textViewer instanceof SourceViewer) {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
((SourceViewer)textViewer).configure(new CSourceViewerConfiguration(tools, null));
|
||||
((SourceViewer)textViewer).configure(getSourceViewerConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue