FileSelector: fix combobox behavior as now ComboBox::onChange() event is generated when the combobox is open

This commit is contained in:
David Capello 2014-03-29 18:42:17 -03:00
parent 7e593e92e1
commit 6ed35b733c
4 changed files with 20 additions and 8 deletions

View File

@ -191,6 +191,7 @@ public:
FileSelector::FileSelector()
: Window(WithTitleBar, "")
, m_navigationLocked(false)
{
app::WidgetLoader loader;
loader.addWidgetType("filenameentry", new CustomFileNameEntryCreator);
@ -239,7 +240,7 @@ FileSelector::FileSelector()
m_goBack->Click.connect(Bind<void>(&FileSelector::onGoBack, this));
m_goForward->Click.connect(Bind<void>(&FileSelector::onGoForward, this));
m_goUp->Click.connect(Bind<void>(&FileSelector::onGoUp, this));
m_location->Change.connect(Bind<void>(&FileSelector::onLocationChange, this));
m_location->CloseListBox.connect(Bind<void>(&FileSelector::onLocationCloseListBox, this));
m_fileType->Change.connect(Bind<void>(&FileSelector::onFileTypeChange, this));
m_fileList->FileSelected.connect(Bind<void>(&FileSelector::onFileListFileSelected, this));
m_fileList->FileAccepted.connect(Bind<void>(&FileSelector::onFileListFileAccepted, this));
@ -610,7 +611,7 @@ void FileSelector::onGoUp()
}
// Hook for the 'location' combo-box
void FileSelector::onLocationChange()
void FileSelector::onLocationCloseListBox()
{
// When the user change the location we have to set the
// current-folder in the 'fileview' widget

View File

@ -51,7 +51,7 @@ namespace app {
void onGoBack();
void onGoForward();
void onGoUp();
void onLocationChange();
void onLocationCloseListBox();
void onFileTypeChange();
void onFileListFileSelected();
void onFileListFileAccepted();

View File

@ -85,7 +85,7 @@ ComboBox::ComboBox()
m_entry = new ComboBoxEntry(this);
m_button = new ComboBoxButton();
m_window = NULL;
m_selected = 0;
m_selected = -1;
m_editable = false;
m_clickopen = true;
m_casesensitive = true;
@ -290,12 +290,16 @@ int ComboBox::getSelectedItemIndex() const
void ComboBox::setSelectedItemIndex(int itemIndex)
{
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
if (itemIndex >= 0 &&
(size_t)itemIndex < m_items.size() &&
m_selected != itemIndex) {
m_selected = itemIndex;
ListItems::iterator it = m_items.begin() + itemIndex;
ListItem* item = *it;
m_entry->setText(item->getText());
onChange();
}
}
@ -481,10 +485,8 @@ void ComboBoxListBox::onChangeSelectedItem()
ListBox::onChangeSelectedItem();
int index = getSelectedIndex();
if (isValidItem(index)) {
if (isValidItem(index))
m_comboBox->setSelectedItemIndex(index);
m_comboBox->onChange();
}
}
// When the mouse is clicked we switch the visibility-status of the list-box
@ -525,6 +527,8 @@ void ComboBox::openListBox()
m_window->openWindow();
getManager()->setFocus(m_listbox);
onOpenListBox();
}
}
@ -570,6 +574,11 @@ void ComboBox::onChange()
Change();
}
void ComboBox::onOpenListBox()
{
OpenListBox();
}
void ComboBox::onCloseListBox()
{
CloseListBox();

View File

@ -83,6 +83,7 @@ namespace ui {
// Signals
Signal0<void> Change;
Signal0<void> OpenListBox;
Signal0<void> CloseListBox;
protected:
@ -90,6 +91,7 @@ namespace ui {
void onResize(ResizeEvent& ev) OVERRIDE;
void onPreferredSize(PreferredSizeEvent& ev) OVERRIDE;
virtual void onChange();
virtual void onOpenListBox();
virtual void onCloseListBox();
private: