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
Try to add comment filter for search in event list #1398
Conversation
That's a good start but there are misconceptions about what an event is :)
|
This means "You try to call GetEvent() on something, but this something is a gd::BaseEvent, and I can't find any method called GetEvent". So this means that you already have an event :) No need then to call GetEvent(), because you already have one ;) |
virtual std::vector<const gd::EventsList*> GetAllCommentsVectors() const; | ||
virtual std::vector<gd::EventsList*> GetAllCommentsVectors(); | ||
virtual std::vector<const gd::String*> GetAllSearchableStrings(BaseEvent &event) const; | ||
virtual std::vector<gd::String*> GetAllSearchableStrings( BaseEvent &event); |
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.
Not sure here i guess there are mistakes in and after parenthesis.
I guess also one of them should return the vector of string ?
I didn't understand why two similar lines. with Const and without.
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.
As said in another comment:
The one that is const
will tell the compiler "please check that the object is not modified". It also tell the compiler "allow me to call this method on a const object". If you do:
class A {
void methodNonConst();
void methodThatIsConst() const;
}
then you can do:
void someOtherFunction(const A &a) { // Here I say "I take a reference to A, and I won't modify it"
a.methodNonConst(); // NOT allowed, compiler will reject it. You're trying to modify the object it seems!
a.methodThatIsConst(); // Fine! Nothing will be modified
}
Note that if you pass just a reference, there is no difference:
void someOtherFunction(A &a) { // Here I say "I take a reference to A, and I maybe modify it"
a.methodNonConst(); // Allowed. The object might be modified
a.methodThatIsConst(); // Also allowed!
}
This is called "const-correctness": https://www.cprogramming.com/tutorial/const_correctness.html
(don't try to understand everything at first)
You also need only one method here (which can be const as not changing anything):
virtual std::vector<gd::String> GetAllSearchableStrings() const;
Write c++ code when i didn't read one tutorial about it is not a good idea lol. |
gd::String search, | ||
bool matchCase) { | ||
// See later for "BuiltinCommonInstructions::Group" when Comment works | ||
if (event.GetType() == = "BuiltinCommonInstructions::Comment") { |
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.
No need for this: GetAllSearchableStrings is a method that was added in BaseEvent
, meaning that all the events now have it!
And it's overriden by CommentEvent, but this method does not care who is overriding it.
If in the future, some events is redefining GetAllSearchableStrings, this will work without any changes.
So you can remove this if (also, no triple equal in C++, just ==)
bool matchCase) { | ||
// See later for "BuiltinCommonInstructions::Group" when Comment works | ||
if (event.GetType() == = "BuiltinCommonInstructions::Comment") { | ||
for (gd::String str : events[id].GetAllSearchableStrings()) { |
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.
Seems like you forgot to iterate on events
. events
is an gd::EventsList
, which, like the name indicates, is a "list", almost an array.
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.
Add the missing for, and this can be just:
for (gd::String str : event.GetAllSearchableStrings()) {
if I suppose you named "event" the "gd::BaseEvent" variable that you will get with "GetEvent(index)" on events
@@ -202,6 +203,11 @@ class GD_CORE_API EventsRefactorer { | |||
gd::InstructionsList& conditions, | |||
gd::String search, | |||
bool matchCase); | |||
static bool GetAllSearchableStrings(gd::ObjectsContainer& project, |
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.
You will have to change Bindings.idl to expose this new parameter to JavaScript
Hopefully these changes are specific enough so that you can do without.. but surely a good idea to get a quick tutorial or two about C++. Will be interesting to see concepts that don't exist in JS and will surely remind you of stuff that you've seen in JS :) |
There are problems
When i get
I think 'ive mix |
GDevelop.js/Bindings/Bindings.idl
Outdated
@@ -1528,7 +1528,8 @@ interface EventsRefactorer { | |||
void STATIC_RenameObjectInEvents([Const, Ref] Platform platform, [Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString oldName, [Const] DOMString newName); | |||
void STATIC_RemoveObjectInEvents([Const, Ref] Platform platform, [Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString name); | |||
void STATIC_ReplaceStringInEvents([Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString toReplace, [Const] DOMString newString, boolean matchCase, boolean inConditions, boolean inActions); | |||
[Value] VectorEventsSearchResult STATIC_SearchInEvents([Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString search, boolean matchCase, boolean inConditions, boolean inActions); | |||
[Value] VectorEventsSearchResult STATIC_SearchInEvents([Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString search, boolean matchCase, boolean inConditions, boolean inActions, boolean inComments); | |||
[Value] VectorEventsSearchResult STATIC_GetAllSearchableStrings([Ref] ObjectsContainer project, [Ref] ObjectsContainer layout, [Ref] EventsList events, [Const] DOMString search, boolean matchCase); |
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.
You dont' need this line - and there is no "GetAllSearchableStrings" in EventsRefactorer, why adding it? :)
if (inComments) { | ||
vector<gd::String> stringsVectors = events[i].GetAllSearchableStrings(); | ||
|
||
for (std::size_t j = 0; j < stringsVectors.size(); ++j) { |
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.
Iterating here is doable, but then you iterate also in SearchStringInComments... you have to choose where! :)
Remove this loop
@@ -631,6 +632,21 @@ vector<EventsSearchResult> EventsRefactorer::SearchInEvents( | |||
} | |||
} | |||
|
|||
if (inComments) { | |||
vector<gd::String> stringsVectors = events[i].GetAllSearchableStrings(); |
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.
You're already doing this in SearchStringInComments, you can remove that
|
||
for (std::size_t j = 0; j < stringsVectors.size(); ++j) { | ||
if (!eventAddedInResults && | ||
SearchStringInComments( |
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.
Pass just the event, not a string:
project, layout, events[i], search, matchCase
@@ -711,6 +728,24 @@ bool EventsRefactorer::SearchStringInConditions( | |||
return false; | |||
} | |||
|
|||
bool EventsRefactorer::SearchStringInComments(gd::ObjectsContainer& project, |
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.
Rename this to SearchStringInEvents
There is no notion of "comments" here. The strings might be in the future strings coming from somewhere else... sure for now only comments have strings, but that's a coincidence :)
@@ -711,6 +728,24 @@ bool EventsRefactorer::SearchStringInConditions( | |||
return false; | |||
} | |||
|
|||
bool EventsRefactorer::SearchStringInComments(gd::ObjectsContainer& project, | |||
gd::ObjectsContainer& layout, | |||
gd::EventsList& events, |
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.
Pass a gd::BaseEvent& event
. You don't need to pass a list of event, just the event where to search in.
gd::EventsList& events, | ||
gd::String search, | ||
bool matchCase) { | ||
for (gd::BaseEvent event : events) { |
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.
No need to iterate, just pass the event.
You can remove this loop
Yes
No, this method will take care of iterating. Just pass it the event.
Yes, everything that is in a cpp file must be in the .h
Yes 😄Think like this:
|
It's works ! |
I need just add and adapt GetAllSearchableStrings() in GroupEvent .cpp and .h :) |
Uumh a group is also a comment field in the IDE, so i get name from group event, and com from comment event, both on same filter option. |
"Search in" would be good - we're doing a search in events, and precisely in some part of them :)
Yes that looks good! :)
In the UI yes - but we'll run out of place I'm afraid? In the code, instead of "inComments", name the parameter "inEventStrings" to be explicit that this is not only comments (and not only groups, can be any event with a string). |
adb343b
to
cfd2bb4
Compare
cfd2bb4
to
eb2504b
Compare
Seems like we're almost there 👍 |
Next option will be search in expressions and search bar will be complete! |
Thanks for working on this 👍👍 |
Thanks for the help! 🐱💻 |
I feel like I'm not far from the solution.
As I don't know C++ I looked at the other functions and I reproduced what I understood from them.
I don't know how to debug a variable, it would have helped me to know where I am and the state of my values, or at least their structure.
I think I'm in gd::CommentEvent, but according to errors during compilation I'm mostly in the parent class gd::BaseEvent ?