[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/actions PyUncomment.java, 1.7, 1.8 PyComme
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-08-22 22:07:11
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv389/src/org/python/pydev/editor/actions Modified Files: PyUncomment.java PyComment.java Log Message: Index: PyComment.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyComment.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PyComment.java 19 Jul 2006 23:43:52 -0000 1.8 --- PyComment.java 22 Aug 2006 22:07:08 -0000 1.9 *************** *** 7,12 **** --- 7,18 ---- package org.python.pydev.editor.actions; + import java.util.List; + import org.eclipse.jface.action.IAction; + import org.eclipse.jface.text.BadLocationException; + import org.eclipse.jface.text.ITextSelection; + import org.python.pydev.core.Tuple; import org.python.pydev.core.docutils.PySelection; + import org.python.pydev.core.docutils.StringUtils; /** *************** *** 25,32 **** PySelection ps = new PySelection(getTextEditor()); // Perform the action ! perform(ps); // Put cursor at the first area of the selection ! revealSelEndLine(ps); } catch (Exception e) { beep(e); --- 31,38 ---- PySelection ps = new PySelection(getTextEditor()); // Perform the action ! Tuple<Integer, Integer> repRegion = perform(ps); // Put cursor at the first area of the selection ! getTextEditor().selectAndReveal(repRegion.o1, repRegion.o2); } catch (Exception e) { beep(e); *************** *** 38,44 **** * * @param ps Given PySelection ! * @return boolean The success or failure of the action */ ! public static boolean perform(PySelection ps) { // What we'll be replacing the selected text with StringBuffer strbuf = new StringBuffer(); --- 44,51 ---- * * @param ps Given PySelection ! * @return the new selection ! * @throws BadLocationException */ ! public Tuple<Integer, Integer> perform(PySelection ps) throws BadLocationException { // What we'll be replacing the selected text with StringBuffer strbuf = new StringBuffer(); *************** *** 47,68 **** ps.selectCompleteLine(); ! int i; ! try { ! // For each line, comment them out ! for (i = ps.getStartLineIndex(); i < ps.getEndLineIndex(); i++) { ! strbuf.append("#" + ps.getLine(i) + ps.getEndLineDelim()); ! } ! // Last line shouldn't add the delimiter ! strbuf.append("#" + ps.getLine(i)); ! ! // Replace the text with the modified information ! ps.getDoc().replace(ps.getStartLine().getOffset(), ps.getSelLength(), strbuf.toString()); ! return true; ! } catch (Exception e) { ! beep(e); } ! ! // In event of problems, return false ! return false; } } --- 54,73 ---- ps.selectCompleteLine(); ! String selectedText = ps.getSelectedText(); ! List<String> ret = StringUtils.splitInLines(selectedText); ! ! for(String line: ret){ ! strbuf.append('#'); ! strbuf.append(line); } ! ! ITextSelection txtSel = ps.getTextSelection(); ! int start = txtSel.getOffset(); ! int len = txtSel.getLength(); ! ! String replacement = strbuf.toString(); ! // Replace the text with the modified information ! ps.getDoc().replace(start, len, replacement); ! return new Tuple<Integer, Integer>(start, replacement.length()); } } Index: PyUncomment.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyUncomment.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PyUncomment.java 19 Jul 2006 23:43:52 -0000 1.7 --- PyUncomment.java 22 Aug 2006 22:07:08 -0000 1.8 *************** *** 7,11 **** package org.python.pydev.editor.actions; ! import org.eclipse.jface.action.IAction; import org.python.pydev.core.docutils.PySelection; --- 7,12 ---- package org.python.pydev.editor.actions; ! import org.eclipse.jface.text.BadLocationException; ! import org.python.pydev.core.Tuple; import org.python.pydev.core.docutils.PySelection; *************** *** 16,33 **** /* Selection element */ - /** - * Grabs the selection information and performs the action. - */ - public void run(IAction action) { - PySelection ps = new PySelection(getTextEditor()); - try { - // Perform the action - perform(ps); - - revealSelEndLine(ps); - } catch (Exception e) { - beep(e); - } - } --- 17,20 ---- *************** *** 36,42 **** * * @param ps Given PySelection ! * @return boolean The success or failure of the action */ ! public static boolean perform(PySelection ps) { // What we'll be replacing the selected text with StringBuffer strbuf = new StringBuffer(); --- 23,30 ---- * * @param ps Given PySelection ! * @return the new selection ! * @throws BadLocationException */ ! public Tuple<Integer, Integer> perform(PySelection ps) throws BadLocationException { // What we'll be replacing the selected text with StringBuffer strbuf = new StringBuffer(); *************** *** 46,69 **** int i; ! try { ! // For each line, comment them out ! for (i = ps.getStartLineIndex(); i <= ps.getEndLineIndex(); i++) { ! String l = ps.getLine(i); ! if (l.trim().startsWith("#")) { // we may want to remove comment that are not really in the beggining... ! strbuf.append(l.replaceFirst("#", "") + (i < ps.getEndLineIndex() ? ps.getEndLineDelim() : "")); ! } else { ! strbuf.append(l + (i < ps.getEndLineIndex() ? ps.getEndLineDelim() : "")); ! } } - - // Replace the text with the modified information - ps.getDoc().replace(ps.getStartLine().getOffset(), ps.getSelLength(), strbuf.toString()); - return true; - } catch (Exception e) { - beep(e); } ! // In event of problems, return false ! return false; } --- 34,52 ---- int i; ! // For each line, comment them out ! for (i = ps.getStartLineIndex(); i <= ps.getEndLineIndex(); i++) { ! String l = ps.getLine(i); ! if (l.trim().startsWith("#")) { // we may want to remove comment that are not really in the beggining... ! strbuf.append(l.replaceFirst("#", "") + (i < ps.getEndLineIndex() ? ps.getEndLineDelim() : "")); ! } else { ! strbuf.append(l + (i < ps.getEndLineIndex() ? ps.getEndLineDelim() : "")); } } ! int start = ps.getStartLine().getOffset(); ! String replacement = strbuf.toString(); ! // Replace the text with the modified information ! ps.getDoc().replace(start, ps.getSelLength(), replacement); ! return new Tuple<Integer, Integer>(start, replacement.length()); } |