add is_load state

This commit is contained in:
yggverse 2024-11-11 13:03:55 +02:00
parent 7bc2d478d0
commit 3d9ea1d54e
5 changed files with 34 additions and 19 deletions

View File

@ -38,8 +38,8 @@ impl Window {
// Init events // Init events
action.append().connect_activate({ action.append().connect_activate({
let tab = tab.clone(); let tab = tab.clone();
move |position, request, is_pinned, is_selected| { move |position, request, is_pinned, is_selected, is_load| {
tab.append(position, request, is_pinned, is_selected); tab.append(position, request, is_pinned, is_selected, is_load);
} }
}); });

View File

@ -9,6 +9,7 @@ const DEFAULT_POSITION: i32 = -1;
const DEFAULT_REQUEST: String = String::new(); const DEFAULT_REQUEST: String = String::new();
const DEFAULT_IS_PINNED: bool = false; const DEFAULT_IS_PINNED: bool = false;
const DEFAULT_IS_SELECTED: bool = true; const DEFAULT_IS_SELECTED: bool = true;
const DEFAULT_IS_LOAD: bool = false;
/// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Append` action of `Window` group /// [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) wrapper for `Append` action of `Window` group
pub struct Append { pub struct Append {
@ -29,6 +30,7 @@ impl Append {
DEFAULT_REQUEST, DEFAULT_REQUEST,
DEFAULT_IS_PINNED, DEFAULT_IS_PINNED,
DEFAULT_IS_SELECTED, DEFAULT_IS_SELECTED,
DEFAULT_IS_LOAD,
) )
.to_variant(), .to_variant(),
), ),
@ -41,7 +43,7 @@ impl Append {
/// * this action reset previous state for action after activation /// * this action reset previous state for action after activation
pub fn activate_default_once(&self) { pub fn activate_default_once(&self) {
// Save current state in memory // Save current state in memory
let (position, request, is_pinned, is_selected) = state(&self.gobject); let (position, request, is_pinned, is_selected, is_load) = state(&self.gobject);
// Set default state // Set default state
self.change_state( self.change_state(
@ -49,13 +51,14 @@ impl Append {
Some(DEFAULT_REQUEST), Some(DEFAULT_REQUEST),
DEFAULT_IS_PINNED, DEFAULT_IS_PINNED,
DEFAULT_IS_SELECTED, DEFAULT_IS_SELECTED,
DEFAULT_IS_LOAD,
); );
// Activate action // Activate action
self.gobject.activate(None); self.gobject.activate(None);
// Return previous state // Return previous state
self.change_state(position, request, is_pinned, is_selected); self.change_state(position, request, is_pinned, is_selected, is_load);
} }
/// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// Emit [activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
@ -66,18 +69,19 @@ impl Append {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_load: bool,
) { ) {
// Save current state in memory // Save current state in memory
let (_position, _request, _is_pinned, _is_selected) = state(&self.gobject); let (_position, _request, _is_pinned, _is_selected, _is_load) = state(&self.gobject);
// Apply requested state // Apply requested state
self.change_state(position, request, is_pinned, is_selected); self.change_state(position, request, is_pinned, is_selected, is_load);
// Activate action // Activate action
self.gobject.activate(None); self.gobject.activate(None);
// Return previous state // Return previous state
self.change_state(_position, _request, _is_pinned, _is_selected); self.change_state(_position, _request, _is_pinned, _is_selected, _is_load);
} }
/// Emit state change for action /// Emit state change for action
@ -87,6 +91,7 @@ impl Append {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_load: bool,
) { ) {
self.gobject.change_state( self.gobject.change_state(
&( &(
@ -103,6 +108,7 @@ impl Append {
}, },
is_pinned, is_pinned,
is_selected, is_selected,
is_load,
) )
.to_variant(), .to_variant(),
); );
@ -112,14 +118,14 @@ impl Append {
/// Define callback function for /// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal /// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
/// * return `position`, `is_pinned`, `is_selected` state as tuple /// * return `position`,`request`,`is_pinned`,`is_selected`,`is_load` state as tuple
pub fn connect_activate( pub fn connect_activate(
&self, &self,
callback: impl Fn(Option<i32>, Option<String>, bool, bool) + 'static, callback: impl Fn(Option<i32>, Option<String>, bool, bool, bool) + 'static,
) { ) {
self.gobject.connect_activate(move |this, _| { self.gobject.connect_activate(move |this, _| {
let (position, request, is_pinned, is_selected) = state(this); let (position, request, is_pinned, is_selected, is_load) = state(this);
callback(position, request, is_pinned, is_selected) callback(position, request, is_pinned, is_selected, is_load)
}); });
} }
@ -137,12 +143,12 @@ impl Append {
} }
/// Shared helper to get C-based action state in Optional format /// Shared helper to get C-based action state in Optional format
pub fn state(this: &SimpleAction) -> (Option<i32>, Option<String>, bool, bool) { pub fn state(this: &SimpleAction) -> (Option<i32>, Option<String>, bool, bool, bool) {
let (position, request, is_pinned, is_selected) = this let (position, request, is_pinned, is_selected, is_load) = this
.state() .state()
.expect("Expected (`position`,`request`,`is_pinned`,`is_selected`) state") .expect("Expected (`position`,`request`,`is_pinned`,`is_selected`,`is_load`) state")
.get::<(i32, String, bool, bool)>() .get::<(i32, String, bool, bool, bool)>()
.expect("Parameter type does not match (`i32`,`String`,`bool`,`bool`) tuple"); .expect("Parameter type does not match (`i32`,`String`,`bool`,`bool`,`bool`) tuple");
( (
// Convert from C-based variant value to Option // Convert from C-based variant value to Option
if position == DEFAULT_POSITION { if position == DEFAULT_POSITION {
@ -157,5 +163,6 @@ pub fn state(this: &SimpleAction) -> (Option<i32>, Option<String>, bool, bool) {
}, },
is_pinned, is_pinned,
is_selected, is_selected,
is_load,
) )
} }

View File

@ -105,6 +105,7 @@ impl Tab {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_load: bool,
) -> Rc<Item> { ) -> Rc<Item> {
// Init new tab item // Init new tab item
let item = Rc::new(Item::new( let item = Rc::new(Item::new(
@ -116,6 +117,7 @@ impl Tab {
request, request,
is_pinned, is_pinned,
is_selected, is_selected,
is_load,
)); ));
// Register dynamically created tab components in the HashMap index // Register dynamically created tab components in the HashMap index
@ -312,7 +314,7 @@ impl Tab {
pub fn init(&self) { pub fn init(&self) {
// Append just one blank page if no tabs available after last session restore // Append just one blank page if no tabs available after last session restore
if self.index.borrow().is_empty() { if self.index.borrow().is_empty() {
self.append(None, None, false, true); self.append(None, None, false, true, false);
} }
// @TODO other/child features.. // @TODO other/child features..

View File

@ -39,6 +39,7 @@ impl Item {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_load: bool,
) -> Self { ) -> Self {
// Generate unique ID for new page components // Generate unique ID for new page components
let id = uuid_string_random(); let id = uuid_string_random();
@ -72,8 +73,11 @@ impl Item {
.widget() .widget()
.gobject() .gobject()
.set_text(&text); .set_text(&text);
page.load(true);
} // @TODO load optionally if is_load {
page.load(true);
}
}
action.load().connect_activate({ action.load().connect_activate({
let page = page.clone(); let page = page.clone();
@ -157,6 +161,7 @@ impl Item {
None, None,
record.is_pinned, record.is_pinned,
record.is_selected, record.is_selected,
false,
)); ));
// Delegate restore action to the item childs // Delegate restore action to the item childs

View File

@ -293,6 +293,7 @@ impl Reader {
Some(uri.to_string()), Some(uri.to_string()),
false, false,
false, false,
true,
); // @TODO ); // @TODO
} }
// Scheme not supported, delegate // Scheme not supported, delegate