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

Added ability for escape key to close editing box in Value column in the Parameters panel #2455

Merged
merged 24 commits into from Dec 21, 2021

Conversation

nickleus27
Copy link
Contributor

#2411

I added changes in cellrenderer_value.cpp. I added the on_key_press_event method to check for escape key and call on_editing_done(). I also had to add the signal_key_press_event() for the value widget.

@ice0 @rodolforg Hey guys can you check out these changes? Thanks again for all the advice to get me started.

@ice0
Copy link
Collaborator

ice0 commented Dec 10, 2021

@nickleus27
Works like a charm!
Ready to merge, but I want Rodolfo's review of this PR, maybe he has some ideas.

ice0
ice0 previously approved these changes Dec 10, 2021
@nickleus27
Copy link
Contributor Author

@ice0 Thank you. Sounds good.

Copy link
Contributor

@rodolforg rodolforg left a comment

Choose a reason for hiding this comment

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

It was a nice trick to simply prevent to call activate.

But somehow I think it should set property_editing_canceled to true before finish editing.
As I'm not sure about it, let it be :)

synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp Outdated Show resolved Hide resolved
@nickleus27
Copy link
Contributor Author

@rodolforg Yes, I think you are right. property_editing_canceled should be set to true. I will work on that and fix the change you requested.

@ice0
Copy link
Collaborator

ice0 commented Dec 11, 2021

It was a nice trick to simply prevent to call activate.

Where?

@nickleus27
Copy link
Contributor Author

nickleus27 commented Dec 11, 2021

@rodolforg I am having some trouble getting bool property_editing_canceled to work. I am trying to connect on_editing_canceled() methods with signal_editing_canceled unsuccessfully. Both value_widget and value_entry say "no member named signal_editing_canceled" when I compile. Any advice?

@rodolforg
Copy link
Contributor

It's a CellRenderer signal. So, CellRenderer_ValueBase should implement it.
In fact, now I see it even has a on_editing_canceled() as a default handler!

@nickleus27
Copy link
Contributor Author

nickleus27 commented Dec 11, 2021

@rodolforg this is the error i am getting:
cellrenderer_value.cpp:699:16: error: no member named 'signal_editing_canceled' in 'studio::ValueBase_Entry' value_entry->signal_editing_canceled().connect(sigc::mem_fun(*this, &CellRenderer_ValueBase::on_value_editing_cancelled));

Not sure what I am doing wrong? ValueBase_Entry *value_entry; isn't that class a subclass of CellRenderer_ValueBase? Any help would be very much appreciated.

edit value_entry is a subclass of gtk::celleditable

@nickleus27
Copy link
Contributor Author

@ice0 @rodolforg Hey fellows, can you check these changes out when you have a chance. There is a problem with these changes for sure. When you escape a value entry more than once it produces this output error:

synfig(11949) [12:22:36] error: on_value_editing_canceled(): Called twice!

@rodolforg
Copy link
Contributor

rodolforg commented Dec 13, 2021

Maybe we should leave as you did before XD
Simpler and worked. I'm unsure about this property behavior now :P
I'm really sorry.

@nickleus27
Copy link
Contributor Author

@rodolforg No problem, I reverted back to previous solution. I enjoyed learning about on_editing_canceled(). I wish I could have gotten it to work properly. Nothing I tried seemed to work though.

@ice0
Copy link
Collaborator

ice0 commented Dec 16, 2021

Hi, guys!
I made a screenshot, just to show what is going on here.

First. Cell in Value row is CellRenderer_ValueBase : public Gtk::CellRendererText (docs)

It is not editable and is only used to display the cell value. But when you click on it, it emits a start_editing signal in which we can create a temporary editable cell (docs). This signal is not caught in Synfig code, instead of this overridden start_editing_vfunc is used here.

Screenshot_3

Next we creating editable cell ValueBase_Entry : public Gtk::CellEditable

