← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2864: select the Documents dir by default when selecting a new shared dir to add

 

------------------------------------------------------------
revno: 2864
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-02-12 13:55:04 +0100
message:
  select the Documents dir by default when selecting a new shared dir to add
modified:
  dwt/include/dwt/widgets/FolderDialog.h
  dwt/src/widgets/FolderDialog.cpp
  win32/UploadPage.cpp


--
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 'dwt/include/dwt/widgets/FolderDialog.h'
--- dwt/include/dwt/widgets/FolderDialog.h	2012-01-13 20:55:20 +0000
+++ dwt/include/dwt/widgets/FolderDialog.h	2012-02-12 12:55:04 +0000
@@ -66,61 +66,38 @@
 	// Constructor Taking pointer to parent
 	explicit FolderDialog( Widget * parent = 0 );
 
-	/// Shows the dialog
-	/** Returns string() or "empty string" if user press cancel. <br>
-	  * Returns a "folder path" if user presses ok. <br>
-	  * Use the inherited functions aspects::folderFilter::addFilter and
-	  * aspects::folderFilter::activeFilter <br>
-	  * before calling this function, if you wish the dialog to show only certain
-	  * types of folders.
-	  */
-	bool open(tstring& folder);
-
-	/// Sets the root directory in the WidgetChooseFolder Widget
-	/** If given your dialog will try to start with the given directory as root, otherwise it
-	  * will use the desktop directory.
-	  */
-	FolderDialog& setRoot( const int CSIDL = CSIDL_DESKTOPDIRECTORY );
-
-	FolderDialog& setTitle( const tstring& title );
+	/** Set the root directory of the dialog. Only this directory or directories below it will be
+	selectable. If not defined, the default is to use the desktop as root. */
+	FolderDialog& setRoot(const int csidl);
+
+	FolderDialog& setTitle(const tstring& title);
+
+	/** Set the initially selected and expanded directory. When both a CSIDL & string are defined,
+	the directory defined by string is given priority. May also be set by using the "dir" parameter
+	of the open function. */
+	FolderDialog& setInitialSelection(const tstring& sel);
+	FolderDialog& setInitialSelection(const int csidl);
+
+	/** Display the dialog.
+	@param dir On input, may define an initially selected dir (shortcut for setInitialSelection).
+	On output, contains the selected directory on success.
+	@return Whether a directory was selected and successfully resolved. */
+	bool open(tstring& dir);
 
 	~FolderDialog();
 
 private:
-	static int CALLBACK browseCallbackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData )
-	{
-		if(lpData && uMsg == BFFM_INITIALIZED) {
-			::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
-		}
-		return 0;
-	}
-
-	Widget* itsParent;
-	tstring itsTitle;
-	LPITEMIDLIST itsPidlRoot;
-
-	HWND getParentHandle() { return itsParent ? itsParent->handle() : NULL; }
-
+	Widget* parent;
+	LPITEMIDLIST pidlRoot;
+	tstring title;
+	tstring initialSel;
+	LPITEMIDLIST pidlInitialSel;
+
+	HWND getParentHandle() const { return parent ? parent->handle() : nullptr; }
+
+	static int CALLBACK browseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM lpData);
 };
 
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Implementation of class
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-inline FolderDialog::FolderDialog( Widget * parent )
- : itsParent( parent ), itsPidlRoot(NULL)
-{
-}
-
-inline FolderDialog& FolderDialog::setTitle( const tstring& title ) {
-	itsTitle = title;
-	return *this;
-}
-
-inline FolderDialog::~FolderDialog() {
-	::CoTaskMemFree(itsPidlRoot);
-}
-
 }
 
 #endif

