2121#include " ServerListPopup.h"
2222
2323#include < strsafe.h>
24+ #include < dwmapi.h>
2425
2526#include " Gui/GuiTools.h"
2627#include " Func/WinUtils.h"
3031#include " Core/AbstractServerIconCache.h"
3132#include " Gui/Helpers/DPIHelper.h"
3233#include " Gui/Models/ServerListModel.h"
34+ #include " AddFtpServerDialog.h"
35+ #include " AddDirectoryServerDialog.h"
36+ #include " Func/MyEngineList.h"
3337
3438namespace {
3539
@@ -50,7 +54,6 @@ CServerListPopup::CServerListPopup(CMyEngineList* engineList, WinServerIconCache
5054 isChildWindow_ = isChildWindow;
5155 hMyDlgTemplate_ = nullptr ;
5256 isPopingUp_ = false ;
53- BasicSettings* settings = ServiceLocator::instance ()->basicSettings ();
5457}
5558
5659CServerListPopup::~CServerListPopup ()
@@ -65,14 +68,21 @@ void CServerListPopup::TranslateUI() {
6568 TRCC (IDC_IMAGERADIO, " serverlist.servertype" , " Image" );
6669 TRCC (IDC_FILERADIO, " serverlist.servertype" , " File" );
6770 TRCC (IDC_VIDEORADIO, " serverlist.servertype" , " Video" );
71+ TRC (IDC_ADDBUTTON, " Add server" );
6872}
6973
7074LRESULT CServerListPopup::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
7175{
76+ DWMNCRENDERINGPOLICY policy = DWMNCRP_DISABLED;
77+ DwmSetWindowAttribute (m_hWnd, DWMWA_NCRENDERING_POLICY, &policy, sizeof (policy));
78+
7279 DlgResize_Init (true , true , 0 ); // resizable dialog without "griper"
7380 DoDataExchange (FALSE );
74- listView_. SetExtendedListViewStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
81+
7582 TranslateUI ();
83+ addServerButton_.SetButtonStyle (BS_SPLITBUTTON);
84+
85+ listView_.SetExtendedListViewStyle (LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
7686
7787 if (selectedServerType_ == CUploadEngineData::TypeImageServer) {
7888 imageTypeRadioButton_.SetCheck (BST_CHECKED);
@@ -92,7 +102,9 @@ LRESULT CServerListPopup::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
92102 createResources ();
93103 updateServerList ();
94104
95- applyFilter ();
105+ applyFilter (false );
106+
107+ selectServerByName (U2W (engineList_->byIndex (serverIndex_)->Name ));
96108 listView_.SetFocus ();
97109
98110 return FALSE ;
@@ -105,6 +117,7 @@ LRESULT CServerListPopup::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOO
105117
106118LRESULT CServerListPopup::OnDpiChanged (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
107119 createResources ();
120+ listView_.SendMessage (WM_MY_DPICHANGED, wParam);
108121 return 0 ;
109122}
110123
@@ -135,7 +148,6 @@ void CServerListPopup::setServersMask(int mask) {
135148
136149void CServerListPopup::notifyChange ()
137150{
138- // ::SendMessage(GetParent(), WM_SERVERSELECTCONTROL_CHANGE, reinterpret_cast<WPARAM>(m_hWnd), 0);
139151 if (onChangeCallback_)
140152 {
141153 onChangeCallback_ (this );
@@ -144,7 +156,6 @@ void CServerListPopup::notifyChange()
144156
145157void CServerListPopup::notifyServerListChanged ()
146158{
147- // ::SendMessage(GetParent(), WM_SERVERSELECTCONTROL_SERVERLIST_CHANGED, reinterpret_cast<WPARAM>(m_hWnd), 0);
148159}
149160
150161void CServerListPopup::updateServerList ()
@@ -163,6 +174,12 @@ void CServerListPopup::createResources() {
163174 const int iconWidth = DPIHelper::GetSystemMetricsForDpi (SM_CXSMICON, dpi);
164175 const int iconHeight = DPIHelper::GetSystemMetricsForDpi (SM_CYSMICON, dpi);
165176
177+ if (addServerButtonIcon_) {
178+ addServerButtonIcon_.DestroyIcon ();
179+ }
180+
181+ addServerButtonIcon_.LoadIconWithScaleDown (MAKEINTRESOURCE (IDI_ICONADDITEM), iconWidth, iconHeight);
182+ addServerButton_.SetIcon (addServerButtonIcon_);
166183}
167184
168185void CServerListPopup::setOnChangeCallback (std::function<void (CServerListPopup*)> cb) {
@@ -499,7 +516,17 @@ LRESULT CServerListPopup::OnSearchQueryEditChanged(WORD wNotifyCode, WORD wID, H
499516 return 0 ;
500517}
501518
502- void CServerListPopup::applyFilter () {
519+ LRESULT CServerListPopup::OnBnClickedAddServerButton (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
520+ showAddServerButtonMenu (hWndCtl);
521+ return 0 ;
522+ }
523+
524+ LRESULT CServerListPopup::OnBnDropdownAddServerButton (int idCtrl, LPNMHDR pnmh, BOOL& bHandled) {
525+ showAddServerButtonMenu (GetDlgItem (IDC_ADDBUTTON));
526+ return 0 ;
527+ }
528+
529+ void CServerListPopup::applyFilter (bool selectItem) {
503530 int mask = 0 ;
504531
505532 if (imageTypeRadioButton_.GetCheck () == BST_CHECKED) {
@@ -519,5 +546,84 @@ void CServerListPopup::applyFilter() {
519546 filter.query = W2U (query);
520547 filter.typeMask = mask;
521548 serverListModel_->applyFilter (filter);
522- listView_.SelectItem (0 );
549+ if (selectItem) {
550+ listView_.SelectItem (0 );
551+ }
552+ }
553+
554+ void CServerListPopup::clearFilter () {
555+ queryEditControl_.SetWindowText (_T (" " ));
556+ allTypesRadioButton_.SetCheck (BST_CHECKED);
557+ imageTypeRadioButton_.SetCheck (BST_UNCHECKED);
558+ fileTypeRadioButton_.SetCheck (BST_UNCHECKED);
559+ videoTypeRadioButton_.SetCheck (BST_UNCHECKED);
560+ }
561+
562+ void CServerListPopup::selectServerByName (const CString& name) {
563+ const std::string serverName = W2U (name);
564+ size_t count = serverListModel_->getCount ();
565+ for (size_t i = 0 ; i < count; ++i) {
566+ if (serverListModel_->getDataByIndex (i).ued ->Name == serverName) {
567+ listView_.SelectItem (i);
568+ return ;
569+ }
570+ }
571+ }
572+
573+ void CServerListPopup::showAddServerButtonMenu (HWND control) {
574+ RECT rc;
575+ ::GetWindowRect (control, &rc);
576+ POINT menuOrigin = { rc.left , rc.bottom };
577+
578+ CMenu popupMenu;
579+ popupMenu.CreatePopupMenu ();
580+ std::wstring itemTitle = str (IuStringUtils::FormatWideNoExcept (TR (" Add %s server..." )) % L" FTP/SFTP/WebDAV" );
581+ popupMenu.AppendMenu (MF_STRING, IDM_ADD_FTP_SERVER, itemTitle.c_str ());
582+ popupMenu.AppendMenu (MF_STRING, IDM_ADD_DIRECTORY_AS_SERVER, TR (" Add folder as new server..." ));
583+ popupMenu.AppendMenu (MF_STRING, IDM_OPEN_SERVERS_FOLDER, TR (" Open servers folder" ));
584+
585+ TPMPARAMS excludeArea;
586+ ZeroMemory (&excludeArea, sizeof (excludeArea));
587+ excludeArea.cbSize = sizeof (excludeArea);
588+ excludeArea.rcExclude = rc;
589+ popupMenu.TrackPopupMenuEx (TPM_LEFTALIGN | TPM_LEFTBUTTON, menuOrigin.x , menuOrigin.y , m_hWnd, &excludeArea);
590+ }
591+
592+ LRESULT CServerListPopup::OnAddFtpServer (WORD wNotifyCode, WORD wID, HWND hWndCtl) {
593+ CAddFtpServerDialog dlg (engineList_);
594+ if (dlg.DoModal (m_hWnd) == IDOK) {
595+ serverListModel_->updateEngineList ();
596+ clearFilter ();
597+ applyFilter (false );
598+ selectServerByName (dlg.createdServerName ());
599+ listView_.SetFocus ();
600+ }
601+ return 0 ;
602+ }
603+
604+ LRESULT CServerListPopup::OnAddDirectoryAsServer (WORD wNotifyCode, WORD wID, HWND hWndCtl) {
605+ CAddDirectoryServerDialog dlg (engineList_);
606+ if (dlg.DoModal (m_hWnd) == IDOK) {
607+ serverListModel_->updateEngineList ();
608+ clearFilter ();
609+ applyFilter (false );
610+ selectServerByName (dlg.createdServerName ());
611+ listView_.SetFocus ();
612+ }
613+ return 0 ;
614+ }
615+
616+ LRESULT CServerListPopup::OnOpenServersFolder (WORD wNotifyCode, WORD wID, HWND hWndCtl) {
617+ auto * settings = ServiceLocator::instance ()->settings <WtlGuiSettings>();
618+ const std::wstring folder = IuCoreUtils::Utf8ToWstring (settings->SettingsFolder + " Servers\\ " );
619+ try {
620+ WinUtils::ShellOpenFileOrUrl (folder.c_str (), m_hWnd, {}, true );
621+ } catch (const Win32Exception& ex) {
622+ const std::wstring msg = str (
623+ IuStringUtils::FormatWideNoExcept (TR (" Cannot open folder '%1%'.\n %2%" ))
624+ % folder
625+ % ex.getMessage ().GetString ());
626+ GuiTools::LocalizedMessageBox (m_hWnd, msg.c_str (), TR (" Error" ), MB_ICONERROR);
627+ }
628+ return 0 ;
523629}
0 commit comments