コード例 #1
0
 def toAtEdit(self, p):
     '''Convert p from @auto to @edit.'''
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree():
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p, enableRedrawFlag=False)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row+1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
コード例 #2
0
 def toAtEdit(self, p):
     """Convert p from @auto to @edit."""
     c = self.c
     w = c.frame.body.wrapper
     p.h = '@edit' + p.h[5:]
     # Compute the position of the present line within the *selected* node c.p
     ins = w.getInsertPoint()
     row, col = g.convertPythonIndexToRowCol(c.p.b, ins)
     # Ignore directive lines.
     directives = [z for z in g.splitLines(c.p.b)[:row] if g.isDirective(z)]
     row -= len(directives)
     row = max(0, row)
     # Count preceding lines from p to c.p, again ignoring directives.
     for p2 in p.self_and_subtree(copy=False):
         if p2 == c.p:
             break
         lines = [z for z in g.splitLines(p2.b) if not g.isDirective(z)]
         row += len(lines)
     # Reload the file into a single node.
     c.selectPosition(p)
     c.refreshFromDisk()
     # Restore the line in the proper node.
     ins = g.convertRowColToPythonIndex(p.b, row + 1, 0)
     w.setInsertPoint(ins)
     p.setDirty()
     c.setChanged()
     c.redraw()
     c.bodyWantsFocus()
コード例 #3
0
 def stringRectangle1(self, event):
     c, k = self.c, self.c.k
     k.clearState()
     k.resetLabel()
     c.bodyWantsFocus()
     w = self.w
     self.beginCommand(w, 'string-rectangle')
     # pylint: disable=unpacking-non-sequence
     r1, r2, r3, r4 = self.stringRect
     s = w.getAllText()
     for r in range(r1, r3 + 1):
         i = g.convertRowColToPythonIndex(s, r - 1, r2)
         j = g.convertRowColToPythonIndex(s, r - 1, r4)
         s = s[:i] + k.arg + s[j:]
     w.setAllText(s)
     i = g.convertRowColToPythonIndex(s, r1 - 1, r2)
     j = g.convertRowColToPythonIndex(s, r3 - 1, r2 + len(k.arg))
     w.setSelectionRange(i, j)
     self.endCommand()
     # 2010/1/1: Fix bug 480422:
     # string-rectangle kills syntax highlighting.
     c.frame.body.recolor(c.p)
コード例 #4
0
 def stringRectangle(self, event):
     '''
     Prompt for a string, then replace the contents of a rectangle
     with a string on each line.
     '''
     c, k = self.c, self.c.k
     state = k.getState('string-rect')
     if g.app.unitTesting:
         state = 1
         k.arg = 's...s'  # This string is known to the unit test.
         w = self.editWidget(event)
         self.stringRect = self.getRectanglePoints(w)
     if state == 0:
         self.w = self.editWidget(event)
         if self.w and self.check(event):
             self.stringRect = self.getRectanglePoints(self.w)
             k.setLabelBlue('String rectangle: ')
             k.getArg(event, 'string-rect', 1, self.stringRectangle)
     else:
         k.clearState()
         k.resetLabel()
         c.bodyWantsFocus()
         w = self.w
         self.beginCommand(w, 'string-rectangle')
         # pylint: disable=unpacking-non-sequence
         r1, r2, r3, r4 = self.stringRect
         s = w.getAllText()
         for r in range(r1, r3 + 1):
             i = g.convertRowColToPythonIndex(s, r - 1, r2)
             j = g.convertRowColToPythonIndex(s, r - 1, r4)
             s = s[:i] + k.arg + s[j:]
         w.setAllText(s)
         i = g.convertRowColToPythonIndex(s, r1 - 1, r2)
         j = g.convertRowColToPythonIndex(s, r3 - 1, r2 + len(k.arg))
         w.setSelectionRange(i, j)
         self.endCommand()
         # 2010/1/1: Fix bug 480422:
         # string-rectangle kills syntax highlighting.
         c.frame.body.recolor(c.p, incremental=False)
コード例 #5
0
 def stringRectangle(self, event):
     '''
     Prompt for a string, then replace the contents of a rectangle
     with a string on each line.
     '''
     c, k = self.c, self.c.k
     state = k.getState('string-rect')
     if g.app.unitTesting:
         state = 1
         k.arg = 's...s' # This string is known to the unit test.
         w = self.editWidget(event)
         self.stringRect = self.getRectanglePoints(w)
     if state == 0:
         self.w = self.editWidget(event)
         if self.w and self.check(event):
             self.stringRect = self.getRectanglePoints(self.w)
             k.setLabelBlue('String rectangle: ')
             k.getArg(event, 'string-rect', 1, self.stringRectangle)
     else:
         k.clearState()
         k.resetLabel()
         c.bodyWantsFocus()
         w = self.w
         self.beginCommand(w, 'string-rectangle')
         # pylint: disable=unpacking-non-sequence
         r1, r2, r3, r4 = self.stringRect
         s = w.getAllText()
         for r in range(r1, r3 + 1):
             i = g.convertRowColToPythonIndex(s, r - 1, r2)
             j = g.convertRowColToPythonIndex(s, r - 1, r4)
             s = s[: i] + k.arg + s[j:]
         w.setAllText(s)
         i = g.convertRowColToPythonIndex(s, r1 - 1, r2)
         j = g.convertRowColToPythonIndex(s, r3 - 1, r2 + len(k.arg))
         w.setSelectionRange(i, j)
         self.endCommand()
         # 2010/1/1: Fix bug 480422:
         # string-rectangle kills syntax highlighting.
         c.frame.body.recolor(c.p, incremental=False)
