This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed GoEditor setup of SourceViewConfiguration and pref store init.
- Loading branch information
1 parent
8b8474e
commit 594d813
Showing
5 changed files
with
168 additions
and
57 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
com.googlecode.goclipse.ui/src-lang/base/melnorme/lang/ide/ui/editor/AbstractLangEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014, 2014 Bruno Medeiros and other Contributors. | ||
* 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: | ||
* Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | ||
package melnorme.lang.ide.ui.editor; | ||
|
||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import melnorme.lang.ide.ui.LangUIPlugin; | ||
import melnorme.utilbox.misc.ArrayUtil; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.preference.IPreferenceStore; | ||
import org.eclipse.jface.text.source.ISourceViewer; | ||
import org.eclipse.jface.text.source.ISourceViewerExtension2; | ||
import org.eclipse.ui.IEditorInput; | ||
import org.eclipse.ui.editors.text.EditorsUI; | ||
import org.eclipse.ui.editors.text.TextEditor; | ||
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; | ||
import org.eclipse.ui.texteditor.ChainedPreferenceStore; | ||
|
||
public abstract class AbstractLangEditor extends TextEditor { | ||
|
||
public AbstractLangEditor() { | ||
super(); | ||
} | ||
|
||
@Override | ||
protected void initializeEditor() { | ||
super.initializeEditor(); | ||
} | ||
|
||
@Override | ||
protected void doSetInput(IEditorInput input) throws CoreException { | ||
super.doSetInput(input); | ||
|
||
ISourceViewer sourceViewer = getSourceViewer(); | ||
|
||
if (!(sourceViewer instanceof ISourceViewerExtension2)) { | ||
setPreferenceStore(createCombinedPreferenceStore(input)); | ||
} else { | ||
ISourceViewerExtension2 sourceViewerExt2 = (ISourceViewerExtension2) sourceViewer; | ||
|
||
getSourceViewerDecorationSupport(sourceViewer).uninstall(); | ||
sourceViewerExt2.unconfigure(); | ||
|
||
setPreferenceStore(createCombinedPreferenceStore(input)); | ||
|
||
sourceViewer.configure(getSourceViewerConfiguration()); | ||
getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore()); | ||
} | ||
|
||
internalDoSetInput(input); | ||
} | ||
|
||
@Override | ||
protected void setPreferenceStore(IPreferenceStore store) { | ||
super.setPreferenceStore(store); | ||
setSourceViewerConfiguration(createSourceViewerConfiguration()); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
protected void internalDoSetInput(IEditorInput input) { | ||
} | ||
|
||
protected abstract TextSourceViewerConfiguration createSourceViewerConfiguration(); | ||
|
||
protected IPreferenceStore createCombinedPreferenceStore(IEditorInput input) { | ||
List<IPreferenceStore> stores = new ArrayList<IPreferenceStore>(4); | ||
|
||
// TODO: add project pref scope | ||
IProject project = EditorUtils.getProject(input); | ||
|
||
stores.add(LangUIPlugin.getInstance().getPreferenceStore()); | ||
stores.add(LangUIPlugin.getInstance().getCorePreferenceStore()); | ||
stores.add(EditorsUI.getPreferenceStore()); | ||
|
||
return new ChainedPreferenceStore(ArrayUtil.createFrom(stores, IPreferenceStore.class)); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
com.googlecode.goclipse.ui/src-lang/base/melnorme/lang/ide/ui/editor/EditorUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014, 2014 Bruno Medeiros and other Contributors. | ||
* 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: | ||
* Bruno Medeiros - initial API and implementation | ||
*******************************************************************************/ | ||
package melnorme.lang.ide.ui.editor; | ||
|
||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.ui.IEditorInput; | ||
import org.eclipse.ui.IFileEditorInput; | ||
|
||
public class EditorUtils { | ||
|
||
public static IProject getProject(IEditorInput input) { | ||
if(input instanceof IFileEditorInput) { | ||
return ((IFileEditorInput) input).getFile().getProject(); | ||
} | ||
|
||
IResource resource = (IResource) input.getAdapter(IResource.class); | ||
if(resource != null) { | ||
return resource.getProject(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters