From 4ceb8bac28941da3e18076020f327347cad766ea Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 29 Sep 2022 15:17:08 +0200 Subject: Add option to force honoring --tab, fuzzy match on selectSession() --- src/dialog.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 94b271c..8acaa9d 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -289,10 +289,11 @@ bool Dialog::selectSession(const QString& name, int preferredTab) { QModelIndex root(ui->treeView->rootIndex()); int bestTab = -1; + int matchLevel = 0; + int boost; QModelIndex bestIndex; for (int tab = TAB_COUNT - 1; tab >= 0; --tab) { - if (bestTab != -1 && preferredTab != tab) // We already have a potential match, only keep going if this is the desired tab - continue; + boost = (tab == preferredTab); for (int i = 0; i < model_[tab]->rowCount(root); ++i) { QModelIndex section(model_[tab]->index(i, 0, root)); if (!section.isValid()) @@ -309,8 +310,19 @@ bool Dialog::selectSession(const QString& name, int preferredTab) { if ((!s->uuid().isEmpty() && s->uuid() == name) || s->shortDescription() == name) { bestTab = tab; bestIndex = index; + matchLevel = 5 + boost; break; // Break inner, keep checking other tabs } + if (matchLevel < 3 + boost && s->shortDescription().startsWith(name)) { + bestTab = tab; + bestIndex = index; + matchLevel = 3 + boost; + } + if (matchLevel < 1 + boost && name.length() > 3 && s->shortDescription().contains(name)) { + bestTab = tab; + bestIndex = index; + matchLevel = 1 + boost; + } } } } @@ -337,8 +349,16 @@ void Dialog::selectPreviousSession() { return; } int lastTab = UserConfig::getLastTab(); + + if (Config::isSet(Config::FORCE_DEFAULT_TAB)) { + // Force specific tab preselect + lastTab = Config::get(Config::DEFAULT_TAB).toInt(); + } + + // Command line default session takes precedence QString lastSession = Config::get(Config::DEFAULT_SESSION); - if (lastSession.isEmpty()) { + if (lastSession.isEmpty() && !Config::isSet(Config::FORCE_DEFAULT_TAB)) { + // If no cmdline, use user's last session if we don't force a tab via cmdline auto list = UserConfig::getLastSessions(); if (!list.isEmpty()) { lastSession = list.back(); @@ -357,7 +377,7 @@ void Dialog::selectPreviousSession() { if (lastTab >= 0 && lastTab < TAB_COUNT) { qDebug() << "Trying to select last tab " << lastTab; this->onTabButtonChanged(lastTab); - } else { + } else if (Config::isSet(Config::DEFAULT_TAB)) { int defaultTab = Config::get(Config::DEFAULT_TAB).toInt(); qDebug() << "Selected default tab " << defaultTab; // Select default tab -- cgit v1.2.3-55-g7522