Skip to content

Commit

Permalink
Move ConversationMessageItem to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
matzipan committed Sep 26, 2023
1 parent 60b9d0e commit 69c0360
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 58 deletions.
59 changes: 1 addition & 58 deletions src/ui/window.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod conversation_message_item;
pub mod dynamic_list_view;
pub mod folder_conversation_item;
pub mod folders_list_item;
Expand Down Expand Up @@ -28,64 +29,6 @@ use self::folder_conversation_item::FolderConversationItem;
use self::folders_list_item::FoldersListItem;
use self::message_view::MessageView;

pub mod conversation_message_item {
use super::*;

// Implementation sub-module of the GObject
mod imp {
use super::*;

// The actual data structure that stores our values. This is not accessible
// directly from the outside.
pub struct ConversationMessageItem {
pub message: Rc<RefCell<Option<models::Message>>>,
}

// Basic declaration of our type for the GObject type system
#[glib::object_subclass]
impl ObjectSubclass for ConversationMessageItem {
const NAME: &'static str = "ConversationMessageItem";
type Type = super::ConversationMessageItem;
type ParentType = gtk::ListBoxRow;
// Called once at the very beginning of instantiation of each instance and
// creates the data structure that contains all our state
fn new() -> Self {
Self {
message: Default::default(),
}
}
}
impl ObjectImpl for ConversationMessageItem {}
impl ListBoxRowImpl for ConversationMessageItem {}
impl WidgetImpl for ConversationMessageItem {}
}

// The public part
glib::wrapper! {
pub struct ConversationMessageItem(ObjectSubclass<imp::ConversationMessageItem>) @extends gtk::ListBoxRow, gtk::Widget, @implements gtk::Buildable, gtk::Actionable;
}
impl ConversationMessageItem {
pub fn new() -> ConversationMessageItem {
glib::Object::new::<ConversationMessageItem>()
}

pub fn new_with_message(message: &models::Message) -> ConversationMessageItem {
let instance = Self::new();

let self_ = imp::ConversationMessageItem::from_obj(&instance);
//@TODO can we get rid of this clone?
self_.message.replace(Some(message.clone()));

instance
}

pub fn get_message(&self) -> Rc<RefCell<Option<models::Message>>> {
let self_ = imp::ConversationMessageItem::from_obj(self);
self_.message.clone()
}
}
}

mod imp {
use gtk::{
glib::{closure_local, ParamSpec, Value},
Expand Down
55 changes: 55 additions & 0 deletions src/ui/window/conversation_message_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use super::*;

// Implementation sub-module of the GObject
mod imp {
use super::*;

// The actual data structure that stores our values. This is not accessible
// directly from the outside.
pub struct ConversationMessageItem {
pub message: Rc<RefCell<Option<models::Message>>>,
}

// Basic declaration of our type for the GObject type system
#[glib::object_subclass]
impl ObjectSubclass for ConversationMessageItem {
const NAME: &'static str = "ConversationMessageItem";
type Type = super::ConversationMessageItem;
type ParentType = gtk::ListBoxRow;
// Called once at the very beginning of instantiation of each instance and
// creates the data structure that contains all our state
fn new() -> Self {
Self {
message: Default::default(),
}
}
}
impl ObjectImpl for ConversationMessageItem {}
impl ListBoxRowImpl for ConversationMessageItem {}
impl WidgetImpl for ConversationMessageItem {}
}

// The public part
glib::wrapper! {
pub struct ConversationMessageItem(ObjectSubclass<imp::ConversationMessageItem>) @extends gtk::ListBoxRow, gtk::Widget, @implements gtk::Buildable, gtk::Actionable;
}
impl ConversationMessageItem {
pub fn new() -> ConversationMessageItem {
glib::Object::new::<ConversationMessageItem>()
}

pub fn new_with_message(message: &models::Message) -> ConversationMessageItem {
let instance = Self::new();

let self_ = imp::ConversationMessageItem::from_obj(&instance);
//@TODO can we get rid of this clone?
self_.message.replace(Some(message.clone()));

instance
}

pub fn get_message(&self) -> Rc<RefCell<Option<models::Message>>> {
let self_ = imp::ConversationMessageItem::from_obj(self);
self_.message.clone()
}
}

0 comments on commit 69c0360

Please sign in to comment.