fix current state detection

This commit is contained in:
yggverse 2024-11-10 12:40:57 +02:00
parent ddead4e870
commit 43abe41b31
7 changed files with 91 additions and 119 deletions

View File

@ -53,27 +53,23 @@ impl Close {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -53,27 +53,23 @@ impl CloseAll {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -52,27 +52,23 @@ impl HistoryBack {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -52,27 +52,23 @@ impl HistoryForward {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -52,27 +52,23 @@ impl Home {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -47,27 +47,23 @@ impl Pin {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject

View File

@ -52,27 +52,23 @@ impl Reload {
/// Define callback function for
/// [SimpleAction::activate](https://docs.gtk.org/gio/signal.SimpleAction.activate.html) signal
pub fn connect_activate(&self, callback: impl Fn(Option<i32>) + 'static) {
let state = self.state();
self.gobject.connect_activate(move |_, _| callback(state));
self.gobject.connect_activate(move |this, _| {
let state = this
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
callback(if state == DEFAULT_STATE {
None
} else {
Some(state)
})
});
}
// Getters
pub fn state(&self) -> Option<i32> {
let state = self
.gobject
.state()
.expect("State value required")
.get::<i32>()
.expect("Parameter type does not match `i32`");
if state != DEFAULT_STATE {
Some(state)
} else {
None
}
}
/// Get reference to [SimpleAction](https://docs.gtk.org/gio/class.SimpleAction.html) GObject
pub fn gobject(&self) -> &SimpleAction {
&self.gobject