Author Topic: Thinking about a wxSmith Clone Dialog Feature  (Read 862 times)

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 194
Thinking about a wxSmith Clone Dialog Feature
« on: May 30, 2024, 02:59:21 pm »
I'd love to have a wxSmith "Clone Dialog" function. Because very often it would be faster to remove unused stuff from an existing dialog than to create a new one from scratch.

Currently I am working in a project with a lot of dialogs so there would be plenty of choice for re-use. So I was thinking about how that could be done. Basic steps would be:

* Read from CBP file: CPP, H, WXS filenames for a given "OldClassName"
* Get a new "NewClassName" from User via dialog
* clone the project CPP and H and WXS file of the old dialog
* search and replace the OldClassName with NewClassName in the CPP, H, WXS files.
* add a new line in the CPB file's <wxsmith> section with the WXS, CPP, H, Classname.

Then somehow make CB be aware of the new files and wxSmith of the new WXS file to reload the Resource window list.
Probably not as simple as it sounds? Is that missing something?

I figured out how to add a menu items to a wxSmith tree. The next problem is to read and write a given line from/to the CBP file, but I could not figure that out yet. Any ideas?



Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1604
Re: Thinking about a wxSmith Clone Dialog Feature
« Reply #1 on: May 30, 2024, 04:32:53 pm »
You can look how wxSmith does it in the wxSmith->Add wxDialog menu.

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 194
Re: Thinking about a wxSmith Clone Dialog Feature
« Reply #2 on: May 30, 2024, 05:34:02 pm »
You can look how wxSmith does it in the wxSmith->Add wxDialog menu.
Great Tried that before but gave up as nobody seemed to had any refernces to wxNewWindowDlg. But now I found that its OnCreate() handler does have the logic

Code
  cbProject* cProject = m_pProject->GetCBProject();      // seems to get the project to add files to 

Then there is a larger Params structure set up used to create the target classes as a wxsFrameRes, a wxsDialogRes or wxPanelRes These classes are then added. In my case I would not do that because that must be parsed from the cloned source files.

Next the files seem to be added to the project. Not sure where the Targets come from - maybe its an interactive call.. Not sure if thats already writing it to the project file, but a "File/SaveAll"  should to that manually.
Code
 wxArrayInt vnTargets;               // I  guess build targets
 Manager::Get()->GetProjectManager()->AddFileToProject( strHeaderFilename, cProject, vnTargets );
 Manager::Get()->GetProjectManager()->AddFileToProject( strCppFilename, cProject, vnTargets );
 Manager::Get()->GetProjectManager()->AddFileToProject( strWxrFilename, cProject, vnTargets );
 Manager::Get()->GetProjectManager()->GetUi()->RebuildTree();

Then there is this section where I am not sure where that saves to. I an not sure I need that. At least the files were not written there. There are quire a few comments in the ConfigManager header but they do not tell what its supposed to do.
Code
 // save configuration
 ConfigManager* Cfg = Manager::Get()->GetConfigManager( "wxsmith" );
 Cfg->Werite( "/newresource/useinitfunc", m_InitFunc->GetValue() );
 ...

I guess the part to re-parse the files needs to be found elsewhere. but restarting the project should do that as well.

So that should be enough for some mindless trial and error  ;). Thanks  a lot.


Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1604
Re: Thinking about a wxSmith Clone Dialog Feature
« Reply #3 on: May 30, 2024, 06:03:49 pm »
The last section is saving the current selections in wxNewWindowDlg to default.conf, so they will be the defaults in the next call. You can ignore it.