------------------------------------------------------------ revno: 2175 committer: poy <p...@123gen.com> branch nick: repo timestamp: Mon 2010-07-05 22:17:42 +0200 message: tweak string list dialogs modified: win32/FavoriteDirsPage.cpp win32/SearchTypesPage.cpp win32/SearchTypesPage.h win32/StringListDlg.cpp win32/StringListDlg.h win32/UploadPage.cpp win32/UploadPage.h
-- lp:dcplusplus https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk Your team Dcplusplus-team is subscribed to branch lp:dcplusplus. To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'win32/FavoriteDirsPage.cpp' --- win32/FavoriteDirsPage.cpp 2010-02-11 21:44:13 +0000 +++ win32/FavoriteDirsPage.cpp 2010-07-05 20:17:42 +0000 @@ -74,6 +74,8 @@ for(StringPairIter j = dirs.begin(); j != dirs.end(); j++) addRow(Text::toT(j->second), Text::toT(j->first)); + handleSelectionChanged(); + directories->onDblClicked(std::tr1::bind(&FavoriteDirsPage::handleDoubleClick, this)); directories->onKeyDown(std::tr1::bind(&FavoriteDirsPage::handleKeyDown, this, _1)); directories->onSelectionChanged(std::tr1::bind(&FavoriteDirsPage::handleSelectionChanged, this)); === modified file 'win32/SearchTypesPage.cpp' --- win32/SearchTypesPage.cpp 2010-06-30 14:40:00 +0000 +++ win32/SearchTypesPage.cpp 2010-07-05 20:17:42 +0000 @@ -103,11 +103,11 @@ fillList(); - handleItemChanged(); + handleSelectionChanged(); types->onDblClicked(std::tr1::bind(&SearchTypesPage::handleDoubleClick, this)); types->onKeyDown(std::tr1::bind(&SearchTypesPage::handleKeyDown, this, _1)); - types->onRaw(std::tr1::bind(&SearchTypesPage::handleItemChanged, this), dwt::Message(WM_NOTIFY, LVN_ITEMCHANGED)); + types->onSelectionChanged(std::tr1::bind(&SearchTypesPage::handleSelectionChanged, this)); } SearchTypesPage::~SearchTypesPage() { @@ -142,13 +142,12 @@ return false; } -LRESULT SearchTypesPage::handleItemChanged() { +void SearchTypesPage::handleSelectionChanged() { bool sel = types->hasSelected(); bool changeable = sel && types->getText(types->getSelected(), 1).empty(); rename->setEnabled(changeable); remove->setEnabled(changeable); modify->setEnabled(sel); - return 0; } void SearchTypesPage::handleAddClicked() { === modified file 'win32/SearchTypesPage.h' --- win32/SearchTypesPage.h 2010-06-30 14:40:00 +0000 +++ win32/SearchTypesPage.h 2010-07-05 20:17:42 +0000 @@ -39,7 +39,7 @@ void handleDoubleClick(); bool handleKeyDown(int c); - LRESULT handleItemChanged(); + void handleSelectionChanged(); void handleAddClicked(); void handleModClicked(); === modified file 'win32/StringListDlg.cpp' --- win32/StringListDlg.cpp 2010-06-19 15:28:04 +0000 +++ win32/StringListDlg.cpp 2010-07-05 20:17:42 +0000 @@ -26,11 +26,17 @@ #include "ParamDlg.h" #include "WinUtil.h" -StringListDlg::StringListDlg(dwt::Widget* parent, const TStringList& initialValues) : +StringListDlg::StringListDlg(dwt::Widget* parent, const TStringList& initialValues, bool ensureUniqueness) : dwt::ModalDialog(parent), grid(0), editBox(0), -list(0) +list(0), +addBtn(0), +up(0), +down(0), +editBtn(0), +remove(0), +unique(ensureUniqueness) { onInitDialog(std::tr1::bind(&StringListDlg::handleInitDialog, this, initialValues)); onHelp(std::tr1::bind(&WinUtil::help, _1, _2)); @@ -45,6 +51,8 @@ } void StringListDlg::insert(const tstring& line, int index) { + if(!checkUnique(line)) + return; int itemCount = list->insert(TStringList(1, line), 0, index); if(index == -1) index = itemCount; @@ -52,6 +60,8 @@ } void StringListDlg::modify(unsigned row, const tstring& text) { + if(!checkUnique(text)) + return; list->setText(row, 0, text); } @@ -102,9 +112,11 @@ editBox->setHelpId(getHelpId(HELP_EDIT_BOX)); { - ButtonPtr add = grid->addChild(Button::Seed(T_("&Add"))); - add->setHelpId(getHelpId(HELP_ADD)); - add->onClicked(std::tr1::bind(&StringListDlg::handleAddClicked, this)); + Button::Seed seed = Button::Seed(T_("&Add")); + seed.menuHandle = reinterpret_cast<HMENU>(IDOK); + addBtn = grid->addChild(seed); + addBtn->setHelpId(getHelpId(HELP_ADD)); + addBtn->onClicked(std::tr1::bind(&StringListDlg::handleAddClicked, this)); } { @@ -119,32 +131,33 @@ cur->row(4).mode = GridInfo::FILL; cur->row(4).align = GridInfo::BOTTOM_RIGHT; - ButtonPtr button; Button::Seed seed; seed.caption = T_("Move &Up"); - button = cur->addChild(seed); - button->setHelpId(getHelpId(HELP_MOVE_UP)); - button->onClicked(std::tr1::bind(&StringListDlg::handleMoveUpClicked, this)); + up = cur->addChild(seed); + up->setHelpId(getHelpId(HELP_MOVE_UP)); + up->onClicked(std::tr1::bind(&StringListDlg::handleMoveUpClicked, this)); seed.caption = T_("Move &Down"); - button = cur->addChild(seed); - button->setHelpId(getHelpId(HELP_MOVE_DOWN)); - button->onClicked(std::tr1::bind(&StringListDlg::handleMoveDownClicked, this)); + down = cur->addChild(seed); + down->setHelpId(getHelpId(HELP_MOVE_DOWN)); + down->onClicked(std::tr1::bind(&StringListDlg::handleMoveDownClicked, this)); seed.caption = T_("&Edit"); - button = cur->addChild(seed); - button->setHelpId(getHelpId(HELP_EDIT)); - button->onClicked(std::tr1::bind(&StringListDlg::handleEditClicked, this)); + editBtn = cur->addChild(seed); + editBtn->setHelpId(getHelpId(HELP_EDIT)); + editBtn->onClicked(std::tr1::bind(&StringListDlg::handleEditClicked, this)); seed.caption = T_("&Remove"); - button = cur->addChild(seed); - button->setHelpId(getHelpId(HELP_REMOVE)); - button->onClicked(std::tr1::bind(&StringListDlg::handleRemoveClicked, this)); + remove = cur->addChild(seed); + remove->setHelpId(getHelpId(HELP_REMOVE)); + remove->onClicked(std::tr1::bind(&StringListDlg::handleRemoveClicked, this)); - WinUtil::addDlgButtons(cur, + ::SetWindowLongPtr( + WinUtil::addDlgButtons(cur, std::tr1::bind(&StringListDlg::handleOKClicked, this), - std::tr1::bind(&StringListDlg::endDialog, this, IDCANCEL)); + std::tr1::bind(&StringListDlg::endDialog, this, IDCANCEL)) + .first->handle(), GWLP_ID, 0); // the def button is the "Add" button } list->createColumns(TStringList(1)); @@ -152,8 +165,13 @@ for(TStringIterC i = initialValues.begin(), iend = initialValues.end(); i != iend; ++i) insert(*i); + handleSelectionChanged(); + handleInputUpdated(); + list->onDblClicked(std::tr1::bind(&StringListDlg::handleDoubleClick, this)); list->onKeyDown(std::tr1::bind(&StringListDlg::handleKeyDown, this, _1)); + list->onSelectionChanged(std::tr1::bind(&StringListDlg::handleSelectionChanged, this)); + editBox->onUpdated(std::tr1::bind(&StringListDlg::handleInputUpdated, this)); setText(getTitle()); @@ -181,8 +199,30 @@ return false; } +void StringListDlg::handleSelectionChanged() { + bool enable = list->hasSelected(); + up->setEnabled(enable); + down->setEnabled(enable); + editBtn->setEnabled(enable); + remove->setEnabled(enable); +} + +void StringListDlg::handleInputUpdated() { + bool enable = editBox->length() > 0; + if(addBtn->getEnabled() != enable) { + addBtn->setEnabled(enable); + } +} + void StringListDlg::handleAddClicked() { + if(editBox->length() <= 0) + return; + add(editBox->getText()); + + if(!editBox->hasFocus()) + editBox->setFocus(); + editBox->setSelection(); } void StringListDlg::handleMoveUpClicked() { @@ -237,3 +277,15 @@ list->setColumnWidth(0, list->getWindowSize().x - 20); } + +bool StringListDlg::checkUnique(const tstring& text) { + if(!unique) + return true; + + int pos = list->find(text); + if(pos == -1) + return true; + + list->ensureVisible(pos); + return false; +} === modified file 'win32/StringListDlg.h' --- win32/StringListDlg.h 2010-06-19 15:28:04 +0000 +++ win32/StringListDlg.h 2010-07-05 20:17:42 +0000 @@ -23,7 +23,8 @@ class StringListDlg : public dwt::ModalDialog { public: - StringListDlg(dwt::Widget* parent, const TStringList& initialValues); + /// @param ensureUniqueness whether items in the list are unique (case insensitive) + StringListDlg(dwt::Widget* parent, const TStringList& initialValues, bool ensureUniqueness = true); virtual ~StringListDlg(); int run(); @@ -56,12 +57,21 @@ GridPtr grid; TextBoxPtr editBox; TablePtr list; + ButtonPtr addBtn; + ButtonPtr up; + ButtonPtr down; + ButtonPtr editBtn; + ButtonPtr remove; TStringList values; + const bool unique; + bool handleInitDialog(const TStringList& initialValues); void handleDoubleClick(); bool handleKeyDown(int c); + void handleSelectionChanged(); + void handleInputUpdated(); void handleAddClicked(); void handleMoveUpClicked(); void handleMoveDownClicked(); @@ -70,6 +80,8 @@ void handleOKClicked(); void layout(); + + bool checkUnique(const tstring& text); }; #endif // !defined(DCPLUSPLUS_WIN32_STRING_LIST_DLG_H) === modified file 'win32/UploadPage.cpp' --- win32/UploadPage.cpp 2010-04-05 17:11:06 +0000 +++ win32/UploadPage.cpp 2010-07-05 20:17:42 +0000 @@ -129,9 +129,11 @@ fillList(); + handleSelectionChanged(); + directories->onDblClicked(std::tr1::bind(&UploadPage::handleDoubleClick, this)); directories->onKeyDown(std::tr1::bind(&UploadPage::handleKeyDown, this, _1)); - directories->onRaw(std::tr1::bind(&UploadPage::handleItemChanged, this), dwt::Message(WM_NOTIFY, LVN_ITEMCHANGED)); + directories->onSelectionChanged(std::tr1::bind(&UploadPage::handleSelectionChanged, this)); directories->onDragDrop(std::tr1::bind(&UploadPage::handleDragDrop, this, _1)); } @@ -177,11 +179,10 @@ return false; } -LRESULT UploadPage::handleItemChanged() { +void UploadPage::handleSelectionChanged() { bool enable = directories->hasSelected(); rename->setEnabled(enable); remove->setEnabled(enable); - return 0; } void UploadPage::handleDragDrop(const TStringList& files) { === modified file 'win32/UploadPage.h' --- win32/UploadPage.h 2010-04-05 17:11:06 +0000 +++ win32/UploadPage.h 2010-07-05 20:17:42 +0000 @@ -42,7 +42,7 @@ void handleDoubleClick(); bool handleKeyDown(int c); - LRESULT handleItemChanged(); + void handleSelectionChanged(); void handleDragDrop(const TStringList& files); void handleShareHiddenClicked(CheckBoxPtr checkBox, Item& item); void handleAddClicked();
_______________________________________________ Mailing list: https://launchpad.net/~linuxdcpp-team Post to : linuxdcpp-team@lists.launchpad.net Unsubscribe : https://launchpad.net/~linuxdcpp-team More help : https://help.launchpad.net/ListHelp