Skip to content

Commit

Permalink
fix: Remove view mode settings when reset view mode
Browse files Browse the repository at this point in the history
When resetting view mode, remove the view mode settings from
FileViewState instead of setting it to default value. This ensures the
view mode settings are completely cleared.

Log: Fix view mode reset behavior by removing settings instead of
setting default value

Bug: https://pms.uniontech.com/bug-view-286389.html
Change-Id: Ib5a6c04bd4ce1a8d6a81b985f4574f02b50c5f98
  • Loading branch information
itsXuSt committed Jan 3, 2025
1 parent 23d44e4 commit 001d5e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
25 changes: 16 additions & 9 deletions src/dfm-base/base/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,27 @@ void Application::appAttributeTrigger(TriggerAttribute ta, quint64 winId)
auto defaultViewMode = appAttribute(Application::kViewMode).toInt();
auto settings = appObtuselySetting();

const QStringList &keys = settings->keyList("FileViewState");
const QStringList &defaultKeys = settings->defaultConfigkeyList("FileViewState");
const QString &kGroupName = "FileViewState";
const QString &kViewModeKey = "viewMode";

const QStringList &keys = settings->keyList(kGroupName);
const QStringList &defaultKeys = settings->defaultConfigkeyList(kGroupName);
for (const QString &url : keys) {
auto map = settings->value(kGroupName, url).toMap();

if (defaultKeys.contains(url)) {
auto defaultMap = settings->defaultConfigValue("FileViewState", url).toMap();
if (defaultMap.contains("viewMode") && defaultMap["viewMode"] != defaultViewMode)
auto defaultMap = settings->defaultConfigValue(kGroupName, url).toMap();
if (defaultMap.contains(kViewModeKey)) {
map.insert(kViewModeKey, defaultMap.value(kViewModeKey));
settings->setValue(kGroupName, url, map);
continue;
}
}

auto map = settings->value("FileViewState", url).toMap();
if (map.contains("viewMode")) {
if (map.contains(kViewModeKey)) {
qCDebug(logDFMBase) << "Set " << url << "viewMode to " << defaultViewMode;
map["viewMode"] = defaultViewMode;
settings->setValue("FileViewState", url, map);
map.remove(kViewModeKey);
settings->setValue(kGroupName, url, map);
}
}

Expand All @@ -305,7 +312,7 @@ void Application::appAttributeTrigger(TriggerAttribute ta, quint64 winId)
if (instance())
Q_EMIT instance()->viewModeChanged(defaultViewMode);
break;
}
}
case kClearSearchHistory:
Q_EMIT instance()->clearSearchHistory(winId);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,6 @@ void FileView::onDefaultViewModeChanged(int mode)
if (newMode == Global::ViewMode::kTreeMode && !WorkspaceHelper::instance()->supportTreeView(rootUrl().scheme()))
return;

if (newMode == d->currentViewMode)
return;

Global::ViewMode oldMode = d->currentViewMode;
loadViewState(rootUrl());

Expand Down

0 comments on commit 001d5e7

Please sign in to comment.