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