|
From: Christopher W. <caw...@us...> - 2005-12-12 20:00:13
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10296/src/org/rubypeople/rdt/internal/ui/text Modified Files: RubySourceViewerConfiguration.java RubyPartitionScanner.java RubyWordFinder.java Added Files: RubyDoubleClickSelector.java Log Message: prefix content types with RUBY_. Change the double click strategy - reuse the RubyWordFinder used to determine the hoevr region. Change it to act more logically on Ruby tokens/words. Now double-clicking will be more likely to select what you really wanted. Index: RubyPartitionScanner.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RubyPartitionScanner.java 3 Oct 2005 11:31:34 -0000 1.9 --- RubyPartitionScanner.java 12 Dec 2005 19:59:58 -0000 1.10 *************** *** 16,27 **** ! public final static String STRING = "partition_scanner_ruby_string"; ! public final static String MULTI_LINE_COMMENT = "partition_scanner_ruby_multiline_comment"; ! public static final String SINGLE_LINE_COMMENT = "partition_scanner_ruby_singleline_comment"; ! public static final String REGULAR_EXPRESSION = "partition_scanner_ruby_regular_expression"; ! public static final String COMMAND = "partition_scanner_ruby_command"; public static final String HERE_DOC = "partition_scanner_here_doc"; ! public static final String[] LEGAL_CONTENT_TYPES = {STRING, MULTI_LINE_COMMENT, SINGLE_LINE_COMMENT, REGULAR_EXPRESSION, COMMAND}; public RubyPartitionScanner() { --- 16,27 ---- ! public final static String RUBY_STRING = "partition_scanner_ruby_string"; ! public final static String RUBY_MULTI_LINE_COMMENT = "partition_scanner_ruby_multiline_comment"; ! public static final String RUBY_SINGLE_LINE_COMMENT = "partition_scanner_ruby_singleline_comment"; ! public static final String RUBY_REGULAR_EXPRESSION = "partition_scanner_ruby_regular_expression"; ! public static final String RUBY_COMMAND = "partition_scanner_ruby_command"; public static final String HERE_DOC = "partition_scanner_here_doc"; ! public static final String[] LEGAL_CONTENT_TYPES = {RUBY_STRING, RUBY_MULTI_LINE_COMMENT, RUBY_SINGLE_LINE_COMMENT, RUBY_REGULAR_EXPRESSION, RUBY_COMMAND}; public RubyPartitionScanner() { *************** *** 31,40 **** protected void initialize() { ! IToken string = new Token(STRING); ! IToken multiLineComment = new Token(MULTI_LINE_COMMENT); ! IToken singleLineComment = new Token(SINGLE_LINE_COMMENT); ! IToken regexp = new Token(REGULAR_EXPRESSION); ! IToken command = new Token(COMMAND); ! IToken hereDoc = new Token(STRING) ; List rules = new ArrayList(); --- 31,40 ---- protected void initialize() { ! IToken string = new Token(RUBY_STRING); ! IToken multiLineComment = new Token(RUBY_MULTI_LINE_COMMENT); ! IToken singleLineComment = new Token(RUBY_SINGLE_LINE_COMMENT); ! IToken regexp = new Token(RUBY_REGULAR_EXPRESSION); ! IToken command = new Token(RUBY_COMMAND); ! IToken hereDoc = new Token(RUBY_STRING) ; List rules = new ArrayList(); Index: RubySourceViewerConfiguration.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubySourceViewerConfiguration.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** RubySourceViewerConfiguration.java 9 Dec 2005 02:05:06 -0000 1.22 --- RubySourceViewerConfiguration.java 12 Dec 2005 19:59:58 -0000 1.23 *************** *** 7,10 **** --- 7,11 ---- import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.ITextHover; + import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.contentassist.ContentAssistant; import org.eclipse.jface.text.contentassist.IContentAssistant; *************** *** 48,69 **** dr = new DefaultDamagerRepairer(getSinglelineCommentScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.SINGLE_LINE_COMMENT); ! reconciler.setRepairer(dr, RubyPartitionScanner.SINGLE_LINE_COMMENT); dr = new DefaultDamagerRepairer(getMultilineCommentScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.MULTI_LINE_COMMENT); ! reconciler.setRepairer(dr, RubyPartitionScanner.MULTI_LINE_COMMENT); dr = new DefaultDamagerRepairer(getStringScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.STRING); ! reconciler.setRepairer(dr, RubyPartitionScanner.STRING); dr = new DefaultDamagerRepairer(getRegexpScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.REGULAR_EXPRESSION); ! reconciler.setRepairer(dr, RubyPartitionScanner.REGULAR_EXPRESSION); dr = new DefaultDamagerRepairer(getCommandScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.COMMAND); ! reconciler.setRepairer(dr, RubyPartitionScanner.COMMAND); --- 49,70 ---- dr = new DefaultDamagerRepairer(getSinglelineCommentScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT); ! reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT); dr = new DefaultDamagerRepairer(getMultilineCommentScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT); ! reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT); dr = new DefaultDamagerRepairer(getStringScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.RUBY_STRING); ! reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_STRING); dr = new DefaultDamagerRepairer(getRegexpScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION); ! reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_REGULAR_EXPRESSION); dr = new DefaultDamagerRepairer(getCommandScanner()); ! reconciler.setDamager(dr, RubyPartitionScanner.RUBY_COMMAND); ! reconciler.setRepairer(dr, RubyPartitionScanner.RUBY_COMMAND); *************** *** 96,100 **** public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { ! return new String[] { IDocument.DEFAULT_CONTENT_TYPE, RubyPartitionScanner.MULTI_LINE_COMMENT, RubyPartitionScanner.STRING, RubyPartitionScanner.SINGLE_LINE_COMMENT}; } --- 97,101 ---- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { ! return new String[] { IDocument.DEFAULT_CONTENT_TYPE, RubyPartitionScanner.RUBY_MULTI_LINE_COMMENT, RubyPartitionScanner.RUBY_STRING, RubyPartitionScanner.RUBY_SINGLE_LINE_COMMENT}; } *************** *** 167,170 **** --- 168,175 ---- return super.getIndentPrefixes(sourceViewer, contentType); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } + + public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { + return new RubyDoubleClickSelector(); + } --- NEW FILE: RubyDoubleClickSelector.java --- package org.rubypeople.rdt.internal.ui.text; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.ITextViewer; public class RubyDoubleClickSelector implements ITextDoubleClickStrategy { public void doubleClicked(ITextViewer text) { int position = text.getSelectedRange().x; if (position < 0) return; IRegion region = RubyWordFinder.findWord(text.getDocument(), position); if (region != null && region.getLength() != 0 ) text.setSelectedRange(region.getOffset(), region.getLength()); } } Index: RubyWordFinder.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyWordFinder.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RubyWordFinder.java 5 Mar 2005 19:38:08 -0000 1.1 --- RubyWordFinder.java 12 Dec 2005 19:59:58 -0000 1.2 *************** *** 10,14 **** *******************************************************************************/ package org.rubypeople.rdt.internal.ui.text; ! import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; --- 10,14 ---- *******************************************************************************/ package org.rubypeople.rdt.internal.ui.text; ! import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; *************** *** 17,66 **** public class RubyWordFinder { ! // FIXME Modify the rules to match ruby words! ! public static IRegion findWord(IDocument document, int offset) { ! ! int start= -1; ! int end= -1; ! ! ! try { ! ! int pos= offset; ! char c; ! ! while (pos >= 0) { ! c= document.getChar(pos); ! if (!Character.isJavaIdentifierPart(c)) ! break; ! --pos; ! } ! ! start= pos; ! ! pos= offset; ! int length= document.getLength(); ! ! while (pos < length) { ! c= document.getChar(pos); ! if (!Character.isJavaIdentifierPart(c)) ! break; ! ++pos; ! } ! ! end= pos; ! ! } catch (BadLocationException x) { ! } ! ! if (start > -1 && end > -1) { ! if (start == offset && end == offset) ! return new Region(offset, 0); ! else if (start == offset) ! return new Region(start, end - start); ! else ! return new Region(start + 1, end - start - 1); ! } ! ! return null; ! } } --- 17,82 ---- public class RubyWordFinder { ! /** ! * The characters which mark the end of a "word" in Ruby. Essentially these ! * are what break up the tokens for double-clicking and for hovers. ! */ ! private static final char[] BOUNDARIES = { ' ', '\n', '\t', '\r', '.', '(', ')', '{', '}', '[', ! ']', '=', '*', '+', '-', '"', '\'', '#'}; ! public static IRegion findWord(IDocument document, int offset) { ! int start = -1; ! int end = -1; ! ! try { ! int pos = offset; ! char c; ! ! while (pos >= 0) { ! c = document.getChar(pos); ! if (!isRubyWordPart(c)) break; ! --pos; ! } ! ! start = pos; ! ! pos = offset; ! int length = document.getLength(); ! ! while (pos < length) { ! c = document.getChar(pos); ! if (!isRubyWordPart(c)) break; ! ++pos; ! } ! ! end = pos; ! ! } catch (BadLocationException x) { ! } ! ! if (start > -1 && end > -1) { ! if (start == offset && end == offset) ! return new Region(offset, 0); ! else if (start == offset) ! return new Region(start, end - start); ! else ! return new Region(start + 1, end - start - 1); ! } ! ! return null; ! } ! ! private static boolean isRubyWordPart(char c) { ! return !isBoundary(c); ! } ! ! private static boolean isBoundary(char c) { ! return contains(BOUNDARIES, c); ! } ! ! private static boolean contains(char[] boundaries2, char c) { ! if (boundaries2 == null || boundaries2.length == 0) return false; ! for (int i = 0; i < boundaries2.length; i++) { ! if (boundaries2[i] == c) return true; ! } ! return false; ! } } |