Skip to content

Commit

Permalink
Bug 1740: Start main window with the last user local folder instead o…
Browse files Browse the repository at this point in the history
…f always starting in Documents folder

https://winscp.net/tracker/1740

Source commit: 8fd910ca9c7851fb03c0ad6c9ce4851dbf363c6b
  • Loading branch information
martinprikryl committed Apr 18, 2019
1 parent b12f13e commit df836a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
39 changes: 25 additions & 14 deletions source/forms/ScpCommander.cpp
Expand Up @@ -232,6 +232,7 @@ void __fastcall TScpCommanderForm::StoreParams()
StorePanelParams(LocalDirView, LocalDriveView, LocalStatusBar, CommanderConfiguration.LocalPanel);
StorePanelParams(RemoteDirView, RemoteDrivePanel, RemoteStatusBar, CommanderConfiguration.RemotePanel);

CommanderConfiguration.LocalPanel.LastPath = LocalDirView->Path;

CommanderConfiguration.WindowParams = StoreForm(this);

Expand Down Expand Up @@ -536,28 +537,21 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
{
UnicodeString LocalDirectory = ManagedTerminal->StateData->LocalDirectory;
bool DocumentsDir = LocalDirectory.IsEmpty();

if (!DocumentsDir)
if (!LocalDirectory.IsEmpty())
{
try
{
LocalDirView->Path = LocalDirectory;
}
catch(Exception & E)
{
DocumentsDir = true;
if (!Terminal->SessionData->UpdateDirectories)
{
Terminal->ShowExtendedException(&E);
}
}
}

if (DocumentsDir)
{
LocalDefaultDirectory();
}
}
FFirstTerminal = false;

Expand Down Expand Up @@ -586,15 +580,32 @@ void __fastcall TScpCommanderForm::TerminalChanged(bool Replaced)
//---------------------------------------------------------------------------
void __fastcall TScpCommanderForm::LocalDefaultDirectory()
{
try
bool DocumentsDir = true;
UnicodeString LastPath = WinConfiguration->ScpCommander.LocalPanel.LastPath;
if (!LastPath.IsEmpty())
{
LocalDirView->HomeDirectory = L"";
LocalDirView->ExecuteHomeDirectory();
try
{
LocalDirView->Path = LastPath;
DocumentsDir = false;
}
catch (...)
{
}
}
catch(Exception & E)

if (DocumentsDir)
{
ShowExtendedException(NULL, &E);
LocalDirView->Path = ExtractFilePath(Application->ExeName);
try
{
LocalDirView->HomeDirectory = L"";
LocalDirView->ExecuteHomeDirectory();
}
catch(Exception & E)
{
ShowExtendedException(NULL, &E);
LocalDirView->Path = ExtractFilePath(Application->ExeName);
}
}
}
//---------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions source/windows/WinConfiguration.cpp
Expand Up @@ -753,13 +753,15 @@ void __fastcall TWinConfiguration::Default()
FScpCommander.RemotePanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
FScpCommander.RemotePanel.DriveViewWidth = 100;
FScpCommander.RemotePanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
FScpCommander.RemotePanel.LastPath = UnicodeString();
FScpCommander.LocalPanel.DirViewParams = L"0;1;0|150,1;70,1;120,1;150,1;55,0;55,0;@" + SaveDefaultPixelsPerInch() + L"|5;0;1;2;3;4";
FScpCommander.LocalPanel.StatusBar = true;
FScpCommander.LocalPanel.DriveView = false;
FScpCommander.LocalPanel.DriveViewHeight = 100;
FScpCommander.LocalPanel.DriveViewHeightPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
FScpCommander.LocalPanel.DriveViewWidth = 100;
FScpCommander.LocalPanel.DriveViewWidthPixelsPerInch = USER_DEFAULT_SCREEN_DPI;
FScpCommander.LocalPanel.LastPath = UnicodeString();

FBookmarks->Clear();
}
Expand Down Expand Up @@ -1133,6 +1135,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
KEY(Integer, ScpCommander.LocalPanel.DriveViewHeightPixelsPerInch); \
KEY(Integer, ScpCommander.LocalPanel.DriveViewWidth); \
KEY(Integer, ScpCommander.LocalPanel.DriveViewWidthPixelsPerInch); \
KEY(String, ScpCommander.LocalPanel.LastPath); \
); \
BLOCK(L"Interface\\Commander\\RemotePanel", CANCREATE, \
KEY(String, ScpCommander.RemotePanel.DirViewParams); \
Expand All @@ -1142,6 +1145,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
KEY(Integer, ScpCommander.RemotePanel.DriveViewHeightPixelsPerInch); \
KEY(Integer, ScpCommander.RemotePanel.DriveViewWidth); \
KEY(Integer, ScpCommander.RemotePanel.DriveViewWidthPixelsPerInch); \
KEY(String, ScpCommander.RemotePanel.LastPath); \
); \
BLOCK(L"Security", CANCREATE, \
KEYEX(Bool, FUseMasterPassword, L"UseMasterPassword"); \
Expand Down
3 changes: 2 additions & 1 deletion source/windows/WinConfiguration.h
Expand Up @@ -40,10 +40,11 @@ struct TScpCommanderPanelConfiguration {
int DriveViewHeightPixelsPerInch;
int DriveViewWidth;
int DriveViewWidthPixelsPerInch;
UnicodeString LastPath;
bool __fastcall operator !=(TScpCommanderPanelConfiguration & rhc)
{ return C(DirViewParams) C(StatusBar)
C(DriveView) C(DriveViewHeight) C(DriveViewHeightPixelsPerInch)
C(DriveViewWidth) C(DriveViewWidthPixelsPerInch) 0; };
C(DriveViewWidth) C(DriveViewWidthPixelsPerInch) C(LastPath) 0; };
};
//---------------------------------------------------------------------------
struct TScpCommanderConfiguration {
Expand Down

0 comments on commit df836a0

Please sign in to comment.