------------------------------------------------------------ revno: 3177 committer: poy <p...@123gen.com> branch nick: trunk timestamp: Mon 2013-01-21 19:43:48 +0100 message: Add copy menus to various lists modified: changelog.txt dwt/include/dwt/widgets/Table.h dwt/src/widgets/Table.cpp win32/ADLSearchFrame.cpp win32/DirectoryListingFrame.cpp win32/FavHubsFrame.cpp win32/FinishedFrameBase.h win32/HubFrame.cpp win32/HubFrame.h win32/PublicHubsFrame.cpp win32/PublicHubsFrame.h win32/QueueFrame.cpp win32/SearchFrame.cpp win32/TransferView.cpp win32/UsersFrame.cpp win32/WinUtil.cpp win32/WinUtil.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 'changelog.txt' --- changelog.txt 2013-01-21 16:09:46 +0000 +++ changelog.txt 2013-01-21 18:43:48 +0000 @@ -17,6 +17,7 @@ * Apply "send unknown /commands" to PMs (poy) * Don't clear the message box when trying to send a message to a disconnected hub (poy) * Improve OpenSSL error handling +* Add copy menus to various lists (poy) Note: The hash registry will be upgraded when running this version for the first time. Make sure all your drives are connected to avoid re-hashing. === modified file 'dwt/include/dwt/widgets/Table.h' --- dwt/include/dwt/widgets/Table.h 2013-01-18 21:28:38 +0000 +++ dwt/include/dwt/widgets/Table.h 2013-01-21 18:43:48 +0000 @@ -443,8 +443,6 @@ void setIndex(LVITEM& item, int index) const; void initGroupSupport(); void updateArrow(); - // Calculates the adjustment from the columns of an item. - int xoffFromColumn( int column, int & logicalColumn ); // aspects::Data int findDataImpl(LPARAM data, int start = -1); === modified file 'dwt/src/widgets/Table.cpp' --- dwt/src/widgets/Table.cpp 2013-01-18 21:28:38 +0000 +++ dwt/src/widgets/Table.cpp 2013-01-21 18:43:48 +0000 @@ -134,7 +134,7 @@ item.mask = HDI_FORMAT; Header_GetItem(header, i, &item); item.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN); - if (i == this->getSortColumn()) + if (i == getSortColumn()) item.fmt |= flag; Header_SetItem(header, i, &item); } @@ -303,7 +303,7 @@ } std::vector<int> Table::getColumnOrderImpl() const { - std::vector<int> ret(this->getColumnCount()); + std::vector<int> ret(getColumnCount()); if(!::SendMessage(handle(), LVM_GETCOLUMNORDERARRAY, static_cast<WPARAM>(ret.size()), reinterpret_cast<LPARAM>(&ret[0]))) { ret.clear(); } @@ -311,7 +311,7 @@ } std::vector<int> Table::getColumnWidthsImpl() const { - std::vector<int> ret(this->getColumnCount()); + std::vector<int> ret(getColumnCount()); for(size_t i = 0; i < ret.size(); ++i) { ret[i] = ::SendMessage(handle(), LVM_GETCOLUMNWIDTH, static_cast<WPARAM>(i), 0); } @@ -534,6 +534,30 @@ } } +std::vector<Column> Table::getColumnsImpl() const { + std::vector<Column> ret(getColumnCount()); + for(size_t i = 0, n = ret.size(); i < n; ++i) { + ret[i] = getColumn(i); + } + return ret; +} + +Column Table::getColumnImpl(unsigned column) const { + LVCOLUMN col { LVCF_FMT | LVCF_WIDTH | LVCF_TEXT }; + + TCHAR buf[1024]; + col.pszText = buf; + col.cchTextMax = sizeof(buf) / sizeof(TCHAR); + + if(!ListView_GetColumn(handle(), column, &col)) { + dwtWin32DebugFail("Failed getting column information in Table"); + return Column(); + } + + return Column(col.pszText, col.cx, + (col.fmt & LVCFMT_LEFT) == LVCFMT_LEFT ? Column::LEFT : (col.fmt & LVCFMT_RIGHT) == LVCFMT_RIGHT ? Column::RIGHT : Column::CENTER); +} + void Table::redraw( int firstRow, int lastRow ) { if(lastRow == -1) { lastRow = size(); @@ -594,32 +618,6 @@ return result; } -int Table::xoffFromColumn( int column, int & logicalColumn ) -{ - HWND hWnd = handle(); - - // Now we must map a absolute column to a logical column - // Columnns can be moved but they keep their Column Number - logicalColumn = - 1; - HWND hHeader = reinterpret_cast< HWND >( ::SendMessage( hWnd, LVM_GETHEADER, 0, 0 ) ); - int noItems = ::SendMessage( hHeader, HDM_GETITEMCOUNT, 0, 0 ); - boost::scoped_array<int> myArrayOfCols(new int[noItems]); - int xOffset = 0; - ::SendMessage( hHeader, HDM_GETORDERARRAY, static_cast< WPARAM >( noItems ), reinterpret_cast< LPARAM >( myArrayOfCols.get() ) ); - for ( int idx = 0; idx < noItems; ++idx ) - { - if ( myArrayOfCols[idx] == column ) - { - logicalColumn = idx; - break; - } - else - xOffset += ListView_GetColumnWidth( hWnd, myArrayOfCols[idx] ); - } - - return xOffset; -} - std::pair<int, int> Table::hitTest(const ScreenCoordinate& pt) { LVHITTESTINFO lvi = { ClientCoordinate(pt, this).getPoint() }; return ListView_SubItemHitTest(handle(), &lvi) == -1 ? std::make_pair(-1, -1) : std::make_pair(lvi.iItem, lvi.iSubItem); === modified file 'win32/ADLSearchFrame.cpp' --- win32/ADLSearchFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/ADLSearchFrame.cpp 2013-01-21 18:43:48 +0000 @@ -319,6 +319,7 @@ menu->appendItem(T_("&New..."), [this] { handleAdd(); }); menu->appendItem(T_("&Properties"), [this] { handleProperties(); }, dwt::IconPtr(), sel); menu->appendItem(T_("&Remove"), [this] { handleRemove(); }, dwt::IconPtr(), sel); + WinUtil::addCopyMenu(menu.get(), items); menu->open(pt); return true; === modified file 'win32/DirectoryListingFrame.cpp' --- win32/DirectoryListingFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/DirectoryListingFrame.cpp 2013-01-21 18:43:48 +0000 @@ -976,6 +976,8 @@ addUserMenu(menu.get()); + WinUtil::addCopyMenu(menu.get(), files); + usingDirMenu = false; menu->open(pt); return true; === modified file 'win32/FavHubsFrame.cpp' --- win32/FavHubsFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/FavHubsFrame.cpp 2013-01-21 18:43:48 +0000 @@ -360,6 +360,7 @@ menu->appendItem(T_("&Move to group"), nullptr, dwt::IconPtr(), false); } menu->appendItem(T_("Manage &groups"), [this] { handleGroups(); }); + WinUtil::addCopyMenu(menu.get(), hubs); menu->open(pt); return true; === modified file 'win32/FinishedFrameBase.h' --- win32/FinishedFrameBase.h 2013-01-18 21:28:38 +0000 +++ win32/FinishedFrameBase.h 2013-01-21 18:43:48 +0000 @@ -469,6 +469,7 @@ menu->appendSeparator(); WinUtil::addUserItems(menu.get(), files->forEachSelectedT(UserCollector()).users, this->getParent()); menu->appendShellMenu(checker.ShellMenuPaths); + WinUtil::addCopyMenu(menu.get(), files); menu->open(pt); return true; @@ -492,6 +493,7 @@ menu->appendItem(T_("Remove &all"), [this] { this->handleRemoveAll(); }); menu->appendSeparator(); WinUtil::addUserItems(menu.get(), users->forEachSelectedT(UserCollector()).users, this->getParent()); + WinUtil::addCopyMenu(menu.get(), users); menu->open(pt); return true; === modified file 'win32/HubFrame.cpp' --- win32/HubFrame.cpp 2013-01-19 14:52:37 +0000 +++ win32/HubFrame.cpp 2013-01-21 18:43:48 +0000 @@ -1231,11 +1231,7 @@ appendUserItems(getParent(), menu.get()); - menu->appendSeparator(); - auto copyMenu = menu->appendPopup(T_("&Copy")); - for(int j=0; j<COLUMN_LAST; j++) { - copyMenu->appendItem(T_(usersColumns[j].name), [this, j] { handleMultiCopy(j); }); - } + WinUtil::addCopyMenu(menu.get(), users); prepareMenu(menu.get(), UserCommand::CONTEXT_USER, url); @@ -1277,23 +1273,6 @@ statusDirty = true; } -void HubFrame::handleMultiCopy(unsigned index) { - if(index > COLUMN_LAST) { - return; - } - - tstring tmpstr; - for(auto& i: selectedUsersImpl()) { - tmpstr += static_cast<UserInfo*>(i)->getText(index); - tmpstr += _T(" / "); - } - if(!tmpstr.empty()) { - // remove last space - tmpstr.erase(tmpstr.length() - 3); - WinUtil::setClipboard(tmpstr); - } -} - void HubFrame::handleCopyHub() { WinUtil::setClipboard(Text::toT(url)); } === modified file 'win32/HubFrame.h' --- win32/HubFrame.h 2013-01-18 21:28:38 +0000 +++ win32/HubFrame.h 2013-01-21 18:43:48 +0000 @@ -235,7 +235,6 @@ bool handleChatContextMenu(dwt::ScreenCoordinate pt); bool handleUsersContextMenu(dwt::ScreenCoordinate pt); void handleShowUsersClicked(); - void handleMultiCopy(unsigned index); void handleDoubleClickUsers(); void handleCopyHub(); void handleAddAsFavorite(); === modified file 'win32/PublicHubsFrame.cpp' --- win32/PublicHubsFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/PublicHubsFrame.cpp 2013-01-21 18:43:48 +0000 @@ -334,7 +334,7 @@ menu->setTitle(escapeMenu(hubs->getSelectedData()->getText(COLUMN_NAME)), getParent()->getIcon(this)); menu->appendItem(T_("&Connect"), [this] { handleConnect(); }, dwt::IconPtr(), true, true); menu->appendItem(T_("Add To &Favorites"), [this] { handleAdd(); }, WinUtil::menuIcon(IDI_FAVORITE_HUBS)); - menu->appendItem(T_("Copy &address to clipboard"), [this] { handleCopyHub(); }); + WinUtil::addCopyMenu(menu.get(), hubs); menu->open(pt); return true; @@ -375,12 +375,6 @@ } } -void PublicHubsFrame::handleCopyHub() { - if(hubs->hasSelected()) { - WinUtil::setClipboard(Text::toT(hubs->getSelectedData()->entry->getServer())); - } -} - void PublicHubsFrame::openSelected() { if(!WinUtil::checkNick()) return; === modified file 'win32/PublicHubsFrame.h' --- win32/PublicHubsFrame.h 2013-01-18 21:28:38 +0000 +++ win32/PublicHubsFrame.h 2013-01-21 18:43:48 +0000 @@ -104,7 +104,6 @@ void handleRefresh(); void handleConnect(); void handleAdd(); - void handleCopyHub(); bool handleContextMenu(dwt::ScreenCoordinate pt); bool handleKeyDown(int c); void handleListSelChanged(); === modified file 'win32/QueueFrame.cpp' --- win32/QueueFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/QueueFrame.cpp 2013-01-21 18:43:48 +0000 @@ -959,16 +959,18 @@ } usingDirMenu = false; - MenuPtr contextMenu; + MenuPtr menu; if(files->countSelected() == 1) { QueueItemInfo* ii = files->getSelectedData(); - contextMenu = makeSingleMenu(ii); + menu = makeSingleMenu(ii); } else { - contextMenu = makeMultiMenu(); + menu = makeMultiMenu(); } - contextMenu->open(pt); + WinUtil::addCopyMenu(menu.get(), files); + + menu->open(pt); return true; } return false; === modified file 'win32/SearchFrame.cpp' --- win32/SearchFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/SearchFrame.cpp 2013-01-21 18:43:48 +0000 @@ -801,6 +801,8 @@ menu->appendSeparator(); menu->appendItem(T_("&Remove"), [this] { handleRemove(); }); + WinUtil::addCopyMenu(menu.get(), results); + prepareMenu(menu.get(), UserCommand::CONTEXT_SEARCH, checkTTH.hubs); return menu; === modified file 'win32/TransferView.cpp' --- win32/TransferView.cpp 2013-01-18 21:28:38 +0000 +++ win32/TransferView.cpp 2013-01-21 18:43:48 +0000 @@ -200,6 +200,8 @@ menu->appendSeparator(); menu->appendItem(T_("&Disconnect"), [this] { handleDisconnect(); }); + WinUtil::addCopyMenu(menu.get(), connections); + menu->open(pt); return true; } @@ -233,6 +235,8 @@ } } + WinUtil::addCopyMenu(menu.get(), downloads); + menu->open(pt); return true; } === modified file 'win32/UsersFrame.cpp' --- win32/UsersFrame.cpp 2013-01-18 21:28:38 +0000 +++ win32/UsersFrame.cpp 2013-01-21 18:43:48 +0000 @@ -464,6 +464,7 @@ menu->appendSeparator(); menu->appendItem(T_("&Description"), [this] { handleDescription(); }); menu->appendItem(T_("&Remove"), [this] { handleRemove(); }); + WinUtil::addCopyMenu(menu.get(), users); menu->open(pt); === modified file 'win32/WinUtil.cpp' --- win32/WinUtil.cpp 2013-01-18 21:28:38 +0000 +++ win32/WinUtil.cpp 2013-01-21 18:43:48 +0000 @@ -1524,6 +1524,43 @@ table->setColumnOrder(o); } +void WinUtil::addCopyMenu(Menu* menu, dwt::TablePtr table) { + if(!table->hasSelected()) { return; } + + menu->appendSeparator(); + menu = menu->appendPopup(T_("Copy")); + + auto cols = table->getColumns(); + auto order = table->getColumnOrder(); + + auto copyF = [table](unsigned col) -> function<void ()> { return [=] { + tstring text; + for(auto row: table->getSelection()) { + if(!text.empty()) { text += _T("\r\n"); } + text += table->getText(row, col); + } + setClipboard(text); + }; }; + for(auto col: order) { + menu->appendItem(cols[col].header, copyF(col)); + } + + menu->appendSeparator(); + menu->appendItem(T_("All columns"), [=] { + tstring text; + for(auto row: table->getSelection()) { + tstring rowText; + for(auto col: order) { + if(!rowText.empty()) { rowText += _T("\r\n"); } + rowText += str(TF_("%1%: %2%") % cols[col].header % table->getText(row, col)); + } + if(!text.empty()) { text += _T("\r\n\r\n"); } + text += move(rowText); + } + setClipboard(text); + }); +} + int WinUtil::tableSortSetting(int column, bool ascending) { return ascending || column == -1 ? column : -column - 2; } === modified file 'win32/WinUtil.h' --- win32/WinUtil.h 2013-01-18 21:28:38 +0000 +++ win32/WinUtil.h 2013-01-21 18:43:48 +0000 @@ -211,6 +211,7 @@ static void makeColumns(dwt::TablePtr table, const ColumnInfo* columnInfo, size_t columnCount, const string& order = Util::emptyString, const string& widths = Util::emptyString); + static void addCopyMenu(Menu* menu, dwt::TablePtr table); /* functions to get / set table column sorting. a little trick is used to encode both the column index & the "ascending sort" flag into an int. */
_______________________________________________ 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