Skip to content

Commit

Permalink
Fix naming conventions, and allow access to const documents
Browse files Browse the repository at this point in the history
This will be used for auto-backup, which doesn't not need non-const access

Bug: #392
  • Loading branch information
cameronwhite committed Oct 29, 2024
1 parent 06c7f10 commit b2d2f01
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions source/app/documentmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,23 @@ Document &DocumentManager::addDefaultDocument(
return doc;
}

Document &DocumentManager::getCurrentDocument()
Document &
DocumentManager::getCurrentDocument()
{
if (!myCurrentIndex)
throw std::logic_error("No documents are currently open");

return *myDocumentList.at(*myCurrentIndex);
}

Document &DocumentManager::getDocument(int i)
Document &
DocumentManager::getDocument(int i)
{
return *myDocumentList.at(i);
}

const Document &
DocumentManager::getDocument(int i) const
{
return *myDocumentList.at(i);
}
Expand Down Expand Up @@ -120,14 +128,15 @@ int DocumentManager::getCurrentDocumentIndex() const
return *myCurrentIndex;
}

size_t DocumentManager::getDocumentListSize() const
int
DocumentManager::getNumDocuments() const
{
return myDocumentList.size();
return static_cast<int>(myDocumentList.size());
}

int DocumentManager::findDocument(const Document::PathType &filepath)
{
for (unsigned int i = 0; i < getDocumentListSize(); ++i)
for (int i = 0, n = getNumDocuments(); i < n; ++i)
{
Document& doc = getDocument(i);

Expand Down
6 changes: 4 additions & 2 deletions source/app/documentmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ class DocumentManager
Document &addDefaultDocument(const SettingsManager &settings_manager);

Document &getCurrentDocument();

Document &getDocument(int i);
const Document &getDocument(int i) const;

void removeDocument(int index);

bool hasOpenDocuments() const;
void setCurrentDocumentIndex(int index);

int getCurrentDocumentIndex() const;
size_t getDocumentListSize() const;

int getNumDocuments() const;

/// Returns -1 if the file at filepath is not open, else it returns the index at which the already open file is at
int findDocument(const Document::PathType &filepath);
Expand Down

0 comments on commit b2d2f01

Please sign in to comment.