Author Topic: bugfix : need info on wxCombo  (Read 8048 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
bugfix : need info on wxCombo
« on: January 25, 2006, 11:24:58 pm »
I am trying to fix the bug reported about the default code.
When you go to the editor settings, and you fill something in for c++ source, then you do the same for C++ header and then switch back to c++ source, the enteredt stuff is gone. This only happens the first time, so if you would fill in new stuff, then go back to header adn then back to source it would be OK.

I now where in the code things go wrong and I can adjust it there to make it work, though I think there's also another problem, related to wxCombo.
The combo can has 2 selections (source and header), apparently it starts up with 'source', when switching the 'header' the function OnChangeDefCodeFileType is called, which is what we want, BUT the very first time (remember this is where it goes wrong) this is called TWICE, all subsequent switches result in exactly ONE call, which seems the correct thing to do.

Does anyone know why there are 2 calls the first time ? Can the combo box be badly initialized, for example do we need to specify in the beginning which selection it should start out with, or does it default to the first one ??

My adjustement will fix the problem, but if that 2 calls would be just 2 call, then the bug is probably also fixed.

Lieven

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: bugfix : need info on wxCombo
« Reply #1 on: January 26, 2006, 09:03:38 am »
Will still waiting on some input ;-) , there's another issue I have seen I'dd like to address.
When you are in the editor settings, should any change be applied before you hit the OK key ?
Since now for those default codes, changes get applied the moment you switch from one type to another, so even when you 'cancel' your way out, stuff has changed.
IMHO nothing should change before OK press, if others (mainly the devs) agree, I would create a patch for this too (well at least for the default code). Anyway normally I will post my patch for the first problem somewhere this morning, even if no feedback comes on that 'wxCombo' question.

Cheers,
Lieven

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: bugfix : need info on wxCombo
« Reply #2 on: January 26, 2006, 12:07:04 pm »
Will still waiting on some input ;-)

I have tried with rev1866 and I have the same bug (as you said).

Michael

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: bugfix : need info on wxCombo
« Reply #3 on: January 26, 2006, 12:17:39 pm »
Well, I already have fixed the first part (will post explanation this evening), but I want to undeerstand why there were 2 OnChange... calls at the beginning, I think their should only be 1. But need the info from the devs here, my knowledge of wx is not that big. I think my fix is an improvement even when their would be only 1 OnChange..., since the code is now doing some stuff which is not needed I think. I know very abstract if I don't show you what I am talking about. Can't get to the source at this very moment. :-(

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: bugfix : need info on wxCombo
« Reply #4 on: January 26, 2006, 12:23:18 pm »
Well, I already have fixed the first part (will post explanation this evening)

Super. Thank you :).

