Skip to content

Commit

Permalink
#355 tab settings: link files are also resolved when text is copied i…
Browse files Browse the repository at this point in the history
…n shell text box.
  • Loading branch information
cbucher committed Sep 22, 2016
1 parent 82e683c commit 4c2c34b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
61 changes: 46 additions & 15 deletions Console/PageSettingsTabs1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ LRESULT PageSettingsTabs1::OnCheckboxClicked(WORD /*wNotifyCode*/, WORD /*wID*/,
//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////

LRESULT PageSettingsTabs1::OnTabKillFocus(WORD /*wCommandCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if( wID == IDC_TAB_SHELL )
{
CString strShell(L"");
this->ConvertShellLink(strShell);
}
return 0;
}

//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////

void PageSettingsTabs1::EnableControls()
Expand Down Expand Up @@ -238,16 +253,38 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell)
{
DoDataExchange(DDX_SAVE);

m_strShell = strShell;
CString strLink;

if( m_strShell.Right(4).CompareNoCase(L".lnk") == 0 )
if( strShell.IsEmpty() )
{
// text modified in shell text box
// this text can contain spaces or quotes
strLink = m_strShell.Trim();
while( strLink.GetLength() > 0 && strLink.GetAt(0) == L'"' )
strLink = strLink.Right(strLink.GetLength() - 1);
while( strLink.GetLength() > 0 && strLink.GetAt(strLink.GetLength() - 1) == L'"' )
strLink = strLink.Left(strLink.GetLength() - 1);
}
else
{
// strShell from drag and drop or select file dialog
strLink = strShell;

m_strShell = strShell;
if( m_strShell.Find(L' ') != -1 && m_strShell.Find(L'"') == -1 )
{
m_strShell.Insert(0, L'"');
m_strShell.Insert(m_strShell.GetLength(), L'"');
}
}

if( strLink.Right(4).CompareNoCase(L".lnk") == 0 )
{
// set title
wchar_t szTitle[_MAX_PATH];

if( _wsplitpath_s(
m_strShell.GetString(),
strLink.GetString(),
nullptr, 0,
nullptr, 0,
szTitle, ARRAYSIZE(szTitle),
Expand All @@ -262,7 +299,7 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell)
CComPtr<IPersistFile> persistFile;
if( SUCCEEDED(shellLink.QueryInterface(&persistFile)) )
{
if( SUCCEEDED(persistFile->Load(m_strShell, STGM_READ)) &&
if( SUCCEEDED(persistFile->Load(strLink, STGM_READ)) &&
SUCCEEDED(shellLink->Resolve(m_hWnd, 0)) )
{
WCHAR szBuffer[MAX_PATH];
Expand All @@ -280,9 +317,11 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell)
m_strShell.Insert(m_strShell.GetLength(), L'"');
}

m_strShell += L" ";
m_strShell += szBuffer2;

if( szBuffer2[0] )
{
m_strShell += L" ";
m_strShell += szBuffer2;
}
}

if( SUCCEEDED(shellLink->GetWorkingDirectory(szBuffer, MAX_PATH)) )
Expand Down Expand Up @@ -313,14 +352,6 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell)
}
}
}
else
{
if( m_strShell.Find(L' ') != -1 )
{
m_strShell.Insert(0, L'"');
m_strShell.Insert(m_strShell.GetLength(), L'"');
}
}

DoDataExchange(DDX_LOAD);
}
Expand Down
3 changes: 3 additions & 0 deletions Console/PageSettingsTabs1.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class PageSettingsTabs1
COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_CURRENT_USER, OnCheckboxClicked)
COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_ADMIN, OnCheckboxClicked)
COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_USER, OnCheckboxClicked)
COMMAND_CODE_HANDLER(EN_KILLFOCUS, OnTabKillFocus)
END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
Expand All @@ -79,6 +80,8 @@ class PageSettingsTabs1
LRESULT OnClickedBtnBrowseDir(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnCheckboxClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

LRESULT OnTabKillFocus(WORD /*wCommandCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

void EnableControls();

void Load(std::shared_ptr<TabData>& tabData);
Expand Down

0 comments on commit 4c2c34b

Please sign in to comment.