Author Topic: UI for project globs aka automatic source directories  (Read 14253 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
UI for project globs aka automatic source directories
« on: February 04, 2023, 12:14:53 am »
Hi,
today i pushed (r13191) a UI for project globs aka automatic source directories.
This adds
+ an UI for the user to easy enter directories and specify if they should be added recursively and with file masks (found under the menu Project->Automatic source paths)
+ a logic based on wxFileSystemWatcher that watches the above added directories for file changes and adds and removes the file as they are added and removed from the file system
+ a rudimentary script binding

BEWARE: this changes behaviour of old file globs, that was only accessible when editing the project file directly.
The old implementation (loading the directories only on project load, and not adding them in the project file directly) made problems with code completion and compiler settings ecc...
I think this implementation is a lot better, but it changes the project file every time a file is added in the directory (as a makefile would).

i worked for this a while ago, obfuscated made some reviews and was ok with it, but because the wxFileSystemWatcher was not available on all platforms in wx2.8 this work was lost. Now that we are on wx3.0 a was thinking to add this to trunk.
Any comments are welcome.
thank you!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1591
Re: UI for project globs aka automatic source directories
« Reply #1 on: February 04, 2023, 10:51:44 am »
I get this warnings/errors when trying to compile in MSW-32 bits:
Code
projectfile.h||In constructor 'ProjectFile::ProjectFile(cbProject*)':|
projectfile.h|237|warning: 'ProjectFile::project' will be initialized after [-Wreorder]|
projectfile.h|195|warning:   'GlobId ProjectFile::globId' [-Wreorder]|
projectfile.cpp|26|warning:   when initialized here [-Wreorder]|

projectmanagerui.o||In function `ZN16ProjectManagerUI13OnManageGlobsER14wxCommandEvent':|
C:\Codeblocks\src\src\projectmanagerui.cpp|1657|undefined reference to `ManageGlobsDlg::ManageGlobsDlg(cbProject*, wxWindow*, int, wxPoint const&, wxSize const&)'|
C:\Codeblocks\src\src\projectmanagerui.cpp|1657|undefined reference to `ManageGlobsDlg::~ManageGlobsDlg()'|
C:\Codeblocks\src\src\projectmanagerui.cpp|1657|undefined reference to `ManageGlobsDlg::~ManageGlobsDlg()'|
The undefined references appear because you added the new files to all projects but CodeBlocks_wx32.cbp. I have attached a patch for this part.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #2 on: February 04, 2023, 04:44:11 pm »
Thank you! Fixed in trunk

Offline gd_on

  • Lives here!
  • ****
  • Posts: 799
Re: UI for project globs aka automatic source directories
« Reply #3 on: February 11, 2023, 07:50:24 pm »
I tried to understand how this "globs" work, how I could eventually use them, and how I can translate the few items.
Until now, no real success.
Could you give us some examples or better add them and a detailed description in the CB wiki (Then, I will be able to add this in the documentation).
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.5 (tests with 3.3), Msys2 Compilers 14.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #4 on: February 11, 2023, 09:31:37 pm »
Quick and dirty wiki article...
i do not know how to describe it better:
https://wiki.codeblocks.org/index.php/Automatic_source_paths

Offline gd_on

  • Lives here!
  • ****
  • Posts: 799
Re: UI for project globs aka automatic source directories
« Reply #5 on: February 12, 2023, 10:10:19 am »
Thanks. It's more clear.
I still have a problem to find an equivallent word for "glob" in french. I don't think that "global' is good. If somebody has an idea ... You can set a translation directly in lauchpad.
« Last Edit: February 12, 2023, 10:12:29 am by gd_on »
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.5 (tests with 3.3), Msys2 Compilers 14.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #6 on: February 12, 2023, 05:47:52 pm »
I think we should remove the word "glob" from the user perspective... I think "automatic source folder" is a better (but no perfect) naming for user. Glob is only used internally, because of historic reasons....

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5504
Re: UI for project globs aka automatic source directories
« Reply #7 on: February 13, 2023, 08:11:33 am »
My point of view is, that the project file is like a make file. You have to modify a makefile if you add source files to be able to build it.
If you do not add them to the project we have some problems:
1) you can not modify properties of them: Only build with certain build targets ecc.
2) I had other problems with the old implementation, i can not remember any more exactly (it is a 3 years), i think code completion did not work correctly...

