implement is_attention tab state decorator

This commit is contained in:
yggverse 2024-11-11 14:47:51 +02:00
parent f6d015c8c1
commit 8f9f5d3eaa
5 changed files with 87 additions and 22 deletions

View File

@ -38,8 +38,15 @@ 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, is_load| { move |position, request, is_pinned, is_selected, is_attention, is_load| {
tab.append(position, request, is_pinned, is_selected, is_load); tab.append(
position,
request,
is_pinned,
is_selected,
is_attention,
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_ATTENTION: bool = false;
const DEFAULT_IS_LOAD: bool = false; 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
@ -30,6 +31,7 @@ impl Append {
DEFAULT_REQUEST, DEFAULT_REQUEST,
DEFAULT_IS_PINNED, DEFAULT_IS_PINNED,
DEFAULT_IS_SELECTED, DEFAULT_IS_SELECTED,
DEFAULT_IS_ATTENTION,
DEFAULT_IS_LOAD, DEFAULT_IS_LOAD,
) )
.to_variant(), .to_variant(),
@ -43,7 +45,8 @@ 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, is_load) = state(&self.gobject); let (position, request, is_pinned, is_selected, is_attention, is_load) =
state(&self.gobject);
// Set default state // Set default state
self.change_state( self.change_state(
@ -51,6 +54,7 @@ impl Append {
Some(DEFAULT_REQUEST), Some(DEFAULT_REQUEST),
DEFAULT_IS_PINNED, DEFAULT_IS_PINNED,
DEFAULT_IS_SELECTED, DEFAULT_IS_SELECTED,
DEFAULT_IS_ATTENTION,
DEFAULT_IS_LOAD, DEFAULT_IS_LOAD,
); );
@ -58,7 +62,14 @@ impl Append {
self.gobject.activate(None); self.gobject.activate(None);
// Return previous state // Return previous state
self.change_state(position, request, is_pinned, is_selected, is_load); self.change_state(
position,
request,
is_pinned,
is_selected,
is_attention,
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
@ -69,19 +80,35 @@ impl Append {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_attention: bool,
is_load: bool, is_load: bool,
) { ) {
// Save current state in memory // Save current state in memory
let (_position, _request, _is_pinned, _is_selected, _is_load) = state(&self.gobject); let (_position, _request, _is_pinned, _is_selected, _is_attention, _is_load) =
state(&self.gobject);
// Apply requested state // Apply requested state
self.change_state(position, request, is_pinned, is_selected, is_load); self.change_state(
position,
request,
is_pinned,
is_selected,
is_attention,
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, _is_load); self.change_state(
_position,
_request,
_is_pinned,
_is_selected,
_is_attention,
_is_load,
);
} }
/// Emit state change for action /// Emit state change for action
@ -91,6 +118,7 @@ impl Append {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_attention: bool,
is_load: bool, is_load: bool,
) { ) {
self.gobject.change_state( self.gobject.change_state(
@ -108,6 +136,7 @@ impl Append {
}, },
is_pinned, is_pinned,
is_selected, is_selected,
is_attention,
is_load, is_load,
) )
.to_variant(), .to_variant(),
@ -118,14 +147,21 @@ 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`,`request`,`is_pinned`,`is_selected`,`is_load` state as tuple /// * return `position`,`request`,`is_pinned`,`is_selected`,`is_attention`,`is_load` state as tuple
pub fn connect_activate( pub fn connect_activate(
&self, &self,
callback: impl Fn(Option<i32>, Option<String>, bool, bool, bool) + 'static, callback: impl Fn(Option<i32>, Option<String>, bool, bool, bool, bool) + 'static,
) { ) {
self.gobject.connect_activate(move |this, _| { self.gobject.connect_activate(move |this, _| {
let (position, request, is_pinned, is_selected, is_load) = state(this); let (position, request, is_pinned, is_selected, is_attention, is_load) = state(this);
callback(position, request, is_pinned, is_selected, is_load) callback(
position,
request,
is_pinned,
is_selected,
is_attention,
is_load,
)
}); });
} }
@ -143,12 +179,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, bool) { pub fn state(this: &SimpleAction) -> (Option<i32>, Option<String>, bool, bool, bool, bool) {
let (position, request, is_pinned, is_selected, is_load) = this let (position, request, is_pinned, is_selected, is_attention, is_load) = this
.state() .state()
.expect("Expected (`position`,`request`,`is_pinned`,`is_selected`,`is_load`) state") .expect("Expected (`position`,`request`,`is_pinned`,`is_selected`,`is_attention`,`is_load`) state")
.get::<(i32, String, bool, bool, bool)>() .get::<(i32, String, bool, bool, bool,bool)>()
.expect("Parameter type does not match (`i32`,`String`,`bool`,`bool`,`bool`) tuple"); .expect("Parameter type does not match (`i32`,`String`,`bool`,`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 {
@ -163,6 +199,7 @@ pub fn state(this: &SimpleAction) -> (Option<i32>, Option<String>, bool, bool, b
}, },
is_pinned, is_pinned,
is_selected, is_selected,
is_attention,
is_load, is_load,
) )
} }

