rename search result object and row
This commit is contained in:
parent
f95fa068f3
commit
f0542071d4
7 changed files with 35 additions and 35 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
mod application_object;
|
mod search_result_object;
|
||||||
mod application_row;
|
mod search_result_row;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use self::application_object::ApplicationObject;
|
use self::search_result_object::SearchResultObject;
|
||||||
use self::window::Window;
|
use self::window::Window;
|
||||||
use crate::utils::BoxedSearchResult;
|
use crate::utils::BoxedSearchResult;
|
||||||
use gdk4::Display;
|
use gdk4::Display;
|
||||||
|
|
@ -126,7 +126,7 @@ fn main() {
|
||||||
let new_results: Vec<glib::Object> = results
|
let new_results: Vec<glib::Object> = results
|
||||||
// [0..std::cmp::min(results.len(), NUM_LAUNCHER_ITEMS.into())]
|
// [0..std::cmp::min(results.len(), NUM_LAUNCHER_ITEMS.into())]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|result| ApplicationObject::new(&BoxedSearchResult(Some(result))).upcast())
|
.map(|result| SearchResultObject::new(&BoxedSearchResult(Some(result))).upcast())
|
||||||
.collect();
|
.collect();
|
||||||
model.splice(0, model_len, &new_results[..]);
|
model.splice(0, model_len, &new_results[..]);
|
||||||
} else if let pop_launcher::Response::DesktopEntry {
|
} else if let pop_launcher::Response::DesktopEntry {
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,20 @@ use std::rc::Rc;
|
||||||
|
|
||||||
// Object holding the state
|
// Object holding the state
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ApplicationObject {
|
pub struct SearchResultObject {
|
||||||
data: Rc<RefCell<BoxedSearchResult>>,
|
data: Rc<RefCell<BoxedSearchResult>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The central trait for subclassing a GObject
|
// The central trait for subclassing a GObject
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for ApplicationObject {
|
impl ObjectSubclass for SearchResultObject {
|
||||||
const NAME: &'static str = "ApplicationObject";
|
const NAME: &'static str = "SearchResultObject";
|
||||||
type Type = super::ApplicationObject;
|
type Type = super::SearchResultObject;
|
||||||
type ParentType = glib::Object;
|
type ParentType = glib::Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trait shared by all GObjects
|
// Trait shared by all GObjects
|
||||||
impl ObjectImpl for ApplicationObject {
|
impl ObjectImpl for SearchResultObject {
|
||||||
fn properties() -> &'static [ParamSpec] {
|
fn properties() -> &'static [ParamSpec] {
|
||||||
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
|
||||||
vec![ParamSpec::new_boxed(
|
vec![ParamSpec::new_boxed(
|
||||||
|
|
@ -3,10 +3,10 @@ use crate::utils::BoxedSearchResult;
|
||||||
use gdk4::glib::Object;
|
use gdk4::glib::Object;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct ApplicationObject(ObjectSubclass<imp::ApplicationObject>);
|
pub struct SearchResultObject(ObjectSubclass<imp::SearchResultObject>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicationObject {
|
impl SearchResultObject {
|
||||||
pub fn new(search_result: &BoxedSearchResult) -> Self {
|
pub fn new(search_result: &BoxedSearchResult) -> Self {
|
||||||
Object::new(&[("data", search_result)]).expect("Failed to create Application Object")
|
Object::new(&[("data", search_result)]).expect("Failed to create Application Object")
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<interface>
|
<interface>
|
||||||
<template class="ApplicationRow" parent="GtkBox">
|
<template class="SearchResultRow" parent="GtkBox">
|
||||||
<property name="orientation">horizontal</property>
|
<property name="orientation">horizontal</property>
|
||||||
<property name="spacing">12</property>
|
<property name="spacing">12</property>
|
||||||
<property name="margin-start">4</property>
|
<property name="margin-start">4</property>
|
||||||
|
|
@ -7,7 +7,7 @@ use gtk::CompositeTemplate;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate)]
|
||||||
#[template(file = "application_row.ui")]
|
#[template(file = "application_row.ui")]
|
||||||
pub struct ApplicationRow {
|
pub struct SearchResultRow {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub name: TemplateChild<gtk::Label>,
|
pub name: TemplateChild<gtk::Label>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
|
@ -21,9 +21,9 @@ pub struct ApplicationRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for ApplicationRow {
|
impl ObjectSubclass for SearchResultRow {
|
||||||
const NAME: &'static str = "ApplicationRow";
|
const NAME: &'static str = "SearchResultRow";
|
||||||
type Type = super::ApplicationRow;
|
type Type = super::SearchResultRow;
|
||||||
type ParentType = gtk::Box;
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
fn class_init(klass: &mut Self::Class) {
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
|
@ -35,6 +35,6 @@ impl ObjectSubclass for ApplicationRow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for ApplicationRow {}
|
impl ObjectImpl for SearchResultRow {}
|
||||||
impl WidgetImpl for ApplicationRow {}
|
impl WidgetImpl for SearchResultRow {}
|
||||||
impl BoxImpl for ApplicationRow {}
|
impl BoxImpl for SearchResultRow {}
|
||||||
|
|
@ -3,29 +3,29 @@ use crate::BoxedSearchResult;
|
||||||
use gtk4 as gtk;
|
use gtk4 as gtk;
|
||||||
mod imp;
|
mod imp;
|
||||||
|
|
||||||
use crate::ApplicationObject;
|
use crate::SearchResultObject;
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct ApplicationRow(ObjectSubclass<imp::ApplicationRow>)
|
pub struct SearchResultRow(ObjectSubclass<imp::SearchResultRow>)
|
||||||
@extends gtk::Widget, gtk::Box;
|
@extends gtk::Widget, gtk::Box;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ApplicationRow {
|
impl Default for SearchResultRow {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicationRow {
|
impl SearchResultRow {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
glib::Object::new(&[]).expect("Failed to create ApplicationRow")
|
glib::Object::new(&[]).expect("Failed to create SearchResultRow")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_search_result(&self, search_obj: ApplicationObject) {
|
pub fn set_search_result(&self, search_obj: SearchResultObject) {
|
||||||
let self_ = imp::ApplicationRow::from_instance(self);
|
let self_ = imp::SearchResultRow::from_instance(self);
|
||||||
if let Ok(search_result) = search_obj.property("data") {
|
if let Ok(search_result) = search_obj.property("data") {
|
||||||
if let Ok(search_result) = search_result.get::<BoxedSearchResult>() {
|
if let Ok(search_result) = search_result.get::<BoxedSearchResult>() {
|
||||||
if let Some(search_result) = search_result.0 {
|
if let Some(search_result) = search_result.0 {
|
||||||
|
|
@ -39,7 +39,7 @@ impl ApplicationRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_shortcut(&self, indx: u32) {
|
pub fn set_shortcut(&self, indx: u32) {
|
||||||
let self_ = imp::ApplicationRow::from_instance(self);
|
let self_ = imp::SearchResultRow::from_instance(self);
|
||||||
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
|
self_.shortcut.set_text(&format!("Ctrl + {}", indx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
use crate::application_row::ApplicationRow;
|
use crate::search_result_row::SearchResultRow;
|
||||||
use crate::ApplicationObject;
|
use crate::SearchResultObject;
|
||||||
use crate::TX;
|
use crate::TX;
|
||||||
use crate::X11_CONN;
|
use crate::X11_CONN;
|
||||||
use gdk4::Rectangle;
|
use gdk4::Rectangle;
|
||||||
|
|
@ -44,7 +44,7 @@ impl Window {
|
||||||
fn setup_model(&self) {
|
fn setup_model(&self) {
|
||||||
// Get state and set model
|
// Get state and set model
|
||||||
let imp = imp::Window::from_instance(self);
|
let imp = imp::Window::from_instance(self);
|
||||||
let model = gio::ListStore::new(ApplicationObject::static_type());
|
let model = gio::ListStore::new(SearchResultObject::static_type());
|
||||||
|
|
||||||
let slice_model = gtk::SliceListModel::new(Some(&model), 0, NUM_LAUNCHER_ITEMS.into());
|
let slice_model = gtk::SliceListModel::new(Some(&model), 0, NUM_LAUNCHER_ITEMS.into());
|
||||||
let selection_model = gtk::SingleSelection::builder()
|
let selection_model = gtk::SingleSelection::builder()
|
||||||
|
|
@ -222,20 +222,20 @@ impl Window {
|
||||||
fn setup_factory(&self) {
|
fn setup_factory(&self) {
|
||||||
let factory = SignalListItemFactory::new();
|
let factory = SignalListItemFactory::new();
|
||||||
factory.connect_setup(move |_, list_item| {
|
factory.connect_setup(move |_, list_item| {
|
||||||
let row = ApplicationRow::new();
|
let row = SearchResultRow::new();
|
||||||
list_item.set_child(Some(&row))
|
list_item.set_child(Some(&row))
|
||||||
});
|
});
|
||||||
factory.connect_bind(move |_, list_item| {
|
factory.connect_bind(move |_, list_item| {
|
||||||
let application_object = list_item
|
let application_object = list_item
|
||||||
.item()
|
.item()
|
||||||
.expect("The item has to exist.")
|
.expect("The item has to exist.")
|
||||||
.downcast::<ApplicationObject>()
|
.downcast::<SearchResultObject>()
|
||||||
.expect("The item has to be an `ApplicationObject`");
|
.expect("The item has to be an `SearchResultObject`");
|
||||||
let row = list_item
|
let row = list_item
|
||||||
.child()
|
.child()
|
||||||
.expect("The list item child needs to exist.")
|
.expect("The list item child needs to exist.")
|
||||||
.downcast::<ApplicationRow>()
|
.downcast::<SearchResultRow>()
|
||||||
.expect("The list item type needs to be `ApplicationRow`");
|
.expect("The list item type needs to be `SearchResultRow`");
|
||||||
if list_item.position() < 9 {
|
if list_item.position() < 9 {
|
||||||
row.set_shortcut(list_item.position() + 1);
|
row.set_shortcut(list_item.position() + 1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue