KeyWorksRW / wxUiEditor

RAD tool used to create and maintain wxWidgets UI elements.
Apache License 2.0
62 stars 5 forks source link

Local and system headers files project selector #1438

Open KeyWorksRW opened 3 months ago

KeyWorksRW commented 3 months ago

Discussed in https://github.com/KeyWorksRW/wxUiEditor/discussions/1434

Originally posted by **rossanoparis** March 12, 2024 It would be very helpful to add a way based on which the user should be able to add files without using "files selector". The current file selector, adds files making them relatives to wxUI project path, but in case I have to move a project from a folder to another all #includes directives referred to external libraries become messy, and it is an hard job make them tidy again. Generally speacking, #include directives for files which belong to a C++ projet can be expressed using their relative paths reffered to wxUI project and that's fine, but for files belonging to external libraries, they are often, in my case always, expressed using relative paths referred to directories defined in IDE tools such as VS, CodeLite, ecc ... Actually the user is able to get it only typing its own files directly into "local_hdr_includes" or "system_hdr_includes" fields. But as you can imagine, when such files are many, it is not confortable. As I see it, another button to add a string inserted by the user would be helpful also a resizable dialog would be useful. ![image](https://github.com/KeyWorksRW/wxUiEditor/assets/33904565/2288c0e6-049d-4a00-8c4b-33863e79bb2c)
KeyWorksRW commented 3 months ago

This is a custom dialog, so unless the same size/button configuration makes sense for all the locations it's used for, then it should get duplicated with a unique class name for System Header Files. That will ensure that the resizing is persistent.

Adding some smarts to a <Add Custom...> could also be helpful. E.g., walk up the directory tree to look for a CMakeLists.txt file, and if found look at the target_include_directories for lists of project-wide directories. Looking for c_cpp_properties.json for VSCode and the equivalent for VS might be useful as well, though less so given that the build system might not be aware of those directories. Just brainstorming, I'm envisioning a list of directories parsed out of a build system or properties that lists all the include directories for the project. Selecting one, would update a second list of all the header files (including subdirectories) in that location. So the user would first click the directory, then click the filename to add.

Edit

There are so many ways to specify an include directory with macros, lists, substitutions, etc. that there isn't any reasonable way to get the actual directory from CMakeLists.txt. Scratch that idea...

Getting it from an IDE also isn't practical because that assumes everyone working on the project file is using the same IDE with the same configuration.

With wxWidgets, files are added in source files as #include "wx/foo.h" which requires the build system to pass the location of the Include directory to the compiler. Even if wxWidgets was a submodule, I can't think of any way to persistently set that location in the project file that would still work if the folder containing the project file was move into any other folder that wasn't at exactly the same level.

Using wxWidgets as the model, I could have a dialog where the dev specifies the prefix such as "wx/generic" which would be stored in the project file and then specify the location of the root folder (Include in the wxWidgets case) which I could store on an individual basis. That would enable a file selector that would easily get to the correct directory, and could generate #include "prefix/foo.h" which would certainly save having to type out all the filenames, and would be immune to the location of the source or header file where the #include is generated.

KeyWorksRW commented 3 months ago

There are other issues revolving around header files, so adding the 1.2.2 milestone with the intention of putting all the header issues in the same milestone.

KeyWorksRW commented 3 months ago

Okay now that I have some time to actually work on this, I have questions. Taking the example of tkxLutEditorPanel.h, if you were editing the source file manually, how would you include this in a way that would work even if you moved that source file to a different directory? Is tkx.www.libraries/imgproc a subfolder that is under a folder you compile with something like -Iroot_include to get "root_include/tkx.www.libraries/imgproc/tkxLutEditorPanel.h"?

See the Edit section in the larger comment above about the way wxWidgets header files are included -- would something like that approach work better for you?

rossanoparis commented 3 months ago

@KeyWorksRW In my case the folder tkx.www.libraries/imgproc/tkxImageViewerPanel.h would be inserted by using system_hdr_includes attribute, which results in a line of code like #include <kx.www.libraries/imgproc/tkxImageViewerPanel.h>

<> symbols are used to include header files that are part of the standard library or other libraries installed in the system's include path. With angle brackets, the compiler searches for the file in predefined directories, such as system directories or directories specified with compiler options.

Actually I can't achive it as the editor you provide inserts always a relative path to the wxUI project. Instead, it is necessary to enable users to insert a header file using the editor while avoiding making it relative for both Local and system headers files.

As I see it, you should modify your dialog in this way, no more than this. That's why, in my picture above, I drew a new button with the sole purpose of inserting 'free text'

It is already possible, but it is necessary to modify directly local_hdr_includes and system_hdr_includes attributes, which is unconfortable if you have may files to insert.