MCPcopy Create free account
hub / github.com/Sigil-Ebook/Sigil / AddLandmarkCode

Method AddLandmarkCode

src/ResourceObjects/NavProcessor.cpp:494–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

492
493
494void NavProcessor::AddLandmarkCode(const Resource *resource, QString new_code, bool toggle, QString tgt_id)
495{
496 if (new_code.isEmpty()) return;
497 QList<NavLandmarkEntry> landlist = GetLandmarks();
498 QWriteLocker locker(&m_NavResource->GetLock());
499 int pos = GetResourceLandmarkPos(resource, landlist, tgt_id);
500 QString current_code;
501 if (pos > -1) {
502 NavLandmarkEntry le = landlist.at(pos);
503 current_code = le.etype;
504 }
505 if ((current_code != new_code) || !toggle) {
506 QString title = Landmarks::instance()->GetTitle(new_code, m_language);
507 if (pos > -1) {
508 NavLandmarkEntry le = landlist.at(pos);
509 le.etype = new_code;
510 le.title = title;
511 landlist.replace(pos, le);
512 } else {
513 NavLandmarkEntry le;
514 le.etype = new_code;
515 le.title = title;
516 QString href = ConvertBookPathToNavRelative(resource->GetRelativePath());
517 if (!tgt_id.isEmpty()) {
518 href = href + "#" + tgt_id;
519 }
520 le.href = href;
521 // special case the nav setting the toc semantic on itself
522 if ((resource == m_NavResource) && (new_code == "toc")) {
523 le.href = "#toc";
524 }
525 landlist.append(le);
526 }
527 } else {
528 // if the current code is the same as the new one, we toggle it off.
529 if (pos > -1) landlist.removeAt(pos);
530 }
531 SetLandmarks(landlist);
532}
533
534void NavProcessor::RemoveLandmarkForResource(const Resource * resource, QString tgt_id)
535{

Callers 4

AddCoverMethod · 0.80
CreateIndexMethod · 0.80
CreateHTMLTOCMethod · 0.80
AddSemanticCodeMethod · 0.80

Calls 5

replaceMethod · 0.80
GetRelativePathMethod · 0.80
appendMethod · 0.80
isEmptyMethod · 0.45
GetTitleMethod · 0.45

Tested by

no test coverage detected