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

Add the button pressed to some signals in Tree #47665

Merged
merged 1 commit into from
May 24, 2022

Conversation

trollodel
Copy link
Contributor

@trollodel trollodel commented Apr 6, 2021

Supersedes #46588
Based on this comment

This PR replaces most rmb (some can't be changed easily due to dependencies with key events) signals with a mouse_button_index parameter.

Changes:

  • button_pressed(TreeItem item, int column, int id) -> button_clicked(int mouse_button_index, TreeItem item, int column, int id)
  • empty_rmb(Vector2 position) -> empty_clicked(Vector2 position, int mouse_button_index)
  • empty_tree_rmb_selected(Vector2 position) -> void
  • item_rmb_edited() -> custom_item_clicked(int mouse_button_index)
  • item_rmb_selected(Vector2 position) -> item_mouse_selected(Vector2 position, int mouse_button_index)

Note: I prefer to wait a review on the signal changes before changing the affected editor code (and fix docs).
EDIT: The signals names were adapted as requested (to be consistent with #59720 changes), and the empty_tree_rmb_selected signal was removed, as discussed here.

@akien-mga
Copy link
Member

As we discussed in a PR review meeting, the proposed changes here make sense. We just need to make sure that we harmonize the API to be similar between Tree and ItemList, the latter being changed in #59720 (so you're welcome to also participate in reviewing #59720 to make sure that the signal names we implement make sense for Tree too).

@trollodel trollodel force-pushed the tree_more_buttons_signals branch 3 times, most recently from b676172 to 441de7b Compare April 9, 2022 08:29
@trollodel trollodel requested review from a team as code owners April 9, 2022 08:29
@trollodel trollodel force-pushed the tree_more_buttons_signals branch from 441de7b to 0719e85 Compare April 9, 2022 08:29
@KoBeWi
Copy link
Member

KoBeWi commented May 11, 2022

button_mouse_clicked

We decided to remove the mouse part, so it should be button_clicked

item_edit_mouse_clicked

This name is awkward. Something like item_mouse_edited would be better.
Although that can be confused with item_edited, which is completely different signal. This one seems to be emitted on cells in custom mode. Maybe something like custom_item_clicked?

EDIT:
I noticed there is item_rmb_selected signal. Should be changed to item_mouse_selected or similar and pass mouse button.

doc/classes/Tree.xml Outdated Show resolved Hide resolved
doc/classes/Tree.xml Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
}

if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) {
// make sure in case of wrong reference after reconstructing whole TreeItems
Copy link
Member

@KoBeWi KoBeWi May 11, 2022

Choose a reason for hiding this comment

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

Suggested change
// make sure in case of wrong reference after reconstructing whole TreeItems
// Make sure in case of wrong reference after reconstructing whole TreeItems.

(also the sentence is a bit unclear. Make sure what?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This block was moved and that comment was already there. I can change it as you suggested if you want.

Comment on lines 3902 to 3914
if (p_lmb) {
if (p_mouse_index == MouseButton::NONE) {
emit_signal(SNAME("item_edited"));
} else {
emit_signal(SNAME("item_rmb_edited"));
emit_signal(SNAME("item_edit_mouse_clicked"), p_mouse_index);
}
Copy link
Member

Choose a reason for hiding this comment

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

From the old code it seems like both signals were for mouse clicks, p_lmb was just for the left click. It's ok to divide it like that, but the method doesn't properly get the mouse buttons (e.g. clicking a checkable item doesn't emit the mouse clicked signal, because it calls item_edited() without the last argument).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with item_edited is that it's not always called from a mouse event, but may come from a keyboard event or even an event that was fired outside Tree (for both, Tree::_text_editor_submit is an example). Maybe I can propagate the mouse button when it's known, but it won't be really consistent or predictable (because it depends on how the user use the Tree).

Copy link
Member

Choose a reason for hiding this comment

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

No I mean e.g. here:

				if (force_edit_checkbox_only_on_checkbox) {
					if (x < cache.checked->get_width()) {
						p_item->set_checked(col, !c.checked);
						item_edited(col, p_item);
					}
				} else {
					p_item->set_checked(col, !c.checked);
					item_edited(col, p_item);
				}

This is done in response to mouse click, but you aren't passing the mouse button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick pass where item_edited is used and added the mouse button where possible.

@KoBeWi
Copy link
Member

KoBeWi commented May 11, 2022

I checked the changes and they are an improvement, but tbh the Tree API is so bad that it would need much bigger rework. This could be good to merge as a start though.

@trollodel trollodel force-pushed the tree_more_buttons_signals branch from 0719e85 to 265f6ec Compare May 11, 2022 18:39
@trollodel trollodel requested review from a team as code owners May 11, 2022 18:39
@trollodel trollodel changed the title WIP: Add the button pressed to some signals in Tree Add the button pressed to signals in Tree May 11, 2022
@trollodel trollodel changed the title Add the button pressed to signals in Tree Add the button pressed to some signals in Tree May 11, 2022
@trollodel
Copy link
Contributor Author

I noticed there is item_rmb_selected signal. Should be changed to item_mouse_selected or similar and pass mouse button.

Done, but now there is overlaps between item_mouse_selected and item_selected. I can't get rid of item_selected because it handles keyboard actions too.

@trollodel trollodel force-pushed the tree_more_buttons_signals branch from 265f6ec to f09560f Compare May 21, 2022 15:04
@trollodel trollodel force-pushed the tree_more_buttons_signals branch from f09560f to 307427a Compare May 21, 2022 15:17
@KoBeWi
Copy link
Member

KoBeWi commented May 21, 2022

Sorry, but I was actually wrong about custom_item_clicked signal :/ It's emitted on any cell type that supports editing.
item_mouse_edited would be a better name.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

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

In any case, the changes look good now.

Tree actually needs much more work. We should look into all signals and methods and evaluate what should be changed/removed, as the class just tries to do too many things at once. I'm going to make a proposal about it.

@akien-mga
Copy link
Member

Thanks!

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.

5 participants