|
From: <caw...@us...> - 2007-06-27 19:00:55
|
Revision: 2699
http://svn.sourceforge.net/rubyeclipse/?rev=2699&view=rev
Author: cawilliams
Date: 2007-06-27 12:00:54 -0700 (Wed, 27 Jun 2007)
Log Message:
-----------
close #4984 - Automatically close =begin with =end
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/comment/RubyCommentAutoIndentStrategy.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/comment/RubyCommentAutoIndentStrategy.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/comment/RubyCommentAutoIndentStrategy.java 2007-06-27 18:35:23 UTC (rev 2698)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/comment/RubyCommentAutoIndentStrategy.java 2007-06-27 19:00:54 UTC (rev 2699)
@@ -11,10 +11,13 @@
import org.eclipse.ui.texteditor.ITextEditor;
import org.rubypeople.rdt.core.IMethod;
import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.corext.util.CodeFormatterUtil;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.WorkingCopyManager;
+import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
public class RubyCommentAutoIndentStrategy extends
DefaultIndentLineAutoEditStrategy {
@@ -22,11 +25,13 @@
private String fPartitioning;
private ITextEditor fEditor;
private WorkingCopyManager fManager;
+ private IRubyProject fProject;
- public RubyCommentAutoIndentStrategy(ITextEditor textEditor, String partitioning) {
+ public RubyCommentAutoIndentStrategy(ITextEditor textEditor, String partitioning, IRubyProject project) {
fPartitioning = partitioning;
fEditor = textEditor;
fManager = RubyPlugin.getDefault().getWorkingCopyManager();
+ fProject = project;
}
public void customizeDocumentCommand(IDocument document,
@@ -56,7 +61,15 @@
* the command to deal with
*/
private void indentAfterNewLine(IDocument d, DocumentCommand c) {
+ if (fPartitioning.equals(IRubyPartitions.RUBY_SINGLE_LINE_COMMENT)) {
+ doSingleLineComment(d, c);
+ } else {
+ doMultiLineComment(d, c);
+ }
+ }
+ private void doMultiLineComment(IDocument d, DocumentCommand c) {
+
int offset = c.offset;
if (offset == -1 || d.getLength() == 0)
return;
@@ -66,6 +79,34 @@
int lineNumber = d.getLineOfOffset(p);
IRegion line = d.getLineInformation(lineNumber);
+ String aLine = getLine(d, lineNumber - 1);
+ StringBuffer buf = new StringBuffer(c.text);
+ if (aLine.trim().equals("=begin")) {
+ // add =end
+ buf.append(CodeFormatterUtil.createIndentString(1, fProject));
+ c.caretOffset= c.offset + buf.length();
+ c.shiftsCaret= false;
+ buf.append(TextUtilities.getDefaultLineDelimiter(d));
+ buf.append("=end");
+ }
+
+ c.text = buf.toString();
+
+ } catch (BadLocationException excp) {
+ // stop work
+ }
+ }
+
+ private void doSingleLineComment(IDocument d, DocumentCommand c) {
+ int offset = c.offset;
+ if (offset == -1 || d.getLength() == 0)
+ return;
+
+ try {
+ int p = (offset == d.getLength() ? offset - 1 : offset);
+
+ int lineNumber = d.getLineOfOffset(p);
+ IRegion line = d.getLineInformation(lineNumber);
if (lineNumber != 0) { // If first line, extend the comment
String nextLine = getLine(d, lineNumber + 1); // otherwise check next line
if (!(isComment(nextLine) || isClassDefinition(nextLine)
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-06-27 18:35:23 UTC (rev 2698)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-06-27 19:00:54 UTC (rev 2699)
@@ -325,8 +325,8 @@
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
- if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType)) {
- return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(fTextEditor, partitioning) };
+ if (IRubyPartitions.RUBY_SINGLE_LINE_COMMENT.equals(contentType) || IRubyPartitions.RUBY_MULTI_LINE_COMMENT.equals(contentType)) {
+ return new IAutoEditStrategy[] { new RubyCommentAutoIndentStrategy(fTextEditor, partitioning, getProject()) };
} else if (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
return new IAutoEditStrategy[] { new RubyAutoIndentStrategy(partitioning, getProject()) };
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|