View File

@ -85,6 +85,8 @@ impl Tab {
item.update(); item.update();
} }
} }
// Reset attention decorator
page.set_needs_attention(false);
} }
} }
}); });
@ -105,6 +107,7 @@ impl Tab {
request: Option<String>, request: Option<String>,
is_pinned: bool, is_pinned: bool,
is_selected: bool, is_selected: bool,
is_attention: bool,
is_load: bool, is_load: bool,
) -> Rc<Item> { ) -> Rc<Item> {
// Init new tab item // Init new tab item
@ -113,9 +116,19 @@ impl Tab {
self.browser_action.clone(), self.browser_action.clone(),
self.window_action.clone(), self.window_action.clone(),
// Options tuple // Options tuple
(position, request, is_pinned, is_selected, is_load), (
position,
request,
is_pinned,
is_selected,
is_attention,
is_load,
),
)); ));
// Apply tab attention request
item.widget().gobject().set_needs_attention(is_attention);
// Register dynamically created tab components in the HashMap index // Register dynamically created tab components in the HashMap index
self.index self.index
.borrow_mut() .borrow_mut()
@ -310,7 +323,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, false); self.append(None, None, false, true, false, false);
} }
// @TODO other/child features.. // @TODO other/child features..

View File

@ -34,10 +34,10 @@ impl Item {
browser_action: Rc<BrowserAction>, browser_action: Rc<BrowserAction>,
window_action: Rc<WindowAction>, window_action: Rc<WindowAction>,
// Options tuple @TODO struct? // Options tuple @TODO struct?
options: (Option<i32>, Option<String>, bool, bool, bool), options: (Option<i32>, Option<String>, bool, bool, bool, bool),
) -> Self { ) -> Self {
// Get item options from tuple // Get item options from tuple
let (position, request, is_pinned, is_selected, is_load) = options; let (position, request, is_pinned, is_selected, _is_attention, is_load) = options;
// Generate unique ID for new page components // Generate unique ID for new page components
let id = uuid_string_random(); let id = uuid_string_random();
@ -150,7 +150,14 @@ impl Item {
browser_action.clone(), browser_action.clone(),
window_action.clone(), window_action.clone(),
// Options tuple // Options tuple
(None, None, record.is_pinned, record.is_selected, false), (
None,
None,
record.is_pinned,
record.is_selected,
false,
false,
),
)); ));
// Delegate restore action to the item childs // Delegate restore action to the item childs

View File

@ -294,7 +294,8 @@ impl Reader {
false, false,
false, false,
true, true,
); // @TODO true,
);
} }
// Scheme not supported, delegate // Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch( _ => UriLauncher::new(&uri.to_str()).launch(