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

Try to add comment filter for search in event list #1398

Merged
merged 12 commits into from Feb 1, 2020

Conversation

Bouh
Copy link
Collaborator

@Bouh Bouh commented Jan 26, 2020

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 ?

@4ian
Copy link
Owner

4ian commented Jan 26, 2020

That's a good start but there are misconceptions about what an event is :)
The idea is:

  • You add a method to the gd::BaseEvent class (Event.h) (which is the base class from which all events are deriving) that is there to extract the strings from an event. By default, just return an empty list.
  • You redefine this method in the CommentEvent to returns the strings that are the comments.
  • In the class doing the search, you're iterating on events and calling the method to extract the strings for all events (most events will nothing, but comments will return the comments content). for each event, you iterate on this list and do the search in these strings.

@4ian
Copy link
Owner

4ian commented Jan 26, 2020

something like GetEvent() is not a member of baseEvent

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);
Copy link
Collaborator Author

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.

Copy link
Owner

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;

Core/GDCore/Events/Event.h Show resolved Hide resolved
Core/GDCore/Events/Builtin/CommentEvent.cpp Outdated Show resolved Hide resolved
@Bouh
Copy link
Collaborator Author

Bouh commented Jan 28, 2020

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") {
Copy link
Owner

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()) {
Copy link
Owner

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.

Copy link
Owner

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,
Copy link
Owner

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

@4ian
Copy link
Owner

4ian commented Jan 28, 2020

Write c++ code when i didn't read one tutorial about it is not a good idea lol.

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 :)
For example, in C++ variables can be passed by value (Car myCar - this copies myCar in memory), reference (Car & car, this does not copy in memory), const-reference (const Car& car, this does not copy in memory and forbid you to change the object) or pointer (Car* car) - though pointer are avoided as much as possible because they can be null.
In JavaScript, all objects and arrays are passed as... reference. But primitive types (boolean, number, strings) are copied (passed by "value").

@Bouh
Copy link
Collaborator Author

Bouh commented Jan 30, 2020

There are problems
If I understand :

  • GetAllSearchableStrings() shouldn't be define in EventsRefectorer at all only in BaseEvent & CommentEvent
  • SearchStringInComments() is now missing in EventsRefectorer O.o

When i get stringsVectors from
vector<gd::String> stringsVectors = events[i].GetAllSearchableStrings();
I need to loop on each string in stringsVectors and pass one string to the missing SearchStringInComments() ?

SearchStringInComments() should be define in EventsRefectorer.cpp & .h ?

I think 'ive mix SearchStringInComments() and GetAllSearchableStrings()

@@ -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);
Copy link
Owner

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) {
Copy link
Owner

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();
Copy link
Owner

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(
Copy link
Owner

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,
Copy link
Owner

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,
Copy link
Owner

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) {
Copy link
Owner

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

Core/GDCore/IDE/Events/EventsRefactorer.cpp Show resolved Hide resolved
@4ian
Copy link
Owner

4ian commented Jan 30, 2020

GetAllSearchableStrings() shouldn't be define in EventsRefectorer at all only in BaseEvent & CommentEvent

Yes

When i get stringsVectors from
vectorgd::String stringsVectors = events[i].GetAllSearchableStrings();
I need to loop on each string in stringsVectors and pass one string to the missing SearchStringInComments() ?

No, this method will take care of iterating. Just pass it the event.

SearchStringInComments() should be define in EventsRefectorer.cpp & .h ?

Yes, everything that is in a cpp file must be in the .h

I think 'ive mix SearchStringInComments() and GetAllSearchableStrings()

Yes 😄Think like this:

  • GetAllSearchableStrings is something that is in the BaseEvent (the common basis for all events) (and it's redefine by CommentEvent, but we don't need to know that). It has on role, which is "When I call you, you give me all the texts of the event please."
  • SearchStringInComments is a helper method. It's role: "When I call you, I'll pass you an event and a string called search (plus a few other things that you might not use, like the project). Please tell me (by sending me true or false) if the event contains the search".
    • To do this, this method has to ask the event "can you please give me all the texts that you have??"... and good news, we just made a method for that! It's called GetAllSearchableStrings and it's available on all events! So we don't event care what kind of event we're dealing with :)

@Bouh
Copy link
Collaborator Author

Bouh commented Jan 31, 2020

It's works !
Before merging this one, can i add rename Comments filter by Comments&Groups ?
Or i create a new button for Groups ?
Also Filter by is fine, if you prefer Search by i can replace it ^^

@Bouh
Copy link
Collaborator Author

Bouh commented Jan 31, 2020

I need just add and adapt GetAllSearchableStrings() in GroupEvent .cpp and .h :)

@Bouh
Copy link
Collaborator Author

Bouh commented Jan 31, 2020

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.

@4ian
Copy link
Owner

4ian commented Jan 31, 2020

Also Filter by is fine, if you prefer Search by i can replace it ^^

"Search in" would be good - we're doing a search in events, and precisely in some part of them :)

I need just add and adapt GetAllSearchableStrings() in GroupEvent .cpp and .h :)

Yes that looks good! :)

Before merging this one, can i add rename Comments filter by Comments&Groups ?

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).
Also clean the code that is commented and should be good :)

@4ian
Copy link
Owner

4ian commented Feb 1, 2020

Seems like we're almost there 👍

@4ian 4ian added the 🏁PR almost ready: final fixes The PR is almost ready and needs final fixes and/or polishing before merge label Feb 1, 2020
@Bouh
Copy link
Collaborator Author

Bouh commented Feb 1, 2020

Next option will be search in expressions and search bar will be complete!
In a next PR later.

@4ian 4ian merged commit ce4fdbe into 4ian:master Feb 1, 2020
@4ian
Copy link
Owner

4ian commented Feb 1, 2020

Thanks for working on this 👍👍
Will be very useful for searching in large events sheets.

@Bouh
Copy link
Collaborator Author

Bouh commented Feb 1, 2020

Thanks for the help! 🐱‍💻

@Bouh Bouh deleted the search_in_comments branch February 1, 2020 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏁PR almost ready: final fixes The PR is almost ready and needs final fixes and/or polishing before merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants