summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2022-09-29 15:17:08 +0200
committerSimon Rettberg2022-09-29 15:17:08 +0200
commit4ceb8bac28941da3e18076020f327347cad766ea (patch)
tree7642f9e30d3137445eec4b3000410409c7ce964e /src/dialog.cpp
parentSupport wildcards * and ? in ldap filters (diff)
downloadvmchooser2-4ceb8bac28941da3e18076020f327347cad766ea.tar.gz
vmchooser2-4ceb8bac28941da3e18076020f327347cad766ea.tar.xz
vmchooser2-4ceb8bac28941da3e18076020f327347cad766ea.zip
Add option to force honoring --tab, fuzzy match on selectSession()
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp28
1 files changed, 24 insertions, 4 deletions
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