mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
give name to gobject variables
This commit is contained in:
parent
702269f1f1
commit
a1617b2b1b
35 changed files with 213 additions and 209 deletions
|
|
@ -57,7 +57,7 @@ impl Item {
|
|||
let widget = Rc::new(Widget::new(
|
||||
id.as_str(),
|
||||
tab_view,
|
||||
page.widget.gobject(),
|
||||
&page.widget.g_box,
|
||||
None,
|
||||
position,
|
||||
(is_pinned, is_selected, is_attention),
|
||||
|
|
@ -118,7 +118,7 @@ impl Item {
|
|||
self.page.update();
|
||||
|
||||
// Update tab loading indicator
|
||||
self.widget.gobject.set_loading(self.page.is_loading());
|
||||
self.widget.tab_page.set_loading(self.page.is_loading());
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ impl Back {
|
|||
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action.history_back.gobject.set_enabled(status);
|
||||
self.action.history_back.simple_action.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,10 @@ impl Forward {
|
|||
// Actions
|
||||
pub fn update(&self, status: bool) {
|
||||
// Update actions
|
||||
self.action.history_forward.gobject.set_enabled(status);
|
||||
self.action
|
||||
.history_forward
|
||||
.simple_action
|
||||
.set_enabled(status);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(status);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl Home {
|
|||
false
|
||||
}
|
||||
};
|
||||
self.action.home.gobject.set_enabled(has_home);
|
||||
self.action.home.simple_action.set_enabled(has_home);
|
||||
self.widget.update(has_home);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ impl Reload {
|
|||
|
||||
pub fn update(&self, is_enabled: bool) {
|
||||
// Update actions
|
||||
self.action.reload.gobject.set_enabled(is_enabled);
|
||||
self.action.reload.simple_action.set_enabled(is_enabled);
|
||||
|
||||
// Update child components
|
||||
self.widget.update(is_enabled);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use gtk::{
|
|||
};
|
||||
|
||||
pub struct Widget {
|
||||
gobject: Box,
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
|
|
@ -17,20 +17,15 @@ impl Widget {
|
|||
input: &impl IsA<gtk::Widget>,
|
||||
) -> Self {
|
||||
// Init self
|
||||
let gobject = Box::builder()
|
||||
let g_box = Box::builder()
|
||||
.orientation(Orientation::Vertical)
|
||||
.name(name)
|
||||
.build();
|
||||
|
||||
gobject.append(navigation);
|
||||
gobject.append(content);
|
||||
gobject.append(input);
|
||||
g_box.append(navigation);
|
||||
g_box.append(content);
|
||||
g_box.append(input);
|
||||
|
||||
Self { gobject }
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &Box {
|
||||
&self.gobject
|
||||
Self { g_box }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use sqlite::Transaction;
|
|||
const DEFAULT_TITLE: &str = "New page";
|
||||
|
||||
pub struct Widget {
|
||||
pub gobject: TabPage,
|
||||
pub tab_page: TabPage,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
|
|
@ -25,8 +25,8 @@ impl Widget {
|
|||
// Define state variables
|
||||
let (is_pinned, is_selected, is_attention) = state;
|
||||
|
||||
// Create new `TabPage` GObject in given `TabView`
|
||||
let gobject = match position {
|
||||
// Create new `TabPage` for given `TabView`
|
||||
let tab_page = match position {
|
||||
Position::After => match tab_view.selected_page() {
|
||||
Some(page) => add(tab_view, child, tab_view.page_position(&page) + 1),
|
||||
None => tab_view.append(child),
|
||||
|
|
@ -35,22 +35,22 @@ impl Widget {
|
|||
Position::Number(value) => add(tab_view, child, value),
|
||||
};
|
||||
|
||||
// Setup `GObject`
|
||||
gobject.set_needs_attention(is_attention);
|
||||
gobject.set_keyword(keyword);
|
||||
gobject.set_title(match title {
|
||||
// Setup
|
||||
tab_page.set_needs_attention(is_attention);
|
||||
tab_page.set_keyword(keyword);
|
||||
tab_page.set_title(match title {
|
||||
Some(value) => value,
|
||||
None => DEFAULT_TITLE,
|
||||
});
|
||||
|
||||
tab_view.set_page_pinned(&gobject, is_pinned);
|
||||
tab_view.set_page_pinned(&tab_page, is_pinned);
|
||||
|
||||
if is_selected {
|
||||
tab_view.set_selected_page(&gobject);
|
||||
tab_view.set_selected_page(&tab_page);
|
||||
}
|
||||
|
||||
// Done
|
||||
Self { gobject }
|
||||
Self { tab_page }
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
|
@ -88,7 +88,7 @@ impl Widget {
|
|||
for record in records {
|
||||
// Record value can be stored as NULL
|
||||
if let Some(title) = record.title {
|
||||
self.gobject.set_title(title.as_str());
|
||||
self.tab_page.set_title(title.as_str());
|
||||
}
|
||||
|
||||
// Delegate restore action to the item childs
|
||||
|
|
@ -107,7 +107,7 @@ impl Widget {
|
|||
app_browser_window_tab_item_id: &i64,
|
||||
) -> Result<(), String> {
|
||||
// Keep value in memory until operation complete
|
||||
let title = self.gobject.title();
|
||||
let title = self.tab_page.title();
|
||||
|
||||
match database::insert(
|
||||
transaction,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use std::rc::Rc;
|
|||
///
|
||||
/// https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/method.TabView.get_menu_model.html
|
||||
pub struct Menu {
|
||||
pub gobject: gtk::gio::Menu,
|
||||
pub main: gtk::gio::Menu,
|
||||
}
|
||||
|
||||
impl Menu {
|
||||
|
|
@ -21,7 +21,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.reload.gobject.name()
|
||||
window_action.reload.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.save_as.gobject.name()
|
||||
window_action.save_as.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.bookmark.gobject.name()
|
||||
window_action.bookmark.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.pin.gobject.name()
|
||||
window_action.pin.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.source.gobject.name()
|
||||
window_action.source.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.home.gobject.name()
|
||||
window_action.home.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.history_back.gobject.name()
|
||||
window_action.history_back.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.history_forward.gobject.name()
|
||||
window_action.history_forward.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.close.gobject.name()
|
||||
window_action.close.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
|
|
@ -120,12 +120,12 @@ impl Menu {
|
|||
Some(&format!(
|
||||
"{}.{}",
|
||||
window_action.id,
|
||||
window_action.close_all.gobject.name()
|
||||
window_action.close_all.simple_action.name()
|
||||
)),
|
||||
);
|
||||
|
||||
main.append_submenu(Some("Close"), &close);
|
||||
|
||||
Self { gobject: main }
|
||||
Self { main }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const DEFAULT_TAB_ICON: &str = "view-pin-symbolic";
|
|||
|
||||
/// Wrapper for [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) GObject
|
||||
pub struct Widget {
|
||||
pub gobject: TabView,
|
||||
pub tab_view: TabView,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
|
|
@ -18,17 +18,17 @@ impl Widget {
|
|||
/// Create new `Self`
|
||||
pub fn new(menu_model: &impl IsA<MenuModel>) -> Self {
|
||||
// Init gobject
|
||||
let gobject = TabView::builder().menu_model(menu_model).build();
|
||||
let tab_view = TabView::builder().menu_model(menu_model).build();
|
||||
|
||||
// Change default icon (if available in the system icon set)
|
||||
// * visible for pinned tabs only
|
||||
// * @TODO not default GTK behavior, make this feature optional
|
||||
if let Ok(default_icon) = Icon::for_string(DEFAULT_TAB_ICON) {
|
||||
gobject.set_default_icon(&default_icon);
|
||||
tab_view.set_default_icon(&default_icon);
|
||||
}
|
||||
|
||||
// Done
|
||||
Self { gobject }
|
||||
Self { tab_view }
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
|
@ -39,8 +39,8 @@ impl Widget {
|
|||
/// * use native [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) API with `GObject` reference getter
|
||||
pub fn close(&self, position: Option<i32>) {
|
||||
if let Some(page) = self.page(position) {
|
||||
self.gobject.set_page_pinned(&page, false);
|
||||
self.gobject.close_page(&page);
|
||||
self.tab_view.set_page_pinned(&page, false);
|
||||
self.tab_view.close_page(&page);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,16 +49,16 @@ impl Widget {
|
|||
/// * deactivate [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) outside if selected page should not be closed
|
||||
/// * use native [TabView](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.TabView.html) API with `GObject` reference getter
|
||||
pub fn close_all(&self) {
|
||||
while let Some(page) = self.gobject.selected_page() {
|
||||
self.gobject.set_page_pinned(&page, false);
|
||||
self.gobject.close_page(&page);
|
||||
while let Some(page) = self.tab_view.selected_page() {
|
||||
self.tab_view.set_page_pinned(&page, false);
|
||||
self.tab_view.close_page(&page);
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggle pin for page at given `position`, `None` to pin selected page (if available)
|
||||
pub fn pin(&self, position: Option<i32>) {
|
||||
if let Some(page) = self.page(position) {
|
||||
self.gobject.set_page_pinned(&page, !page.is_pinned()); // toggle
|
||||
self.tab_view.set_page_pinned(&page, !page.is_pinned()); // toggle
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +68,8 @@ impl Widget {
|
|||
/// * return `None` if requested or selected page not found
|
||||
pub fn page(&self, position: Option<i32>) -> Option<TabPage> {
|
||||
match position {
|
||||
Some(value) => Some(self.gobject.nth_page(value)),
|
||||
None => self.gobject.selected_page(),
|
||||
Some(value) => Some(self.tab_view.nth_page(value)),
|
||||
None => self.tab_view.selected_page(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue