lean explorer: correctly handle path of command line argument in explore mode
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.cpp
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.h
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/mainframe.cpp
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.cpp
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.h
Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellfs.cpp

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.cpp
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.cpp	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.cpp	2005-12-31 18:36:39 UTC (rev 20490)
@@ -129,36 +129,6 @@
 }
 
 
- // read directory tree and expand to the given location
-ShellEntry* ShellDirectory::read_tree(const void* path, SORT_ORDER sortOrder)
-{
-	CONTEXT("ShellEntry::read_tree()");
-
-	HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT));
-
-	ShellDirectory* entry = this;
-
-	for(const void*p=path; p && entry; ) {
-		if (!(entry->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
-			break;
-
-		entry->read_directory(sortOrder);
-
-		if (entry->_down)
-			entry->_expanded = true;
-
-		ShellEntry* next_entry = entry->find_entry(p);
-		p = entry->get_next_path_component(p);
-
-		entry = static_cast<ShellDirectory*>(next_entry);
-	}
-
-	SetCursor(old_cursor);
-
-	return entry;
-}
-
-
 void ShellDirectory::read_directory(SORT_ORDER sortOrder, int scan_flags)
 {
 	CONTEXT("ShellEntry::read_directory(SORT_ORDER)");

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.h
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.h	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/entries.h	2005-12-31 18:36:39 UTC (rev 20490)
@@ -155,17 +155,15 @@
 		pFolder->Release();
 	}
 
-	ShellEntry*	read_tree(const void* path, SORT_ORDER sortOrder);
 	void	read_directory(SORT_ORDER sortOrder, int scan_flags=0);
 	void	read_directory(int scan_flags=0);
 	void	sort_directory(SORT_ORDER sortOrder);
 	void	smart_scan(int scan_flags=0);
-	virtual const void* get_next_path_component(const void*) const;
-	virtual ShellEntry* find_entry(const void* p);
 
+	virtual ShellEntry* find_entry(const void* p);
 	virtual bool get_path(PTSTR path) const;
 
-	int	extract_icons();
+	int		extract_icons();
 
 	ShellFolder _folder;
 	HWND	_hwnd;
@@ -178,7 +176,7 @@
 inline IShellFolder* ShellEntry::get_parent_folder() const
 {
 	if (_up)
-		return static_cast<ShellDirectory*>(_up)->_folder;
+		return _up->_folder;
 	else
 		return GetDesktopFolder();
 }

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/mainframe.cpp
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/mainframe.cpp	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/mainframe.cpp	2005-12-31 18:36:39 UTC (rev 20490)
@@ -82,8 +82,6 @@
 		delete _shellBrowser.release();
 	}
 
-	///@todo use OWM_ROOTED flag
-
 	 // create explorer treeview
 	if (_create_info._open_mode & OWM_EXPLORE) {
 		if (!_left_hwnd) {

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.cpp
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.cpp	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.cpp	2005-12-31 18:36:39 UTC (rev 20490)
@@ -103,8 +103,6 @@
 
 	_root._entry = new ShellDirectory(GetDesktopFolder(), _create_info._root_shell_path, _hwnd);
 
-	jump_to(_create_info._shell_path);
-
 	 // -> set_curdir()
 	_root._entry->read_directory();
 
@@ -113,8 +111,7 @@
 		InitDragDrop();
 	}
 
-	/* already filled by ShellDirectory constructor
-	lstrcpy(_root._entry->_data.cFileName, TEXT("Desktop")); */
+	jump_to(_create_info._shell_path);
 
 	return 0;
 }
