2021-11-08 10:43:08 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2021-11-15 00:14:59 +00:00
|
|
|
use crate::components::tab_label::TabLabel;
|
2021-11-03 10:06:51 +00:00
|
|
|
use glib::IsA;
|
2021-12-18 10:17:53 +00:00
|
|
|
use gtk::{prelude::*, Widget};
|
2021-11-03 10:06:51 +00:00
|
|
|
|
|
|
|
pub trait ClosableTabImplementedNotebook {
|
2021-11-08 22:18:23 +00:00
|
|
|
fn prepend_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
2021-11-03 10:06:51 +00:00
|
|
|
&self,
|
|
|
|
child: &T,
|
|
|
|
tab_label: Option<&U>,
|
|
|
|
) -> u32;
|
2021-11-08 22:18:23 +00:00
|
|
|
fn append_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
2021-11-06 10:01:39 +00:00
|
|
|
&self,
|
|
|
|
child: &T,
|
|
|
|
tab_label: Option<&U>,
|
|
|
|
) -> u32;
|
2021-11-03 10:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ClosableTabImplementedNotebook for gtk::Notebook {
|
|
|
|
fn prepend_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
|
|
|
&self,
|
|
|
|
child: &T,
|
|
|
|
tab_label: Option<&U>,
|
|
|
|
) -> u32 {
|
2021-11-15 00:14:59 +00:00
|
|
|
let tab_label_widget = TabLabel::new(tab_label);
|
|
|
|
let page = self.prepend_page(child, Some(&tab_label_widget));
|
2021-11-03 10:06:51 +00:00
|
|
|
|
2021-11-15 00:14:59 +00:00
|
|
|
tab_label_widget
|
|
|
|
.to_imp()
|
|
|
|
.button
|
|
|
|
.connect_clicked(glib::clone!(@weak self as notebook =>
|
|
|
|
move |_| {
|
|
|
|
notebook.remove_page(Some(page));
|
|
|
|
}));
|
2021-11-03 10:06:51 +00:00
|
|
|
|
|
|
|
page
|
|
|
|
}
|
2021-11-06 10:01:39 +00:00
|
|
|
|
2021-11-08 22:18:23 +00:00
|
|
|
fn append_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
2021-11-06 10:01:39 +00:00
|
|
|
&self,
|
|
|
|
child: &T,
|
|
|
|
tab_label: Option<&U>,
|
|
|
|
) -> u32 {
|
2021-11-15 00:14:59 +00:00
|
|
|
let tab_label_widget = TabLabel::new(tab_label);
|
|
|
|
let page = self.append_page(child, Some(&tab_label_widget));
|
|
|
|
|
|
|
|
tab_label_widget
|
|
|
|
.to_imp()
|
|
|
|
.button
|
|
|
|
.connect_clicked(glib::clone!(@weak self as notebook =>
|
|
|
|
move |_| {
|
|
|
|
notebook.remove_page(Some(page));
|
|
|
|
}));
|
2021-11-06 10:01:39 +00:00
|
|
|
|
|
|
|
page
|
|
|
|
}
|
2021-11-03 10:06:51 +00:00
|
|
|
}
|