diff options
| author | Alexander Kurtakov | 2013-02-08 13:46:27 +0000 |
|---|---|---|
| committer | Camilo Bernal | 2013-02-08 15:31:20 +0000 |
| commit | 2f61a097098d99b3299cdd589df38db50d17032f (patch) | |
| tree | d7023fca8990d4eb7bdda8d25356b6ee6418b273 | |
| parent | 4a63f736f375b5c09f43256460fbff6b25f78f4d (diff) | |
| download | org.eclipse.linuxtools-2f61a097098d99b3299cdd589df38db50d17032f.tar.gz org.eclipse.linuxtools-2f61a097098d99b3299cdd589df38db50d17032f.tar.xz org.eclipse.linuxtools-2f61a097098d99b3299cdd589df38db50d17032f.zip | |
Add auto edit strategy to .stp editor.
Very basic initial implementation just covering parenthesis and quotes.
Fixes Bug 397627 .
Change-Id: I4a00cdfc177e0af22228d6a6ba9d905b086db2c4
Reviewed-on: https://git.eclipse.org/r/10251
Tested-by: Hudson CI
Reviewed-by: Camilo Bernal <cabernal@redhat.com>
IP-Clean: Camilo Bernal <cabernal@redhat.com>
Tested-by: Camilo Bernal <cabernal@redhat.com>
2 files changed, 56 insertions, 11 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPAutoEditStrategy.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPAutoEditStrategy.java new file mode 100644 index 0000000000..a15dc7569f --- /dev/null +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPAutoEditStrategy.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Red Hat, Inc. + * 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: + * Red Hat - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp; + +import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy; +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IDocument; + +/** + * Very basic auto edit strategy simply completing opening with closing brackets and quotes. + */ +public class STPAutoEditStrategy extends + DefaultIndentLineAutoEditStrategy { + @Override + public void customizeDocumentCommand(IDocument document, + DocumentCommand command) { + if (command.text.equals("\"")) { //$NON-NLS-1$ + command.text = "\"\""; //$NON-NLS-1$ + } else if (command.text.equals("(")){ //$NON-NLS-1$ + command.text = "()"; //$NON-NLS-1$ + } else if (command.text.equals("{")) { //$NON-NLS-1$ + command.text = "{}"; //$NON-NLS-1$ + } else if (command.text.equals("[")) { //$NON-NLS-1$ + command.text = "[]"; //$NON-NLS-1$ + } + command.caretOffset = command.offset + 1; + command.shiftsCaret = false; + + } +}
\ No newline at end of file diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPConfiguration.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPConfiguration.java index ad69a94782..bb7d3b479d 100644 --- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPConfiguration.java +++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/internal/systemtap/ui/ide/editors/stp/STPConfiguration.java @@ -1,17 +1,18 @@ /******************************************************************************* * Copyright (c) 2008 Phil Muldoon <pkmuldoon@picobot.org>. - * + * * 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: - * Phil Muldoon <pkmuldoon@picobot.org> - initial API and implementation. + * Phil Muldoon <pkmuldoon@picobot.org> - initial API and implementation. *******************************************************************************/ package org.eclipse.linuxtools.internal.systemtap.ui.ide.editors.stp; +import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.TextAttribute; @@ -35,7 +36,7 @@ public class STPConfiguration extends SourceViewerConfiguration { private ColorManager colorManager; private STPEditor editor; private DoubleClickStrategy doubleClickStrategy; - + public STPConfiguration(ColorManager colorManager, STPEditor editor) { this.colorManager = colorManager; this.editor = editor; @@ -69,14 +70,14 @@ public class STPConfiguration extends SourceViewerConfiguration { assistant.setContentAssistProcessor(processor,IDocument.DEFAULT_CONTENT_TYPE); assistant.setContentAssistProcessor(processor,STPPartitionScanner.STP_PROBE); - + assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); return assistant; } /** * Return the default Element scanner. - * + * * @return default element scanner. */ protected STPElementScanner getSTPScanner() { @@ -90,20 +91,20 @@ public class STPConfiguration extends SourceViewerConfiguration { /* (non-Javadoc) * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getReconciler(org.eclipse.jface.text.source.ISourceViewer) - * + * * Return the reconciler built on the custom Systemtap reconciling strategy that enables code folding for this editor. */ @Override public IReconciler getReconciler(ISourceViewer sourceViewer) { STPReconcilingStrategy strategy = new STPReconcilingStrategy(); - strategy.setEditor(editor); - MonoReconciler reconciler = new MonoReconciler(strategy,false); + strategy.setEditor(editor); + MonoReconciler reconciler = new MonoReconciler(strategy,false); return reconciler; } - + /** - * Instantiates and returns a double click strategy object if one does not exist, and returns the + * Instantiates and returns a double click strategy object if one does not exist, and returns the * current one if it does. */ @Override @@ -113,7 +114,7 @@ public class STPConfiguration extends SourceViewerConfiguration { return doubleClickStrategy; } - + /* (non-Javadoc) * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer) */ @@ -150,4 +151,10 @@ public class STPConfiguration extends SourceViewerConfiguration { return reconciler; } + @Override + public IAutoEditStrategy[] getAutoEditStrategies( + ISourceViewer sourceViewer, String contentType) { + return new IAutoEditStrategy[] {new STPAutoEditStrategy()}; + } + }
\ No newline at end of file |
