← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2312: Add titles to various menus

 

------------------------------------------------------------
revno: 2312
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-11-30 19:21:53 +0100
message:
  Add titles to various menus
modified:
  changelog.txt
  dwt/include/dwt/widgets/Menu.h
  dwt/src/widgets/Menu.cpp
  win32/ADLSearchFrame.cpp
  win32/FavHubsFrame.cpp
  win32/HubFrame.cpp
  win32/HubFrame.h
  win32/MDIChildFrame.h
  win32/MainWindow.cpp
  win32/PrivateFrame.cpp
  win32/QueueFrame.cpp
  win32/SearchFrame.cpp
  win32/ShellMenu.cpp
  win32/SpyFrame.cpp
  win32/UsersFrame.cpp
  win32/stdafx.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	2010-11-28 15:52:39 +0000
+++ changelog.txt	2010-11-30 18:21:53 +0000
@@ -38,6 +38,7 @@
 * [L#378829] Make sure our OpenSSL binaries aren't "optimized for MS-DOS" (poy)
 * [L#674545] Add magnet keyword search (thanks flow84)
 * [L#506288] Save settings periodically (poy)
+* Add titles to various menus (poy)
 
 -- 0.770 2010-07-05 --
 * [L#550300] Catch more potential file corruptions (thanks bigmuscle)

=== modified file 'dwt/include/dwt/widgets/Menu.h'
--- dwt/include/dwt/widgets/Menu.h	2010-11-12 17:22:02 +0000
+++ dwt/include/dwt/widgets/Menu.h	2010-11-30 18:21:53 +0000
@@ -132,7 +132,7 @@
 	* A popup is basically another branch in the menu hierarchy <br>
 	* See the Menu project for a demonstration.
 	*/
-	ObjectType appendPopup(const tstring& text, const IconPtr& icon = IconPtr());
+	ObjectType appendPopup(const tstring& text, const IconPtr& icon = IconPtr(), bool subTitle = true);
 
 	/// Returns the "System Menu"
 	/** The system menu is a special menu that ( normally ) is accessed by pressing

=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp	2010-10-29 15:40:14 +0000
+++ dwt/src/widgets/Menu.cpp	2010-11-30 18:21:53 +0000
@@ -230,12 +230,16 @@
 	}
 }
 
-Menu::ObjectType Menu::appendPopup(const tstring& text, const IconPtr& icon) {
+Menu::ObjectType Menu::appendPopup(const tstring& text, const IconPtr& icon, bool subTitle) {
 	// create the sub-menu
 	ObjectType sub(new Menu(getParent()));
 	sub->create(Seed(ownerDrawn, colors, iconSize, font));
 	sub->parentMenu = this;
 
+	if(subTitle && popup) {
+		sub->setTitle(text, icon);
+	}
+
 	// init structure for new item
 	MENUITEMINFO info = { sizeof(MENUITEMINFO), MIIM_SUBMENU | MIIM_STRING };
 
@@ -383,14 +387,14 @@
 
 	const bool hasTitle = !itsTitle.empty();
 	// set the new title
-	itsTitle = util::escapeMenu(title);
+	itsTitle = title;
 
 	if(!drawSidebar) {
 		// init struct for title info
 		MENUITEMINFO info = { sizeof(MENUITEMINFO), MIIM_STATE | MIIM_STRING | MIIM_FTYPE | MIIM_DATA, MFT_OWNERDRAW, MF_DISABLED };
 
 		// set title text
-		info.dwTypeData = const_cast< LPTSTR >( title.c_str() );
+		info.dwTypeData = const_cast<LPTSTR>(itsTitle.c_str());
 
 		// create wrapper for title item
 		ItemDataWrapper * wrapper = new ItemDataWrapper(this, 0, true, icon);
@@ -900,13 +904,6 @@
 		y = HIWORD(pos);
 	}
 
-	if(!itsTitle.empty()) {
-		// adjust "y" so that the first command ends up in front of the cursor, not the title
-		/// @todo fix for menus that open upwards
-		y -= std::max(static_cast<unsigned>(getTextSize(getText(0), itsTitleFont).y), // 0 is the title index
-			static_cast<unsigned>(::GetSystemMetrics(SM_CYMENU)));
-	}
-
 	// sub-menus of the menu bar send WM_MENUCOMMAND; however, commands from ephemeral menus are handled right here.
 	if(getRootMenu()->popup && (flags & TPM_RETURNCMD) != TPM_RETURNCMD)
 		flags |= TPM_RETURNCMD;

=== modified file 'win32/ADLSearchFrame.cpp'
--- win32/ADLSearchFrame.cpp	2010-07-10 14:36:48 +0000
+++ win32/ADLSearchFrame.cpp	2010-11-30 18:21:53 +0000
@@ -275,14 +275,16 @@
 		pt = items->getContextMenuPos();
 	}
 
-	bool hasSelected = items->hasSelected();
-
-	MenuPtr contextMenu = addChild(WinUtil::Seeds::menu);
-	contextMenu->appendItem(T_("&New..."), std::bind(&ADLSearchFrame::handleAdd, this));
-	contextMenu->appendItem(T_("&Properties"), std::bind(&ADLSearchFrame::handleProperties, this), dwt::IconPtr(), hasSelected);
-	contextMenu->appendItem(T_("&Remove"), std::bind(&ADLSearchFrame::handleRemove, this), dwt::IconPtr(), hasSelected);
-
-	contextMenu->open(pt);
+	size_t sel = items->countSelected();
+
+	MenuPtr menu = addChild(WinUtil::Seeds::menu);
+	menu->setTitle((sel == 0) ? getText() : (sel == 1) ? escapeMenu(items->getText(items->getSelected(), COLUMN_ACTIVE_SEARCH_STRING)) :
+		str(TF_("%1% items") % sel), getParent()->getIcon(this));
+	menu->appendItem(T_("&New..."), std::bind(&ADLSearchFrame::handleAdd, this));
+	menu->appendItem(T_("&Properties"), std::bind(&ADLSearchFrame::handleProperties, this), dwt::IconPtr(), sel);
+	menu->appendItem(T_("&Remove"), std::bind(&ADLSearchFrame::handleRemove, this), dwt::IconPtr(), sel);
+
+	menu->open(pt);
 	return true;
 }
 

=== modified file 'win32/FavHubsFrame.cpp'
--- win32/FavHubsFrame.cpp	2010-11-18 18:23:40 +0000
+++ win32/FavHubsFrame.cpp	2010-11-30 18:21:53 +0000
@@ -330,22 +330,24 @@
 		pt = hubs->getContextMenuPos();
 	}
 
-	const size_t selected = hubs->countSelected();
+	size_t sel = hubs->countSelected();
 
 	MenuPtr menu = addChild(WinUtil::Seeds::menu);
-	menu->appendItem(T_("&Connect"), std::bind(&FavHubsFrame::openSelected, this), dwt::IconPtr(), selected, true);
+	menu->setTitle((sel == 0) ? getText() : (sel == 1) ? escapeMenu(hubs->getText(hubs->getSelected(), COLUMN_NAME)) :
+		str(TF_("%1% hubs") % sel), getParent()->getIcon(this));
+	menu->appendItem(T_("&Connect"), std::bind(&FavHubsFrame::openSelected, this), dwt::IconPtr(), sel, true);
 	menu->appendSeparator();
 	menu->appendItem(T_("&New..."), std::bind(&FavHubsFrame::handleAdd, this));
-	menu->appendItem(T_("&Properties"), std::bind(&FavHubsFrame::handleProperties, this), dwt::IconPtr(), selected == 1);
-	menu->appendItem(T_("Move &Up"), std::bind(&FavHubsFrame::handleMove, this, true), dwt::IconPtr(), selected);
-	menu->appendItem(T_("Move &Down"), std::bind(&FavHubsFrame::handleMove, this, false), dwt::IconPtr(), selected);
-	menu->appendSeparator();
-	menu->appendItem(T_("&Remove"), std::bind(&FavHubsFrame::handleRemove, this), dwt::IconPtr(), selected);
-	menu->appendSeparator();
-	if(selected) {
+	menu->appendItem(T_("&Properties"), std::bind(&FavHubsFrame::handleProperties, this), dwt::IconPtr(), sel == 1);
+	menu->appendItem(T_("Move &Up"), std::bind(&FavHubsFrame::handleMove, this, true), dwt::IconPtr(), sel);
+	menu->appendItem(T_("Move &Down"), std::bind(&FavHubsFrame::handleMove, this, false), dwt::IconPtr(), sel);
+	menu->appendSeparator();
+	menu->appendItem(T_("&Remove"), std::bind(&FavHubsFrame::handleRemove, this), dwt::IconPtr(), sel);
+	menu->appendSeparator();
+	if(sel) {
 		fillGroupMenu(menu->appendPopup(T_("&Move to group")));
 	} else {
-		menu->appendItem(T_("&Move to group"), 0, dwt::IconPtr(), selected);
+		menu->appendItem(T_("&Move to group"), 0, dwt::IconPtr(), false);
 	}
 	menu->appendItem(T_("Manage &groups"), std::bind(&FavHubsFrame::handleGroups, this));
 

=== modified file 'win32/HubFrame.cpp'
--- win32/HubFrame.cpp	2010-11-25 18:35:55 +0000
+++ win32/HubFrame.cpp	2010-11-30 18:21:53 +0000
@@ -583,7 +583,7 @@
 
 HubFrame::UserInfo* HubFrame::findUser(const tstring& nick) {
 	for(UserMapIter i = userMap.begin(); i != userMap.end(); ++i) {
-		if(i->second->columns[COLUMN_NICK] == nick)
+		if(i->second->getText(COLUMN_NICK) == nick)
 			return i->second;
 	}
 	return 0;
@@ -595,7 +595,7 @@
 		return Util::emptyStringT;
 
 	UserInfo* ui = i->second;
-	return ui->columns[COLUMN_NICK];
+	return ui->getText(COLUMN_NICK);
 }
 
 bool HubFrame::updateUser(const UserTask& u) {
@@ -1093,6 +1093,8 @@
 
 	MenuPtr menu = chat->getMenu();
 
+	menu->setTitle(escapeMenu(getText()), getParent()->getIcon(this));
+
 	prepareMenu(menu, UserCommand::CONTEXT_HUB, url);
 
 	hubMenu = true;
@@ -1101,12 +1103,17 @@
 }
 
 bool HubFrame::handleUsersContextMenu(dwt::ScreenCoordinate pt) {
-	if(showUsers->getChecked() ? users->hasSelected() : (currentUser != 0)) {
+	auto sel = selectedUsersImpl();
+	if(!sel.empty()) {
 		if(pt.x() == -1 || pt.y() == -1) {
 			pt = users->getContextMenuPos();
 		}
 
 		MenuPtr menu = addChild(WinUtil::Seeds::menu);
+
+		menu->setTitle((sel.size() == 1) ? escapeMenu(getNick(sel[0]->getUser())) : str(TF_("%1% users") % sel.size()),
+			WinUtil::userImages->getIcon(IMAGE_USER));
+
 		appendUserItems(getParent(), menu);
 
 		menu->appendSeparator();

=== modified file 'win32/HubFrame.h'
--- win32/HubFrame.h	2010-10-20 20:49:31 +0000
+++ win32/HubFrame.h	2010-11-30 18:21:53 +0000
@@ -133,8 +133,10 @@
 		string getNick() const { return identity.getNick(); }
 		bool isHidden() const { return identity.isHidden(); }
 
+		GETSET(Identity, identity, Identity);
+
+	private:
 		tstring columns[COLUMN_LAST];
-		GETSET(Identity, identity, Identity);
 	};
 
 	typedef unordered_map<UserPtr, UserInfo*, User::Hash> UserMap;

=== modified file 'win32/MDIChildFrame.h'
--- win32/MDIChildFrame.h	2010-10-02 22:00:14 +0000
+++ win32/MDIChildFrame.h	2010-11-30 18:21:53 +0000
@@ -214,7 +214,7 @@
 	bool handleContextMenu(const dwt::ScreenCoordinate& pt) {
 		dwt::Menu::ObjectType menu = addChild(WinUtil::Seeds::menu);
 
-		menu->setTitle(getText(), getParent()->getIcon(this));
+		menu->setTitle(escapeMenu(getText()), getParent()->getIcon(this));
 
 		tabMenuImpl(menu);
 		menu->appendItem(T_("&Close"), std::bind(&ThisType::close, this, true), WinUtil::menuIcon(IDI_EXIT));

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2010-11-25 18:39:38 +0000
+++ win32/MainWindow.cpp	2010-11-30 18:21:53 +0000
@@ -69,7 +69,6 @@
 #include <dwt/widgets/ToolBar.h>
 #include <dwt/widgets/Spinner.h>
 #include <dwt/widgets/Notification.h>
-#include <dwt/util/StringUtils.h>
 
 #ifdef HAVE_HTMLHELP_H
 #include <htmlhelp.h>
@@ -581,7 +580,7 @@
 		groupMenus.insert(make_pair(i->first, MenuPtr()));
 
 	for(GroupMenus::iterator i = groupMenus.begin(); i != groupMenus.end(); ++i) {
-		i->second = menu->appendPopup(dwt::util::escapeMenu(Text::toT(i->first)));
+		i->second = menu->appendPopup(escapeMenu(Text::toT(i->first)));
 		i->second->appendItem(T_("Connect to all hubs in this group"), std::bind(&multiConnect, i->first, getTabView()));
 		i->second->appendSeparator();
 	}
@@ -591,7 +590,7 @@
 		FavoriteHubEntry* entry = *i;
 		GroupMenus::iterator groupMenu = groupMenus.find(entry->getGroup());
 		((groupMenu == groupMenus.end()) ? menu : groupMenu->second)->appendItem(
-			dwt::util::escapeMenu(Text::toT(entry->getName())),
+			escapeMenu(Text::toT(entry->getName())),
 			[this, entry] { HubFrame::openWindow(getTabView(), entry->getServer()); });
 	}
 
@@ -622,7 +621,7 @@
 			if(title == params.end() || title->second.empty())
 				continue;
 
-			popup->appendItem(dwt::util::escapeMenu(Text::toT(title->second)),
+			popup->appendItem(escapeMenu(Text::toT(title->second)),
 				std::bind(&T::parseWindowParams, mainWindow->getTabView(), params),
 				T::isFavorite(params) ? favIcon : 0);
 		}

=== modified file 'win32/PrivateFrame.cpp'
--- win32/PrivateFrame.cpp	2010-10-07 16:40:23 +0000
+++ win32/PrivateFrame.cpp	2010-11-30 18:21:53 +0000
@@ -326,6 +326,8 @@
 
 	MenuPtr menu = chat->getMenu();
 
+	menu->setTitle(escapeMenu(getText()), getParent()->getIcon(this));
+
 	prepareMenu(menu, UserCommand::CONTEXT_USER, ClientManager::getInstance()->getHubs(replyTo.getUser().user->getCID(),
 		replyTo.getUser().hint, priv));
 

=== modified file 'win32/QueueFrame.cpp'
--- win32/QueueFrame.cpp	2010-11-23 17:14:48 +0000
+++ win32/QueueFrame.cpp	2010-11-30 18:21:53 +0000
@@ -27,8 +27,6 @@
 #include <dcpp/QueueManager.h>
 #include <dcpp/version.h>
 
-#include <dwt/util/StringUtils.h>
-
 const string QueueFrame::id = "Queue";
 const string& QueueFrame::getId() const { return id; }
 
@@ -940,7 +938,7 @@
 		const QueueItem::Source& source = *i;
 		const HintedUser& user = source.getUser();
 		if(offline || user.user->isOnline()) {
-			menu->appendItem(dwt::util::escapeMenu(WinUtil::getNicks(user)), std::bind(handler, this, user));
+			menu->appendItem(escapeMenu(WinUtil::getNicks(user)), std::bind(handler, this, user));
 			added = true;
 		}
 	}

=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp	2010-11-25 18:35:55 +0000
+++ win32/SearchFrame.cpp	2010-11-30 18:21:53 +0000
@@ -707,6 +707,9 @@
 	StringPairList favoriteDirs = FavoriteManager::getInstance()->getFavoriteDirs();
 	SearchInfo::CheckTTH checkTTH = results->forEachSelectedT(SearchInfo::CheckTTH());
 
+	menu->setTitle(checkTTH.hasTTH ? escapeMenu(checkTTH.name) : str(TF_("%1% results") % results->countSelected()),
+		getParent()->getIcon(this));
+
 	menu->appendItem(T_("&Download"), std::bind(&SearchFrame::handleDownload, this), dwt::IconPtr(), true, true);
 	addTargetMenu(menu, favoriteDirs, checkTTH);
 	menu->appendItem(T_("Download whole directory"), std::bind(&SearchFrame::handleDownloadDir, this));

=== modified file 'win32/ShellMenu.cpp'
--- win32/ShellMenu.cpp	2010-07-10 14:36:48 +0000
+++ win32/ShellMenu.cpp	2010-11-30 18:21:53 +0000
@@ -22,8 +22,6 @@
 
 #include "ShellMenu.h"
 
-#include <dwt/util/StringUtils.h>
-
 #include "resource.h"
 #include "WinUtil.h"
 
@@ -111,11 +109,11 @@
 	appendSeparator();
 
 	if(valid.size() == 1)
-		handlers.push_back(make_pair(appendPopup(T_("Shell menu")), valid[0].second));
+		handlers.push_back(make_pair(appendPopup(T_("Shell menu"), dwt::IconPtr(), false), valid[0].second));
 	else {
 		MenuPtr popup = appendPopup(T_("Shell menus"));
 		for(valid_type::const_iterator i = valid.begin(); i != valid.end(); ++i)
-			handlers.push_back(make_pair(popup->appendPopup(dwt::util::escapeMenu(Text::toT(i->first))), i->second));
+			handlers.push_back(make_pair(popup->appendPopup(escapeMenu(Text::toT(i->first)), dwt::IconPtr(), false), i->second));
 	}
 
 	callbacks.push_back(make_pair(dwt::Message(WM_DRAWITEM), getParent()->addCallback(dwt::Message(WM_DRAWITEM),

=== modified file 'win32/SpyFrame.cpp'
--- win32/SpyFrame.cpp	2010-11-25 18:35:55 +0000
+++ win32/SpyFrame.cpp	2010-11-30 18:21:53 +0000
@@ -152,11 +152,13 @@
 			pt = searches->getContextMenuPos();
 		}
 
-		MenuPtr contextMenu = addChild(WinUtil::Seeds::menu);
-		contextMenu->appendItem(T_("&Search"), std::bind(&SpyFrame::handleSearch, this,
-			searches->getText(searches->getSelected(), COLUMN_STRING)), WinUtil::menuIcon(IDI_SEARCH));
-
-		contextMenu->open(pt);
+		tstring selText = searches->getText(searches->getSelected(), COLUMN_STRING);
+
+		MenuPtr menu = addChild(WinUtil::Seeds::menu);
+		menu->setTitle(escapeMenu(selText), getParent()->getIcon(this));
+		menu->appendItem(T_("&Search"), std::bind(&SpyFrame::handleSearch, this, selText), WinUtil::menuIcon(IDI_SEARCH));
+
+		menu->open(pt);
 		return true;
 	}
 	return false;

=== modified file 'win32/UsersFrame.cpp'
--- win32/UsersFrame.cpp	2010-07-10 14:36:48 +0000
+++ win32/UsersFrame.cpp	2010-11-30 18:21:53 +0000
@@ -180,12 +180,14 @@
 }
 
 bool UsersFrame::handleContextMenu(dwt::ScreenCoordinate pt) {
-	if (users->hasSelected()) {
+	size_t sel = users->countSelected();
+	if(sel > 0) {
 		if(pt.x() == -1 && pt.y() == -1) {
 			pt = users->getContextMenuPos();
 		}
 
 		MenuPtr menu = addChild(WinUtil::Seeds::menu);
+		menu->setTitle((sel == 1) ? escapeMenu(users->getSelectedData()->getText(COLUMN_NICK)) : str(TF_("%1% users") % sel));
 		appendUserItems(getParent(), menu);
 		menu->appendSeparator();
 		menu->appendItem(T_("&Description"), std::bind(&UsersFrame::handleDescription, this));

=== modified file 'win32/stdafx.h'
--- win32/stdafx.h	2010-10-28 22:43:23 +0000
+++ win32/stdafx.h	2010-11-30 18:21:53 +0000
@@ -26,6 +26,7 @@
 
 #include <dwt/Application.h>
 #include <dwt/resources/Pen.h>
+#include <dwt/util/StringUtils.h>
 #include <dwt/widgets/Button.h>
 #include <dwt/widgets/CheckBox.h>
 #include <dwt/widgets/ComboBox.h>
@@ -53,6 +54,7 @@
 
 using namespace dcpp;
 
+using dwt::util::escapeMenu;
 using dwt::Button;
 using dwt::ButtonPtr;
 using dwt::CheckBox;