def onAutoAddDoc(self): """Create a doc file, add a link and open for editing""" if not self.__actionPrerequisites(): return selectedItem = self.selectedItems()[0] # Exactly one is selected editor = selectedItem.getEditor() fileName = editor._parent.getFileName() if not fileName: logging.error('Save file before invoking auto doc') return needContent = False newAnchor = 'doc' + str(uuid.uuid4().fields[-1])[-6:] docFileName = self.__getAutoDocFileName(fileName) if not os.path.exists(docFileName): # Create file and populate with the default content try: os.makedirs(os.path.dirname(docFileName), exist_ok=True) with open(docFileName, 'w') as f: pass except Exception as exc: logging.error('Error creating the documentation file ' + docFileName + ': ' + str(exc)) return needContent = True project = GlobalData().project if project.isProjectFile(docFileName): link = project.getRelativePath(docFileName) else: link = os.path.relpath(docFileName, fileName) # Insert a doc link with editor: lineNo = selectedItem.getFirstLine() line = CMLdoc.generate(link, newAnchor, 'See documentation', None, None, None, selectedItem.ref.body.beginPos) editor.insertLines(line, lineNo) QApplication.processEvents() self.parent().redrawNow() # Open the file if GlobalData().mainWindow.openFile(docFileName, -1): if needContent: widget = GlobalData().mainWindow.em.getWidgetForFileName(docFileName) editor = widget.getEditor() editor.text = getDefaultFileDoc(fileName, newAnchor) editor.document().setModified(False)
def addCallTrace(self, isCall, fromFile, fromLine, fromFunction, toFile, toLine, toFunction): """Adds a record to the list""" tooltip = 'Return\n' icon = self.__retIcon if isCall: tooltip = 'Call\n' icon = self.__callIcon if self.projectLoaded: project = GlobalData().project fromFile = project.getRelativePath(fromFile) toFile = project.getRelativePath(toFile) parentItem = self if self.__callStack: parentItem = self.__callStack[-1] fromItem = self.__entryFormat.format(fromFile, fromLine, fromFunction) toItem = self.__entryFormat.format(toFile, toLine, toFunction) item = QTreeWidgetItem(parentItem, ['', fromItem, toItem]) item.setIcon(0, icon) item.setData(0, Qt.UserRole, isCall) item.setExpanded(True) tooltip += 'From: ' + fromItem + '\nTo: ' + toItem item.setToolTip(1, tooltip) item.setToolTip(2, tooltip) if isCall: self.__callStack.append(item) else: if self.__callStack: self.__callStack.pop(-1) self.count += 1
def __getContent(self): project = GlobalData().project projectMDFile = project.getStartupMarkdownFile() projectPart = "" if projectMDFile: if os.path.exists(projectMDFile): relativeMDFile = project.getRelativePath(projectMDFile) projectPart = """<p align="left">The currently lodaded project <b>""" + GlobalData().project.getProjectName( ) + """</b> provides documentation. <br>Open it by clicking <a href="action://project-cocumentation">""" + relativeMDFile + """</a> or clicking any time the main toolbar button with the markdown icon.</p> <br> <hr> <br>""" pixmapPath = os.path.dirname(os.path.realpath(sys.argv[0])) + \ os.path.sep + 'pixmaps' + os.path.sep logoPath = pixmapPath + 'logo-48x48.png' welcome = " Codimension version " + str(GlobalData().version) + \ " <font size=-2>(GPL v3)</font>" return """ <body bgcolor="#EFF0F2"> <p> <table cellspacing="0" cellpadding="8" width="100%" align="left" bgcolor="#EFF0F2" border="0" style="width: 100%"> <tr> <td width="1%" valign="middle"> <a href="http://codimension.org"> <img border="0" align="left" src='file:""" + logoPath + """' width="48" height="48"> </a> </td> <td valign="middle"> <h2 align="left"> """ + welcome + """</h2> </td> </tr> </table> <br><br> <table cellspacing="0" cellpadding="8" width="100%" align="left" bgcolor="#EFF0F2" border="0" style="width: 100%"> <tr> <td>""" + projectPart + """