コード例 #6
0
 def stringRectangle1(self, event):
     c, k = self.c, self.c.k
     k.clearState()
     k.resetLabel()
     c.bodyWantsFocus()
     w = self.w
     self.beginCommand(w, 'string-rectangle')
     # pylint: disable=unpacking-non-sequence
     r1, r2, r3, r4 = self.stringRect
     s = w.getAllText()
     for r in range(r1, r3 + 1):
         i = g.convertRowColToPythonIndex(s, r - 1, r2)
         j = g.convertRowColToPythonIndex(s, r - 1, r4)
         s = s[: i] + k.arg + s[j:]
     w.setAllText(s)
     i = g.convertRowColToPythonIndex(s, r1 - 1, r2)
     j = g.convertRowColToPythonIndex(s, r3 - 1, r2 + len(k.arg))
     w.setSelectionRange(i, j)
     self.endCommand()
     # 2010/1/1: Fix bug 480422:
     # string-rectangle kills syntax highlighting.
     c.frame.body.recolor(c.p)
コード例 #7
0
 def success(self, n, n2, p):
     """Place the cursor on line n2 of p.b."""
     c = self.c
     w = c.frame.body.wrapper
     # Select p and make it visible.
     c.selectPosition(p)
     c.redraw(p)
     # Put the cursor on line n2 of the body text.
     s = w.getAllText()
     ins = g.convertRowColToPythonIndex(s, n2 - 1, 0)
     c.frame.clearStatusLine()
     c.frame.putStatusLine(f"goto-global-line found: {n2}")
     w.setInsertPoint(ins)
     c.bodyWantsFocus()
     w.seeInsertPoint()
コード例 #8
0
 def success(self, lines, n, n2, p):
     '''Place the cursor on line n2 of p.b.'''
     c = self.c
     w = c.frame.body.wrapper
     # Select p and make it visible.
     if c.p.isOutsideAnyAtFileTree():
         p = c.findNodeOutsideAnyAtFileTree(p)
     c.redraw(p)
     # Put the cursor on line n2 of the body text.
     s = w.getAllText()
     ins = g.convertRowColToPythonIndex(s, n2 - 1, 0)
     c.frame.clearStatusLine()
     c.frame.putStatusLine('goto-global-line found: %s' % (n2))
     w.setInsertPoint(ins)
     c.bodyWantsFocus()
     w.seeInsertPoint()
コード例 #9
0
 def success(self, lines, n, n2, p):
     '''Place the cursor on line n2 of p.b.'''
     c = self.c
     w = c.frame.body.wrapper
     # Select p and make it visible.
     if c.p.isOutsideAnyAtFileTree():
         p = c.findNodeOutsideAnyAtFileTree(p)
     c.redraw(p)
     # Put the cursor on line n2 of the body text.
     s = w.getAllText()
     ins = g.convertRowColToPythonIndex(s, n2 - 1, 0)
     c.frame.clearStatusLine()
     c.frame.putStatusLine('goto-global-line found: %s' % (n2))
     w.setInsertPoint(ins)
     c.bodyWantsFocus()
     w.seeInsertPoint()
コード例 #10
0
 def success(self, lines, n, n2, p):
     '''Place the cursor on line n2 of p.b.'''
     trace = False and not g.unitTesting
     c = self.c
     w = c.frame.body.wrapper
     # Select p and make it visible.
     if c.p.isOutsideAnyAtFileTree():
         p = c.findNodeOutsideAnyAtFileTree(p)
     c.redraw(p)
     # Put the cursor on line n2 of the body text.
     s = w.getAllText()
     ins = g.convertRowColToPythonIndex(s, n2 - 1, 0)
     if trace:
         i, j = g.getLine(s, ins)
         g.trace('%2s %2s %15s %s' % (n, n2, p.h, repr(s[i: j])))
     w.setInsertPoint(ins)
     c.bodyWantsFocus()
     w.seeInsertPoint()
コード例 #11
0
ファイル: gotoCommands.py プロジェクト: node-ex/leo-editor
 def success(self, lines, n, n2, p):
     '''Place the cursor on line n2 of p.b.'''
     trace = False and not g.unitTesting
     c = self.c
     w = c.frame.body.wrapper
     # Select p and make it visible.
     if c.p.isOutsideAnyAtFileTree():
         p = c.findNodeOutsideAnyAtFileTree(p)
     c.redraw(p)
     # Put the cursor on line n2 of the body text.
     s = w.getAllText()
     ins = g.convertRowColToPythonIndex(s, n2 - 1, 0)
     if trace:
         i, j = g.getLine(s, ins)
         g.trace('%2s %2s %15s %s' % (n, n2, p.h, repr(s[i: j])))
     w.setInsertPoint(ins)
     c.bodyWantsFocus()
     w.seeInsertPoint()