forked from Shinonome/dots-hyprland
search: run command
This commit is contained in:
@@ -19,6 +19,10 @@ Item { // Wrapper
|
|||||||
|
|
||||||
property string mathResult: ""
|
property string mathResult: ""
|
||||||
|
|
||||||
|
function focusFirstItemIfNeeded() {
|
||||||
|
if (searchInput.focus) appResults.currentIndex = 0; // Focus the first item
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: nonAppResultsTimer
|
id: nonAppResultsTimer
|
||||||
interval: ConfigOptions.search.nonAppResultDelay
|
interval: ConfigOptions.search.nonAppResultDelay
|
||||||
@@ -38,7 +42,7 @@ Item { // Wrapper
|
|||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
root.mathResult = data
|
root.mathResult = data
|
||||||
if (searchInput.focus) appResults.currentIndex = 0; // Focus the first item
|
root.focusFirstItemIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +71,18 @@ Item { // Wrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: executor
|
||||||
|
property list<string> baseCommand: ["bash", "-c"]
|
||||||
|
function executeCommand(command) {
|
||||||
|
executor.running = false
|
||||||
|
executor.command = baseCommand.concat(
|
||||||
|
`${command} || ${ConfigOptions.apps.terminal} fish -C 'echo "${qsTr("Searching for package with that command")}..." && pacman -F ${command}'`
|
||||||
|
)
|
||||||
|
executor.running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Keys.onPressed: (event) => {
|
Keys.onPressed: (event) => {
|
||||||
// Prevent Esc and Backspace from registering
|
// Prevent Esc and Backspace from registering
|
||||||
if (event.key === Qt.Key_Escape) return;
|
if (event.key === Qt.Key_Escape) return;
|
||||||
@@ -148,12 +164,6 @@ Item { // Wrapper
|
|||||||
RowLayout {
|
RowLayout {
|
||||||
id: searchBar
|
id: searchBar
|
||||||
spacing: 5
|
spacing: 5
|
||||||
KeyNavigation.down: {
|
|
||||||
if (appResults.count > 1) {
|
|
||||||
appResults.currentIndex = 1;
|
|
||||||
appResults.forceActiveFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MaterialSymbol {
|
MaterialSymbol {
|
||||||
id: searchIcon
|
id: searchIcon
|
||||||
Layout.leftMargin: 15
|
Layout.leftMargin: 15
|
||||||
@@ -169,10 +179,17 @@ Item { // Wrapper
|
|||||||
padding: 15
|
padding: 15
|
||||||
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
|
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
|
||||||
selectedTextColor: Appearance.m3colors.m3onSurface
|
selectedTextColor: Appearance.m3colors.m3onSurface
|
||||||
placeholderText: qsTr("Search")
|
placeholderText: qsTr("Search, calculate or run")
|
||||||
placeholderTextColor: Appearance.m3colors.m3outline
|
placeholderTextColor: Appearance.m3colors.m3outline
|
||||||
implicitWidth: root.searchingText == "" ? Appearance.sizes.searchWidthCollapsed : Appearance.sizes.searchWidth
|
implicitWidth: root.searchingText == "" ? Appearance.sizes.searchWidthCollapsed : Appearance.sizes.searchWidth
|
||||||
|
|
||||||
|
KeyNavigation.down: {
|
||||||
|
if (appResults.count > 1) {
|
||||||
|
appResults.focus = true;
|
||||||
|
appResults.currentIndex = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Behavior on implicitWidth {
|
Behavior on implicitWidth {
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
duration: Appearance.animation.elementDecelFast.duration
|
duration: Appearance.animation.elementDecelFast.duration
|
||||||
@@ -271,6 +288,16 @@ Item { // Wrapper
|
|||||||
copyText.copyTextToClipboard(root.mathResult);
|
copyText.copyTextToClipboard(root.mathResult);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
result.push({
|
||||||
|
name: searchingText,
|
||||||
|
clickActionName: "Run",
|
||||||
|
type: qsTr("Run command"),
|
||||||
|
fontType: "monospace",
|
||||||
|
materialSymbol: 'terminal',
|
||||||
|
execute: () => {
|
||||||
|
executor.executeCommand(searchingText.startsWith('sudo') ? `${ConfigOptions.apps.terminal} fish -C '${root.searchingText}'` : root.searchingText);
|
||||||
|
}
|
||||||
|
});
|
||||||
result.push({
|
result.push({
|
||||||
name: root.searchingText,
|
name: root.searchingText,
|
||||||
clickActionName: "Search",
|
clickActionName: "Search",
|
||||||
|
|||||||
Reference in New Issue
Block a user