mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
launcher v2: allow categories in plugins
This commit is contained in:
@@ -48,9 +48,14 @@ Item {
|
|||||||
Connections {
|
Connections {
|
||||||
target: PluginService
|
target: PluginService
|
||||||
function onRequestLauncherUpdate(pluginId) {
|
function onRequestLauncherUpdate(pluginId) {
|
||||||
if (activePluginId === pluginId || searchQuery) {
|
if (activePluginId === pluginId) {
|
||||||
|
if (activePluginCategories.length <= 1)
|
||||||
|
loadPluginCategories(pluginId);
|
||||||
performSearch();
|
performSearch();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (searchQuery)
|
||||||
|
performSearch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +138,8 @@ Item {
|
|||||||
|
|
||||||
property string pluginFilter: ""
|
property string pluginFilter: ""
|
||||||
property string activePluginName: ""
|
property string activePluginName: ""
|
||||||
|
property var activePluginCategories: []
|
||||||
|
property string activePluginCategory: ""
|
||||||
|
|
||||||
function getSectionViewMode(sectionId) {
|
function getSectionViewMode(sectionId) {
|
||||||
if (sectionId === "browse_plugins")
|
if (sectionId === "browse_plugins")
|
||||||
@@ -307,10 +314,33 @@ Item {
|
|||||||
isSearching = false;
|
isSearching = false;
|
||||||
activePluginId = "";
|
activePluginId = "";
|
||||||
activePluginName = "";
|
activePluginName = "";
|
||||||
|
activePluginCategories = [];
|
||||||
|
activePluginCategory = "";
|
||||||
pluginFilter = "";
|
pluginFilter = "";
|
||||||
collapsedSections = {};
|
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() {
|
function clearPluginFilter() {
|
||||||
if (pluginFilter) {
|
if (pluginFilter) {
|
||||||
pluginFilter = "";
|
pluginFilter = "";
|
||||||
@@ -342,6 +372,8 @@ Item {
|
|||||||
if (cachedSections && !searchQuery && searchMode === "all" && !pluginFilter) {
|
if (cachedSections && !searchQuery && searchMode === "all" && !pluginFilter) {
|
||||||
activePluginId = "";
|
activePluginId = "";
|
||||||
activePluginName = "";
|
activePluginName = "";
|
||||||
|
activePluginCategories = [];
|
||||||
|
activePluginCategory = "";
|
||||||
clearActivePluginViewPreference();
|
clearActivePluginViewPreference();
|
||||||
sections = cachedSections.map(function (s) {
|
sections = cachedSections.map(function (s) {
|
||||||
var copy = Object.assign({}, s, {
|
var copy = Object.assign({}, s, {
|
||||||
@@ -363,10 +395,14 @@ Item {
|
|||||||
|
|
||||||
var triggerMatch = detectTrigger(searchQuery);
|
var triggerMatch = detectTrigger(searchQuery);
|
||||||
if (triggerMatch.pluginId) {
|
if (triggerMatch.pluginId) {
|
||||||
|
var pluginChanged = activePluginId !== triggerMatch.pluginId;
|
||||||
activePluginId = triggerMatch.pluginId;
|
activePluginId = triggerMatch.pluginId;
|
||||||
activePluginName = getPluginName(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
activePluginName = getPluginName(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
||||||
applyActivePluginViewPreference(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
applyActivePluginViewPreference(triggerMatch.pluginId, triggerMatch.isBuiltIn);
|
||||||
|
|
||||||
|
if (pluginChanged && !triggerMatch.isBuiltIn)
|
||||||
|
loadPluginCategories(triggerMatch.pluginId);
|
||||||
|
|
||||||
var pluginItems = getPluginItems(triggerMatch.pluginId, triggerMatch.query);
|
var pluginItems = getPluginItems(triggerMatch.pluginId, triggerMatch.query);
|
||||||
allItems = allItems.concat(pluginItems);
|
allItems = allItems.concat(pluginItems);
|
||||||
|
|
||||||
@@ -401,6 +437,8 @@ Item {
|
|||||||
|
|
||||||
activePluginId = "";
|
activePluginId = "";
|
||||||
activePluginName = "";
|
activePluginName = "";
|
||||||
|
activePluginCategories = [];
|
||||||
|
activePluginCategory = "";
|
||||||
clearActivePluginViewPreference();
|
clearActivePluginViewPreference();
|
||||||
|
|
||||||
if (searchMode === "files") {
|
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 {
|
Item {
|
||||||
width: parent.width
|
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
|
opacity: root.parentModal?.isClosing ? 0 : 1
|
||||||
|
|
||||||
ResultsList {
|
ResultsList {
|
||||||
|
|||||||
@@ -884,4 +884,52 @@ Singleton {
|
|||||||
|
|
||||||
return allItems;
|
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
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
root.currentValue = delegateRoot.modelData;
|
|
||||||
root.valueChanged(delegateRoot.modelData);
|
root.valueChanged(delegateRoot.modelData);
|
||||||
dropdownMenu.close();
|
dropdownMenu.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user