From cafdd193b62acfaf556491eaa46ccb3dfdff82dd Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 24 Feb 2021 11:26:27 -0500 Subject: Now remembers most recently used module --- sword.cc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'sword.cc') diff --git a/sword.cc b/sword.cc index 1487cd1..ada3d6e 100644 --- a/sword.cc +++ b/sword.cc @@ -10,11 +10,18 @@ bool isNoMods; Sword::Sword() { auto mods = libbible::getModules(); isNoMods = mods.empty(); - defaultMod = libbible::settingsRead("module"); - if(mods.find(defaultMod) == mods.end()) { - defaultMod = string(); + string defaultMod = libbible::settingsRead("module"); + currMod = libbible::settingsRead("biblereader::currMod"); + if(mods.find(currMod) == mods.end()) { + currMod = defaultMod; + } + if(mods.find(currMod) == mods.end()) { + currMod = string(); if(! mods.empty()) { + // New default mod (previous was deleted) defaultMod = mods.begin()->first; + libbible::settingsWrite("module", defaultMod); + currMod = defaultMod; } } } @@ -31,7 +38,8 @@ vector Sword::getModules() { } void Sword::setModule(string version) { - defaultMod = version; + currMod = version; + libbible::settingsWrite("biblereader::currMod", currMod); } void Sword::fillBuffer(string ref, Glib::RefPtr buf) { @@ -46,7 +54,7 @@ void Sword::fillBuffer(string ref, Glib::RefPtr buf) { return; } - auto texts = libbible::getText(libbible::getPassage(defaultMod, ref)); + auto texts = libbible::getText(libbible::getPassage(currMod, ref)); auto iter = buf->get_iter_at_offset(0); @@ -128,12 +136,12 @@ void Sword::getConfig(string book, int chapter, struct config *conf) { conf->maxChapter = 0; conf->version = ""; } else { - auto passages = libbible::getPassages(defaultMod, book); + auto passages = libbible::getPassages(currMod, book); conf->chapter = chapter; conf->book = passages[0].bookShort; conf->bookFull = passages[0].book; conf->maxChapter = passages.back().chapterStart; - conf->version = defaultMod; + conf->version = currMod; } } @@ -141,5 +149,5 @@ vector Sword::getBooks() { if(isNoMods) { return vector(); } - return libbible::getModules()[defaultMod]; + return libbible::getModules()[currMod]; } -- cgit v1.2.3