✨ ags(runner): only show placeholders if there are no results for search
This commit is contained in:
+10
-9
@@ -6,11 +6,11 @@ import { ResultWidget, ResultWidgetProps } from "../widget/runner/ResultWidget";
|
|||||||
import { Windows } from "../windows";
|
import { Windows } from "../windows";
|
||||||
|
|
||||||
export let runnerInstance: (Gtk.Window|null) = null;
|
export let runnerInstance: (Gtk.Window|null) = null;
|
||||||
let onClickTimeout: (AstalIO.Time|undefined);
|
|
||||||
|
|
||||||
export function startRunnerDefault() {
|
export function startRunnerDefault() {
|
||||||
return Runner.openRunner({
|
return Runner.openRunner({
|
||||||
entryPlaceHolder: "Start typing..."
|
entryPlaceHolder: "Start typing...",
|
||||||
|
showResultsPlaceHolderOnStartup: false,
|
||||||
} as Runner.RunnerProps,
|
} as Runner.RunnerProps,
|
||||||
() => [
|
() => [
|
||||||
new ResultWidget({
|
new ResultWidget({
|
||||||
@@ -43,6 +43,7 @@ export namespace Runner {
|
|||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
entryPlaceHolder?: string;
|
entryPlaceHolder?: string;
|
||||||
|
showResultsPlaceHolderOnStartup?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function close() {
|
export function close() {
|
||||||
@@ -90,6 +91,7 @@ export namespace Runner {
|
|||||||
export function openRunner(props?: RunnerProps, placeholder?: () => Array<ResultWidget>): (Gtk.Window|null) {
|
export function openRunner(props?: RunnerProps, placeholder?: () => Array<ResultWidget>): (Gtk.Window|null) {
|
||||||
let subs: Array<() => void> = [];
|
let subs: Array<() => void> = [];
|
||||||
const entryText: Variable<string> = new Variable<string>("");
|
const entryText: Variable<string> = new Variable<string>("");
|
||||||
|
let onClickTimeout: (AstalIO.Time|undefined);
|
||||||
|
|
||||||
const searchEntry = new Widget.Entry({
|
const searchEntry = new Widget.Entry({
|
||||||
className: "search",
|
className: "search",
|
||||||
@@ -110,7 +112,7 @@ export namespace Runner {
|
|||||||
expand: true
|
expand: true
|
||||||
} as Gtk.ListBox.ConstructorProps);
|
} as Gtk.ListBox.ConstructorProps);
|
||||||
|
|
||||||
if(placeholder) {
|
if(props?.showResultsPlaceHolderOnStartup && placeholder) {
|
||||||
const placeholderWidgets = placeholder();
|
const placeholderWidgets = placeholder();
|
||||||
placeholderWidgets.map(widget =>
|
placeholderWidgets.map(widget =>
|
||||||
resultsList.insert(widget, -1));
|
resultsList.insert(widget, -1));
|
||||||
@@ -134,7 +136,7 @@ export namespace Runner {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Insert placeholder if somehow no results are found
|
// Insert placeholder if somehow no results are found
|
||||||
if(placeholder && (!entryText || !widgets || widgets.length === 0))
|
if(placeholder && widgets.length === 0)
|
||||||
widgets.push(...placeholder());
|
widgets.push(...placeholder());
|
||||||
|
|
||||||
// Insert results inside GtkListBox
|
// Insert results inside GtkListBox
|
||||||
@@ -146,7 +148,7 @@ export namespace Runner {
|
|||||||
if(rWidget instanceof ResultWidget) {
|
if(rWidget instanceof ResultWidget) {
|
||||||
if(!onClickTimeout) {
|
if(!onClickTimeout) {
|
||||||
rWidget.onClick();
|
rWidget.onClick();
|
||||||
// Timeout, so it doesn't fire the executable a hundred times :skull:
|
// Timeout, so it doesn't fire the event a hundred times :skull:
|
||||||
onClickTimeout = timeout(500, () => onClickTimeout = undefined);
|
onClickTimeout = timeout(500, () => onClickTimeout = undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +167,7 @@ export namespace Runner {
|
|||||||
monitor: mon,
|
monitor: mon,
|
||||||
widthRequest: props?.width || 750,
|
widthRequest: props?.width || 750,
|
||||||
heightRequest: props?.height || 0,
|
heightRequest: props?.height || 0,
|
||||||
marginTop: 250,
|
marginTop: 230,
|
||||||
valign: Gtk.Align.START,
|
valign: Gtk.Align.START,
|
||||||
onKeyPressEvent: (_, event: Gdk.Event) => {
|
onKeyPressEvent: (_, event: Gdk.Event) => {
|
||||||
const keyVal = event.get_keyval()[1];
|
const keyVal = event.get_keyval()[1];
|
||||||
@@ -178,9 +180,8 @@ export namespace Runner {
|
|||||||
|
|
||||||
event.get_keyval()[1] === Gdk.KEY_F5 &&
|
event.get_keyval()[1] === Gdk.KEY_F5 &&
|
||||||
updateApps();
|
updateApps();
|
||||||
|
|
||||||
},
|
},
|
||||||
closeAction: (_) => {
|
closeAction: () => {
|
||||||
subs.map(sub => sub());
|
subs.map(sub => sub());
|
||||||
close();
|
close();
|
||||||
},
|
},
|
||||||
@@ -195,7 +196,7 @@ export namespace Runner {
|
|||||||
hscroll: Gtk.PolicyType.NEVER,
|
hscroll: Gtk.PolicyType.NEVER,
|
||||||
expand: true,
|
expand: true,
|
||||||
propagateNaturalHeight: true,
|
propagateNaturalHeight: true,
|
||||||
maxContentHeight: 450,
|
maxContentHeight: (props?.height ?? 450),
|
||||||
child: resultsList
|
child: resultsList
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user