linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #01311
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2158: add a generic StringListDlg based on the public hub list config dialog
------------------------------------------------------------
revno: 2158
committer: poy <poy@xxxxxxxxxx>
branch nick: repo
timestamp: Tue 2010-06-08 22:04:18 +0200
message:
add a generic StringListDlg based on the public hub list config dialog
added:
help/dialog_string_list.html
win32/StringListDlg.cpp
win32/StringListDlg.h
modified:
dcpp/Util.cpp
dcpp/Util.h
help/DCPlusPlus.hhp
help/index.html
help/resource.h
win32/HubListsDlg.cpp
win32/HubListsDlg.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 'dcpp/Util.cpp'
--- dcpp/Util.cpp 2010-05-04 16:37:43 +0000
+++ dcpp/Util.cpp 2010-06-08 20:04:18 +0000
@@ -576,28 +576,12 @@
return Text::toLower(c);
}
-string Util::toString(const string& sep, const StringList& lst) {
- string ret;
- for(StringList::const_iterator i = lst.begin(), iend = lst.end(); i != iend; ++i) {
- ret += *i;
- if(i + 1 != iend)
- ret += sep;
- }
- return ret;
-}
-
string Util::toString(const StringList& lst) {
+ if(lst.empty())
+ return emptyString;
if(lst.size() == 1)
return lst[0];
- string tmp("[");
- for(StringList::const_iterator i = lst.begin(), iend = lst.end(); i != iend; ++i) {
- tmp += *i + ',';
- }
- if(tmp.length() == 1)
- tmp.push_back(']');
- else
- tmp[tmp.length()-1] = ']';
- return tmp;
+ return '[' + toString(",", lst) + ']';
}
string::size_type Util::findSubString(const string& aString, const string& aSubString, string::size_type start) throw() {
=== modified file 'dcpp/Util.h'
--- dcpp/Util.h 2010-03-20 16:51:58 +0000
+++ dcpp/Util.h 2010-06-08 20:04:18 +0000
@@ -342,7 +342,20 @@
return buf;
}
- static string toString(const string& sep, const StringList& lst);
+ template<typename string_t>
+ static string_t toString(const string_t& sep, const vector<string_t>& lst) {
+ string_t ret;
+ for(typename vector<string_t>::const_iterator i = lst.begin(), iend = lst.end(); i != iend; ++i) {
+ ret += *i;
+ if(i + 1 != iend)
+ ret += sep;
+ }
+ return ret;
+ }
+ template<typename string_t>
+ static inline string_t toString(const typename string_t::value_type* sep, const vector<string_t>& lst) {
+ return toString(string_t(sep), lst);
+ }
static string toString(const StringList& lst);
static string toHexEscape(char val) {
=== modified file 'help/DCPlusPlus.hhp'
--- help/DCPlusPlus.hhp 2010-01-14 20:25:12 +0000
+++ help/DCPlusPlus.hhp 2010-06-08 20:04:18 +0000
@@ -53,6 +53,7 @@
IDH_ADLSP=dialog_adls_properties.html
IDH_PUBLIC_HUB_LISTS=dialog_public_hub_lists.html
IDH_CUSTOMIZE_TB=dialog_customize_tb.html
+IDH_STRING_LIST=dialog_string_list.html
IDH_ADVANCED3PAGE=settings_expert.html
IDH_ADVANCEDPAGE=settings_advanced.html
IDH_APPEARANCE2PAGE=settings_colors_and_sounds.html
=== added file 'help/dialog_string_list.html'
--- help/dialog_string_list.html 1970-01-01 00:00:00 +0000
+++ help/dialog_string_list.html 2010-06-08 20:04:18 +0000
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+<link type="text/css" rel="stylesheet" href="office11.css"/>
+<link type="text/css" rel="stylesheet" href="style.css"/>
+</head>
+<body>
+<h1>List configuration</h1>
+These instructions apply to generic list management dialogs.
+<h2>Field to add a new item (top)</h2>
+<p cshelp="IDH_STRING_LIST_EDIT_BOX">
+Use this input box to write a new item you want to add.
+</p>
+<h2>List</h2>
+<p cshelp="IDH_STRING_LIST_LIST">
+Shows the current list. It will only be altered once you have pressed "OK".
+</p>
+<h2>Buttons (right)</h2>
+<dl style="margin-left: 40px;">
+ <dt>Add</dt>
+ <dd cshelp="IDH_STRING_LIST_ADD">Add the item specified in the field on the top left to the current list.</dd>
+ <dt>Move Up</dt>
+ <dd cshelp="IDH_STRING_LIST_MOVE_UP">Move selected items upwards in the list.</dd>
+ <dt>Move Down</dt>
+ <dd cshelp="IDH_STRING_LIST_MOVE_DOWN">Move selected items downwards in the list.</dd>
+ <dt>Edit</dt>
+ <dd cshelp="IDH_STRING_LIST_EDIT">Open a dialog to edit currently selected items.</dd>
+ <dt>Remove</dt>
+ <dd cshelp="IDH_STRING_LIST_REMOVE">Remove selected items from the current list.</dd>
+</dl>
+</body>
+</html>
=== modified file 'help/index.html'
--- help/index.html 2010-02-06 19:38:21 +0000
+++ help/index.html 2010-06-08 20:04:18 +0000
@@ -64,6 +64,7 @@
<li><placeholder><a href="dialog_adls_properties.html">ADLSearch Properties</a></placeholder></li>
<li><placeholder><a href="dialog_public_hub_lists.html">Configured Public Hub Lists</a></placeholder></li>
<li><placeholder><a href="dialog_customize_tb.html">Toolbar customization</a></placeholder></li>
+<li><placeholder><a href="dialog_string_list.html">List configuration</a></placeholder></li>
</ul>
</li>
<li>
=== modified file 'help/resource.h'
--- help/resource.h 2010-01-14 20:25:12 +0000
+++ help/resource.h 2010-06-08 20:04:18 +0000
@@ -40,6 +40,7 @@
#define IDH_ADLSP 10204
#define IDH_PUBLIC_HUB_LISTS 10205
#define IDH_CUSTOMIZE_TB 10206
+#define IDH_STRING_LIST 10207
// settings pages
#define IDH_ADVANCED3PAGE 10300
=== modified file 'win32/HubListsDlg.cpp'
--- win32/HubListsDlg.cpp 2010-02-11 21:44:13 +0000
+++ win32/HubListsDlg.cpp 2010-06-08 20:04:18 +0000
@@ -24,192 +24,57 @@
#include <dcpp/FavoriteManager.h>
#include <dcpp/StringTokenizer.h>
-#include "HoldRedraw.h"
-#include "ParamDlg.h"
-#include "WinUtil.h"
HubListsDlg::HubListsDlg(dwt::Widget* parent) :
-dwt::ModalDialog(parent),
-grid(0),
-editBox(0),
-hubLists(0)
+StringListDlg(parent, getHubLists())
{
- onInitDialog(std::tr1::bind(&HubListsDlg::handleInitDialog, this));
- onHelp(std::tr1::bind(&WinUtil::help, _1, _2));
-}
-
-HubListsDlg::~HubListsDlg() {
}
int HubListsDlg::run() {
- create(Seed(dwt::Point(400, 316), DS_CONTEXTHELP));
- return show();
-}
-
-bool HubListsDlg::handleInitDialog() {
- setHelpId(IDH_PUBLIC_HUB_LISTS);
-
- grid = addChild(Grid::Seed(2, 2));
- grid->column(0).mode = GridInfo::FILL;
- grid->row(1).mode = GridInfo::FILL;
- grid->row(1).align = GridInfo::STRETCH;
-
- editBox = grid->addChild(WinUtil::Seeds::Dialog::textBox);
- editBox->setHelpId(IDH_PUBLIC_HUB_LISTS_EDIT_BOX);
-
- {
- ButtonPtr add = grid->addChild(Button::Seed(T_("&Add")));
- add->setHelpId(IDH_PUBLIC_HUB_LISTS_ADD);
- add->onClicked(std::tr1::bind(&HubListsDlg::handleAddClicked, this));
- }
-
- {
- Table::Seed seed = WinUtil::Seeds::Dialog::table;
- seed.style |= LVS_NOCOLUMNHEADER;
- hubLists = grid->addChild(seed);
- hubLists->setHelpId(IDH_PUBLIC_HUB_LISTS_LIST);
- }
-
- {
- GridPtr cur = grid->addChild(Grid::Seed(6, 1));
- 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(IDH_PUBLIC_HUB_LISTS_MOVE_UP);
- button->onClicked(std::tr1::bind(&HubListsDlg::handleMoveUpClicked, this));
-
- seed.caption = T_("Move &Down");
- button = cur->addChild(seed);
- button->setHelpId(IDH_PUBLIC_HUB_LISTS_MOVE_DOWN);
- button->onClicked(std::tr1::bind(&HubListsDlg::handleMoveDownClicked, this));
-
- seed.caption = T_("&Edit");
- button = cur->addChild(seed);
- button->setHelpId(IDH_PUBLIC_HUB_LISTS_EDIT);
- button->onClicked(std::tr1::bind(&HubListsDlg::handleEditClicked, this));
-
- seed.caption = T_("&Remove");
- button = cur->addChild(seed);
- button->setHelpId(IDH_PUBLIC_HUB_LISTS_REMOVE);
- button->onClicked(std::tr1::bind(&HubListsDlg::handleRemoveClicked, this));
-
- WinUtil::addDlgButtons(cur,
- std::tr1::bind(&HubListsDlg::handleOKClicked, this),
- std::tr1::bind(&HubListsDlg::endDialog, this, IDCANCEL));
- }
-
- hubLists->createColumns(TStringList(1));
-
+ int ret = StringListDlg::run();
+ if(ret == IDOK) {
+ SettingsManager::getInstance()->set(SettingsManager::HUBLIST_SERVERS,
+ Text::fromT(Util::toString(_T(";"), getValues())));
+ }
+ return ret;
+}
+
+tstring HubListsDlg::getTitle() const {
+ return T_("Configured Public Hub Lists");
+}
+
+tstring HubListsDlg::getEditTitle() const {
+ return T_("Hublist");
+}
+
+tstring HubListsDlg::getEditDescription() const {
+ return T_("Address");
+}
+
+unsigned HubListsDlg::getHelpId(HelpFields field) const {
+ switch(field) {
+ case HELP_DIALOG: return IDH_PUBLIC_HUB_LISTS;
+ case HELP_EDIT_BOX: return IDH_PUBLIC_HUB_LISTS_EDIT_BOX;
+ case HELP_LIST: return IDH_PUBLIC_HUB_LISTS_LIST;
+ case HELP_ADD: return IDH_PUBLIC_HUB_LISTS_ADD;
+ case HELP_MOVE_UP: return IDH_PUBLIC_HUB_LISTS_MOVE_UP;
+ case HELP_MOVE_DOWN: return IDH_PUBLIC_HUB_LISTS_MOVE_DOWN;
+ case HELP_EDIT: return IDH_PUBLIC_HUB_LISTS_EDIT;
+ case HELP_REMOVE: return IDH_PUBLIC_HUB_LISTS_REMOVE;
+ }
+}
+
+void HubListsDlg::add(const tstring& s) {
+ StringTokenizer<tstring> t(s, ';');
+ for(TStringIterC i = t.getTokens().begin(), iend = t.getTokens().end(); i != iend; ++i)
+ if(!i->empty())
+ insert(*i);
+}
+
+TStringList HubListsDlg::getHubLists() {
+ TStringList ret;
StringList lists(FavoriteManager::getInstance()->getHubLists());
- for(StringIterC idx = lists.begin(); idx != lists.end(); ++idx)
- addHubList(Text::toT(*idx));
-
- hubLists->onDblClicked(std::tr1::bind(&HubListsDlg::handleDoubleClick, this));
- hubLists->onKeyDown(std::tr1::bind(&HubListsDlg::handleKeyDown, this, _1));
-
- setText(T_("Configured Public Hub Lists"));
-
- layout();
- centerWindow();
-
- return false;
-}
-
-void HubListsDlg::handleDoubleClick() {
- if(hubLists->hasSelected()) {
- handleEditClicked();
- }
-}
-
-bool HubListsDlg::handleKeyDown(int c) {
- switch(c) {
- case VK_INSERT:
- handleAddClicked();
- return true;
- case VK_DELETE:
- handleRemoveClicked();
- return true;
- }
- return false;
-}
-
-void HubListsDlg::handleAddClicked() {
- StringTokenizer<tstring> t(editBox->getText(), ';');
- for(TStringList::reverse_iterator i = t.getTokens().rbegin(); i != t.getTokens().rend(); ++i)
- if(!i->empty())
- addHubList(*i);
-}
-
-void HubListsDlg::handleMoveUpClicked() {
- HoldRedraw hold(hubLists);
- std::vector<unsigned> selected = hubLists->getSelection();
- for(std::vector<unsigned>::const_iterator i = selected.begin(); i != selected.end(); ++i) {
- if(*i > 0) {
- tstring selText = hubLists->getText(*i, 0);
- hubLists->erase(*i);
- addHubList(selText, *i - 1);
- hubLists->select(*i - 1);
- }
- }
-}
-
-void HubListsDlg::handleMoveDownClicked() {
- HoldRedraw hold(hubLists);
- std::vector<unsigned> selected = hubLists->getSelection();
- for(std::vector<unsigned>::reverse_iterator i = selected.rbegin(); i != selected.rend(); ++i) {
- if(*i < hubLists->size() - 1) {
- tstring selText = hubLists->getText(*i, 0);
- hubLists->erase(*i);
- addHubList(selText, *i + 1);
- hubLists->select(*i + 1);
- }
- }
-}
-
-void HubListsDlg::handleEditClicked() {
- int i = -1;
- while((i = hubLists->getNext(i, LVNI_SELECTED)) != -1) {
- ParamDlg dlg(this, T_("Hublist"), T_("Edit the hublist"), hubLists->getText(i, 0));
- if(dlg.run() == IDOK)
- hubLists->setText(i, 0, dlg.getValue());
- }
-}
-
-void HubListsDlg::handleRemoveClicked() {
- int i = -1;
- while((i = hubLists->getNext(-1, LVNI_SELECTED)) != -1)
- hubLists->erase(i);
-}
-
-void HubListsDlg::handleOKClicked() {
- tstring tmp;
- int j = hubLists->size();
- for(int i = 0; i < j; ++i) {
- if(i != 0)
- tmp += ';';
- tmp += hubLists->getText(i, 0);
- }
- SettingsManager::getInstance()->set(SettingsManager::HUBLIST_SERVERS, Text::fromT(tmp));
- endDialog(IDOK);
-}
-
-void HubListsDlg::addHubList(const tstring& address, int index) {
- TStringList row;
- row.push_back(address);
- int itemCount = hubLists->insert(row, 0, index);
- if(index == -1)
- index = itemCount;
- hubLists->ensureVisible(index);
-}
-
-void HubListsDlg::layout() {
- dwt::Point sz = getClientSize();
- grid->layout(dwt::Rectangle(3, 3, sz.x - 6, sz.y - 6));
-
- hubLists->setColumnWidth(0, hubLists->getWindowSize().x - 20);
+ for(StringIterC i = lists.begin(), iend = lists.end(); i != iend; ++i)
+ ret.push_back(Text::toT(*i));
+ return ret;
}
=== modified file 'win32/HubListsDlg.h'
--- win32/HubListsDlg.h 2010-02-11 21:44:13 +0000
+++ win32/HubListsDlg.h 2010-06-08 20:04:18 +0000
@@ -19,32 +19,23 @@
#ifndef DCPLUSPLUS_WIN32_HUB_LISTS_DLG_H
#define DCPLUSPLUS_WIN32_HUB_LISTS_DLG_H
-class HubListsDlg : public dwt::ModalDialog
+#include "StringListDlg.h"
+
+class HubListsDlg : public StringListDlg
{
public:
HubListsDlg(dwt::Widget* parent);
- virtual ~HubListsDlg();
int run();
private:
- GridPtr grid;
- TextBoxPtr editBox;
- TablePtr hubLists;
-
- bool handleInitDialog();
- void handleDoubleClick();
- bool handleKeyDown(int c);
- void handleAddClicked();
- void handleMoveUpClicked();
- void handleMoveDownClicked();
- void handleEditClicked();
- void handleRemoveClicked();
- void handleOKClicked();
-
- void addHubList(const tstring& address, int index = -1);
-
- void layout();
+ tstring getTitle() const;
+ tstring getEditTitle() const;
+ tstring getEditDescription() const;
+ unsigned getHelpId(HelpFields field) const;
+ void add(const tstring& s);
+
+ static TStringList getHubLists();
};
#endif // !defined(DCPLUSPLUS_WIN32_HUB_LISTS_DLG_H)
=== added file 'win32/StringListDlg.cpp'
--- win32/StringListDlg.cpp 1970-01-01 00:00:00 +0000
+++ win32/StringListDlg.cpp 2010-06-08 20:04:18 +0000
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "stdafx.h"
+
+#include "resource.h"
+
+#include "StringListDlg.h"
+
+#include "HoldRedraw.h"
+#include "ParamDlg.h"
+#include "WinUtil.h"
+
+StringListDlg::StringListDlg(dwt::Widget* parent, const TStringList& initialValues) :
+dwt::ModalDialog(parent),
+grid(0),
+editBox(0),
+list(0)
+{
+ onInitDialog(std::tr1::bind(&StringListDlg::handleInitDialog, this, initialValues));
+ onHelp(std::tr1::bind(&WinUtil::help, _1, _2));
+}
+
+StringListDlg::~StringListDlg() {
+}
+
+int StringListDlg::run() {
+ create(Seed(dwt::Point(400, 316), DS_CONTEXTHELP));
+ return show();
+}
+
+void StringListDlg::insert(const tstring& line, int index) {
+ int itemCount = list->insert(TStringList(1, line), 0, index);
+ if(index == -1)
+ index = itemCount;
+ list->ensureVisible(index);
+}
+
+tstring StringListDlg::getTitle() const {
+ return T_("List configuration");
+}
+
+tstring StringListDlg::getEditTitle() const {
+ return T_("Item edition");
+}
+
+tstring StringListDlg::getEditDescription() const {
+ return T_("Value");
+}
+
+unsigned StringListDlg::getHelpId(HelpFields field) const {
+ switch(field) {
+ case HELP_DIALOG: return IDH_STRING_LIST;
+ case HELP_EDIT_BOX: return IDH_STRING_LIST_EDIT_BOX;
+ case HELP_LIST: return IDH_STRING_LIST_LIST;
+ case HELP_ADD: return IDH_STRING_LIST_ADD;
+ case HELP_MOVE_UP: return IDH_STRING_LIST_MOVE_UP;
+ case HELP_MOVE_DOWN: return IDH_STRING_LIST_MOVE_DOWN;
+ case HELP_EDIT: return IDH_STRING_LIST_EDIT;
+ case HELP_REMOVE: return IDH_STRING_LIST_REMOVE;
+ }
+}
+
+void StringListDlg::add(const tstring& s) {
+ insert(s);
+}
+
+bool StringListDlg::handleInitDialog(const TStringList& initialValues) {
+ setHelpId(getHelpId(HELP_DIALOG));
+
+ grid = addChild(Grid::Seed(2, 2));
+ grid->column(0).mode = GridInfo::FILL;
+ grid->row(1).mode = GridInfo::FILL;
+ grid->row(1).align = GridInfo::STRETCH;
+
+ editBox = grid->addChild(WinUtil::Seeds::Dialog::textBox);
+ 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));
+ }
+
+ {
+ Table::Seed seed = WinUtil::Seeds::Dialog::table;
+ seed.style |= LVS_NOCOLUMNHEADER;
+ list = grid->addChild(seed);
+ list->setHelpId(getHelpId(HELP_LIST));
+ }
+
+ {
+ GridPtr cur = grid->addChild(Grid::Seed(6, 1));
+ 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));
+
+ seed.caption = T_("Move &Down");
+ button = cur->addChild(seed);
+ button->setHelpId(getHelpId(HELP_MOVE_DOWN));
+ button->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));
+
+ seed.caption = T_("&Remove");
+ button = cur->addChild(seed);
+ button->setHelpId(getHelpId(HELP_REMOVE));
+ button->onClicked(std::tr1::bind(&StringListDlg::handleRemoveClicked, this));
+
+ WinUtil::addDlgButtons(cur,
+ std::tr1::bind(&StringListDlg::handleOKClicked, this),
+ std::tr1::bind(&StringListDlg::endDialog, this, IDCANCEL));
+ }
+
+ list->createColumns(TStringList(1));
+
+ for(TStringIterC i = initialValues.begin(), iend = initialValues.end(); i != iend; ++i)
+ insert(*i);
+
+ list->onDblClicked(std::tr1::bind(&StringListDlg::handleDoubleClick, this));
+ list->onKeyDown(std::tr1::bind(&StringListDlg::handleKeyDown, this, _1));
+
+ setText(getTitle());
+
+ layout();
+ centerWindow();
+
+ return false;
+}
+
+void StringListDlg::handleDoubleClick() {
+ if(list->hasSelected()) {
+ handleEditClicked();
+ }
+}
+
+bool StringListDlg::handleKeyDown(int c) {
+ switch(c) {
+ case VK_INSERT:
+ handleAddClicked();
+ return true;
+ case VK_DELETE:
+ handleRemoveClicked();
+ return true;
+ }
+ return false;
+}
+
+void StringListDlg::handleAddClicked() {
+ add(editBox->getText());
+}
+
+void StringListDlg::handleMoveUpClicked() {
+ HoldRedraw hold(list);
+ std::vector<unsigned> selected = list->getSelection();
+ for(std::vector<unsigned>::const_iterator i = selected.begin(); i != selected.end(); ++i) {
+ if(*i > 0) {
+ tstring selText = list->getText(*i, 0);
+ list->erase(*i);
+ insert(selText, *i - 1);
+ list->select(*i - 1);
+ }
+ }
+}
+
+void StringListDlg::handleMoveDownClicked() {
+ HoldRedraw hold(list);
+ std::vector<unsigned> selected = list->getSelection();
+ for(std::vector<unsigned>::reverse_iterator i = selected.rbegin(); i != selected.rend(); ++i) {
+ if(*i < list->size() - 1) {
+ tstring selText = list->getText(*i, 0);
+ list->erase(*i);
+ insert(selText, *i + 1);
+ list->select(*i + 1);
+ }
+ }
+}
+
+void StringListDlg::handleEditClicked() {
+ int i = -1;
+ while((i = list->getNext(i, LVNI_SELECTED)) != -1) {
+ ParamDlg dlg(this, getEditTitle(), getEditDescription(), list->getText(i, 0));
+ if(dlg.run() == IDOK)
+ list->setText(i, 0, dlg.getValue());
+ }
+}
+
+void StringListDlg::handleRemoveClicked() {
+ int i;
+ while((i = list->getNext(-1, LVNI_SELECTED)) != -1)
+ list->erase(i);
+}
+
+void StringListDlg::handleOKClicked() {
+ for(int i = 0, iend = list->size(); i < iend; ++i)
+ values.push_back(list->getText(i, 0));
+
+ endDialog(IDOK);
+}
+
+void StringListDlg::layout() {
+ dwt::Point sz = getClientSize();
+ grid->layout(dwt::Rectangle(3, 3, sz.x - 6, sz.y - 6));
+
+ list->setColumnWidth(0, list->getWindowSize().x - 20);
+}
=== added file 'win32/StringListDlg.h'
--- win32/StringListDlg.h 1970-01-01 00:00:00 +0000
+++ win32/StringListDlg.h 2010-06-08 20:04:18 +0000
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef DCPLUSPLUS_WIN32_STRING_LIST_DLG_H
+#define DCPLUSPLUS_WIN32_STRING_LIST_DLG_H
+
+/// generic dialog to manage a list of strings, that can be used as is or specialized.
+class StringListDlg : public dwt::ModalDialog
+{
+public:
+ StringListDlg(dwt::Widget* parent, const TStringList& initialValues);
+ virtual ~StringListDlg();
+
+ int run();
+
+ const TStringList& getValues() const { return values; }
+
+protected:
+ enum HelpFields {
+ HELP_DIALOG,
+ HELP_EDIT_BOX,
+ HELP_LIST,
+ HELP_ADD,
+ HELP_MOVE_UP,
+ HELP_MOVE_DOWN,
+ HELP_EDIT,
+ HELP_REMOVE
+ };
+
+ void insert(const tstring& line, int index = -1);
+
+private:
+ virtual tstring getTitle() const;
+ virtual tstring getEditTitle() const;
+ virtual tstring getEditDescription() const;
+ virtual unsigned getHelpId(HelpFields field) const;
+ virtual void add(const tstring& s);
+
+ GridPtr grid;
+ TextBoxPtr editBox;
+ TablePtr list;
+
+ TStringList values;
+
+ bool handleInitDialog(const TStringList& initialValues);
+ void handleDoubleClick();
+ bool handleKeyDown(int c);
+ void handleAddClicked();
+ void handleMoveUpClicked();
+ void handleMoveDownClicked();
+ void handleEditClicked();
+ void handleRemoveClicked();
+ void handleOKClicked();
+
+ void layout();
+};
+
+#endif // !defined(DCPLUSPLUS_WIN32_STRING_LIST_DLG_H)