refactor: rename app_library application row to app_item
This commit is contained in:
parent
b23ec4976f
commit
6484f886ed
5 changed files with 18 additions and 22 deletions
|
|
@ -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="AppItem" parent="GtkBox">
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="hexpand">true</property>
|
<property name="hexpand">true</property>
|
||||||
|
|
@ -6,8 +6,8 @@ use gtk4 as gtk;
|
||||||
use gtk::CompositeTemplate;
|
use gtk::CompositeTemplate;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate)]
|
||||||
#[template(file = "application_row.ui")]
|
#[template(file = "app_item.ui")]
|
||||||
pub struct ApplicationRow {
|
pub struct AppItem {
|
||||||
#[template_child]
|
#[template_child]
|
||||||
pub name: TemplateChild<gtk::Label>,
|
pub name: TemplateChild<gtk::Label>,
|
||||||
#[template_child]
|
#[template_child]
|
||||||
|
|
@ -15,9 +15,9 @@ pub struct ApplicationRow {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for ApplicationRow {
|
impl ObjectSubclass for AppItem {
|
||||||
const NAME: &'static str = "ApplicationRow";
|
const NAME: &'static str = "AppItem";
|
||||||
type Type = super::ApplicationRow;
|
type Type = super::AppItem;
|
||||||
type ParentType = gtk::Box;
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
fn class_init(klass: &mut Self::Class) {
|
fn class_init(klass: &mut Self::Class) {
|
||||||
|
|
@ -29,6 +29,6 @@ impl ObjectSubclass for ApplicationRow {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for ApplicationRow {}
|
impl ObjectImpl for AppItem {}
|
||||||
impl WidgetImpl for ApplicationRow {}
|
impl WidgetImpl for AppItem {}
|
||||||
impl BoxImpl for ApplicationRow {}
|
impl BoxImpl for AppItem {}
|
||||||
|
|
@ -6,23 +6,23 @@ use gtk::subclass::prelude::*;
|
||||||
use gtk::{gio, glib};
|
use gtk::{gio, glib};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct ApplicationRow(ObjectSubclass<imp::ApplicationRow>)
|
pub struct AppItem(ObjectSubclass<imp::AppItem>)
|
||||||
@extends gtk::Widget, gtk::Box;
|
@extends gtk::Widget, gtk::Box;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ApplicationRow {
|
impl Default for AppItem {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicationRow {
|
impl AppItem {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
glib::Object::new(&[]).expect("Failed to create ApplicationRow")
|
glib::Object::new(&[]).expect("Failed to create AppItem")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_app_info(&self, app_info: &gio::AppInfo) {
|
pub fn set_app_info(&self, app_info: &gio::AppInfo) {
|
||||||
let self_ = imp::ApplicationRow::from_instance(self);
|
let self_ = imp::AppItem::from_instance(self);
|
||||||
self_.name.set_text(&app_info.name());
|
self_.name.set_text(&app_info.name());
|
||||||
if let Some(icon) = app_info.icon() {
|
if let Some(icon) = app_info.icon() {
|
||||||
self_.image.set_from_gicon(&icon);
|
self_.image.set_from_gicon(&icon);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
mod application_row;
|
mod app_item;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use gtk::gdk::Display;
|
use gtk::gdk::Display;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
use gtk4 as gtk;
|
use gtk4 as gtk;
|
||||||
|
|
||||||
use crate::application_row::ApplicationRow;
|
use crate::app_item::AppItem;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
|
|
@ -183,7 +183,7 @@ impl Window {
|
||||||
fn setup_factory(&self) {
|
fn setup_factory(&self) {
|
||||||
let factory = SignalListItemFactory::new();
|
let factory = SignalListItemFactory::new();
|
||||||
factory.connect_setup(move |_factory, item| {
|
factory.connect_setup(move |_factory, item| {
|
||||||
let row = ApplicationRow::new();
|
let row = AppItem::new();
|
||||||
item.set_child(Some(&row));
|
item.set_child(Some(&row));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -195,11 +195,7 @@ impl Window {
|
||||||
.downcast::<gio::AppInfo>()
|
.downcast::<gio::AppInfo>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let child = grid_item
|
let child = grid_item.child().unwrap().downcast::<AppItem>().unwrap();
|
||||||
.child()
|
|
||||||
.unwrap()
|
|
||||||
.downcast::<ApplicationRow>()
|
|
||||||
.unwrap();
|
|
||||||
child.set_app_info(&app_info);
|
child.set_app_info(&app_info);
|
||||||
});
|
});
|
||||||
// Set the factory of the list view
|
// Set the factory of the list view
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue