1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

launcher v2: improve danksearch context switching behavior

This commit is contained in:
bbedward
2026-01-20 21:55:05 -05:00
parent 553f5257b3
commit 0e7f628c4a
3 changed files with 50 additions and 24 deletions

View File

@@ -11,6 +11,9 @@ Item {
property string searchQuery: "" property string searchQuery: ""
property string searchMode: "all" property string searchMode: "all"
property string previousSearchMode: "all"
property bool autoSwitchedToFiles: false
property bool isFileSearching: false
property var sections: [] property var sections: []
property var flatModel: [] property var flatModel: []
property int selectedFlatIndex: 0 property int selectedFlatIndex: 0
@@ -198,9 +201,15 @@ Item {
} }
} }
function setMode(mode) { function setMode(mode, isAutoSwitch) {
if (searchMode === mode) if (searchMode === mode)
return; return;
if (isAutoSwitch) {
previousSearchMode = searchMode;
autoSwitchedToFiles = true;
} else {
autoSwitchedToFiles = false;
}
searchMode = mode; searchMode = mode;
modeChanged(mode); modeChanged(mode);
performSearch(); performSearch();
@@ -209,6 +218,15 @@ Item {
} }
} }
function restorePreviousMode() {
if (!autoSwitchedToFiles)
return;
autoSwitchedToFiles = false;
searchMode = previousSearchMode;
modeChanged(previousSearchMode);
performSearch();
}
function cycleMode() { function cycleMode() {
var modes = ["all", "apps", "files", "plugins"]; var modes = ["all", "apps", "files", "plugins"];
var currentIndex = modes.indexOf(searchMode); var currentIndex = modes.indexOf(searchMode);
@@ -219,6 +237,9 @@ Item {
function reset() { function reset() {
searchQuery = ""; searchQuery = "";
searchMode = "all"; searchMode = "all";
previousSearchMode = "all";
autoSwitchedToFiles = false;
isFileSearching = false;
sections = []; sections = [];
flatModel = []; flatModel = [];
selectedFlatIndex = 0; selectedFlatIndex = 0;
@@ -307,6 +328,8 @@ Item {
clearActivePluginViewPreference(); clearActivePluginViewPreference();
if (searchMode === "files") { if (searchMode === "files") {
var fileQuery = searchQuery.startsWith("/") ? searchQuery.substring(1).trim() : searchQuery.trim();
isFileSearching = fileQuery.length >= 2 && DSearchService.dsearchAvailable;
sections = []; sections = [];
flatModel = []; flatModel = [];
selectedFlatIndex = 0; selectedFlatIndex = 0;
@@ -482,8 +505,12 @@ Item {
return; return;
} }
if (fileQuery.length < 2) if (fileQuery.length < 2) {
isFileSearching = false;
return; return;
}
isFileSearching = true;
var params = { var params = {
limit: 20, limit: 20,
fuzzy: true, fuzzy: true,
@@ -492,6 +519,7 @@ Item {
}; };
DSearchService.search(fileQuery, params, function (response) { DSearchService.search(fileQuery, params, function (response) {
isFileSearching = false;
if (response.error) if (response.error)
return; return;
var fileItems = []; var fileItems = [];

View File

@@ -247,7 +247,7 @@ FocusScope {
return; return;
case Qt.Key_Slash: case Qt.Key_Slash:
if (event.modifiers === Qt.NoModifier && searchField.text.length === 0) { if (event.modifiers === Qt.NoModifier && searchField.text.length === 0) {
controller.setMode("files"); controller.setMode("files", true);
return; return;
} }
event.accepted = false; event.accepted = false;
@@ -446,6 +446,9 @@ FocusScope {
onTextChanged: { onTextChanged: {
controller.setSearchQuery(text); controller.setSearchQuery(text);
if (text.length === 0) {
controller.restorePreviousMode();
}
if (actionPanel.expanded) { if (actionPanel.expanded) {
actionPanel.hide(); actionPanel.hide();
} }

View File

@@ -421,7 +421,7 @@ Item {
Item { Item {
anchors.centerIn: parent anchors.centerIn: parent
visible: !root.controller?.sections || root.controller.sections.length === 0 visible: (!root.controller?.sections || root.controller.sections.length === 0) && !root.controller?.isFileSearching
width: emptyColumn.implicitWidth width: emptyColumn.implicitWidth
height: emptyColumn.implicitHeight height: emptyColumn.implicitHeight
@@ -437,15 +437,16 @@ Item {
function getEmptyIcon() { function getEmptyIcon() {
var mode = root.controller?.searchMode ?? "all"; var mode = root.controller?.searchMode ?? "all";
if (mode === "files") switch (mode) {
case "files":
return "folder_open"; return "folder_open";
if (mode === "plugins") case "plugins":
return "extension"; return "extension";
if (mode === "apps") case "apps":
return "apps"; return "apps";
if (root.controller?.searchQuery?.length > 0) default:
return "search_off"; return root.controller?.searchQuery?.length > 0 ? "search_off" : "search";
return "search"; }
} }
} }
@@ -460,7 +461,8 @@ Item {
var mode = root.controller?.searchMode ?? "all"; var mode = root.controller?.searchMode ?? "all";
var hasQuery = root.controller?.searchQuery?.length > 0; var hasQuery = root.controller?.searchQuery?.length > 0;
if (mode === "files") { switch (mode) {
case "files":
if (!DSearchService.dsearchAvailable) if (!DSearchService.dsearchAvailable)
return I18n.tr("File search requires dsearch\nInstall from github.com/morelazers/dsearch"); return I18n.tr("File search requires dsearch\nInstall from github.com/morelazers/dsearch");
if (!hasQuery) if (!hasQuery)
@@ -468,20 +470,13 @@ Item {
if (root.controller.searchQuery.length < 2) if (root.controller.searchQuery.length < 2)
return I18n.tr("Type at least 2 characters"); return I18n.tr("Type at least 2 characters");
return I18n.tr("No files found"); return I18n.tr("No files found");
} case "plugins":
if (mode === "plugins") { return hasQuery ? I18n.tr("No plugin results") : I18n.tr("Browse or search plugins");
if (!hasQuery) case "apps":
return I18n.tr("Browse or search plugins"); return hasQuery ? I18n.tr("No apps found") : I18n.tr("Type to search apps");
return I18n.tr("No plugin results"); default:
} return hasQuery ? I18n.tr("No results found") : I18n.tr("Type to search");
if (mode === "apps") { }
if (!hasQuery)
return I18n.tr("Type to search apps");
return I18n.tr("No apps found");
}
if (hasQuery)
return I18n.tr("No results found");
return I18n.tr("Type to search");
} }
} }
} }