@@ -278,11 +275,11 @@
 	if (pnmtv->action == TVE_COLLAPSE)
         TreeView_Expand(_left_hwnd, pnmtv->itemNew.hItem, TVE_COLLAPSE|TVE_COLLAPSERESET);
     else if (pnmtv->action == TVE_EXPAND) {
-		ShellDirectory* entry = (ShellDirectory*)TreeView_GetItemData(_left_hwnd, pnmtv->itemNew.hItem);
+		ShellDirectory* dir = (ShellDirectory*)TreeView_GetItemData(_left_hwnd, pnmtv->itemNew.hItem);
 
-		if (entry)
-			if (!InsertSubitems(pnmtv->itemNew.hItem, entry)) {
-				entry->_shell_attribs &= ~SFGAO_HASSUBFOLDER;
+		if (dir)
+			if (!InsertSubitems(pnmtv->itemNew.hItem, dir)) {
+				dir->_shell_attribs &= ~SFGAO_HASSUBFOLDER;
 
 				 // remove subitem "+"
 				TV_ITEM tvItem;
@@ -359,10 +356,11 @@
 {
 	CONTEXT("ShellBrowserChild::OnTreeItemSelected()");
 
-	_last_sel = pnmtv->itemNew.hItem;
-	ShellDirectory* entry = (ShellDirectory*)pnmtv->itemNew.lParam;
+	ShellDirectory* dir = (ShellDirectory*)pnmtv->itemNew.lParam;
 
-	jump_to(entry);
+	jump_to(dir);
+
+	_last_sel = pnmtv->itemNew.hItem;
 }
 
 void ShellBrowserChild::UpdateFolderView(IShellFolder* folder)
@@ -576,26 +574,24 @@
 
 	if (pida->cidl >= 1) {
 		if (_left_hwnd) {	// explorer mode
-			//@@if (_last_sel) {
-				ShellDirectory* parent = _cur_dir;//@@(ShellDirectory*)TreeView_GetItemData(_left_hwnd, _last_sel);
+			ShellDirectory* parent = _cur_dir;
 
-				if (parent) {
-					try {
-						parent->smart_scan();
-					} catch(COMException& e) {
-						return e.Error();
-					}
+			if (parent) {
+				try {
+					parent->smart_scan();
+				} catch(COMException& e) {
+					return e.Error();
+				}
 
-					UINT firstOffset = pida->aoffset[1];
-					LPITEMIDLIST pidl = (LPITEMIDLIST)((LPBYTE)pida+firstOffset);
+				UINT firstOffset = pida->aoffset[1];
+				LPITEMIDLIST pidl = (LPITEMIDLIST)((LPBYTE)pida+firstOffset);
 
-					ShellEntry* entry = parent->find_entry(pidl);
+				ShellEntry* entry = parent->find_entry(pidl);
 
-					if (entry && (entry->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
-						if (expand_folder(static_cast<ShellDirectory*>(entry)))
-							return S_OK;
-				}
-			//@@}
+				if (entry && (entry->_data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
+					if (select_folder(static_cast<ShellDirectory*>(entry), true))
+						return S_OK;
+			}
 		} else { // no tree control
 			if (MainFrame::OpenShellFolders(pida, _hWndFrame))
 				return S_OK;
@@ -611,7 +607,7 @@
 }
 
 
-bool ShellBrowserChild::expand_folder(ShellDirectory* entry)
+bool ShellBrowserChild::select_folder(ShellDirectory* dir, bool expand)
 {
 	CONTEXT("ShellBrowserChild::expand_folder()");
 
@@ -619,14 +615,19 @@
 	if (!_last_sel)
 		return false;
 
-	if (!TreeView_Expand(_left_hwnd, _last_sel, TVE_EXPAND))
-		return false;
+	if (expand)
+		if (!TreeView_Expand(_left_hwnd, _last_sel, TVE_EXPAND))
+			return false;
 
 	for(HTREEITEM hitem=TreeView_GetChild(_left_hwnd,_last_sel); hitem; hitem=TreeView_GetNextSibling(_left_hwnd,hitem)) {
-		if ((ShellDirectory*)TreeView_GetItemData(_left_hwnd,hitem) == entry) {
-			if (TreeView_SelectItem(_left_hwnd, hitem) &&
-				TreeView_Expand(_left_hwnd, hitem, TVE_EXPAND))
+		if ((ShellDirectory*)TreeView_GetItemData(_left_hwnd,hitem) == dir) {
+			if (TreeView_SelectItem(_left_hwnd, hitem)) {
+				if (expand)
+					if (!TreeView_Expand(_left_hwnd, hitem, TVE_EXPAND))
+						return false;
+
 				return true;
+			}
 
 			break;
 		}
@@ -645,7 +646,7 @@
 
 void ShellBrowserChild::jump_to(LPCITEMIDLIST pidl)
 {
-	ShellDirectory* entry = NULL;
+	ShellDirectory* dir = NULL;
 
 	if (!_cur_dir)
 		_cur_dir = _root._entry;
@@ -661,48 +662,36 @@
 
 				_cur_dir->smart_scan();
 
-				entry = static_cast<ShellDirectory*>(_cur_dir->find_entry(child_pidl));
-				if (!entry)
+				dir = static_cast<ShellDirectory*>(_cur_dir->find_entry(child_pidl));
+				if (!dir)
 					break;
 
-				jump_to(entry);
+				jump_to(dir);
 			}
 		} else {
 			_cur_dir->smart_scan();
 
-			entry = static_cast<ShellDirectory*>(_cur_dir->find_entry(pidl));	// This is not correct in the common case, but works on the desktop level.
+			dir = static_cast<ShellDirectory*>(_cur_dir->find_entry(pidl));	// This is not correct in the common case, but works on the desktop level.
 
-			if (entry)
-				jump_to(entry);
+			if (dir)
+				jump_to(dir);
 		}
 	}
 
 	 // If not already called, now directly call UpdateFolderView() using pidl.
-	if (!entry)
+	if (!dir)
 		UpdateFolderView(ShellFolder(pidl));
 }
 
-void ShellBrowserChild::jump_to(ShellDirectory* entry)
+void ShellBrowserChild::jump_to(ShellDirectory* dir)
 {
-	IShellFolder* folder;
-	ShellDirectory* se = entry;
-
-	if (se->_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
-		folder = static_cast<ShellDirectory*>(se)->_folder;
-	else
-		folder = se->get_parent_folder();
-
-	if (!folder) {
-		assert(folder);
+	if (dir == _cur_dir)
 		return;
-	}
 
-	if (_create_info._open_mode & OWM_EXPLORE) {
+	if (_left_hwnd)
+		select_folder(dir, false);
 
-		//@@ todo
+	UpdateFolderView(dir->_folder);
 
-	} else;
-		UpdateFolderView(folder);
-
-	_cur_dir = se;
+	_cur_dir = dir;
 }

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.h
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.h	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/shellbrowser.h	2005-12-31 18:36:39 UTC (rev 20490)
@@ -138,7 +138,7 @@
 
 	void	UpdateFolderView(IShellFolder* folder);
 	void	Tree_DoItemMenu(HWND hwndTreeView, HTREEITEM hItem, LPPOINT pptScreen);
-	bool	expand_folder(ShellDirectory* entry);
+	bool	select_folder(ShellDirectory* dir, bool expand);
 
 	// SDI integration
 public:
@@ -150,7 +150,7 @@
 	void	jump_to(LPCTSTR path);
 	void	jump_to(LPCITEMIDLIST pidl);
 
-	void	jump_to(ShellDirectory* entry);
+	void	jump_to(ShellDirectory* dir);
 
 protected:
 	ShellDirectory*	_cur_dir;

Modified: branches/lean-explorer/reactos/subsys/system/explorer/shell/shellfs.cpp
--- branches/lean-explorer/reactos/subsys/system/explorer/shell/shellfs.cpp	2005-12-31 17:27:25 UTC (rev 20489)
+++ branches/lean-explorer/reactos/subsys/system/explorer/shell/shellfs.cpp	2005-12-31 18:36:39 UTC (rev 20490)
@@ -96,7 +96,7 @@
 	CONTEXT("ShellEntry::create_absolute_pidl()");
 
 	if (_up) {
-		ShellDirectory* dir = static_cast<ShellDirectory*>(_up);
+		ShellDirectory* dir = _up;
 
 		if (dir->_pidl->mkid.cb)	// Caching of absolute PIDLs could enhance performance.
 			return _pidl.create_absolute_pidl(dir->create_absolute_pidl());
@@ -306,19 +306,6 @@
 	_scanned = true;
 }
 
-const void* ShellDirectory::get_next_path_component(const void* p) const
-{
-	LPITEMIDLIST pidl = (LPITEMIDLIST)p;
-
-	if (!pidl || !pidl->mkid.cb)
-		return NULL;
-
-	 // go to next element
-	pidl = (LPITEMIDLIST)((LPBYTE)pidl+pidl->mkid.cb);
-
-	return pidl;
-}
-
 ShellEntry* ShellDirectory::find_entry(const void* p)
 {
 	LPITEMIDLIST pidl = (LPITEMIDLIST) p;