Skip to content
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

Partial properties generation #640

Merged
merged 2 commits into from Sep 28, 2018
Merged

Conversation

EPashkin
Copy link
Member

Part of #639 and #510

cc @GuillaumeGomez, @sdroege

IMHO needed other name instead "object.property.generate", maybe for PropertyGenerateFlags too.

WIP as I don't like current parser implementation and try to rework it.

README.md Outdated
@@ -189,6 +189,12 @@ cfg_condition = "mycond"
name = "baseline-position"
version = "3.10"
ignore = true
[[object.property]]
name = "events"
# generate only `connect_property_notify_event`, without `get_property_events` and `set_property_events`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be connect_property_notify_eventS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange, but is not:

    fn connect_property_notify_event<F: Fn(&Self, &gdk::EventProperty) -> Inhibit + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self, &gdk::EventProperty) -> Inhibit + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "property-notify-event",
                transmute(property_notify_event_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it dark magic haha.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You was right, I looked to wrong function: connect_property_events_notify

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah now it seems more logical! (And explain why I couldn't find it...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO needed other name instead "object.property.generate", maybe for PropertyGenerateFlags too.

generate seems fine to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, forgot to answer this question: seems fine to me as well.

@GuillaumeGomez
Copy link
Member

Seems good to me. Thanks a lot for adding it!

README.md Outdated
name = "events"
# generate only `connect_property_events_notify`, without `get_property_events` and `set_property_events`
# supported values: "get", "set", "notify",
# also supported union "get|set" and inverting "not(notify)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated that we even need nom? :)

I would simply list the things that should be generated. What is the use-case of negations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 3 only cases not really unusable, I was do it automatically.
Maybe better only support union with simple list splitting and parsing.
I also thought that we need other generate flags in future (for signal), but seems I mixed up with something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes better just have a list :)

@EPashkin
Copy link
Member Author

Changed expression parsing

README.md Outdated
name = "events"
# generate only `connect_property_events_notify`, without `get_property_events` and `set_property_events`
# supported values: "get", "set", "notify", also allowed union "get|set"
generate = "notify"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a toml list of strings?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need accept both array and single value: too much work on Toml types,
and only array IMHO redundantly.
Can change if @GuillaumeGomez prefer array too.

@sdroege
Copy link
Member

sdroege commented Sep 26, 2018

Looks good to me otherwise

@EPashkin
Copy link
Member Author

@GuillaumeGomez Which config format for flags you prefer:
generate="get|set" or generate=["get","set"]?

@GuillaumeGomez
Copy link
Member

I have a preference for generate=["get","set"].

@EPashkin
Copy link
Member Author

Ok, then I do it tomorrow

@EPashkin
Copy link
Member Author

Updated

@EPashkin EPashkin changed the title WIP: Partial properties generation Partial properties generation Sep 27, 2018
let name_for_func = nameutil::signal_to_snake(&name);
let var_name = nameutil::mangle_keywords(&*name_for_func).into_owned();
let get_func_name = format!("get_property_{}", name_for_func);
let set_func_name = format!("set_property_{}", name_for_func);
let check_get_func_name = format!("get_{}", name_for_func);
let check_set_func_name = format!("set_{}", name_for_func);

let mut readable = prop.readable;
let mut readable = prop.readable && generate.contains(PropertyGenerateFlags::GET);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably warn if GET is configured but the property is write-only (and same for writable)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

@sdroege
Copy link
Member

sdroege commented Sep 27, 2018

Seems good to me except for some cosmetic detail #640 (review)

@EPashkin
Copy link
Member Author

Added commit with warning

@EPashkin
Copy link
Member Author

Maybe it need be error for faster detection

@sdroege
Copy link
Member

sdroege commented Sep 27, 2018

Fine with me either way :) Thanks!

@EPashkin
Copy link
Member Author

Then I merge it

@EPashkin EPashkin merged commit 9790f3c into gtk-rs:master Sep 28, 2018
@EPashkin EPashkin deleted the partial_properties branch September 28, 2018 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants