Updating the index now only rehighlights lines with meta keywords
This commit is contained in:
+3
-6
@@ -288,13 +288,10 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reHighLightText(self, forceBigDoc=False):
|
def updateTagHighLighting(self, forceBigDoc=False):
|
||||||
"""Run the syntax highlighter again.
|
"""Rerun the syntax highlighter on all meta data lines.
|
||||||
"""
|
"""
|
||||||
if not self.bigDoc or forceBigDoc:
|
self.hLight.rehighlightByType(GuiDocHighlighter.BLOCK_META)
|
||||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
|
||||||
self.hLight.rehighlight()
|
|
||||||
qApp.restoreOverrideCursor()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def redrawText(self):
|
def redrawText(self):
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class GuiDocHighlighter(QSyntaxHighlighter):
|
class GuiDocHighlighter(QSyntaxHighlighter):
|
||||||
|
|
||||||
|
BLOCK_NONE = 0
|
||||||
|
BLOCK_TEXT = 1
|
||||||
|
BLOCK_META = 2
|
||||||
|
BLOCK_TITLE = 4
|
||||||
|
|
||||||
def __init__(self, theDoc, theParent):
|
def __init__(self, theDoc, theParent):
|
||||||
QSyntaxHighlighter.__init__(self, theDoc)
|
QSyntaxHighlighter.__init__(self, theDoc)
|
||||||
|
|
||||||
@@ -229,6 +234,22 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self.theHandle = theHandle
|
self.theHandle = theHandle
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
##
|
||||||
|
# Methods
|
||||||
|
##
|
||||||
|
|
||||||
|
def rehighlightByType(self, theType):
|
||||||
|
"""Loop through all blocks and rehighlight those of a given
|
||||||
|
content type.
|
||||||
|
"""
|
||||||
|
qDocument = self.document()
|
||||||
|
nBlocks = qDocument.blockCount()
|
||||||
|
for i in range(nBlocks):
|
||||||
|
theBlock = qDocument.findBlockByNumber(i)
|
||||||
|
if theBlock.userState() & theType == theType:
|
||||||
|
self.rehighlightBlock(theBlock)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Highlight Block
|
# Highlight Block
|
||||||
##
|
##
|
||||||
@@ -239,10 +260,12 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
is significantly faster than running the regex checks used for
|
is significantly faster than running the regex checks used for
|
||||||
text paragraphs.
|
text paragraphs.
|
||||||
"""
|
"""
|
||||||
|
self.setCurrentBlockState(self.BLOCK_NONE)
|
||||||
if self.theHandle is None or not theText:
|
if self.theHandle is None or not theText:
|
||||||
return
|
return
|
||||||
|
|
||||||
if theText.startswith("@"): # Keywords and commands
|
if theText.startswith("@"): # Keywords and commands
|
||||||
|
self.setCurrentBlockState(self.BLOCK_META)
|
||||||
tItem = self.theParent.theProject.projTree[self.theHandle]
|
tItem = self.theParent.theProject.projTree[self.theHandle]
|
||||||
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
isValid, theBits, thePos = self.theIndex.scanThis(theText)
|
||||||
isGood = self.theIndex.checkThese(theBits, tItem)
|
isGood = self.theIndex.checkThese(theBits, tItem)
|
||||||
@@ -266,22 +289,27 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
return
|
return
|
||||||
|
|
||||||
elif theText.startswith("# "): # Header 1
|
elif theText.startswith("# "): # Header 1
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||||
self.setFormat(0, 1, self.hStyles["header1h"])
|
self.setFormat(0, 1, self.hStyles["header1h"])
|
||||||
self.setFormat(1, len(theText), self.hStyles["header1"])
|
self.setFormat(1, len(theText), self.hStyles["header1"])
|
||||||
|
|
||||||
elif theText.startswith("## "): # Header 2
|
elif theText.startswith("## "): # Header 2
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||||
self.setFormat(0, 2, self.hStyles["header2h"])
|
self.setFormat(0, 2, self.hStyles["header2h"])
|
||||||
self.setFormat(2, len(theText), self.hStyles["header2"])
|
self.setFormat(2, len(theText), self.hStyles["header2"])
|
||||||
|
|
||||||
elif theText.startswith("### "): # Header 3
|
elif theText.startswith("### "): # Header 3
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||||
self.setFormat(0, 3, self.hStyles["header3h"])
|
self.setFormat(0, 3, self.hStyles["header3h"])
|
||||||
self.setFormat(3, len(theText), self.hStyles["header3"])
|
self.setFormat(3, len(theText), self.hStyles["header3"])
|
||||||
|
|
||||||
elif theText.startswith("#### "): # Header 4
|
elif theText.startswith("#### "): # Header 4
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TITLE)
|
||||||
self.setFormat(0, 4, self.hStyles["header4h"])
|
self.setFormat(0, 4, self.hStyles["header4h"])
|
||||||
self.setFormat(4, len(theText), self.hStyles["header4"])
|
self.setFormat(4, len(theText), self.hStyles["header4"])
|
||||||
|
|
||||||
elif theText.startswith("%"): # Comments
|
elif theText.startswith("%"): # Comments
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TEXT)
|
||||||
toCheck = theText[1:].lstrip()
|
toCheck = theText[1:].lstrip()
|
||||||
synTag = toCheck[:9].lower()
|
synTag = toCheck[:9].lower()
|
||||||
tLen = len(theText)
|
tLen = len(theText)
|
||||||
@@ -294,6 +322,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
|
|||||||
self.setFormat(0, tLen, self.hStyles["hidden"])
|
self.setFormat(0, tLen, self.hStyles["hidden"])
|
||||||
|
|
||||||
else: # Text Paragraph
|
else: # Text Paragraph
|
||||||
|
self.setCurrentBlockState(self.BLOCK_TEXT)
|
||||||
for rX, xFmt in self.rxRules:
|
for rX, xFmt in self.rxRules:
|
||||||
rxItt = rX.globalMatch(theText, 0)
|
rxItt = rX.globalMatch(theText, 0)
|
||||||
while rxItt.hasNext():
|
while rxItt.hasNext():
|
||||||
|
|||||||
+1
-2
@@ -716,13 +716,12 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
tEnd = time()
|
tEnd = time()
|
||||||
self.statusBar.setStatus("Indexing completed in %.1f ms" % ((tEnd - tStart)*1000.0))
|
self.statusBar.setStatus("Indexing completed in %.1f ms" % ((tEnd - tStart)*1000.0))
|
||||||
|
self.docEditor.updateTagHighLighting()
|
||||||
qApp.restoreOverrideCursor()
|
qApp.restoreOverrideCursor()
|
||||||
|
|
||||||
if not beQuiet:
|
if not beQuiet:
|
||||||
self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO)
|
self.makeAlert("The project index has been successfully rebuilt.", nwAlert.INFO)
|
||||||
|
|
||||||
self.docEditor.reHighLightText()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def rebuildOutline(self):
|
def rebuildOutline(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user