=== modified file 'dwt/src/widgets/FolderDialog.cpp'
--- dwt/src/widgets/FolderDialog.cpp	2012-02-04 18:32:29 +0000
+++ dwt/src/widgets/FolderDialog.cpp	2012-02-12 12:55:04 +0000
@@ -33,24 +33,51 @@
 
 namespace dwt {
 
-FolderDialog& FolderDialog::setRoot( const int csidl ) {
-	if (FAILED(SHGetSpecialFolderLocation( getParentHandle(), csidl, &itsPidlRoot ))) {
-		itsPidlRoot = NULL;
+FolderDialog::FolderDialog(Widget* parent) :
+parent(parent),
+pidlRoot(nullptr),
+pidlInitialSel(nullptr)
+{
+}
+
+FolderDialog::~FolderDialog() {
+	if(pidlRoot) {
+		::CoTaskMemFree(pidlRoot);
 	}
-	return *this;
-}
-
-bool FolderDialog::open(tstring& folder) {
-	BROWSEINFO bws = { 0 };
-	bws.hwndOwner = getParentHandle();
-	bws.pidlRoot = itsPidlRoot;
-	if(!itsTitle.empty()) {
-		bws.lpszTitle = itsTitle.c_str();
+}
+
+FolderDialog& FolderDialog::setRoot(const int csidl) {
+	SHGetSpecialFolderLocation(getParentHandle(), csidl, &pidlRoot);
+	return *this;
+}
+
+FolderDialog& FolderDialog::setTitle(const tstring& title) {
+	this->title = title;
+	return *this;
+}
+
+FolderDialog& FolderDialog::setInitialSelection(const tstring& sel) {
+	initialSel = sel;
+	return *this;
+}
+
+FolderDialog& FolderDialog::setInitialSelection(const int csidl) {
+	SHGetSpecialFolderLocation(getParentHandle(), csidl, &pidlInitialSel);
+	return *this;
+}
+
+bool FolderDialog::open(tstring& dir) {
+	if(!dir.empty())
+		setInitialSelection(dir);
+
+	BROWSEINFO bws = { getParentHandle(), pidlRoot };
+	if(!title.empty()) {
+		bws.lpszTitle = title.c_str();
 	}
 	bws.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
-	if(!folder.empty()) {
-		bws.lParam = reinterpret_cast<LPARAM>(folder.c_str());
+	if(!initialSel.empty() || pidlInitialSel) {
 		bws.lpfn = &browseCallbackProc;
+		bws.lParam = reinterpret_cast<LPARAM>(this);
 	}
 
 	// Avoid errors about missing cdroms, floppies etc..
@@ -60,21 +87,34 @@
 
 	::SetErrorMode(oldErrorMode);
 
+	bool ret = false;
+
 	if(lpIDL) {
 		TCHAR buf[MAX_PATH + 1];
-		if ( ::SHGetPathFromIDList( lpIDL, buf ) ) {
-			folder = buf;
-
-			if(!folder.empty() && folder[folder.size()-1] != _T('\\')) {
-				folder += _T('\\');
+		if(::SHGetPathFromIDList(lpIDL, buf)) {
+			dir = buf;
+			if(!dir.empty() && *(dir.end() - 1) != _T('\\')) {
+				dir += _T('\\');
 			}
-
-			::CoTaskMemFree(lpIDL);
-			return true;
+			ret = true;
 		}
+
 		::CoTaskMemFree(lpIDL);
 	}
-	return false;
+
+	return ret;
+}
+
+int CALLBACK FolderDialog::browseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM lpData) {
+	if(lpData && uMsg == BFFM_INITIALIZED) {
+		auto& dialog = *reinterpret_cast<FolderDialog*>(lpData);
+		auto wparam = dialog.initialSel.empty() ? FALSE : TRUE;
+		auto lparam = wparam ? reinterpret_cast<LPARAM>(dialog.initialSel.c_str()) :
+			reinterpret_cast<LPARAM>(dialog.pidlInitialSel);
+		::SendMessage(hwnd, BFFM_SETSELECTION, wparam, lparam);
+		::SendMessage(hwnd, BFFM_SETEXPANDED, wparam, lparam);
+	}
+	return 0;
 }
 
 }

=== modified file 'win32/UploadPage.cpp'
--- win32/UploadPage.cpp	2012-01-23 20:18:58 +0000
+++ win32/UploadPage.cpp	2012-02-12 12:55:04 +0000
@@ -217,7 +217,7 @@
 
 void UploadPage::handleAddClicked() {
 	tstring target;
-	if(FolderDialog(this).open(target)) {
+	if(FolderDialog(this).setInitialSelection(CSIDL_PERSONAL).open(target)) {
 		addDirectory(target);
 		HashProgressDlg(this, true).run();
 	}