-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow implementing a GAction interface #1640
base: main
Are you sure you want to change the base?
Conversation
1c5636b
to
c4de546
Compare
Another issue I have is that
I have no clue what would be an idiomatic way to use |
GtkEditable provides a method to automatically add the properties for you along with the get_property and set_property. Either the example implementing a custom Action would have to do that manually or you could add helpers that would do it automatically for you, see the EditableImpl in the gtk4-rs repo. |
|
||
#[derive(glib::Properties, Default)] | ||
#[properties(wrapper_type = super::RenamedAction)] | ||
pub struct RenamedAction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The properties macro allows overriding properties by the way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it a try but received an error
(process:718176): GLib-GObject-CRITICAL **: 22:59:07.010: When installing property: type 'ExampleRenamedAction' already has a property named 'name'
I guess it's because of the sequence of initialization. When I define a class and implement an interface then class installs properties first and interface fails to install them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way how you do it now should work or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not work. I guess It works as expected in the cases like
class A implements IFace
class B extends A implements IFace {
override property x of IFace
}
where initialization sequence is: A
, IFace
, B
. So, when B
is initializing IFace
is already there and could be overriden.
but does not work for
class B implements IFace {
override property x of IFace
}
where initialization sequence is: B
, IFace
. So, B
has nothing to override yet.
c4de546
to
59cbb3a
Compare
@bilelmoussaoui Thanks for pointing a direction! Unfortunately Gio does not provide helpers similar to I am not sure if I fully understand the subject but this line seems wrong. Gtk's doc uses |
59cbb3a
to
482d8ef
Compare
glib::ffi::g_free(properties as *mut _); | ||
let first_prop = first_prop.assume_init() + 1; | ||
|
||
set_first_prop(instance_type, first_prop as usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice hack for the properties :)
gio/src/subclass/action.rs
Outdated
_pspec: &glib::ParamSpec, | ||
) -> Option<glib::Value> { | ||
let type_: glib::Type = self.obj().type_(); | ||
let property = ActionProperty::from_type(type_, prop_id)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you pass in Self::type_()
here then you don't need to do all the parent type walking inside from_type()
and always have directly the correct type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I've found in GtkEditable
's code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bilelmoussaoui Why does it do things so complicated, do you remember? :)
gio/src/subclass/action.rs
Outdated
let instance = &*(actionptr as *mut T::Instance); | ||
let imp = instance.imp(); | ||
|
||
if let Some(parameter_type) = imp.parameter_type() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be moved into the set_qdata()
call. Now you'd get inconsistent behaviour if the function returns Some
on the first call and None
afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not directly forbidden by Gio's docs, but I think it could be insane if the type of a parameter would change during the action's lifetime.
A similar assumption is made in ActionGroup
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal approach here would be to either only call the function once to don't give the user a chance to do it wrong, or otherwise at least to add an assertion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this and other places (name
, parameter_type
and state_type
) in the way that the function is called once.
bef560a
to
ecae6f6
Compare
ecae6f6
to
066dd78
Compare
Closes #1636