We have discussed this with the problems of the original implementation here: http://forums.codeblocks.org/index.php/topic,22783.msg154862/topicseen.html

My opinion on this: This feature was never/seldom used by user before, because it had no ui/documentation. So the risk of breaking some project files is minimal. I also pointed this out in the announcement post (https://forums.codeblocks.org/index.php/topic,25276.0.html). Now it has UI and documentation and we can expect it to be used... I for example need it for an upcoming plugin i currently am working on...
If you are absolutely against this implementation i can try to look into it and add some flag for old and new behavior?

I will look into the problems with the ids. Thank you for testing and pointing it out.


When I created this feature, long time ago, the intention is to mimic the glob feature of cmake. We have been relying on this feature extensively, and indeed it is not documented, since one needs to know how to use it, it has limitations, eg when new file is added, one needs to reload the project  to pick up the new files. Code completion works, but not always, but with the old code completion plug-in it also worked like this, sometimes yes, sometimes no, but I can indeed think with this glob it is a bit worse.


Now that said, the cmake world is also no longer in favor of their glob feature (it also has some problems), and want sources to be explicitly added. Which we could translate to CB as :
  • we also don't want this feature
  • we remove both new and old behavior
  • we keep the old behavior as is for backwards compatibility

I do think we need to keep the old behavior for backwards compatibility, since it was there to mimic cmake glob (and then you also did not have to touch the CMakeLists.txt anymore), this needs to be re-instated, because overhere everything is now collapsing.

So please provide the old way, and when the new way is wanted, have CB add per directory an extra flag to say new behavior (old behavior should need no changes to be made by the user), absence of this flag means old behavior.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5504
Re: UI for project globs aka automatic source directories
« Reply #8 on: February 15, 2023, 08:28:06 am »
any fixes coming up ?

I also note other strange behaviors, not sure due to this topic, but when I save files that were adjusted, they save and then they auto close.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #9 on: February 15, 2023, 09:43:18 am »
I work on it. The earliest i can do is this weekend...


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #10 on: February 15, 2023, 11:21:25 am »
Is it also not desired, that the globs get automatically reloaded when new files are added in the directory? So no automatic reloading?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5504
Re: UI for project globs aka automatic source directories
« Reply #11 on: February 15, 2023, 05:37:25 pm »
Is it also not desired, that the globs get automatically reloaded when new files are added in the directory? So no automatic reloading?

I think this would be a very welcome addition.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1591
Re: UI for project globs aka automatic source directories
« Reply #12 on: February 15, 2023, 06:18:05 pm »
After commiting this feature files can't be removed from projects (I am not using globs). See this forum thread.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #13 on: February 16, 2023, 10:40:20 pm »
Quote
After commiting this feature files can't be removed from projects (I am not using globs). See this forum thread.
fixed in trunk

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: UI for project globs aka automatic source directories
« Reply #14 on: February 17, 2023, 12:57:07 am »
I have a working test here: https://github.com/bluehazzard/codeblocks_sf/tree/fix/globs/fix_not_add_to_prj/1

@killerbot: can you test it?

Be aware:
*) I found out, that i have to add some option to add globs only to certain targets, so first work for this is in this commit also, but not functional at the moment.
*) I have not looked at the Ids yet.
*) I have added a checkbox  "Add to project" in the globs settings. This naming is not right and i will rename it in "Add files to project file". If you create a new glob this will be set by default. If you load a glob from a project file with this option not present it will be deactivated.

More work on the weekend...


[Edit:] I also saw that the comments in project file are not right...