, but I want to undeerstand why there were 2 OnChange... calls at the beginning, I think their should only be 1. But need the info from the devs here, my knowledge of wx is not that big. I think my fix is an improvement even when their would be only 1 OnChange..., since the code is now doing some stuff which is not needed I think. I know very abstract if I don't show you what I am talking about. Can't get to the source at this very moment. :-(

It seems to me too that 2 calls are not needed, but better to have input from devs (as you said). May be this is needed for some kind of initialization. Anyway, if just one call was enough, your fix indeed improves the performance of C::B (a fact that it is always appreciate :D).

Michael

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: bugfix : need info on wxCombo
« Reply #5 on: January 26, 2006, 01:42:14 pm »
Revision 1870 works as you would expect it. I am not saying "properly" or "correctly" on purpose, because that's not what it is.
The original implementation is perfectly correct, and it should work (but it does not because wxWidgets sends out bad events...).

The "fix" comments out the if which checks whether the page has changed, thus the page is now saved every time, whether changed or not. This is not as it should be, but it works...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: bugfix : need info on wxCombo
« Reply #6 on: January 26, 2006, 02:09:36 pm »
This was how I fixed it  :

original code :
Code
void EditorConfigurationDlg::OnChangeDefCodeFileType(wxCommandEvent& event)
{
int sel = XRCCTRL(*this, "cmbDefCodeFileType", wxComboBox)->GetSelection();
if (sel != m_DefCodeFileType)
{
wxString key;
key.Printf(_T("/default_code/set%d"), IdxToFileType[m_DefCodeFileType]);
Manager::Get()->GetConfigManager(_T("editor"))->Write(key, XRCCTRL(*this, "txtDefCode", wxTextCtrl)->GetValue());
}
m_DefCodeFileType = sel;
key.Printf(_T("/default_code/set%d"), IdxToFileType[m_DefCodeFileType]);
XRCCTRL(*this, "txtDefCode", wxTextCtrl)->SetValue(Manager::Get()->GetConfigManager(_T("editor"))->Read(key, wxEmptyString));
}

MY code :
Code
void EditorConfigurationDlg::OnChangeDefCodeFileType(wxCommandEvent& event)
{
int sel = XRCCTRL(*this, "cmbDefCodeFileType", wxComboBox)->GetSelection();
if (sel != m_DefCodeFileType)
{
wxString key;
key.Printf(_T("/default_code/set%d"), IdxToFileType[m_DefCodeFileType]);
Manager::Get()->GetConfigManager(_T("editor"))->Write(key, XRCCTRL(*this, "txtDefCode", wxTextCtrl)->GetValue());
m_DefCodeFileType = sel;
key.Printf(_T("/default_code/set%d"), IdxToFileType[m_DefCodeFileType]);
XRCCTRL(*this, "txtDefCode", wxTextCtrl)->SetValue(Manager::Get()->GetConfigManager(_T("editor"))->Read(key, wxEmptyString));
}
}
During my debugging sessions I saw yesterday that, the first we changed the selection in the combo box from 'source' to 'header', we ended up TWICE in this method, the very first time, sel will be 0 (!!!! so extra event with the old value), and the member m_DefCodeFileTYpe is initially 0 (constructor), so the if test failes, it thinks the selection has not changed, then after the if test it updates the member (in this case, no change), then reads out the 'default code' that's in the configuration file, and sets/shows that in the dialog. That means that in this case it will show the old default 'source' code (which in my test was , just nothing, nada, empty).
Then the second call arrives, and now sel is 1, correct that's the 'header' we switched to, if test succeeds and we SAVE (note : next thing I will fix, we should not save yet, nobody pressed OK !!!) the current default code to the configuration file. Well we just have reloaded the old stuff, so our new stuff is gone. That's why we loose it. Then we set the member to the new selection, and we set/show what we had for this new selection in the configuration file.

Every other switch from this moment on, for example 'header' -> 'source', or again 'source'->'header' works ok (when dialog is closed, and you go back to this settings dialog, the story restarts off course), because there's only 1 call to the method, and the sel will always be the new selection.

So the ultimate solution : not that errounous first call, Yiannis and Thomas told me it's a wx event problem.

Thomas his fix, does not have this problem, since he now always save, even if the selection did not change (eg : in the combo, mouse from 'source' to 'header' and back to 'source' and then left click with you mouse).

My fix does it a little bit different : if the selection did not change, why would we read out the the 'default' code , which was set to the ctrl, back from the configuration file, to set again to the ctrl. The ctrl still has it (I think/hope this is correct and there are no other reasons to come here). Therefor those 3 lines (setting the member with the new sel, and readout fron configuration file and setting ctrl) can be moved inside the if test.

So when that erronous first call comes, the sel == m_DefCodeFileType, if test fails, and nothing else get's done (so no overwriting the new stuff with the old stuff), when the correct second call (and all other correct 'first and only' calls) come and the selection has changed, save to file (ahem ahem, we did not click on OK ;-) ) and the default code for the new selection is loaded from the configuration file and set/shown to the ctrl.


So as said, next I will fix the issue that stuff gets save before clicking on ok, so we can bail/cancel our way out.

Lieven

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5529
Re: bugfix : need info on wxCombo
« Reply #7 on: January 27, 2006, 12:24:30 am »
all mentioned bugs (loosing the first entrance in source, and storing before 'OK'-ed by the user) have been fixed with this patch : https://sourceforge.net/tracker/index.php?func=detail&aid=1415821&group_id=126998&atid=707418

The only thing that remains is the double call from wx, seems it's a change : undocumented correct behaviour ? bug ? from wx.

But our functional problems though are solved ;-)

Cheers,
Lieven