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

connect! with TreeSelection #50

Closed
credmp opened this issue Jul 12, 2017 · 2 comments
Closed

connect! with TreeSelection #50

credmp opened this issue Jul 12, 2017 · 2 comments
Labels

Comments

@credmp
Copy link

credmp commented Jul 12, 2017

Hi,

This might be a dumb question, but based on the examples and documentation I couldn't figure it out, so I am hoping you can help me.

I have a widget which contains a gtk::TreeView. Of course I want something to happen when you select and item in the view, so I created the following code in the view():

let left_selection = left_tree.get_selection();
connect!(relm, left_selection, connect_changed(treesel), {
    let (left_model, iter) = treesel.get_selected().unwrap();
    let value = left_model.get_value(&iter, 0).get::<String>().unwrap();
    println!("connect! Value: {}", value);
    Open(value)
});

Which correctly prints out the "connect!" line to the console when clicked, but the Open(value) event is not sent to/received by the update function:

fn update(&mut self, event: Msg, _model: &mut Model) {
    println!("Update!");
    match event {
        Open(path) => {
              println!("Path {} was selected", path);
        }
        Closed => println!("Closed!"),
    }
}

Neither the "Update!" not the "Path.." string get printed.

Any ideas as to why the event is triggered, but the message is not sent to the update function?

@antoyo
Copy link
Owner

antoyo commented Jul 13, 2017

I think you don't save your widget in a variable or a struct.
Here is how you do that.
The problem, I think, is that: if you don't save the relm widget somewhere, the communication channel will be closed when the widget is dropped, and the update() method won't be called.

This is one design issue with relm that I want to fix.
So, this is not a dumb question at all: this issue happened to me a few days ago and I really want to provide a way to avoid that.

If this is not the issue, please provide a complete code example.

By the way, in the feature/futures-glib branch, I added support for event on "child" widget, which will allow you to connect the selection changed event of a TreeView with the view! macro. See this example.

@antoyo antoyo changed the title connect! with TreeSelection (question) connect! with TreeSelection Jul 13, 2017
@credmp
Copy link
Author

credmp commented Jul 13, 2017

You were spot on! Adding the component to the Win struct made the messages work like a charm.

The improvements to the views that you are doing look like a great step forward! When I have my project up and running (just getting the hang of it up to now) I will surely check it out, I will have a more balanced view on the do's and don'ts of the library.

Thanks! I will close the issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants