← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2955: Replace the slot up-down control by a context menu

 

------------------------------------------------------------
revno: 2955
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2012-06-18 18:32:14 +0200
message:
  Replace the slot up-down control by a context menu
modified:
  changelog.txt
  dwt/include/dwt/widgets/Menu.h
  dwt/src/widgets/Menu.cpp
  help/window_main.html
  win32/FavHubsFrame.cpp
  win32/MainWindow.cpp
  win32/MainWindow.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	2012-06-18 14:50:09 +0000
+++ changelog.txt	2012-06-18 16:32:14 +0000
@@ -12,6 +12,7 @@
 * [L#1007099] Fix disabled buttons in user matching settings (poy)
 * Do not automatch queue for bad/removed sources (emtee)
 * Minor DL queue tab fixes (poy)
+* Replace the slot up-down control by a context menu (poy)
 
 -- 0.799 2012-05-05 --
 * Add icons (iceman50)

=== modified file 'dwt/include/dwt/widgets/Menu.h'
--- dwt/include/dwt/widgets/Menu.h	2012-01-23 21:02:12 +0000
+++ dwt/include/dwt/widgets/Menu.h	2012-06-18 16:32:14 +0000
@@ -152,31 +152,12 @@
 	/// Return the number of items in the menu
 	unsigned size() const;
 
-	/// Displays and handles a menu which can appear anywhere in the window.
-	/** Typically called by a Right Mouse click. If both the x and the y coordinate
-	* is - 1 ( default ) it'll show the context menu on the position the mouse was
-	* at when the system last recieved a message, basically the "right" place...
-	* <br>
-	* < ul >
-	* < li >TPM_CENTERALIGN : Centers the shortcut menu horizontally relative to the coordinate specified by the x parameter< /li >
-	* < li >TPM_LEFTALIGN : Function positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter< /li >
-	* < li >TPM_RIGHTALIGN : Opposite of LEFTALIGN< /li >
-	* < li >TPM_BOTTOMALIGN : Aligns menu bottoms to the coordinate specified by the y parameter< /li >
-	* < li >TPM_TOPALIGN : Opposite of BOTTOMALIGN< /li >
-	* < li >TPM_VCENTERALIGN : Centers vertically relative to the y parameter< /li >
-	* < li >TPM_LEFTBUTTON  : Restricts users to selecting menu items with only left mouse button< /li >
-	* < li >TPM_RIGHTBUTTON : User can choose menu item with both mouse buttons< /li >
-	* < /ul >
-	* None of the following are used by default but can be manually chosen if you
-	* manually call SystemParametersInfo
-	* < ul >
-	* < li >TPM_HORNEGANIMATION : Animates the menu from right to left< /li >
-	* < li >TPM_HORPOSANIMATION : Animates the menu from left to right< /li >
-	* < li >TPM_NOANIMATION : Displays menu without animation< /li >
-	* < li >TPM_VERNEGANIMATION : Animates the menu from bottom to top< /li >
-	* < li >TPM_VERPOSANIMATION : Animates the menu from top to bottom< /li >
-	* < /ul >
-	*/
+	/** Display the menu at the last known mouse position and handle the selected command, if any.
+	@param flags refer to the TrackPopupMenu doc for possible values. */
+	void open(unsigned flags = TPM_LEFTALIGN | TPM_RIGHTBUTTON);
+	/** Display the menu and handle the selected command, if any.
+	@param sc Where the menu should be displayed.
+	@param flags Refer to the TrackPopupMenu doc for possible values. */
 	void open(const ScreenCoordinate& sc, unsigned flags = TPM_LEFTALIGN | TPM_RIGHTBUTTON);
 
 	/// Sets menu title

=== modified file 'dwt/src/widgets/Menu.cpp'
--- dwt/src/widgets/Menu.cpp	2012-03-03 19:33:45 +0000
+++ dwt/src/widgets/Menu.cpp	2012-06-18 16:32:14 +0000
@@ -828,19 +828,15 @@
 	return index;
 }
 
