From 93571ec2f131ab54ffb118227dec0fed28b2b46f Mon Sep 17 00:00:00 2001 From: Christopher Harvey Date: Sun, 6 Jun 2010 14:21:02 -0400 Subject: Comment blocks are displayed as individual nodes and the rest of the docs are put into the html documentation viewer. This is a nice balance between showing all doc nodes and showing none. --- src/frontend/main.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/src/frontend/main.py b/src/frontend/main.py index d12d8db..4383dc3 100644 --- a/src/frontend/main.py +++ b/src/frontend/main.py @@ -126,9 +126,22 @@ class MainWindow(gtk.Window): """ def nodeChanged(self, treeview, user_param1): p = self.edit_tv.getSelectedEntryPath() - p = augeas_utils.removeNumbers(p) - xmlPath = osp.join("/VentooModule/root", p) - docPath = self.currentModule.getDocURLOf(xmlPath) + docPath = None + #if this is a comment node display all surround docs/comments + if osp.split(p)[1].startswith("#comment["): + toDisplay = self.getDocsStartingAt(osp.join("/files", augeas_utils.stripBothSlashes(self.currentConfigFilePath), p), "
") + docPath = "/tmp/commentsDoc.html" + outFile = open("/tmp/commentsDoc.html", 'w') + outFile.write("\n") + outFile.write(toDisplay) + outFile.write("\n") + outFile.close() + else: + #this is a normal node, normal display + p = augeas_utils.removeNumbers(p) + xmlPath = osp.join("/VentooModule/root", p) + docPath = self.currentModule.getDocURLOf(xmlPath) + if docPath == None: self.docWindow.load_url("about:blank") else: @@ -250,14 +263,25 @@ class MainWindow(gtk.Window): maxIndex = 0 #matches / and stores as group 1 indexProg = re.compile('^.+/([0-9]+)/?$') + commentProg = re.compile('"^#comment\[(.*)]$"') + lastLineWasDoc = False for match in matches: #add all existing entries indexResult = indexProg.match(match) + commentResult = commentProg.match(match) if indexResult != None: #sometimes there are entries on these levels we don't care about. have += 1 thisIndex = int(indexResult.group(1)) maxIndex = max(maxIndex, thisIndex) created = model.append(modelPathIter, [True, indexResult.group(1), '-------']) self.__buildEditModel(model, match, created, xmlRoot) + lastLineWasDoc = False + elif commentProg != None: #got a comment + #only display the first line, the rest can be displayed in the doc frame when requested. + if not lastLineWasDoc: + docText = self.a.get(match) + created = model.append(modelPathIter, [True, osp.split(match)[1], docText]) + lastLineWasDoc = True + #add the missing entries numNeeded = augeas_utils.matchDiff(thisMult, have) #add the required ones. @@ -320,14 +344,38 @@ class MainWindow(gtk.Window): break #now search for and add nodes that haven't been added yet, and may not be in the VentooModule specifically. allInAugeas = self.a.match(osp.join(augeasFileRoot, '*')) + lastLineWasDoc = False for a in allInAugeas: if not a in listedNodes: #found that 'a' is not in listedNodes, but is in augeasTree, add it, if it is not supposed to be ignored. - if not osp.split(a)[1].startswith('#'): #always ignore comments + if not osp.split(a)[1].startswith('#'): #always ignore comments (delt with later) userData = self.a.get(a) created = model.append(modelPathIter, [True, osp.split(a)[1], userData]) self.__buildEditModel(model, a, created, osp.join(xmlRoot, 'ventoo_dynamic')) - + lastLineWasDoc = False + else: + #Add docs inline here + if not lastLineWasDoc: + docText = self.a.get(a) + created = model.append(modelPathIter, [True, osp.split(a)[1], docText]) + lastLineWasDoc = True + + """ + Get doc text starting at the augeas path p, until another non-comment is found + nl stands for new line and is a string to be added after each comment node. + """ + def getDocsStartingAt(self, p, nl = "\n"): + docStr = "" + commentProg = re.compile('^.*#comment\[(.*)\]$') + thisNodes = self.a.match(osp.join(osp.split(p)[0], "*")) + try: + idx = thisNodes.index(p) + while commentProg.match(thisNodes[idx])!=None: + docStr = docStr + nl + self.a.get(thisNodes[idx]) + idx += 1 + except IndexError: + pass + return docStr """ Called when the user picks a new file to view. -- cgit v1.2.3-65-gdbad