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