mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 13:32:50 -05:00
launcher v2: improve danksearch context switching behavior
This commit is contained in:
@@ -11,6 +11,9 @@ Item {
|
||||
|
||||
property string searchQuery: ""
|
||||
property string searchMode: "all"
|
||||
property string previousSearchMode: "all"
|
||||
property bool autoSwitchedToFiles: false
|
||||
property bool isFileSearching: false
|
||||
property var sections: []
|
||||
property var flatModel: []
|
||||
property int selectedFlatIndex: 0
|
||||
@@ -198,9 +201,15 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function setMode(mode) {
|
||||
function setMode(mode, isAutoSwitch) {
|
||||
if (searchMode === mode)
|
||||
return;
|
||||
if (isAutoSwitch) {
|
||||
previousSearchMode = searchMode;
|
||||
autoSwitchedToFiles = true;
|
||||
} else {
|
||||
autoSwitchedToFiles = false;
|
||||
}
|
||||
searchMode = mode;
|
||||
modeChanged(mode);
|
||||
performSearch();
|
||||
@@ -209,6 +218,15 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function restorePreviousMode() {
|
||||
if (!autoSwitchedToFiles)
|
||||
return;
|
||||
autoSwitchedToFiles = false;
|
||||
searchMode = previousSearchMode;
|
||||
modeChanged(previousSearchMode);
|
||||
performSearch();
|
||||
}
|
||||
|
||||
function cycleMode() {
|
||||
var modes = ["all", "apps", "files", "plugins"];
|
||||
var currentIndex = modes.indexOf(searchMode);
|
||||
@@ -219,6 +237,9 @@ Item {
|
||||
function reset() {
|
||||
searchQuery = "";
|
||||
searchMode = "all";
|
||||
previousSearchMode = "all";
|
||||
autoSwitchedToFiles = false;
|
||||
isFileSearching = false;
|
||||
sections = [];
|
||||
flatModel = [];
|
||||
selectedFlatIndex = 0;
|
||||
@@ -307,6 +328,8 @@ Item {
|
||||
clearActivePluginViewPreference();
|
||||
|
||||
if (searchMode === "files") {
|
||||
var fileQuery = searchQuery.startsWith("/") ? searchQuery.substring(1).trim() : searchQuery.trim();
|
||||
isFileSearching = fileQuery.length >= 2 && DSearchService.dsearchAvailable;
|
||||
sections = [];
|
||||
flatModel = [];
|
||||
selectedFlatIndex = 0;
|
||||
@@ -482,8 +505,12 @@ Item {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileQuery.length < 2)
|
||||
if (fileQuery.length < 2) {
|
||||
isFileSearching = false;
|
||||
return;
|
||||
}
|
||||
|
||||
isFileSearching = true;
|
||||
var params = {
|
||||
limit: 20,
|
||||
fuzzy: true,
|
||||
@@ -492,6 +519,7 @@ Item {
|
||||
};
|
||||
|
||||
DSearchService.search(fileQuery, params, function (response) {
|
||||
isFileSearching = false;
|
||||
if (response.error)
|
||||
return;
|
||||
var fileItems = [];
|
||||
|
||||
@@ -247,7 +247,7 @@ FocusScope {
|
||||
return;
|
||||
case Qt.Key_Slash:
|
||||
if (event.modifiers === Qt.NoModifier && searchField.text.length === 0) {
|
||||
controller.setMode("files");
|
||||
controller.setMode("files", true);
|
||||
return;
|
||||
}
|
||||
event.accepted = false;
|
||||
@@ -446,6 +446,9 @@ FocusScope {
|
||||
|
||||
onTextChanged: {
|
||||
controller.setSearchQuery(text);
|
||||
if (text.length === 0) {
|
||||
controller.restorePreviousMode();
|
||||
}
|
||||
if (actionPanel.expanded) {
|
||||
actionPanel.hide();
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ Item {
|
||||
|
||||
Item {
|
||||
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
|
||||
height: emptyColumn.implicitHeight
|
||||
|
||||
@@ -437,15 +437,16 @@ Item {
|
||||
|
||||
function getEmptyIcon() {
|
||||
var mode = root.controller?.searchMode ?? "all";
|
||||
if (mode === "files")
|
||||
switch (mode) {
|
||||
case "files":
|
||||
return "folder_open";
|
||||
if (mode === "plugins")
|
||||
case "plugins":
|
||||
return "extension";
|
||||
if (mode === "apps")
|
||||
case "apps":
|
||||
return "apps";
|
||||
if (root.controller?.searchQuery?.length > 0)
|
||||
return "search_off";
|
||||
return "search";
|
||||
default:
|
||||
return root.controller?.searchQuery?.length > 0 ? "search_off" : "search";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +461,8 @@ Item {
|
||||
var mode = root.controller?.searchMode ?? "all";
|
||||
var hasQuery = root.controller?.searchQuery?.length > 0;
|
||||
|
||||
if (mode === "files") {
|
||||
switch (mode) {
|
||||
case "files":
|
||||
if (!DSearchService.dsearchAvailable)
|
||||
return I18n.tr("File search requires dsearch\nInstall from github.com/morelazers/dsearch");
|
||||
if (!hasQuery)
|
||||
@@ -468,20 +470,13 @@ Item {
|
||||
if (root.controller.searchQuery.length < 2)
|
||||
return I18n.tr("Type at least 2 characters");
|
||||
return I18n.tr("No files found");
|
||||
}
|
||||
if (mode === "plugins") {
|
||||
if (!hasQuery)
|
||||
return I18n.tr("Browse or search plugins");
|
||||
return I18n.tr("No plugin results");
|
||||
}
|
||||
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");
|
||||
case "plugins":
|
||||
return hasQuery ? I18n.tr("No plugin results") : I18n.tr("Browse or search plugins");
|
||||
case "apps":
|
||||
return hasQuery ? I18n.tr("No apps found") : I18n.tr("Type to search apps");
|
||||
default:
|
||||
return hasQuery ? I18n.tr("No results found") : I18n.tr("Type to search");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user