Closed Bug 2226 Opened 26 years ago Closed 24 years ago

File->Open dialog does not 'remember' browsing directory across invocations

Categories

(Core Graveyard :: Viewer App, defect, P2)

x86
Windows NT
defect

Tracking

(Not tracked)

VERIFIED DUPLICATE of bug 27493

People

(Reporter: michael.j.lowe, Assigned: law)

Details

(Keywords: platform-parity)

The FileWidget does not have a facility to set the initial directory the user will start browsing from, nor a facility to return the directory the user finishes browsing at when they close it. So, in the Viewer app. the file Open dialog always starts browsing from the directory the executable is contained in, and does not restart from the directory they were last browsing at when they reopen the dialog. This patch adds methods to the FileWidget to Set and Get the users initial and final browsing directory. It changes the Viewer.exe BrowserWindow to utilitise these methods so that their browsing directory is saved when they close the File Open dialog and restored when they reopen it. Index: widget/public/nsIFileWidget.h =================================================================== RCS file: /cvsroot/mozilla/widget/public/nsIFileWidget.h,v retrieving revision 3.9 diff -u -r3.9 nsIFileWidget.h --- nsIFileWidget.h 1998/09/28 22:32:23 3.9 +++ nsIFileWidget.h 1999/01/07 22:49:53 @@ -105,7 +105,24 @@ */ NS_IMETHOD SetDefaultString(nsString& aString) = 0; -}; + + /** + * Set the directory that the file open/save dialog initially displays + * + * @param aDirectory the name of the directory + * @return void + * + */ + NS_IMETHOD SetDisplayDirectory(nsString& aDirectory) = 0; -#endif // nsIFileWidget_h__ + /** + * Get the directory that the file open/save dialog was last displaying + * + * @param aDirectory the name of the directory + * @return void + * + */ + NS_IMETHOD GetDisplayDirectory(nsString& aDirectory) = 0; +}; +#endif // nsIFileWidget_h__ \ No newline at end of file Index: widget/src/gtk/nsFileWidget.cpp =================================================================== RCS file: /cvsroot/mozilla/widget/src/gtk/nsFileWidget.cpp,v retrieving revision 1.5 diff -u -r1.5 nsFileWidget.cpp --- nsFileWidget.cpp 1998/11/09 15:49:28 1.5 +++ nsFileWidget.cpp 1999/01/07 22:49:59 @@ -240,6 +240,29 @@ } +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(nsString& aDirectory) +{ + mDisplayDirectory = aDirectory; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetDisplayDirectory(nsString& aDirectory) +{ + aDirectory = mDisplayDirectory; + return NS_OK; +} + //------------------------------------------------------------------------- // Index: widget/src/gtk/nsFileWidget.h =================================================================== RCS file: /cvsroot/mozilla/widget/src/gtk/nsFileWidget.h,v retrieving revision 1.3 diff -u -r1.3 nsFileWidget.h --- nsFileWidget.h 1998/11/07 17:00:10 1.3 +++ nsFileWidget.h 1999/01/07 22:50:01 @@ -73,6 +73,8 @@ NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, const nsString aTitles[], const nsString aFilters[]); + NS_IMETHOD GetDisplayDirectory(nsString& aDirectory); + NS_IMETHOD SetDisplayDirectory(nsString& aDirectory); NS_IMETHOD OnOk(); NS_IMETHOD OnCancel(); @@ -87,6 +89,7 @@ const nsString* mTitles; const nsString* mFilters; nsString mDefault; + nsString mDisplayDirectory; void GetFilterListArray(nsString& aFilterList); Index: widget/src/mac/nsFileWidget.cpp =================================================================== RCS file: /cvsroot/mozilla/widget/src/mac/nsFileWidget.cpp,v retrieving revision 1.5 diff -u -r1.5 nsFileWidget.cpp --- nsFileWidget.cpp 1998/12/15 03:11:59 1.5 +++ nsFileWidget.cpp 1999/01/07 22:50:06 @@ -240,13 +240,35 @@ } +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(nsString& aDirectory) +{ + mDisplayDirectory = aDirectory; + return NS_OK; +} + //------------------------------------------------------------------------- // -// nsFileWidget destructor +// Get the display directory // //------------------------------------------------------------------------- -nsFileWidget::~nsFileWidget() +NS_METHOD nsFileWidget::GetDisplayDirectory(nsString& aDirectory) { + aDirectory = mDisplayDirectory; + return NS_OK; } + +//------------------------------------------------------------------------- +// +// nsFileWidget destructor +// +//------------------------------------------------------------------------- +nsFileWidget::~nsFileWidget() +{ +} \ No newline at end of file Index: widget/src/mac/nsFileWidget.h =================================================================== RCS file: /cvsroot/mozilla/widget/src/mac/nsFileWidget.h,v retrieving revision 1.4 diff -u -r1.4 nsFileWidget.h --- nsFileWidget.h 1998/11/04 06:49:50 1.4 +++ nsFileWidget.h 1999/01/07 22:50:09 @@ -65,12 +65,15 @@ nsIToolkit *aToolkit = nsnull, void *aInitData = nsnull); - virtual PRBool Show(); + virtual PRBool Show(); NS_IMETHOD GetFile(nsString& aFile); NS_IMETHOD SetDefaultString(nsString& aString); - NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, + NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, const nsString aTitles[], const nsString aFilters[]); + NS_IMETHOD GetDisplayDirectory(nsString& aDirectory); + NS_IMETHOD SetDisplayDirectory(nsString& aDirectory); + protected: NS_IMETHOD OnOk(); NS_IMETHOD OnCancel(); @@ -87,6 +90,7 @@ const nsString* mTitles; const nsString* mFilters; nsString mDefault; + nsString mDisplayDirectory; void GetFilterListArray(nsString& aFilterList); Index: widget/src/motif/nsFileWidget.cpp =================================================================== RCS file: /cvsroot/mozilla/widget/src/motif/nsFileWidget.cpp,v retrieving revision 1.17 diff -u -r1.17 nsFileWidget.cpp --- nsFileWidget.cpp 1998/10/12 23:05:15 1.17 +++ nsFileWidget.cpp 1999/01/07 22:50:14 @@ -243,6 +243,29 @@ } +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(nsString& aDirectory) +{ + mDisplayDirectory = aDirectory; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetDisplayDirectory(nsString& aDirectory) +{ + aDirectory = mDisplayDirectory; + return NS_OK; +} + //------------------------------------------------------------------------- // Index: widget/src/motif/nsFileWidget.h =================================================================== RCS file: /cvsroot/mozilla/widget/src/motif/nsFileWidget.h,v retrieving revision 1.11 diff -u -r1.11 nsFileWidget.h --- nsFileWidget.h 1998/10/08 18:33:45 1.11 +++ nsFileWidget.h 1999/01/07 22:50:16 @@ -73,6 +73,9 @@ NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, const nsString aTitles[], const nsString aFilters[]); + NS_IMETHOD GetDisplayDirectory(nsString& aDirectory); + NS_IMETHOD SetDisplayDirectory(nsString& aDirectory); + NS_IMETHOD OnOk(); NS_IMETHOD OnCancel(); @@ -86,6 +89,7 @@ const nsString* mTitles; const nsString* mFilters; nsString mDefault; + nsString mDisplayDirectory; void GetFilterListArray(nsString& aFilterList); Index: widget/src/windows/nsFileWidget.cpp =================================================================== RCS file: /cvsroot/mozilla/widget/src/windows/nsFileWidget.cpp,v retrieving revision 3.11 diff -u -r3.11 nsFileWidget.cpp --- nsFileWidget.cpp 1998/09/28 22:32:36 3.11 +++ nsFileWidget.cpp 1999/01/07 22:50:21 @@ -47,7 +47,7 @@ PRBool nsFileWidget::Show() { char fileBuffer[MAX_PATH+1] = ""; - mDefault.ToCString(fileBuffer,MAX_PATH); + mDefault.ToCString(fileBuffer, MAX_PATH); OPENFILENAME ofn; memset(&ofn, 0, sizeof(ofn)); @@ -58,17 +58,21 @@ GetFilterListArray(filterList); char *filterBuffer = filterList.ToNewCString(); char *title = mTitle.ToNewCString(); + char *initialDir = mDisplayDirectory.ToNewCString(); + if (mDisplayDirectory.Length() > 0) { + ofn.lpstrInitialDir = initialDir; + } ofn.lpstrTitle = title; ofn.lpstrFilter = filterBuffer; ofn.nFilterIndex = 1; ofn.hwndOwner = mWnd; ofn.lpstrFile = fileBuffer; ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_SHAREAWARE | OFN_NOCHANGEDIR | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + ofn.Flags = OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; - BOOL result; + PRBool result; - // Save current directory, so we can reset if it changes. + // Save current directory, so we can reset if it changes. char* currentDirectory = new char[MAX_PATH+1]; VERIFY(::GetCurrentDirectory(MAX_PATH, currentDirectory) > 0); @@ -82,15 +86,23 @@ NS_ASSERTION(0, "Only load and save are supported modes"); } + char* newCurrentDirectory = new char[MAX_PATH+1]; + VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0); + mDisplayDirectory.SetLength(0); + mDisplayDirectory.Append(newCurrentDirectory); + delete newCurrentDirectory; + VERIFY(::SetCurrentDirectory(currentDirectory)); + delete currentDirectory; - // Clean up filter buffers + // Clean up filter buffers delete filterBuffer; delete title; + delete initialDir; - // Set user-selected location of file or directory + // Set user-selected location of file or directory mFile.SetLength(0); - if (result==PR_TRUE) { + if (result == PR_TRUE) { mFile.Append(fileBuffer); } @@ -157,8 +169,30 @@ return NS_OK; } + +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(nsString& aDirectory) +{ + mDisplayDirectory = aDirectory; + return NS_OK; +} + - +//------------------------------------------------------------------------- +// +// Get the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetDisplayDirectory(nsString& aDirectory) +{ + aDirectory = mDisplayDirectory; + return NS_OK; +} + //------------------------------------------------------------------------- NS_METHOD nsFileWidget::Create(nsIWidget *aParent, @@ -184,6 +218,4 @@ //------------------------------------------------------------------------- nsFileWidget::~nsFileWidget() { -} - - +} \ No newline at end of file Index: widget/src/windows/nsFileWidget.h =================================================================== RCS file: /cvsroot/mozilla/widget/src/windows/nsFileWidget.h,v retrieving revision 3.9 diff -u -r3.9 nsFileWidget.h --- nsFileWidget.h 1998/09/28 22:32:36 3.9 +++ nsFileWidget.h 1999/01/07 22:50:33 @@ -53,6 +53,9 @@ NS_IMETHOD GetFile(nsString& aFile); NS_IMETHOD SetDefaultString(nsString& aFile); NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]); + + NS_IMETHOD GetDisplayDirectory(nsString& aDirectory); + NS_IMETHOD SetDisplayDirectory(nsString& aDirectory); protected: @@ -64,6 +67,7 @@ const nsString* mTitles; const nsString* mFilters; nsString mDefault; + nsString mDisplayDirectory; void GetFilterListArray(nsString& aFilterList); Index: webshell/tests/viewer/nsBrowserWindow.cpp =================================================================== RCS file: /cvsroot/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp,v retrieving revision 3.127 diff -u -r3.127 nsBrowserWindow.cpp --- nsBrowserWindow.cpp 1999/01/07 02:06:44 3.127 +++ nsBrowserWindow.cpp 1999/01/07 22:52:26 @@ -520,11 +520,12 @@ #define FILE_PROTOCOL "file://" static PRBool GetFileNameFromFileSelector(nsIWidget* aParentWindow, - nsString* aFileName) + nsString* aFileName, + nsString* aDisplayDirectory) { PRBool selectedFileName = PR_FALSE; nsIFileWidget *fileWidget; - nsString title("Open HTML"); + nsString title("Open"); nsresult rv = nsRepository::CreateInstance(kFileWidgetCID, nsnull, kIFileWidgetIID, @@ -538,17 +539,17 @@ "*.gif; *.jpg; *.jpeg; *.png", "*.*"}; fileWidget->SetFilterList(5, titles, filters); + fileWidget->SetDisplayDirectory(*aDisplayDirectory); fileWidget->Create(aParentWindow, title, - eMode_load, - nsnull, - nsnull); + eMode_load); PRUint32 result = fileWidget->Show(); if (result) { fileWidget->GetFile(*aFileName); selectedFileName = PR_TRUE; } + fileWidget->GetDisplayDirectory(*aDisplayDirectory); NS_RELEASE(fileWidget); } @@ -561,7 +562,7 @@ { nsAutoString fileName; char szFile[1000]; - if (GetFileNameFromFileSelector(mWindow, &fileName)) { + if (GetFileNameFromFileSelector(mWindow, &fileName, &mOpenFileDirectory)) { fileName.ToCString(szFile, sizeof(szFile)); PRInt32 len = strlen(szFile); PRInt32 sum = len + sizeof(FILE_PROTOCOL); Index: webshell/tests/viewer/nsBrowserWindow.h =================================================================== RCS file: /cvsroot/mozilla/webshell/tests/viewer/nsBrowserWindow.h,v retrieving revision 1.45 diff -u -r1.45 nsBrowserWindow.h --- nsBrowserWindow.h 1999/01/06 21:59:16 1.45 +++ nsBrowserWindow.h 1999/01/07 22:52:30 @@ -200,6 +200,8 @@ nsIWidget* mWindow; nsIWebShell* mWebShell; + nsString mOpenFileDirectory; + // "Toolbar" nsITextWidget* mLocation; nsIButton* mBack;
Assignee: kipp → karnaze
Status: ASSIGNED → NEW
Since this will also aid the File form element, I'm giving this one to you.
Assignee: karnaze → kmcclusk
Setting all current Open/Normal to M4.
Status: NEW → ASSIGNED
per leger, assigning QA contacts to all open bugs without QA contacts according to list at http://bugzilla.mozilla.org/describecomponents.cgi?product=Browser
QA Contact: 3853 → 3849
Target Milestone: M4 → M3
beppe- Please change QA Contact for a check with ths latest build. Thanks!
QA Contact: 3849 → 4137
using 3/10 viewer the open dialog does not remember the previous directory location. Also setting Christopher as QA contact
this patch looks ok for gtk...
Checked in the patch provided.The patch fixes WIN32. It also defines member variables and functions for Mac and Unix to keep tinderbox building. Mac and Unix need implementations which honor the SetDisplayDirectory method so that the browsing directory is actually set.
This bug, as described, doesn't happen on Mac: the File|Open dialog reopens where it was last closed. The Mac still needs implementations of Get/ SetDisplayDirectory for other purposes but it shouldn't be a requirement for the M3 milestone.
The file form element will not yet take advantage of this patch. Either the current display directory needs to be stored as a global setting (in the preferences so it can be restored across application launches?) and set/retrived for each instance of the file widget, or the Windows file widget code should be modified so that the Windows operating system's record of the current directory is not clobbered by the call: ::SetCurrentDirectory(currentDirectory) (in mozilla/widget/src/windows/nsFileWidget.cpp) after the file widget has been closed. Removing this line would bring the Windows widget into line with how the Mac widget currently operates.
Target Milestone: M3 → M4
moving to m4
Target Milestone: M4 → M5
Target Milestone: M5 → M6
Target Milestone: M6 → M7
Target Milestone: M7 → M6
Assignee: kmcclusk → ramiro
Status: ASSIGNED → NEW
WIN32 FileWidget Fixed in 5-10-99 4:00pm build. Removed WIN32 code which saved and restored the current directory. The current directory is now maintained by the operating system and is no longer set back to the original directory after launching a browse dialog. This brings its behavior in line with the MAC. Ramiro, I am re-assigning to you. On GTK it behaves like WIN32 used to. it always restores the directory.
m7
Assignee: ramiro → pavlov
Sounds a pavlov bug to me.
Marking M8. If you plan to fix any of these for m7, mark them so.
Status: NEW → ASSIGNED
Target Milestone: M8 → M11
Target Milestone: M11 → M14
Joining cc list, since I find this behavior very annoying when trying to use the editor.
Summary: [PATCH] File->Open dialog does not 'remember' browsing directory across invocations → [PP]File->Open dialog does not 'remember' browsing directory across invocations
Target Milestone: M14 → M16
QA Contact: cpratt → sairuh
setting sairuh as qa contact, another test case for you :-)
Keywords: pp
Summary: [PP]File->Open dialog does not 'remember' browsing directory across invocations → File->Open dialog does not 'remember' browsing directory across invocations
bill, i'm not sure if the windows or mac file pickers save the directory internally. I've noticed a lot of places that are using a pref to save the location of the last directory, but this seems pretty silly to me. We should just have the file picker save this information. The new unix filepicker saves the last directory it was in when you ok out of it and will automagically put you there when you open a new one.
Assignee: pavlov → law
Status: ASSIGNED → NEW
Target Milestone: M16 → M18
Move to M21 target milestone.
Target Milestone: M18 → M21
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
*** This bug has been marked as a duplicate of 27493 ***
v
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.