Author Topic: Patch #1  (Read 16019 times)

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Patch #1
« on: March 03, 2008, 06:33:04 am »
As I can't register in BerliOS i put this patch here. In this patch I change "Set program argument" dialog:
  - removed some hardcoded size from dialog
  - added support for change settings for many target (in current version only one)
  - after running select settings for global target or active target (in current version always first item)

[attachment deleted by admin]

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #1 on: March 05, 2008, 05:59:46 am »
Is this patch will be apply to Code::Blocks source by developers?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Patch #1
« Reply #2 on: March 05, 2008, 09:23:19 am »
I would doubt so. Half of the patch seems to be indenting or formatting, which makes it needlessly hard to read the actual changes. At least I won't read through 470 lines to identify the few lines that contain changes, maybe someone else does :)
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #3 on: March 06, 2008, 06:56:32 am »
Ok. I remove changes in .xrc files. This is corrected patch, where only code reimplementation (patch #1a):

Code
Index: selecttargetdlg.cpp
===================================================================
--- selecttargetdlg.cpp (revision 4934)
+++ selecttargetdlg.cpp (working copy)
@@ -21,18 +21,30 @@
     #include "cbproject.h"
 #endif
 #include <wx/filedlg.h>
+#include <wx/valgen.h>
 #include "selecttargetdlg.h"
 
+struct SelectTargetStruct
+{
+ wxString txtBuildTarget;
+ bool isSetAsDefaultExec;
+ wxString txtParams;
+ wxString txtHostApp;
+};
+
+
+#include <wx/arrimpl.cpp>
+WX_DEFINE_OBJARRAY(ArrayOfSelectTargetStruct);
+
+
 BEGIN_EVENT_TABLE(SelectTargetDlg, wxDialog)
- EVT_CHECKBOX(XRCID("chkSetAsDefaultExec"), SelectTargetDlg::OnCheckboxSelection)
  EVT_LISTBOX(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
- EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxDClick)
+ EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
  EVT_BUTTON(XRCID("btnHostApplication"), SelectTargetDlg::OnHostApplicationButtonClick)
 END_EVENT_TABLE()
 
 SelectTargetDlg::SelectTargetDlg(wxWindow* parent, cbProject* project, int selected)
- : m_pProject(project),
- m_Selected(selected)
+ : m_Selected(-1), m_pProject(project)
 {
  //ctor
  wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgSelectTarget"));
@@ -43,14 +55,20 @@
  {
  ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
  list->Append(target->GetTitle());
+ //Add project param to array
+ SelectTargetStruct t;
+ t.txtBuildTarget = target->GetTitle();
+ t.isSetAsDefaultExec = (target->GetTitle() == m_pProject->GetDefaultExecuteTarget());
+ t.txtParams = target->GetExecutionParameters();
+ t.txtHostApp = target->GetHostApplication();
+ m_ProjectParam.Add(t);
  }
- if (selected != -1)
- list->SetSelection(selected);
+ if (!m_pProject->GetDefaultExecuteTarget().IsEmpty())
+ list->SetStringSelection(m_pProject->GetDefaultExecuteTarget());
  else
- list->SetSelection(list->FindString(m_pProject->GetDefaultExecuteTarget()));
+ list->SetStringSelection(project->GetActiveBuildTarget());
 
  UpdateSelected();
- XRCCTRL(*this, "wxID_OK", wxButton)->MoveBeforeInTabOrder (XRCCTRL(*this, "lstItems", wxListBox));
 }
 
 SelectTargetDlg::~SelectTargetDlg()
@@ -60,22 +78,41 @@
 
 void SelectTargetDlg::UpdateSelected()
 {
-    wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
- ProjectBuildTarget* target = m_pProject->GetBuildTarget(name);
- if (target)
+ //Save data in m_ProjectParam array
+ TransferDataFromWindow();
+
+ //Remove default check from other target
+ if (m_Selected != -1 && m_ProjectParam[m_Selected].isSetAsDefaultExec)
  {
-        XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValue(name == m_pProject->GetDefaultExecuteTarget());
- XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(target->GetExecutionParameters());
- XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValue(target->GetHostApplication());
+ //Uncheck all options except selected
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ if ((int)i != m_Selected)
+ m_ProjectParam[i].isSetAsDefaultExec = false;
+ }
  }
- XRCCTRL(*this, "wxID_OK", wxButton)->Enable(target);
+
+ //Check list for empty (if this dialog show on empty project)
+ if (m_ProjectParam.Count() == 0)
+ return;
+
+ //Get current elem
+ m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
+ if (m_Selected==wxNOT_FOUND)
+ {
+ XRCCTRL(*this, "lstItems", wxListBox)->SetSelection(0);
+ m_Selected = 0;
+ }
+
+ //Set new validator
+ XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].isSetAsDefaultExec));
+ XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtParams));
+ XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtHostApp));
+
+ //Update data
+ TransferDataToWindow();
 } // end of UpdateSelected
 
-ProjectBuildTarget* SelectTargetDlg::GetSelectionTarget()
-{
-    return m_pProject->GetBuildTarget(m_Selected);
-}
-
 // events
 
 void SelectTargetDlg::OnListboxSelection(wxCommandEvent& /*event*/)
@@ -83,21 +120,6 @@
  UpdateSelected();
 } // end of OnListboxSelection
 
-void SelectTargetDlg::OnListboxDClick(wxCommandEvent& /*event*/)
-{
-    UpdateSelected();
-    EndModal(wxID_OK);
-} // end of OnListboxDClick
-
-void SelectTargetDlg::OnCheckboxSelection(wxCommandEvent& /*event*/)
-{
-    if (XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->GetValue())
-    {
-        wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
-        m_pProject->SetDefaultExecuteTarget(name);
-    }
-} // end of OnCheckboxSelection
-
 void SelectTargetDlg::OnHostApplicationButtonClick(wxCommandEvent& /*event*/)
 {
     if(wxTextCtrl* obj = XRCCTRL(*this, "txtHostApp", wxTextCtrl))
@@ -111,7 +133,7 @@
                             #else
                             _("All files (*)|*"),
                             #endif
-                            wxOPEN | wxFILE_MUST_EXIST | compatibility::wxHideReadonly);
+                            wxOPEN | wxFILE_MUST_EXIST);
         dlg->SetFilterIndex(0);
         PlaceWindow(dlg);
         if (dlg->ShowModal() != wxID_OK)
@@ -123,26 +145,26 @@
 
 void SelectTargetDlg::EndModal(int retCode)
 {
+ UpdateSelected();
     if (retCode == wxID_OK)
     {
-        m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
-        ProjectBuildTarget* target = m_pProject->GetBuildTarget(m_Selected);
-        if (target)
-        {
-            // Search all '\n' in the program-parameters and replace them by
-            // ' '. This is necessary because a multiline text control may add
-            // '\n' to the text but these characters must not be part of the
-            // parameters when executing the program.
-            wxString execution_parameters = XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue();
-            wxString::size_type pos = 0;
+         m_pProject->SetDefaultExecuteTarget(wxEmptyString);
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
+ // Search all '\n' in the program-parameters and replace them by
+ // ' '. This is necessary because a multiline text control may add
+ // '\n' to the text but these characters must not be part of the
+ // parameters when executing the program.
+ m_ProjectParam[i].txtParams.Replace(wxT("\n"), wxT(" "));
 
-            while ((pos = execution_parameters.find('\n', pos)) != wxString::npos)
-            {
-                execution_parameters[pos] = ' ';
-            }
-            target->SetExecutionParameters(execution_parameters);
-            target->SetHostApplication(XRCCTRL(*this, "txtHostApp", wxTextCtrl)->GetValue());
-        }
+ target->SetExecutionParameters(m_ProjectParam[i].txtParams);
+ target->SetHostApplication(m_ProjectParam[i].txtHostApp);
+ if (m_ProjectParam[i].isSetAsDefaultExec)
+ {
+ m_pProject->SetDefaultExecuteTarget(m_ProjectParam[i].txtBuildTarget);
+ }
+ }
     }
  wxDialog::EndModal(retCode);
 } // end of EndModal
Index: src/include/selecttargetdlg.h
===================================================================
--- src/include/selecttargetdlg.h (revision 4921)
+++ src/include/selecttargetdlg.h (working copy)
@@ -7,10 +7,17 @@
 #define SELECTTARGETDLG_H
 
 #include <wx/dialog.h>
+#include <wx/dynarray.h>
 
 class cbProject;
 class ProjectBuildTarget;
 
+//Forward declaration for internal class storage
+class SelectTargetStruct;
+
+WX_DECLARE_OBJARRAY(SelectTargetStruct, ArrayOfSelectTargetStruct);
+
+//Dialog class for "Set program argument" menu item
 class SelectTargetDlg : public wxDialog
 {
  public:
@@ -19,15 +26,14 @@
 
  void EndModal(int retCode);
  int GetSelection() const { return m_Selected; }
- ProjectBuildTarget* GetSelectionTarget();
  private:
  void OnListboxSelection(wxCommandEvent& event);
- void OnListboxDClick(wxCommandEvent& event);
-        void OnCheckboxSelection(wxCommandEvent& event);
        void OnHostApplicationButtonClick(wxCommandEvent& event);
  void UpdateSelected();
+
+ int m_Selected;
  cbProject* m_pProject;
- int m_Selected;
+ ArrayOfSelectTargetStruct m_ProjectParam;
 
  DECLARE_EVENT_TABLE()
 };

I also change behaviour of choice target to add file in. In most case (~95%) when user add new file or class to project he want add it to all targets. Add user always need press button "Select all" in choice target dialog before "Ok". I change this and now all target always selected in "Multiple selection" dialog by default (patch #2):
Code
Index: projectmanager.cpp
===================================================================
--- projectmanager.cpp (revision 4934)
+++ projectmanager.cpp (working copy)
@@ -1402,7 +1402,7 @@
     for (int i = 0; i < count; ++i)
         array.Add(prj->GetBuildTarget(i)->GetTitle());
 
-    MultiSelectDlg dlg(0, array, false, _("Select the targets this file should belong to:"));
+    MultiSelectDlg dlg(0, array, true, _("Select the targets this file should belong to:"));
     PlaceWindow(&dlg);
     if (dlg.ShowModal() == wxID_OK)
         indices = dlg.GetSelectedIndices();
@@ -2021,7 +2021,7 @@
         }
         wxString msg;
         msg.Printf(_("Select files to remove from %s:"), prj->GetTitle().c_str());
-        MultiSelectDlg dlg(0, files, false, msg);
+        MultiSelectDlg dlg(0, files, true, msg);
         PlaceWindow(&dlg);
         if (dlg.ShowModal() == wxID_OK)
         {
« Last Edit: March 06, 2008, 06:58:12 am by AlekseyT »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #4 on: March 06, 2008, 08:28:13 am »
Mmmmmh... still a little suspicious. Why do you do things like that:
Code
-                            wxOPEN | wxFILE_MUST_EXIST | compatibility::wxHideReadonly);
+                            wxOPEN | wxFILE_MUST_EXIST);
??? This has nothing to do with what you have in mind. And (inf fact) it introduced an UI "bug" on certain systems.
Probably I should just apply the patch once to see in more detail.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #5 on: March 06, 2008, 08:46:53 am »
I remove flag "compatibility::wxHideReadonly" as I think, what user can execute program with read-only attribute. I can't found any comments about problems without wxHideReadonly flag in Google. If this flag solve some unknown for me problems, then you can simply don't change this line. :)
« Last Edit: March 06, 2008, 09:11:48 am by AlekseyT »

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #6 on: March 06, 2008, 10:36:05 am »
Probably I should just apply the patch once to see in more detail.
Dammed. I cannot apply this patch. When looking into the first patch of your last post than it is obvious why: You have selecttargetdlg.cpp there directly, so you require to be into the src/sdk folder and later comes src/include/selecttargetdlg.h which requires to be in the root folder... will try to fix that on my machine...

Edit: Sorry, but these patches do not work for me ("failed hunk #21"). They re not based on a clean SVN revision I guess. Mind trying again, please?! ;-)
« Last Edit: March 06, 2008, 10:39:01 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #7 on: March 07, 2008, 07:09:12 am »
I am sorry. This is my error. Next patch I tested and applied successfully (patch #1c)
Code
Index: src/sdk/selecttargetdlg.cpp
===================================================================
--- src/sdk/selecttargetdlg.cpp (revision 4934)
+++ src/sdk/selecttargetdlg.cpp (working copy)
@@ -21,18 +21,30 @@
     #include "cbproject.h"
 #endif
 #include <wx/filedlg.h>
+#include <wx/valgen.h>
 #include "selecttargetdlg.h"
 
+struct SelectTargetStruct
+{
+ wxString txtBuildTarget;
+ bool isSetAsDefaultExec;
+ wxString txtParams;
+ wxString txtHostApp;
+};
+
+
+#include <wx/arrimpl.cpp>
+WX_DEFINE_OBJARRAY(ArrayOfSelectTargetStruct);
+
+
 BEGIN_EVENT_TABLE(SelectTargetDlg, wxDialog)
- EVT_CHECKBOX(XRCID("chkSetAsDefaultExec"), SelectTargetDlg::OnCheckboxSelection)
  EVT_LISTBOX(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
- EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxDClick)
+ EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
  EVT_BUTTON(XRCID("btnHostApplication"), SelectTargetDlg::OnHostApplicationButtonClick)
 END_EVENT_TABLE()
 
 SelectTargetDlg::SelectTargetDlg(wxWindow* parent, cbProject* project, int selected)
- : m_pProject(project),
- m_Selected(selected)
+ : m_Selected(-1), m_pProject(project)
 {
  //ctor
  wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgSelectTarget"));
@@ -43,14 +55,20 @@
  {
  ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
  list->Append(target->GetTitle());
+ //Add project param to array
+ SelectTargetStruct t;
+ t.txtBuildTarget = target->GetTitle();
+ t.isSetAsDefaultExec = (target->GetTitle() == m_pProject->GetDefaultExecuteTarget());
+ t.txtParams = target->GetExecutionParameters();
+ t.txtHostApp = target->GetHostApplication();
+ m_ProjectParam.Add(t);
  }
- if (selected != -1)
- list->SetSelection(selected);
+ if (!m_pProject->GetDefaultExecuteTarget().IsEmpty())
+ list->SetStringSelection(m_pProject->GetDefaultExecuteTarget());
  else
- list->SetSelection(list->FindString(m_pProject->GetDefaultExecuteTarget()));
+ list->SetStringSelection(project->GetActiveBuildTarget());
 
  UpdateSelected();
- XRCCTRL(*this, "wxID_OK", wxButton)->MoveBeforeInTabOrder (XRCCTRL(*this, "lstItems", wxListBox));
 }
 
 SelectTargetDlg::~SelectTargetDlg()
@@ -60,22 +78,41 @@
 
 void SelectTargetDlg::UpdateSelected()
 {
-    wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
- ProjectBuildTarget* target = m_pProject->GetBuildTarget(name);
- if (target)
+ //Save data in m_ProjectParam array
+ TransferDataFromWindow();
+
+ //Remove default check from other target
+ if (m_Selected != -1 && m_ProjectParam[m_Selected].isSetAsDefaultExec)
  {
-        XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValue(name == m_pProject->GetDefaultExecuteTarget());
- XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(target->GetExecutionParameters());
- XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValue(target->GetHostApplication());
+ //Uncheck all options except selected
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ if ((int)i != m_Selected)
+ m_ProjectParam[i].isSetAsDefaultExec = false;
+ }
  }
- XRCCTRL(*this, "wxID_OK", wxButton)->Enable(target);
+
+ //Check list for empty (if this dialog show on empty project)
+ if (m_ProjectParam.Count() == 0)
+ return;
+
+ //Get current elem
+ m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
+ if (m_Selected==wxNOT_FOUND)
+ {
+ XRCCTRL(*this, "lstItems", wxListBox)->SetSelection(0);
+ m_Selected = 0;
+ }
+
+ //Set new validator
+ XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].isSetAsDefaultExec));
+ XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtParams));
+ XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtHostApp));
+
+ //Update data
+ TransferDataToWindow();
 } // end of UpdateSelected
 
-ProjectBuildTarget* SelectTargetDlg::GetSelectionTarget()
-{
-    return m_pProject->GetBuildTarget(m_Selected);
-}
-
 // events
 
 void SelectTargetDlg::OnListboxSelection(wxCommandEvent& /*event*/)
@@ -83,21 +120,6 @@
  UpdateSelected();
 } // end of OnListboxSelection
 
-void SelectTargetDlg::OnListboxDClick(wxCommandEvent& /*event*/)
-{
-    UpdateSelected();
-    EndModal(wxID_OK);
-} // end of OnListboxDClick
-
-void SelectTargetDlg::OnCheckboxSelection(wxCommandEvent& /*event*/)
-{
-    if (XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->GetValue())
-    {
-        wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
-        m_pProject->SetDefaultExecuteTarget(name);
-    }
-} // end of OnCheckboxSelection
-
 void SelectTargetDlg::OnHostApplicationButtonClick(wxCommandEvent& /*event*/)
 {
     if(wxTextCtrl* obj = XRCCTRL(*this, "txtHostApp", wxTextCtrl))
@@ -111,7 +133,7 @@
                             #else
                             _("All files (*)|*"),
                             #endif
-                            wxOPEN | wxFILE_MUST_EXIST | compatibility::wxHideReadonly);
+                            wxOPEN | wxFILE_MUST_EXIST);
         dlg->SetFilterIndex(0);
         PlaceWindow(dlg);
         if (dlg->ShowModal() != wxID_OK)
@@ -123,26 +145,26 @@
 
 void SelectTargetDlg::EndModal(int retCode)
 {
+ UpdateSelected();
     if (retCode == wxID_OK)
     {
-        m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
-        ProjectBuildTarget* target = m_pProject->GetBuildTarget(m_Selected);
-        if (target)
-        {
-            // Search all '\n' in the program-parameters and replace them by
-            // ' '. This is necessary because a multiline text control may add
-            // '\n' to the text but these characters must not be part of the
-            // parameters when executing the program.
-            wxString execution_parameters = XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue();
-            wxString::size_type pos = 0;
+         m_pProject->SetDefaultExecuteTarget(wxEmptyString);
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
+ // Search all '\n' in the program-parameters and replace them by
+ // ' '. This is necessary because a multiline text control may add
+ // '\n' to the text but these characters must not be part of the
+ // parameters when executing the program.
+ m_ProjectParam[i].txtParams.Replace(wxT("\n"), wxT(" "));
 
-            while ((pos = execution_parameters.find('\n', pos)) != wxString::npos)
-            {
-                execution_parameters[pos] = ' ';
-            }
-            target->SetExecutionParameters(execution_parameters);
-            target->SetHostApplication(XRCCTRL(*this, "txtHostApp", wxTextCtrl)->GetValue());
-        }
+ target->SetExecutionParameters(m_ProjectParam[i].txtParams);
+ target->SetHostApplication(m_ProjectParam[i].txtHostApp);
+ if (m_ProjectParam[i].isSetAsDefaultExec)
+ {
+ m_pProject->SetDefaultExecuteTarget(m_ProjectParam[i].txtBuildTarget);
+ }
+ }
     }
  wxDialog::EndModal(retCode);
 } // end of EndModal
Index: src/include/selecttargetdlg.h
===================================================================
--- src/include/selecttargetdlg.h (revision 4934)
+++ src/include/selecttargetdlg.h (working copy)
@@ -7,10 +7,17 @@
 #define SELECTTARGETDLG_H
 
 #include <wx/dialog.h>
+#include <wx/dynarray.h>
 
 class cbProject;
 class ProjectBuildTarget;
 
+//Forward declaration for internal class storage
+class SelectTargetStruct;
+
+WX_DECLARE_OBJARRAY(SelectTargetStruct, ArrayOfSelectTargetStruct);
+
+//Dialog class for "Set program argument" menu item
 class SelectTargetDlg : public wxDialog
 {
  public:
@@ -19,15 +26,14 @@
 
  void EndModal(int retCode);
  int GetSelection() const { return m_Selected; }
- ProjectBuildTarget* GetSelectionTarget();
  private:
  void OnListboxSelection(wxCommandEvent& event);
- void OnListboxDClick(wxCommandEvent& event);
-        void OnCheckboxSelection(wxCommandEvent& event);
-        void OnHostApplicationButtonClick(wxCommandEvent& event);
+ void OnHostApplicationButtonClick(wxCommandEvent& event);
  void UpdateSelected();
+
+ int m_Selected;
  cbProject* m_pProject;
- int m_Selected;
+ ArrayOfSelectTargetStruct m_ProjectParam;
 
  DECLARE_EVENT_TABLE()
 };

Also I made another patch. Ussually after compile CB write all warnings and errors in table ("Build messages"). Ussually all projects compiling in ditectory /very/very/long/path/to/project and width of first row not enough for show full path. I think better for files inside project show only relative path and name. For file not in project (for example for 3rd-party libraries) show full name. This patch do this (patch #3):
Code
Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp (revision 4934)
+++ src/plugins/compilergcc/compilergcc.cpp (working copy)
@@ -3279,7 +3279,14 @@
 {
     // add build message
     wxArrayString errors;
-    errors.Add(filename);
+
+    //Remove project path from filename (in this case filname be shorter)
+    wxString shortname;
+    if (filename.StartsWith(m_Project->GetBasePath(), &shortname))
+        errors.Add(shortname);
+    else
+        errors.Add(filename);
+
     errors.Add(line);
     errors.Add(msg);

Offline Seronis

  • Almost regular
  • **
  • Posts: 197
Re: Patch #1
« Reply #8 on: March 07, 2008, 03:56:28 pm »
Also I made another patch...I think better for files inside project show only relative path and name. For file not in project .. show full name...

Now this is something id like in 8.02.1

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #9 on: March 07, 2008, 07:09:44 pm »
Now this is something id like in 8.02.1
Won't happen as february 2008 is over. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #10 on: March 13, 2008, 03:16:11 pm »
Is any of this patches is applied?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #11 on: March 13, 2008, 03:51:29 pm »
Is any of this patches is applied?
No. This is what makes me refusing it currently:
Code
SelectTargetDlg::SelectTargetDlg(wxWindow* parent, cbProject* project, int selected)
    : m_Selected(-1), m_pProject(project)
You ignore the usage of the explicitly provided "selected" variable in the constructor. Thus this interface is broken. We cannot leave it like that.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #12 on: March 13, 2008, 04:18:25 pm »
Ok. I change "select choice" in src/src/app.cpp[672-683] and after put new patch. And what about other two patch?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #13 on: March 13, 2008, 08:06:49 pm »
In most case (~95%) when user add new file or class to project he want add it to all targets.
This is simply not true. Take the C::B project itself as an example. You definitely do *not* want new files to all targets. What you say is usually true for users coming from the MS VS world. But definitely not for the majority. So my personal feeling is: Post this at BerliOS so that everybody who feels like needing this feature can add it, but I wouldn't add it to C::B generally. The big boss would definitely kill me if I do so.

...the other patch I haven't tried yet...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Patch #1
« Reply #14 on: March 13, 2008, 08:37:36 pm »
In most case (~95%) when user add new file or class to project he want add it to all targets.
Funny, I never wanted that... must be that I'm still in the 5% that are left over.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #15 on: March 17, 2008, 04:23:35 am »
Ok. I fixed patch with execution parameter (patch 1d "Execution parameters settings"). Now it use all of its parameters:
Code
Index: src/sdk/projectmanager.cpp
===================================================================
--- src/sdk/projectmanager.cpp (revision 4921)
+++ src/sdk/projectmanager.cpp (working copy)
@@ -1736,7 +1736,15 @@
 void ProjectManager::OnExecParameters(wxCommandEvent& event)
 {
     if (m_pActiveProject)
-        m_pActiveProject->SelectTarget(0, true);
+    {
+        //Get target name
+        wxString target;
+        if (!m_pActiveProject->GetDefaultExecuteTarget().IsEmpty())
+                target = m_pActiveProject->GetDefaultExecuteTarget();
+        else
+                target = m_pActiveProject->GetActiveBuildTarget();
+        m_pActiveProject->SelectTarget(m_pActiveProject->IndexOfBuildTargetName(target), true);
+    }
 }
 
 void ProjectManager::OnRightClick(wxCommandEvent& event)
Index: src/sdk/selecttargetdlg.cpp
===================================================================
--- src/sdk/selecttargetdlg.cpp (revision 4921)
+++ src/sdk/selecttargetdlg.cpp (working copy)
@@ -21,18 +21,29 @@
     #include "cbproject.h"
 #endif
 #include <wx/filedlg.h>
+#include <wx/valgen.h>
+#include <wx/arrimpl.cpp>
 #include "selecttargetdlg.h"
 
+struct SelectTargetStruct
+{
+ wxString txtBuildTarget;
+ bool isSetAsDefaultExec;
+ wxString txtParams;
+ wxString txtHostApp;
+};
+
+
+WX_DEFINE_OBJARRAY(ArrayOfSelectTargetStruct);
+
 BEGIN_EVENT_TABLE(SelectTargetDlg, wxDialog)
- EVT_CHECKBOX(XRCID("chkSetAsDefaultExec"), SelectTargetDlg::OnCheckboxSelection)
  EVT_LISTBOX(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
- EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxDClick)
+ EVT_LISTBOX_DCLICK(XRCID("lstItems"), SelectTargetDlg::OnListboxSelection)
  EVT_BUTTON(XRCID("btnHostApplication"), SelectTargetDlg::OnHostApplicationButtonClick)
 END_EVENT_TABLE()
 
 SelectTargetDlg::SelectTargetDlg(wxWindow* parent, cbProject* project, int selected)
- : m_pProject(project),
- m_Selected(selected)
+ : m_pProject(project), m_Selected(-1)
 {
  //ctor
  wxXmlResource::Get()->LoadDialog(this, parent, _T("dlgSelectTarget"));
@@ -43,14 +54,20 @@
  {
  ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
  list->Append(target->GetTitle());
+ //Add project param to array
+ SelectTargetStruct t;
+ t.txtBuildTarget = target->GetTitle();
+ t.isSetAsDefaultExec = (target->GetTitle() == m_pProject->GetDefaultExecuteTarget());
+ t.txtParams = target->GetExecutionParameters();
+ t.txtHostApp = target->GetHostApplication();
+ m_ProjectParam.Add(t);
  }
- if (selected != -1)
- list->SetSelection(selected);
- else
- list->SetSelection(list->FindString(m_pProject->GetDefaultExecuteTarget()));
 
+ // Check selection value
+ if (selected<0 || selected>=list->GetCount()) selected = 0;
+
+ list->SetSelection(selected);
  UpdateSelected();
- XRCCTRL(*this, "wxID_OK", wxButton)->MoveBeforeInTabOrder (XRCCTRL(*this, "lstItems", wxListBox));
 }
 
 SelectTargetDlg::~SelectTargetDlg()
@@ -60,22 +77,41 @@
 
 void SelectTargetDlg::UpdateSelected()
 {
-    wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
- ProjectBuildTarget* target = m_pProject->GetBuildTarget(name);
- if (target)
+ //Save data in m_ProjectParam array
+ TransferDataFromWindow();
+
+ //Remove default check from other target
+ if (m_Selected != -1 && m_ProjectParam[m_Selected].isSetAsDefaultExec)
  {
-        XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValue(name == m_pProject->GetDefaultExecuteTarget());
- XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValue(target->GetExecutionParameters());
- XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValue(target->GetHostApplication());
+ //Uncheck all options except selected
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ if ((int)i != m_Selected)
+ m_ProjectParam[i].isSetAsDefaultExec = false;
+ }
  }
- XRCCTRL(*this, "wxID_OK", wxButton)->Enable(target);
+
+ //Check list for empty (if this dialog show on empty project)
+ if (m_ProjectParam.Count() == 0)
+ return;
+
+ //Get current elem
+ m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
+ if (m_Selected==wxNOT_FOUND)
+ {
+ XRCCTRL(*this, "lstItems", wxListBox)->SetSelection(0);
+ m_Selected = 0;
+ }
+
+ //Set new validator
+ XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].isSetAsDefaultExec));
+ XRCCTRL(*this, "txtParams", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtParams));
+ XRCCTRL(*this, "txtHostApp", wxTextCtrl)->SetValidator(wxGenericValidator(&m_ProjectParam[m_Selected].txtHostApp));
+
+ //Update data
+ TransferDataToWindow();
 } // end of UpdateSelected
 
