Author Topic: Proposed patch to ScriptedWizard with Extensions by YWX  (Read 10414 times)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Proposed patch to ScriptedWizard with Extensions by YWX
« on: May 08, 2017, 12:15:05 am »
This is a patch to implement the ScripedWizard extension by YWX

He added:
    Wiz::FillContainerWithSelCompilers()
    Wiz::AppendContainerWithSelCompilers()
    Wiz::FillContainerWithChoices()
    Wiz::AppendContainerWithChoices()
    Wiz::GetWizardScriptFolder()

This patch has been tested on both Windows (10) and Linux (Mint) by pecan
using the ArmNoneEabiWizard plugin at
https://github.com/ywx/cbArmNoneEabiWizard/releases

Code
Index: src/plugins/scriptedwizard/resources/manifest.xml
===================================================================
--- src/plugins/scriptedwizard/resources/manifest.xml (revision 11053)
+++ src/plugins/scriptedwizard/resources/manifest.xml (working copy)
@@ -3,12 +3,17 @@
     <SdkVersion major="1" minor="10" release="0" />
     <Plugin name="ScriptedWizard">
         <Value title="Scripted wizard" />
-        <Value version="0.9" />
-        <Value description="A generic scripted wizard" />
+        <Value version="1.1" />
+        <Value description="An extended generic scripted wizard
+Add Wiz::FillContainerWithSelCompilers()
+    Wiz::AppendContainerWithSelCompilers()
+    Wiz::FillContainerWithChoices()
+    Wiz::AppendContainerWithChoices()
+    Wiz::GetWizardScriptFolder()" />
         <Value author="Yiannis An. Mandravellos" />
         <Value authorEmail="info@codeblocks.org" />
         <Value authorWebsite="http://www.codeblocks.org" />
-        <Value thanksTo="" />
+        <Value thanksTo="YWX for extended additions." />
         <Value license="GPL" />
     </Plugin>
 </CodeBlocks_plugin_manifest_file>
Index: src/plugins/scriptedwizard/wiz.cpp
===================================================================
--- src/plugins/scriptedwizard/wiz.cpp (revision 11053)
+++ src/plugins/scriptedwizard/wiz.cpp (working copy)
@@ -277,6 +277,8 @@
         InfoWindow::Display(_("Error"), _("Failed to load the wizard's script.\nPlease check the debug log for details..."));
         return nullptr;
     }
+    m_WizardScriptFolder = script.BeforeLast( _T('/') );
+    m_WizardScriptFolder = m_WizardScriptFolder.AfterLast( _T('/') );
 
     // call BeginWizard()
     try
@@ -680,7 +682,7 @@
         {
             const wxString &filename = files.BeforeFirst(_T(';'));
             if (pFilename)
-                *pFilename = filename;
+                *pFilename = files.BeforeFirst(_T(';'));
             EditorBase *editor = Manager::Get()->GetEditorManager()->GetEditor(filename);
             if (editor && editor->IsBuiltinEditor())
                 static_cast<cbEditor*>(editor)->SetEditorStyle();
@@ -898,6 +900,78 @@
     }
 }
 