+void Menu::open(unsigned flags) {
+	open(ScreenCoordinate(Point::fromLParam(::GetMessagePos())), flags);
+}
+
 void Menu::open(const ScreenCoordinate& sc, unsigned flags) {
-	long x = sc.getPoint().x, y = sc.getPoint().y;
-
-	if(x == - 1 || y == - 1) {
-		DWORD pos = ::GetMessagePos();
-		x = LOWORD(pos);
-		y = HIWORD(pos);
-	}
-
 	// 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;
-	unsigned ret = ::TrackPopupMenu(handle(), flags, x, y, 0, getParent()->handle(), 0);
+	unsigned ret = ::TrackPopupMenu(handle(), flags, sc.getPoint().x, sc.getPoint().y, 0, getParent()->handle(), 0);
 	if(ret >= id_offset) {
 		commands_type& commands_ref = getRootMenu()->commands;
 		if(commands_ref.get() && ret - id_offset < commands_ref->size())

=== modified file 'help/window_main.html'
--- help/window_main.html	2012-06-08 13:56:39 +0000
+++ help/window_main.html	2012-06-18 16:32:14 +0000
@@ -335,9 +335,6 @@
     <dt><img src="Slots.ico" width="16" height="16" alt="Slots"/><img src="SlotsFull.ico" width="16" height="16" alt="Slots full"/> Slots</dt>
     <dd cshelp="IDH_MAIN_SLOTS">Indicates the number of currently free upload slots out of the total number of slots opened.</dd>
 
-    <dt>Slots up-down control</dt>
-    <dd cshelp="IDH_MAIN_SLOTS_SPIN">Use this control, which consists of 2 arrows, to increase (up arrow) or decrease (down arrow) the number of upload slots you want to have opened.</dd>
-
     <dt><img src="Download.ico" width="16" height="16" alt="Downloaded bytes"/> Total downloaded bytes</dt>
 	<dd cshelp="IDH_MAIN_DOWN_TOTAL"><div>Shows the total number of bytes received in the current session, including file transfers, hub-client communication and hublists.</div>
 	<div>Double-click to open the <placeholder><a href="window_network_stats.html">Network Statistics</a></placeholder> window.</div></dd>

=== modified file 'win32/FavHubsFrame.cpp'
--- win32/FavHubsFrame.cpp	2012-06-01 17:26:20 +0000
+++ win32/FavHubsFrame.cpp	2012-06-18 16:32:14 +0000
@@ -294,7 +294,7 @@
 void FavHubsFrame::handleGroup() {
 	auto menu = addChild(WinUtil::Seeds::menu);
 	fillGroupMenu(menu.get());
-	menu->open(dwt::ScreenCoordinate(dwt::Point::fromLParam(::GetMessagePos())));
+	menu->open();
 }
 
 void FavHubsFrame::handleGroup(const string& group) {

=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp	2012-06-18 15:56:01 +0000
+++ win32/MainWindow.cpp	2012-06-18 16:32:14 +0000
@@ -101,7 +101,6 @@
 transfers(0),
 toolbar(0),
 tabs(0),
-slotsSpin(0),
 tray_pm(false),
 stopperThread(NULL),
 lastUp(0),
@@ -498,12 +497,6 @@
 
 	updateAwayStatus();
 
-	slotsSpin = addChild(Spinner::Seed());
-	slotsSpin->setHelpId(IDH_MAIN_SLOTS_SPIN);
-	slotsSpin->onUpdate([this](int, int delta) { return handleSlotsUpdate(delta); });
-	status->setWidget(STATUS_SLOTS_SPIN, slotsSpin, dwt::Rectangle(0, 0, 3, 1));
-	status->setSize(STATUS_SLOTS_SPIN, 22);
-
 	/// @todo set to resizedrag width really
 	status->setSize(STATUS_DUMMY, 32);
 
@@ -521,6 +514,12 @@
 	status->setIcon(STATUS_UP_LIMIT, WinUtil::statusIcon(IDI_ULIMIT));
 
 	{
+		auto f = [this] { handleSlotsMenu(); };
+		status->onClicked(STATUS_SLOTS, f);
+		status->onRightClicked(STATUS_SLOTS, f);
+	}
+
+	{
 		auto f = [this] { handleLimiterMenu(false); };
 		status->onClicked(STATUS_DOWN_LIMIT, f);
 		status->onRightClicked(STATUS_DOWN_LIMIT, f);
@@ -801,7 +800,7 @@
 void MainWindow::handleLimiterMenu(bool upload) {
 	auto menu = addChild(WinUtil::Seeds::menu);
 	fillLimiterMenu(menu.get(), upload);
-	menu->open(dwt::ScreenCoordinate(dwt::Point::fromLParam(::GetMessagePos())));
+	menu->open();
 }
 
 void MainWindow::handleReconnect() {
@@ -1050,7 +1049,7 @@
 	auto freeSlots = UploadManager::getInstance()->getFreeSlots();
 	auto totalSlots = SETTING(SLOTS);
 	status->setText(STATUS_SLOTS, str(TF_("%1%/%2%") % freeSlots % totalSlots), true);
-	status->setToolTip(STATUS_SLOTS, str(TF_("%1% free slots of %2% total upload slots") % freeSlots % totalSlots));
+	status->setToolTip(STATUS_SLOTS, str(TF_("%1% free slots of %2% total upload slots - Click to adjust") % freeSlots % totalSlots));
 	if(!freeSlots ^ fullSlots) {
 		fullSlots = !freeSlots;
 		status->setIcon(STATUS_SLOTS, WinUtil::statusIcon(fullSlots ? IDI_SLOTS_FULL : IDI_SLOTS));
@@ -1576,7 +1575,7 @@
 void MainWindow::switchToolbar() {
 	if(toolbar) {
 		rebar->remove(toolbar);
-		::DestroyWindow(toolbar->handle());
+		toolbar->close();
 		toolbar = 0;
 
 		SettingsManager::getInstance()->set(SettingsManager::SHOW_TOOLBAR, false);
@@ -1614,12 +1613,9 @@
 
 void MainWindow::switchStatus() {
 	if(status) {
-		::DestroyWindow(status->handle());
+		status->close();
 		status = 0;
 
-		::DestroyWindow(slotsSpin->handle());
-		slotsSpin = 0;
-
 		SettingsManager::getInstance()->set(SettingsManager::SHOW_STATUSBAR, false);
 		viewMenu->checkItem(viewIndexes["Status"], false);
 
@@ -1631,12 +1627,25 @@
 	layout();
 }
 
-bool MainWindow::handleSlotsUpdate(int delta) {
-	int newSlots = SETTING(SLOTS) + delta;
-	SettingsManager::getInstance()->set(SettingsManager::SLOTS, newSlots);
-	ThrottleManager::setSetting(ThrottleManager::getCurSetting(SettingsManager::SLOTS), newSlots);
-	updateStatus();
-	return true;
+void MainWindow::handleSlotsMenu() {
+	auto changeSlots = [this](int slots) -> function<void ()> { return [=] {
+		SettingsManager::getInstance()->set(SettingsManager::SLOTS, slots);
+		ThrottleManager::setSetting(ThrottleManager::getCurSetting(SettingsManager::SLOTS), slots);
+		updateStatus();
+	}; };
+
+	auto menu = addChild(WinUtil::Seeds::menu);
+
+	menu->setTitle(T_("Upload slots"), WinUtil::menuIcon(IDI_SLOTS));
+
+	auto setting = SETTING(SLOTS);
+	for(decltype(setting) i = 1; i < setting + 10; ++i) {
+		auto pos = menu->appendItem(Text::toT(Util::toString(i)), changeSlots(i), nullptr, true, i == setting);
+		if(i == setting)
+			menu->checkItem(pos);
+	}
+
+	menu->open();
 }
 
 void MainWindow::handleRefreshFileList() {

=== modified file 'win32/MainWindow.h'
--- win32/MainWindow.h	2012-06-03 17:22:16 +0000
+++ win32/MainWindow.h	2012-06-18 16:32:14 +0000
@@ -44,7 +44,6 @@
 		STATUS_AWAY,
 		STATUS_COUNTS,
 		STATUS_SLOTS,
-		STATUS_SLOTS_SPIN,
 		STATUS_DOWN_TOTAL,
 		STATUS_UP_TOTAL,
 		STATUS_DOWN_DIFF,
@@ -123,7 +122,6 @@
 	TransferView* transfers;
 	ToolBarPtr toolbar;
 	TabViewPtr tabs;
-	SpinnerPtr slotsSpin;
 
 	typedef unordered_map<string, unsigned> ViewIndexes;
 	ViewIndexes viewIndexes; /// indexes of menu commands of the "View" menu that open static windows
@@ -178,7 +176,7 @@
 	void switchToolbar();
 	void switchTransfers();
 	void switchStatus();
-	bool handleSlotsUpdate(int delta);
+	void handleSlotsMenu();
 	void handleReconnect();
 	void forwardHub(void (HubFrame::*f_t)());