-ProjectBuildTarget* SelectTargetDlg::GetSelectionTarget()
-{
-    return m_pProject->GetBuildTarget(m_Selected);
-}
-
 // events
 
 void SelectTargetDlg::OnListboxSelection(wxCommandEvent& /*event*/)
@@ -83,21 +119,6 @@
  UpdateSelected();
 } // end of OnListboxSelection
 
-void SelectTargetDlg::OnListboxDClick(wxCommandEvent& /*event*/)
-{
-    UpdateSelected();
-    EndModal(wxID_OK);
-} // end of OnListboxDClick
-
-void SelectTargetDlg::OnCheckboxSelection(wxCommandEvent& /*event*/)
-{
-    if (XRCCTRL(*this, "chkSetAsDefaultExec", wxCheckBox)->GetValue())
-    {
-        wxString name = XRCCTRL(*this, "lstItems", wxListBox)->GetStringSelection();
-        m_pProject->SetDefaultExecuteTarget(name);
-    }
-} // end of OnCheckboxSelection
-
 void SelectTargetDlg::OnHostApplicationButtonClick(wxCommandEvent& /*event*/)
 {
     if(wxTextCtrl* obj = XRCCTRL(*this, "txtHostApp", wxTextCtrl))
@@ -123,26 +144,26 @@
 
 void SelectTargetDlg::EndModal(int retCode)
 {
+    UpdateSelected();
     if (retCode == wxID_OK)
     {
-        m_Selected = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection();
-        ProjectBuildTarget* target = m_pProject->GetBuildTarget(m_Selected);
-        if (target)
-        {
-            // Search all '\n' in the program-parameters and replace them by
-            // ' '. This is necessary because a multiline text control may add
-            // '\n' to the text but these characters must not be part of the
-            // parameters when executing the program.
-            wxString execution_parameters = XRCCTRL(*this, "txtParams", wxTextCtrl)->GetValue();
-            wxString::size_type pos = 0;
+         m_pProject->SetDefaultExecuteTarget(wxEmptyString);
+ for (size_t i = 0; i < m_ProjectParam.Count(); ++i)
+ {
+ ProjectBuildTarget* target = m_pProject->GetBuildTarget(i);
+ // Search all '\n' in the program-parameters and replace them by
+ // ' '. This is necessary because a multiline text control may add
+ // '\n' to the text but these characters must not be part of the
+ // parameters when executing the program.
+ m_ProjectParam[i].txtParams.Replace(wxT("\n"), wxT(" "));
 
-            while ((pos = execution_parameters.find('\n', pos)) != wxString::npos)
-            {
-                execution_parameters[pos] = ' ';
-            }
-            target->SetExecutionParameters(execution_parameters);
-            target->SetHostApplication(XRCCTRL(*this, "txtHostApp", wxTextCtrl)->GetValue());
-        }
+ target->SetExecutionParameters(m_ProjectParam[i].txtParams);
+ target->SetHostApplication(m_ProjectParam[i].txtHostApp);
+ if (m_ProjectParam[i].isSetAsDefaultExec)
+ {
+ m_pProject->SetDefaultExecuteTarget(m_ProjectParam[i].txtBuildTarget);
+ }
+ }
     }
  wxDialog::EndModal(retCode);
 } // end of EndModal
Index: src/include/selecttargetdlg.h
===================================================================
--- src/include/selecttargetdlg.h (revision 4921)
+++ src/include/selecttargetdlg.h (working copy)
@@ -7,10 +7,17 @@
 #define SELECTTARGETDLG_H
 
 #include <wx/dialog.h>
+#include <wx/dynarray.h>
 
 class cbProject;
 class ProjectBuildTarget;
 
+//Forward declaration for internal class storage
+class SelectTargetStruct;
+
+WX_DECLARE_OBJARRAY(SelectTargetStruct, ArrayOfSelectTargetStruct);
+
+//Dialog class for "Set program argument" menu item
 class SelectTargetDlg : public wxDialog
 {
  public:
@@ -19,15 +26,14 @@
 
  void EndModal(int retCode);
  int GetSelection() const { return m_Selected; }
- ProjectBuildTarget* GetSelectionTarget();
  private:
  void OnListboxSelection(wxCommandEvent& event);
- void OnListboxDClick(wxCommandEvent& event);
-        void OnCheckboxSelection(wxCommandEvent& event);
         void OnHostApplicationButtonClick(wxCommandEvent& event);
  void UpdateSelected();
+
  cbProject* m_pProject;
  int m_Selected;
+ ArrayOfSelectTargetStruct m_ProjectParam;
 
  DECLARE_EVENT_TABLE()
 };
Index: src/include/cbproject.h
===================================================================
--- src/include/cbproject.h (revision 4921)
+++ src/include/cbproject.h (working copy)
@@ -666,13 +666,17 @@
           */
         virtual void ProjectFileRenamed(ProjectFile* pf);
 
+        /** Get index for target with name "targetName"
+          * @param targetName The name of the build target for search.
+          * @return Index of build target or -1 if not found.
+          */
+        int IndexOfBuildTargetName(const wxString& targetName) const;
     private:
         void Open();
         void ExpandVirtualBuildTargetGroup(const wxString& alias, wxArrayString& result) const;
         wxTreeItemId AddTreeNode(wxTreeCtrl* tree, const wxString& text, const wxTreeItemId& parent, bool useFolders, FileTreeData::FileTreeDataKind folders_kind, bool compiles, int image, FileTreeData* data = 0L);
         wxTreeItemId FindNodeToInsertAfter(wxTreeCtrl* tree, const wxString& text, const wxTreeItemId& parent, bool in_folders); // alphabetical sorting
         ProjectBuildTarget* AddDefaultBuildTarget();
-        int IndexOfBuildTargetName(const wxString& targetName) const;
         wxString CreateUniqueFilename();
         void NotifyPlugins(wxEventType type, const wxString& targetName = wxEmptyString, const wxString& oldTargetName = wxEmptyString);
         void CopyTreeNodeRecursively(wxTreeCtrl* tree, const wxTreeItemId& item, const wxTreeItemId& new_parent);

I write constructor's initialization as
Code
+	: m_pProject(project), m_Selected(-1)
because bellow
Code
+	list->SetSelection(selected);
« Last Edit: March 18, 2008, 02:40:46 pm by AlekseyT »

Offline DrewBoo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: Patch #1
« Reply #16 on: March 17, 2008, 06:31:18 am »
Funny, I never wanted that... must be that I'm still in the 5% that are left over.

For what it's worth, I find that feature unusual as AlekseyT does.

I've worked on large projects that have certainly had files that were unique to a particular build, but I've always made that the exception and not the norm.  After all, code that is unique to a particular build will always make testing more difficult.

Perhaps -- at the very least -- there could be a checkbox to make the current build selection the default.

Currently, the default is that a newly added file belongs to none of my build options.  By comparison, that has never been what I want.

I have had experience with MS VS projects, as Morten mentions.  Perhaps someone could explain why that is undesirable?

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #17 on: March 18, 2008, 02:39:30 pm »
Developers, hi again. Is last "Execution parameters" patch applyed? If not, what wrong with it again?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Patch #1
« Reply #18 on: March 18, 2008, 03:43:45 pm »
Developers, hi again. Is last "Execution parameters" patch applyed? If not, what wrong with it again?
I haven' had time to look into yet. But don't you worry - it's on my list and USB stick... so it won't get lost. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline AlekseyT

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch #1
« Reply #19 on: March 19, 2008, 07:51:03 am »
Ok. Thank you.