Skip to content

Commit

Permalink
Finishing ability to find library Os w/ orphan docs and deprecate them.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvorka committed Apr 1, 2024
1 parent 20f6210 commit e1b9b0a
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/qt/main_menu_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ MainMenuPresenter::MainMenuPresenter(MainWindowPresenter* mwp)
QObject::connect(view->actionLibraryAdd, SIGNAL(triggered()), mwp, SLOT(doActionLibraryNew()));
QObject::connect(view->actionLibrarySync, SIGNAL(triggered()), mwp, SLOT(doActionLibrarySync()));
QObject::connect(view->actionLibraryOrphans, SIGNAL(triggered()), mwp, SLOT(doActionLibraryOrphans()));
QObject::connect(view->actionLibraryDeprecateOrphanOs, SIGNAL(triggered()), mwp, SLOT(doActionLibraryDeprecateOrphanOs()));
QObject::connect(view->actionLibraryDeprecate, SIGNAL(triggered()), mwp, SLOT(doActionLibraryRm()));

// menu: Organizer
Expand Down
10 changes: 9 additions & 1 deletion app/src/qt/main_menu_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ MainMenuView::MainMenuView(MainWindowView& mainWindowView)
mainWindow);
actionLibrarySync->setStatusTip(
tr("Find library Notebooks which reference non-existent documents..."));
// library: deprecate
// library: deprecate orphan Os
actionLibraryDeprecateOrphanOs = new QAction(
QIcon(":/menu-icons/delete.svg"),
tr("Deprecate &orphans"),
mainWindow);
actionLibraryDeprecateOrphanOs->setStatusTip(
tr("Deprecate library Notebooks that has tag which indicates reference of non-existent document..."));
// library: delete
actionLibraryDeprecate = new QAction(
QIcon(":/menu-icons/delete.svg"), tr("&Delete library"), mainWindow);
actionLibraryDeprecate->setStatusTip(tr(
Expand All @@ -156,6 +163,7 @@ MainMenuView::MainMenuView(MainWindowView& mainWindowView)
submenuMindLibrary->addAction(actionLibraryAdd);
submenuMindLibrary->addAction(actionLibrarySync);
submenuMindLibrary->addAction(actionLibraryOrphans);
submenuMindLibrary->addAction(actionLibraryDeprecateOrphanOs);
submenuMindLibrary->addAction(actionLibraryDeprecate);

// dream ... sanity, integrity, detox, inference, assoc discovery, ...
Expand Down
1 change: 1 addition & 0 deletions app/src/qt/main_menu_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class MainMenuView : public QObject
QAction* actionLibraryAdd;
QAction* actionLibrarySync;
QAction* actionLibraryOrphans;
QAction* actionLibraryDeprecateOrphanOs;
QAction* actionLibraryDeprecate;
QAction* actionMindPreferences;
QMenu* submenuMindExport;
Expand Down
51 changes: 50 additions & 1 deletion app/src/qt/main_window_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3466,7 +3466,56 @@ void MainWindowPresenter::handleSyncLibrary()

void MainWindowPresenter::doActionLibraryOrphans()
{
mind->findLibraryOrphanOs();
int orphans = mind->findLibraryOrphanOs();
if(orphans) {
doActionViewOutlines();

QMessageBox::information(
&view,
tr("Library Orphans"),
tr(
"Found %1 library Notebooks with orphaned documents. "
"Notebooks were tagged with 'library-orphan-document' tag. "
"Use scopes to filter them out."
).arg(orphans)
);
} else {
QMessageBox::information(
&view,
tr("Library Orphans"),
tr("No Notebooks with orphaned documents found.")
);
}
}

void MainWindowPresenter::doActionLibraryDeprecateOrphanOs()
{
vector<const Tag*> tags{};
tags.push_back(
mind->getOntology().findOrCreateTag(
MarkdownDocumentRepresentation::TAG_LIB_DOC_ORPHAN));
vector<Outline*> os{};
mind->findOutlinesByTags(tags, os);

if(os.size()) {
for(Outline* o:os) {
mind->outlineForget(o->getKey());
}

QMessageBox::information(
&view,
tr("Library Orphans"),
tr("%1 Notebooks tagged as library orphans were deprecated.").arg(os.size())
);

doActionViewOutlines();
} else {
QMessageBox::information(
&view,
tr("Library Orphans"),
tr("No Notebooks with library orphan tag found.")
);
}
}

void MainWindowPresenter::doActionLibraryRm()
Expand Down
1 change: 1 addition & 0 deletions app/src/qt/main_window_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public slots:
void handleNewLibrary();
void doActionLibrarySync();
void doActionLibraryOrphans();
void doActionLibraryDeprecateOrphanOs();
void handleSyncLibrary();
void doActionLibraryRm();
void handleRmLibrary();
Expand Down
26 changes: 22 additions & 4 deletions lib/src/mind/mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ vector<Note*>* Mind::getNotesOfType(const NoteType& type, const Outline& outline
return nullptr;
}

void Mind::findOutlinesByTags(const std::vector<const Tag*>& tags, std::vector<Outline*>& result) const
void Mind::findOutlinesByTags(const vector<const Tag*>& tags, vector<Outline*>& result) const
{
for(Outline* o:memory.getOutlines()) {
bool allMatched = true;
Expand Down Expand Up @@ -1502,7 +1502,7 @@ void Mind::initWingman()
wingmanLlmProvider = WingmanLlmProviders::WINGMAN_PROVIDER_NONE;
}

void Mind::findLibraryOrphanOs()
int Mind::findLibraryOrphanOs()
{
vector<Outline*> orphanOutlines{};
const vector<Outline*>& outlines = memory.getOutlines();
Expand Down Expand Up @@ -1539,14 +1539,32 @@ void Mind::findLibraryOrphanOs()
MF_DEBUG(" '" << documentPath << "'" << endl);
if(!isFile(documentPath.c_str())) {
MF_DEBUG(" ORPHAN" << endl);
// TODO
detect whether the file exists
orphanOutlines.push_back(outline);

// tag O as orphan
const Tag* orphanTag = memory.getOntology().findOrCreateTag(
MarkdownDocumentRepresentation::TAG_LIB_DOC_ORPHAN);
if(!outline->hasTag(orphanTag)) {
outline->addTag(orphanTag);
memory.remember(outline);
}
}
}
}
}
}
}

if(orphanOutlines.size()) {
MF_DEBUG("ORPHAN library outlines found:" << endl);
for(Outline* o:orphanOutlines) {
MF_DEBUG(" " << o->getName() << endl);
}
} else {
MF_DEBUG("NO ORPHAN library outlines found." << endl);
}

return orphanOutlines.size();
}

Wingman* Mind::getWingman()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mind/mind.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ class Mind : public OntologyProvider
/**
* @brief Find Os which reference non-existent documents.
*/
void findLibraryOrphanOs();
int findLibraryOrphanOs();

/*
* WINGMAN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MarkdownDocumentRepresentation
public:

static constexpr const auto TAG_LIB_DOC = "library-document";
static constexpr const auto TAG_LIB_DOC_ORPHAN = "library-orphan-document";

static constexpr const auto PREFIX_1ST_LINE = "This is a notebook for the document: ";

Expand Down

0 comments on commit e1b9b0a

Please sign in to comment.