Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Patch #1

(1/4) > >>

AlekseyT:
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]

AlekseyT:
Is this patch will be apply to Code::Blocks source by developers?

thomas:
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 :)

AlekseyT:
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()
 };

--- End code ---

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)
         {

--- End code ---

MortenMacFly:
Mmmmmh... still a little suspicious. Why do you do things like that:

--- Quote from: AlekseyT on March 06, 2008, 06:56:32 am ---
--- Code: ----                            wxOPEN | wxFILE_MUST_EXIST | compatibility::wxHideReadonly);
+                            wxOPEN | wxFILE_MUST_EXIST);

--- End code ---

--- End quote ---
??? 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.

Navigation

[0] Message Index

[#] Next page

Go to full version