+void Wiz::FillContainerWithSelCompilers( const wxString& name, const wxString& validCompilerIDs )
+{
+    wxWizardPage* page = m_pWizard->GetCurrentPage();
+    if (page)
+    {
+        wxItemContainer* win = dynamic_cast<wxItemContainer*>( page->FindWindowByName( name.IsEmpty() ? _T("GenericChoiceList") : name , page ) );
+        if (win)
+        {
+            wxArrayString valids = GetArrayFromString(validCompilerIDs, _T(";"), true);
+            win->Clear();
+            for (size_t i = 0; i < CompilerFactory::GetCompilersCount(); ++i)
+            {
+                Compiler* compiler = CompilerFactory::GetCompiler(i);
+                if (compiler)
+                {
+                    for (size_t n = 0; n < valids.GetCount(); ++n)
+                    {
+                        // match not only if IDs match, but if ID inherits from it too
+                        if (CompilerFactory::CompilerInheritsFrom(compiler, valids[n]))
+                        {
+                            win->Append(compiler->GetName());
+                            break;
+                        }
+                    }
+                }
+            }
+            Compiler* compiler = CompilerFactory::GetDefaultCompiler();
+            if (compiler)
+                win->SetSelection(win->FindString(compiler->GetName()));
+        }
+    }
+}
+
+void Wiz::AppendContainerWithSelCompilers( const wxString& name, const wxString& validCompilerIDs )
+{
+    wxWizardPage* page = m_pWizard->GetCurrentPage();
+    if (page)
+    {
+        wxItemContainer* win = dynamic_cast<wxItemContainer*>( page->FindWindowByName( name.IsEmpty() ? _T("GenericChoiceList") : name , page ) );
+        if (win)
+        {
+            wxArrayString valids = GetArrayFromString(validCompilerIDs, _T(";"), true);
+            size_t iItemsCount = win->GetCount();
+            wxString nameInItems = _T(";");
+            for( size_t i = 0; i < iItemsCount; ++i )
+            {
+                nameInItems += win->GetString(i) + _T(";");
+            }
+            for (size_t i = 0; i < CompilerFactory::GetCompilersCount(); ++i)
+            {
+                Compiler* compiler = CompilerFactory::GetCompiler(i);
+                if (compiler)
+                {
+                    wxString compilerName = compiler->GetName();
+                    if( wxNOT_FOUND != nameInItems.Find( _T(";") + compilerName + _T(";") ) )
+                        continue;
+                    for (size_t n = 0; n < valids.GetCount(); ++n)
+                    {
+                        // match not only if IDs match, but if ID inherits from it too
+                        if (CompilerFactory::CompilerInheritsFrom(compiler, valids[n]))
+                        {
+                            win->Append( compilerName );
+                            nameInItems += compilerName + _T(";");
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
 void Wiz::EnableWindow(const wxString& name, bool enable)
 {
     wxWizardPage* page = m_pWizard->GetCurrentPage();
@@ -1567,6 +1641,66 @@
     m_ReleaseObjOutputDir = releaseObjOut;
 }
 
+
+int Wiz::FillContainerWithChoices( const wxString& name, const wxString& choices )
+{
+    wxWizardPage* page = m_pWizard->GetCurrentPage();
+    if (page)
+    {
+        wxItemContainer* win = dynamic_cast<wxItemContainer*>( page->FindWindowByName( name.IsEmpty() ? _T("GenericChoiceList") : name , page ) );
+        if (win)
+        {
+            win->Clear();
+            wxArrayString items = GetArrayFromString( choices, _T(";") );
+            unsigned int nItems = items.GetCount();
+            for ( unsigned int i = 0; i < nItems; i++ )
+            {
+                win->Append( items[i] );
+            }
+
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int Wiz::AppendContainerWithChoices( const wxString& name, const wxString& choices )
+{
+    wxWizardPage* page = m_pWizard->GetCurrentPage();
+    if (page)
+    {
+        wxItemContainer* win = dynamic_cast<wxItemContainer*>( page->FindWindowByName( name.IsEmpty() ? _T("GenericChoiceList") : name , page ) );
+        if (win)
+        {
+            wxArrayString items = GetArrayFromString( choices, _T(";") );
+            size_t iItemsCount = win->GetCount();
+            wxString nameInItems = _T(";");
+            for( size_t i = 0; i < iItemsCount; ++i )
+            {
+                nameInItems += win->GetString(i) + _T(";");
+            }
+            unsigned int nItems = items.GetCount();
+            for ( unsigned int i = 0; i < nItems; i++ )
+            {
+                wxString tItemsName = items[i];
+                if( wxNOT_FOUND != nameInItems.Find( _T(";") + tItemsName + _T(";") ) )
+                    continue;
+                win->Append( tItemsName );
+                nameInItems += tItemsName + _T(";");
+            }
+
+            return 0;
+        }
+    }
+    return -1;
+}
+
+wxString Wiz::GetWizardScriptFolder(void)
+{
+    return m_WizardScriptFolder;
+}
+
+
 void Wiz::RegisterWizard()
 {
     SqPlus::SQClassDef<Wiz>("Wiz").
@@ -1646,8 +1780,15 @@
             func(&Wiz::GetFileHeaderGuard, "GetFileHeaderGuard").
             func(&Wiz::GetFileAddToProject, "GetFileAddToProject").
             func(&Wiz::GetFileTargetIndex, "GetFileTargetIndex").
-            func(&Wiz::SetFilePathSelectionFilter, "SetFilePathSelectionFilter");
+            func(&Wiz::SetFilePathSelectionFilter, "SetFilePathSelectionFilter").
 
+            // extender
+            func(&Wiz::FillContainerWithSelCompilers, "FillContainerWithSelCompilers").
+            func(&Wiz::AppendContainerWithSelCompilers, "AppendContainerWithSelCompilers").
+            func(&Wiz::FillContainerWithChoices, "FillContainerWithChoices").
+            func(&Wiz::AppendContainerWithChoices, "AppendContainerWithChoices").
+            func(&Wiz::GetWizardScriptFolder, "GetWizardScriptFolder");
+
     SqPlus::BindVariable(this, "Wizard", SqPlus::VAR_ACCESS_READ_ONLY);
 }
 
Index: src/plugins/scriptedwizard/wiz.h
===================================================================
--- src/plugins/scriptedwizard/wiz.h (revision 11053)
+++ src/plugins/scriptedwizard/wiz.h (working copy)
@@ -78,6 +78,8 @@
         bool IsCheckboxChecked(const wxString& name);
 
         void FillComboboxWithCompilers(const wxString& name);
+        void FillContainerWithSelCompilers( const wxString& name, const wxString& validCompilerIDs );
+        void AppendContainerWithSelCompilers( const wxString& name, const wxString& validCompilerIDs );
         wxString GetCompilerFromCombobox(const wxString& name);
         void FillContainerWithCompilers(const wxString& name, const wxString& compilerID,
                                         const wxString& validCompilerIDs);
@@ -150,6 +152,11 @@
                                         const wxString& releaseOut,
                                         const wxString& releaseObjOut);
 
+        // extender
+        int       FillContainerWithChoices( const wxString& name, const wxString& choices );
+        int       AppendContainerWithChoices( const wxString& name, const wxString& choices );
+        wxString  GetWizardScriptFolder(void);
+
         // pre-defined pages
         void AddInfoPage(const wxString& pageId, const wxString& intro_msg);
         void AddFilePathPage(bool showHeaderGuard);
@@ -190,6 +197,8 @@
         wxString m_ReleaseName;
         wxString m_ReleaseOutputDir;
         wxString m_ReleaseObjOutputDir;
+
+        wxString m_WizardScriptFolder;
  private:
         Wiz(cb_unused const Wiz& rhs); // prevent copy construction
 };
Index: src/plugins/scriptedwizard/wizpage.h
===================================================================
--- src/plugins/scriptedwizard/wizpage.h (revision 11053)
+++ src/plugins/scriptedwizard/wizpage.h (working copy)
@@ -94,6 +94,7 @@
         wxString m_Filename;
         wxString m_HeaderGuard;
         bool m_AddToProject;
+        int m_TargetIndex;
 };
 
 class WizProjectPathPanel : public WizPageBase

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #1 on: May 08, 2017, 12:32:53 am »
Some comments:
1. I'll remove the description field in the xml. I don't think it is appropriate or useful to users.
2. I'll remove any mention of "// extender" or similar
3. Can we replace Sel with something more meaningful in FillContainerWithSelCompilers and AppendContainerWithSelCompilers?
4. Can we have some documentation for the new methods? What are they doing? What parameters do they expect?
5. I would like const and const& added to as many places in the patch as possible.
6. The bracket spacing is not consistent with the rest of the code - too much spaces on both sides.

After 4 is resolved I suppose I'll make more comments :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #2 on: May 27, 2017, 11:59:15 am »
@Pecan
Thanks for this patch.
I install 'cbScriptedWizardPlugin' in 'cb-11021' (Vista business).
I have found differences between 'cbArmNoneEabiWizard' and original plugin CB.
Your current proposal can it be installed without problems ? 
Do you have a new version ?
Have a good day.


« Last Edit: May 27, 2017, 12:04:54 pm by LETARTARE »
CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #3 on: June 04, 2017, 07:03:05 pm »
oBFusCATed,

Do you actually mean "I'll remove...." or do you mean you'd prefer me to remove.... ?

Some comments:
1. I'll remove the description field in the xml. I don't think it is appropriate or useful to users.
2. I'll remove any mention of "// extender" or similar
3. Can we replace Sel with something more meaningful in FillContainerWithSelCompilers and AppendContainerWithSelCompilers?
4. Can we have some documentation for the new methods? What are they doing? What parameters do they expect?
5. I would like const and const& added to as many places in the patch as possible.
6. The bracket spacing is not consistent with the rest of the code - too much spaces on both sides.

After 4 is resolved I suppose I'll make more comments :)

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #4 on: June 04, 2017, 07:05:59 pm »
If you have already installed cbScriptedWizardPlugin, you will not need this patch.
This patch does not make any changes to cbArmNoneEabiWizard.
 
@Pecan
Thanks for this patch.
I install 'cbScriptedWizardPlugin' in 'cb-11021' (Vista business).
I have found differences between 'cbArmNoneEabiWizard' and original plugin CB.
Your current proposal can it be installed without problems ? 
Do you have a new version ?
Have a good day.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #5 on: June 04, 2017, 07:13:40 pm »
Do you actually mean "I'll remove...." or do you mean you'd prefer me to remove.... ?
No, I hope I won't remove anything. I mean that I would prefer if you remove X or Y.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline LETARTARE

  • Lives here!
  • ****
  • Posts: 531
  • L'ami de l'homme.The friend of man.
    • LETARTARE
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #6 on: June 07, 2017, 02:01:11 pm »
@pecan
in  'cbScriptedWizardPlugin->ArmNoneEabiWizard::GetJLinkDevices()'
Code
LinesDeviceCSV = GetArrayFromString(ContentDeviceCSV, _T("\r\n"), 0);
is to verify because the file 'jlinkdevices.csv is saved with _T ( "\ n")
You either change 'jlinkdevices.csv' or the line of the program.


CB-13483, plugins-sdk-2.25.0 : Collector-2.0.0, AddOnForQt-3.9.1
1-Win7 Business Pack1 64bits : wx-3.2.4, gcc-8.1.0,
2-OpenSuse::Leap-15.4-64bits : wx-3.2.4;gtk3, gcc-8.2.1,
=> !! The messages are translated by Deepl

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #7 on: June 29, 2017, 09:25:04 pm »
SVN reports that I don't have commit authority, so the patch is at:

https://sourceforge.net/p/codeblocks/tickets/519/


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #8 on: June 29, 2017, 09:49:45 pm »
You should probably send a PM to Morten, so he can give you access.

About the second patch:
1. Can you move the function comments before the method definition and change write them with a doxygen comment (no need to explain every parameter, just in case if we decide to generate doxygen docs for the full repo, not only for the sdk).
2. The initialization of m_WizardScriptFolder is strange. Could you redo it with the use of wxFileName?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #9 on: June 30, 2017, 05:38:31 pm »
You should probably send a PM to Morten, so he can give you access.

About the second patch:
1. Can you move the function comments before the method definition and change write them with a doxygen comment (no need to explain every parameter, just in case if we decide to generate doxygen docs for the full repo, not only for the sdk).
2. The initialization of m_WizardScriptFolder is strange. Could you redo it with the use of wxFileName?

Please go ahead and make the changes to your preferences and make the commit.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #10 on: June 30, 2017, 07:12:49 pm »
Sorry, I have no time to work on this. My comments aren't obligatory. If you think that they aren't valid or worth doing you can ignore them.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2750
Re: Proposed patch to ScriptedWizard with Extensions by YWX
« Reply #11 on: August 15, 2017, 09:27:17 pm »
YWX Scripted Wizard Additions applied SVN 11148.

   GetWizardScriptFolder() return last directory of script file path
   FillContainerWithSelectCompilers() using mask eg., FillContainerWithSelectCompilers("*arm*;mips*" );
   AppendContainerWithSelectCompilers() using mask.
   FillContainerWithChoices() using semi-comma separated strings, eg., FillContainerWithChoices("this;that;someother");.
   AppendContainerWithChoices() using semi-comma separated strings