Esempio n. 1
0
 def createChapterByName(self, name, p, undoType='Create Chapter'):
     cc, c = self, self.c
     if g.isInt(name):
         return cc.note('PyQt5 chapters not supported yet.')
     if not name:
         return cc.note('no name')
     oldChapter = cc.getSelectedChapter()
     theChapter = cc.chaptersDict.get(name)
     if theChapter:
         return cc.note('duplicate chapter name: %s' % (name), killUnitTest=True)
     oldName = oldChapter.name if oldChapter else ''
     bunch = cc.beforeCreateChapter(c.p, oldName, name, undoType)
     if undoType == 'Convert Node To Chapter':
         root = p.insertAfter()
         root.initHeadString('@chapter %s' % name)
         p.moveToFirstChildOf(root)
     elif undoType in ('Create Chapter From Node', 'Create Chapter'):
         # Create the @chapter node.
         # If p exists, clone it as the first child, else create a dummy first child.
         root = cc.getChapterNode(name, p=p)
     else:
         return g.trace('Can not happen: bad undoType: %s' % undoType)
     cc.chaptersDict[name] = Chapter(c, cc, name)
     cc.selectChapterByName(name)
     cc.afterCreateChapter(bunch, c.p)
     return True
Esempio n. 2
0
 def selectChapterByName(self, name, collapse=True):
     '''Select a chapter.  Return True if a redraw is needed.'''
     cc = self
     if self.selectChapterLockout:
         return
     if g.isInt(name):
         return cc.note('PyQt5 chapters not supported')
     chapter = cc.getChapter(name)
     if not chapter:
         g.es_print('no such @chapter node: %s' % name)
         return
     try:
         cc.selectChapterLockout = True
         cc.selectChapterByNameHelper(chapter, collapse=collapse)
     finally:
         cc.selectChapterLockout = False
Esempio n. 3
0
 def selectChapterByName(self, name, collapse=True):
     '''Select a chapter.  Return True if a redraw is needed.'''
     cc = self
     if self.selectChapterLockout:
         return
     if g.isInt(name):
         return cc.note('PyQt5 chapters not supported')
     chapter = cc.getChapter(name)
     if not chapter:
         g.es_print('no such @chapter node: %s' % name)
         return
     try:
         cc.selectChapterLockout = True
         cc.selectChapterByNameHelper(chapter, collapse=collapse)
     finally:
         cc.selectChapterLockout = False
Esempio n. 4
0
 def selectChapterByName(self, name, collapse=True, create=True):
     '''Select a chapter.  Return True if a redraw is needed.'''
     trace = False and not g.unitTesting
     cc, c = self, self.c
     if g.isInt(name):
         return cc.note('PyQt5 chapaters not supported')
     chapter = cc.chaptersDict.get(name)
     if chapter:
         cc.selectChapterByNameHelper(chapter, collapse=collapse)
     elif create:
         # There is an @chapter node, but no actual chapter.
         if trace: g.trace('*** creating', name)
         cc.createChapterByName(name, p=c.p, undoType='Create Chapter')
     else:
         # create is False if called from the minibuffer.
         # do nothing if the user mis-types.
         cc.note('no such chapter: %s' % name)
         chapter = cc.chaptersDict.get('main')
         if chapter:
             self.selectChapterByNameHelper(chapter, collapse=collapse)
         else:
             g.trace(g.callers())
             cc.error('no main chapter!')