Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init():
'''Return True if the plugin has loaded successfully.'''
ok = not g.unitTesting
# Not for unit testing: overrides core methods.
if ok:
if 0:
# Override the LeoFrame class.
class myLeoFrame(leoFrame.LeoFrame):
def __init__(self, title=None):
g.pr("myLeoFrame ctor", title)
super().__init__(title)
leoFrame.LeoFrame = myLeoFrame
if 0:
# Override methods of the LeoApp class.
oldAppCloseLeoWindow = g.app.closeLeoWindow
def as_you_type_toggle(self, event):
"""as_you_type_toggle - toggle spell as you type."""
# c = self.c
if self.spell_as_you_type:
self.spell_as_you_type = False
if not self.wrap_as_you_type:
g.unregisterHandler('bodykey2', self.as_you_type_onkey)
g.es("Spell as you type disabled")
return
self.spell_as_you_type = True
if not self.wrap_as_you_type:
g.registerHandler('bodykey2', self.as_you_type_onkey)
g.es("Spell as you type enabled")
#@+node:ekr.20150514063305.494: *4* as_you_type_wrap
lines = self.handleSpecialDocParts(lines, None, retainContents=False)
lines = self.removeLeoDirectives(lines)
if self.getOption(p, 'expand_noweb_references'):
lines = self.expandSectionRefs(lines, p, seen=[])
if self.getOption(
p, 'generate_rst') and self.getOption(p, 'use_alternate_code_block'):
lines = self.replaceCodeBlockDirectives(lines)
# Write the lines.
s = ''.join(lines)
if self.getOption(p, 'table'):
# Support @rst-table: Leo 5.3.
s = s.rstrip() + '\n'
else:
# We no longer add newlines to the start of nodes because
# we write a blank line after all sections.
s = g.ensureTrailingNewlines(s, 2)
self.write(s)
#@+node:ekr.20110610144305.6749: *7* rst.isSectionDef/Ref
def _relinkAsCloneOf(self, p2):
"""A low-level method to replace p.v by a p2.v."""
p = self
v, v2 = p.v, p2.v
parent_v = p._parentVnode()
if not parent_v:
g.internalError('no parent_v', p)
return
if parent_v.children[p._childIndex] == v:
parent_v.children[p._childIndex] = v2
v2.parents.append(parent_v)
# p.v no longer truly exists.
# p.v = p2.v
else:
g.internalError(
'parent_v.children[childIndex] != v',
p, parent_v.children, p._childIndex, v)
#@+node:ekr.20080416161551.217: *4* p._unlink
# This encoding must match the encoding used in putLeoOutline.
hidden_v = FastRead(c, self.gnxDict).readFileFromClipboard(s)
v = hidden_v.children[0]
v.parents = []
# Restore the hidden root's children
c.hiddenRootNode.children = old_children
if not v:
return g.es("the clipboard is not valid ", color="blue")
# Create the position.
p = leoNodes.Position(v)
# Do *not* adjust links when linking v.
if current.hasChildren() and current.isExpanded():
p._linkCopiedAsNthChild(current, 0)
else:
p._linkCopiedAfter(current)
assert not p.isCloned(), g.objToString(p.v.parents)
self.gnxDict = oldGnxDict
self.reassignAllIndices(p)
c.selectPosition(p)
self.initReadIvars()
return p
def center(self):
"""Center any leoGtkDialog."""
g.app.gui.center_dialog(self.top)
#@-node:ekr.20080112145409.5:center
def insert_ignore_directive(self, parent):
c = self.c
parent.v.b = parent.v.b.rstrip() + '\n@ignore\n'
# Do *not* update the screen by setting p.b.
if g.unitTesting:
g.app.unitTestDict['fail'] = g.callers()
elif parent.isAnyAtFileNode() and not parent.isAtAutoNode():
g.warning('inserting @ignore')
c.import_error_nodes.append(parent.h)
#@+node:ekr.20161108155143.4: *4* i.match
def find_gnx(self, root, gnx, vnodeName):
"""
Scan root's tree for a node with the given gnx and vnodeName.
return (p,found)
"""
if gnx:
gnx = g.toUnicode(gnx)
for p in root.self_and_subtree(copy=False):
if p.matchHeadline(vnodeName):
if p.v.fileIndex == gnx:
return p.copy(), True
return None, False
return root, False
#@+node:ekr.20100216141722.5627: *4* goto.find_root
def init ():
'''Return True if the plugin has loaded successfully.'''
# Note: call onCreate _after_ reading the .leo file.
# That is, the 'after-create-leo-frame' hook is too early!
g.registerHandler(('new','open2'),onCreate)
g.plugin_signon(__name__)
return True
#@+node:ekr.20060328125925.5: ** onCreate
@g.command('todo-dec-pri')
def todo_dec_pri(event, direction=1):
c = event['c']
p = c.p
pri = int(c.cleo.getat(p.v, 'priority'))
if pri not in c.cleo.priorities:
pri = 1
else:
ordered = sorted(c.cleo.priorities.keys())
pri = ordered[(ordered.index(pri) + direction) % len(ordered)]
pri = c.cleo.setPri(pri)
c.redraw()