mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
launcher v2: allow categories in plugins
This commit is contained in:
@@ -48,9 +48,14 @@ Item {
|
||||
Connections {
|
||||
target: PluginService
|
||||
function onRequestLauncherUpdate(pluginId) {
|
||||
if (activePluginId === pluginId || searchQuery) {
|
||||
if (activePluginId === pluginId) {
|
||||
if (activePluginCategories.length <= 1)
|
||||
loadPluginCategories(pluginId);
|
||||
performSearch();
|
||||
return;
|
||||
}
|
||||
if (searchQuery)
|
||||
performSearch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +138,8 @@ Item {
|
||||
|
||||
property string pluginFilter: ""
|
||||
property string activePluginName: ""
|
||||
property var activePluginCategories: []
|
||||
property string activePluginCategory: ""
|
||||
|
||||
function getSectionViewMode(sectionId) {
|
||||
if (sectionId === "browse_plugins")
|
||||
@@ -307,10 +314,33 @@ Item {
|
||||
isSearching = false;
|
||||
activePluginId = "";
|
||||
activePluginName = "";
|
||||
activePluginCategories = [];
|
||||
activePluginCategory = "";
|
||||
pluginFilter = "";
|
||||
collapsedSections = {};
|
||||
}
|
||||
|
||||
function loadPluginCategories(pluginId) {
|
||||
if (!pluginId) {
|
||||
activePluginCategories = [];
|
||||
activePluginCategory = "";
|
||||
return;
|
||||
}
|
||||
|
||||
const categories = AppSearchService.getPluginLauncherCategories(pluginId);
|
||||
activePluginCategories = categories;
|
||||
activePluginCategory = "";
|
||||
AppSearchService.setPluginLauncherCategory(pluginId, "");
|
||||
}
|
||||
|
||||
function setActivePluginCategory(categoryId) {
|
||||
if (activePluginCategory === categoryId)
|
||||
return;
|
||||
activePluginCategory = categoryId;
|
||||
AppSearchService.setPluginLauncherCategory(activePluginId, categoryId);
|
||||
performSearch();
|
||||
}
|
||||
|
||||
function clearPluginFilter() {
|
||||
if (pluginFilter) {
|
||||
pluginFilter = "";
|
||||
@@ -342,6 +372,8 @@ Item {
|
||||
if (cachedSections && !searchQuery && searchMode === "all" && !pluginFilter) {
|
||||
activePluginId = "";
|
||||
activePluginName = "";
|
||||
activePluginCategories = [];
|
||||
activePluginCategory = "";
|
||||
clearActivePluginViewPreference();
|
||||
sections = cachedSections.map(function (s) {
|
||||
var copy = Object.assign({}, s, {
|
||||
@@ -363,10 +395,14 @@ Item {
|
||||
|
||||
var triggerMatch = detectTrigger(searchQuery);
|
||||
if (triggerMatch.pluginId) {
|
||||
var pluginChanged = activePluginId !== triggerMatch.pluginId;
|
||||
activePluginId = triggerMatch.pluginId;
|
||||
activePluginName = getPluginName(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
||||
applyActivePluginViewPreference(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
||||
|
||||
if (pluginChanged && !triggerMatch.isBuiltIn)
|
||||
loadPluginCategories(triggerMatch.pluginId);
|
||||
|
||||
var pluginItems = getPluginItems(triggerMatch.pluginId, triggerMatch.query);
|
||||
allItems = allItems.concat(pluginItems);
|
||||
|
||||
@@ -401,6 +437,8 @@ Item {
|
||||
|
||||
activePluginId = "";
|
||||
activePluginName = "";
|
||||
activePluginCategories = [];
|
||||
activePluginCategory = "";
|
||||
clearActivePluginViewPreference();
|
||||
|
||||
if (searchMode === "files") {
|
||||
|
||||
@@ -483,9 +483,64 @@ FocusScope {
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: categoryRow
|
||||
width: parent.width
|
||||
height: controller.activePluginCategories.length > 0 ? 36 : 0
|
||||
visible: controller.activePluginCategories.length > 0
|
||||
spacing: Theme.spacingS
|
||||
|
||||
clip: true
|
||||
|
||||
Behavior on height {
|
||||
NumberAnimation {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
|
||||
DankDropdown {
|
||||
id: categoryDropdown
|
||||
width: Math.min(200, parent.width)
|
||||
compactMode: true
|
||||
dropdownWidth: 200
|
||||
popupWidth: 240
|
||||
maxPopupHeight: 300
|
||||
enableFuzzySearch: controller.activePluginCategories.length > 8
|
||||
currentValue: {
|
||||
const cats = controller.activePluginCategories;
|
||||
const current = controller.activePluginCategory;
|
||||
if (!current)
|
||||
return cats.length > 0 ? cats[0].name : "";
|
||||
for (let i = 0; i < cats.length; i++) {
|
||||
if (cats[i].id === current)
|
||||
return cats[i].name;
|
||||
}
|
||||
return cats.length > 0 ? cats[0].name : "";
|
||||
}
|
||||
options: {
|
||||
const cats = controller.activePluginCategories;
|
||||
const names = [];
|
||||
for (let i = 0; i < cats.length; i++)
|
||||
names.push(cats[i].name);
|
||||
return names;
|
||||
}
|
||||
|
||||
onValueChanged: value => {
|
||||
const cats = controller.activePluginCategories;
|
||||
for (let i = 0; i < cats.length; i++) {
|
||||
if (cats[i].name === value) {
|
||||
controller.setActivePluginCategory(cats[i].id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: parent.height - searchField.height - actionPanel.height - Theme.spacingXS * 2
|
||||
height: parent.height - searchField.height - categoryRow.height - actionPanel.height - Theme.spacingXS * (categoryRow.visible ? 3 : 2)
|
||||
opacity: root.parentModal?.isClosing ? 0 : 1
|
||||
|
||||
ResultsList {
|
||||
|
||||
@@ -884,4 +884,52 @@ Singleton {
|
||||
|
||||
return allItems;
|
||||
}
|
||||
|
||||
function getPluginLauncherCategories(pluginId) {
|
||||
if (typeof PluginService === "undefined")
|
||||
return [];
|
||||
|
||||
const instance = PluginService.pluginInstances[pluginId];
|
||||
if (!instance)
|
||||
return [];
|
||||
|
||||
if (typeof instance.getCategories !== "function")
|
||||
return [];
|
||||
|
||||
try {
|
||||
return instance.getCategories() || [];
|
||||
} catch (e) {
|
||||
console.warn("AppSearchService: Error getting categories from plugin", pluginId, ":", e);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function setPluginLauncherCategory(pluginId, categoryId) {
|
||||
if (typeof PluginService === "undefined")
|
||||
return;
|
||||
|
||||
const instance = PluginService.pluginInstances[pluginId];
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
if (typeof instance.setCategory !== "function")
|
||||
return;
|
||||
|
||||
try {
|
||||
instance.setCategory(categoryId);
|
||||
} catch (e) {
|
||||
console.warn("AppSearchService: Error setting category on plugin", pluginId, ":", e);
|
||||
}
|
||||
}
|
||||
|
||||
function pluginHasCategories(pluginId) {
|
||||
if (typeof PluginService === "undefined")
|
||||
return false;
|
||||
|
||||
const instance = PluginService.pluginInstances[pluginId];
|
||||
if (!instance)
|
||||
return false;
|
||||
|
||||
return typeof instance.getCategories === "function";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +396,6 @@ Item {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.currentValue = delegateRoot.modelData;
|
||||
root.valueChanged(delegateRoot.modelData);
|
||||
dropdownMenu.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user