value_entry = manage(new ValueBase_Entry());
value_entry->set_path(path);
value_entry->set_canvas(get_canvas());
value_entry->set_param_desc(get_param_desc());
value_entry->set_value_desc(get_value_desc());

This class is the place where we can catch keypresses and other events and should signal to the parent cell when editing is done or canceled. If editing is canceled then we should set property_editing_canceled() to true, so parent can check this property and handle the event correctly (it should call stop_editing(true) method). After that we should emit signal_editing_done().

I think the current implementation works as expected only because it just hides the widget without emitting signals.
For example if you change on_editing_done() to editing_done() as it should be, then the value will be changed even then you hit the Esc key.

To make it work correctly you need to set property_editing_canceled() in ValueBase_Entry and check this property in CellRenderer_ValueBase::on_value_editing_done.

@nickleus27
Copy link
Contributor Author

Thank you @ice0 ! I will work on this. :)

@nickleus27
Copy link
Contributor Author

@ice0 Am I understanding this correctly? I should keep on_key_press_event() where it is in class ValueBase_Entry? I added property_editing_canceled() = true; to on_key_press_event() and I am checking for it in CellRenderer_ValueBase::on_value_editing_done. I am having trouble with the stop_editing(true) and emitting signal_editing_done correctly. Every way I have tried so far does not work as expected.

@ice0
Copy link
Collaborator

ice0 commented Dec 17, 2021

@ice0 Am I understanding this correctly? I should keep on_key_press_event() where it is in class ValueBase_Entry?...

@nickleus27
Yes, this is correct. Just push your code, so I can check it.

@ice0
Copy link
Collaborator

ice0 commented Dec 18, 2021

@ice0 my code doesn't seem to be calling on_value_editing_done() when you press esc? Not sure what is missing.

Yes. on_value_editing_done() is called when signal_editing_done() is emitted.

value_entry->signal_editing_done().connect(sigc::mem_fun(*this, &CellRenderer_ValueBase::on_value_editing_done));

But Esc key handler doesn't emit signal, it's just calls on_editing_done() method.

if(key_event->keyval == GDK_KEY_Escape)
{
	...
	on_editing_done();

To emit signal_editing_done() signal you should use editing_done() method here(docs).

@nickleus27
Copy link
Contributor Author

nickleus27 commented Dec 18, 2021

@ice0 alright I think this is it. Thank you for being so patient. I had made this assumption that on_editing_done() should be emitting the signal_editing_done(), but that assumption was wrong. You had mentioned this a while ago, but I was reluctant to make sense of it.

@ice0
Copy link
Collaborator

ice0 commented Dec 19, 2021

@ice0 alright I think this is it. Thank you for being so patient.

You are welcome!

@nickleus27
Copy link
Contributor Author

@ice0 Yes, good idea! I like the idea of returning from on_value_editing_done if property_editing_canceled is true. Much cleaner and simpler.

ice0
ice0 previously approved these changes Dec 21, 2021
@ice0 ice0 requested a review from rodolforg December 21, 2021 02:51
rodolforg
rodolforg previously approved these changes Dec 21, 2021
Copy link
Contributor

@rodolforg rodolforg left a comment

Choose a reason for hiding this comment

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

In case of @ice0 doesn't think my comment is relevant, I let here my approval :)

synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp Outdated Show resolved Hide resolved
synfig-studio/src/gui/cellrenderer/cellrenderer_value.cpp Outdated Show resolved Hide resolved
@nickleus27 nickleus27 dismissed stale reviews from rodolforg and ice0 via d6c1df9 December 21, 2021 04:14
@rodolforg rodolforg requested a review from ice0 December 21, 2021 05:18
@rodolforg
Copy link
Contributor

Very nice and clean :)

@ice0 ice0 merged commit d5b4443 into synfig:master Dec 21, 2021
@ice0
Copy link
Collaborator

ice0 commented Dec 21, 2021

Merged. Thank you!

@nickleus27
Copy link
Contributor Author

@ice0 thank you

@nickleus27 nickleus27 deleted the esc_param_val branch December 24, 2021 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants