Skip to content

Commit

Permalink
Copy folders ID item to folders context menu, add checkbox to exit co…
Browse files Browse the repository at this point in the history
…nfirmation dialog

Fix folders context menu position in CServerFolderSelect dialog
Show confirmation dialog with checkbox on app exit
Add showServerIcons option to CServerSelectorControl
  • Loading branch information
zenden2k committed Feb 10, 2024
1 parent dbce403 commit afcb1ab
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 153 deletions.
110 changes: 58 additions & 52 deletions Lang/imageuploader.pot

Large diffs are not rendered by default.

112 changes: 59 additions & 53 deletions Lang/locale/ru/LC_MESSAGES/imageuploader.po

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions Source/Gui/Controls/ServerSelectorControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ char* DuplicateString(const char* str) {
}

// CServerSelectorControl
CServerSelectorControl::CServerSelectorControl(UploadEngineManager* uploadEngineManager, bool defaultServer, bool isChildWindow)
CServerSelectorControl::CServerSelectorControl(UploadEngineManager* uploadEngineManager, bool defaultServer, bool isChildWindow, bool showServerIcons)
{
showDefaultServerItem_ = false;
serversMask_ = smImageServers | smFileServers;
Expand All @@ -66,6 +66,7 @@ CServerSelectorControl::CServerSelectorControl(UploadEngineManager* uploadEngine
hMyDlgTemplate_ = nullptr;
isPopingUp_ = false;
showEmptyItem_ = false;
showServerIcons_ = showServerIcons;
}

CServerSelectorControl::~CServerSelectorControl()
Expand Down Expand Up @@ -389,8 +390,10 @@ void CServerSelectorControl::updateServerList()
{
serverComboBox_.ResetContent();
comboBoxImageList_.Destroy();
DWORD rtlStyle = ServiceLocator::instance()->translator()->isRTL() ? ILC_MIRROR | ILC_PERITEMMIRROR : 0;
comboBoxImageList_.Create(16, 16, ILC_COLOR32 | ILC_MASK | rtlStyle, 0, 6);
if (showServerIcons_) {
DWORD rtlStyle = ServiceLocator::instance()->translator()->isRTL() ? ILC_MIRROR | ILC_PERITEMMIRROR : 0;
comboBoxImageList_.Create(16, 16, ILC_COLOR32 | ILC_MASK | rtlStyle, 0, 6);
}

CMyEngineList* myEngineList = ServiceLocator::instance()->myEngineList();
if (showEmptyItem_) {
Expand Down Expand Up @@ -433,10 +436,13 @@ void CServerSelectorControl::updateServerList()
if ( !ue->hasType(CUploadEngineData::TypeUrlShorteningServer) && (currentLoopMask & smUrlShorteners) ) {
continue;
}
HICON hImageIcon = myEngineList->getIconForServer(ue->Name);
int nImageIndex = -1;
if ( hImageIcon ) {
nImageIndex = comboBoxImageList_.AddIcon( hImageIcon);
if (showServerIcons_) {
HICON hImageIcon = myEngineList->getIconForServer(ue->Name);

if (hImageIcon) {
nImageIndex = comboBoxImageList_.AddIcon(hImageIcon);
}
}
char *serverName = new char[ue->Name.length() + 1];
lstrcpyA( serverName, ue->Name.c_str() );
Expand All @@ -457,7 +463,9 @@ void CServerSelectorControl::updateServerList()
serverComboBox_.AddItem(TR("Add local folder..."), -1, -1, 1, reinterpret_cast<LPARAM>(kAddDirectoryAsServer));
}

serverComboBox_.SetImageList( comboBoxImageList_ );
if (showServerIcons_) {
serverComboBox_.SetImageList(comboBoxImageList_);
}
serverComboBox_.SetCurSel( selectedIndex );
serverChanged();
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Gui/Controls/ServerSelectorControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CServerSelectorControl :
public CDialogIndirectImpl<CServerSelectorControl>
{
public:
explicit CServerSelectorControl(UploadEngineManager* uploadEngineManager, bool defaultServer = false, bool isChildWindow = true);
explicit CServerSelectorControl(UploadEngineManager* uploadEngineManager, bool defaultServer = false, bool isChildWindow = true, bool showServerIcons = true);
virtual ~CServerSelectorControl();
enum { IDD = IDD_SERVERSELECTORCONTROL, IDC_LOGINMENUITEM = 4020, IDC_USERNAME_FIRST_ID = 20000, IDC_USERNAME_LAST_ID = 21000,
IDC_ADD_ACCOUNT= 21001, IDC_NO_ACCOUNT = 21003
Expand Down Expand Up @@ -134,6 +134,7 @@ virtual ~CServerSelectorControl();
HGLOBAL hMyDlgTemplate_;
std::function<void(CServerSelectorControl*)> onChangeCallback_;
bool showEmptyItem_;
bool showServerIcons_;
};

#endif
Expand Down
8 changes: 8 additions & 0 deletions Source/Gui/Dialogs/HotkeySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ LRESULT CHotkeySettingsPage::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lPar
{
ClientPoint.x = 0;
ClientPoint.y = 0;

int nCurItem = m_HotkeyList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
if (nCurItem >= 0) {
CRect rc;
if (m_HotkeyList.GetItemRect(nCurItem, &rc, LVIR_BOUNDS)) {
ClientPoint = rc.CenterPoint();
}
}
ScreenPoint = ClientPoint;
::ClientToScreen(hwnd, &ScreenPoint);
}
Expand Down
92 changes: 66 additions & 26 deletions Source/Gui/Dialogs/ServerFolderSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,49 +230,67 @@ LRESULT CServerFolderSelect::OnFolderlistLbnDblclk(int idCtrl, LPNMHDR pnmh, BOO

LRESULT CServerFolderSelect::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CMenu sub;
MENUITEMINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;
sub.CreatePopupMenu();

POINT ClientPoint, ScreenPoint;
POINT screenPoint{};
HWND hwnd = reinterpret_cast<HWND>(wParam);
if (hwnd != m_FolderTree.m_hWnd)
if (hwnd != m_FolderTree.m_hWnd) {
return 0;

if (lParam == -1)
{
ClientPoint.x = 0;
ClientPoint.y = 0;
ScreenPoint = ClientPoint;
::ClientToScreen(hwnd, &ScreenPoint);
}
else
{
ScreenPoint.x = GET_X_LPARAM(lParam);
ScreenPoint.y = GET_Y_LPARAM(lParam);
ClientPoint = ScreenPoint;
::ScreenToClient(hwnd, &ClientPoint);

HTREEITEM selectedItem{};
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);

if (xPos == -1 && yPos == -1) {
// If the context menu is generated from the keyboard, the application should display
// the context menu at the location of the current selection rather than at (xPos, yPos).
CRect rc;
HTREEITEM firstSelectedItem = m_FolderTree.GetNextSelectedItem(nullptr);
if (firstSelectedItem) {
if (m_FolderTree.GetItemRect(firstSelectedItem, &rc, FALSE) ) {
m_FolderTree.MapWindowPoints(nullptr, &rc);
screenPoint = { rc.left, rc.bottom };
selectedItem = firstSelectedItem;
}
}
} else {
screenPoint.x = xPos;
screenPoint.y = yPos;
POINT clientPoint = screenPoint;
::ScreenToClient(hwnd, &clientPoint);

UINT flags{};
HTREEITEM testItem = m_FolderTree.HitTest(clientPoint, &flags);
if (testItem && flags & TVHT_ONITEM) {
selectedItem = testItem;
}
}

UINT flags;
HTREEITEM selectedItem = m_FolderTree.HitTest(ClientPoint, &flags);
if (!selectedItem)
if (!selectedItem) {
return 0;
}

m_FolderTree.SelectItem(selectedItem);

int nIndex = m_FolderTree.GetItemData(selectedItem);
bool showViewInBrowserItem = false;
BOOL copyFolderIdFlag = MFS_DISABLED;
if (nIndex >= 0 && nIndex < m_FolderList.GetCount()) {
const CFolderItem& folder = m_FolderList[nIndex];
if (!folder.getViewUrl().empty()) {
showViewInBrowserItem = true;
}
if (!folder.getId().empty() && folder.getId() != CFolderItem::NewFolderMark) {
copyFolderIdFlag = MFS_ENABLED;
}
}

CMenu sub;
MENUITEMINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;
sub.CreatePopupMenu();

mi.wID = ID_EDITFOLDER;
CString editStr = TR("Edit");
mi.dwTypeData = const_cast<LPWSTR>(editStr.GetString());
Expand All @@ -290,7 +308,9 @@ LRESULT CServerFolderSelect::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lPar
mi.dwTypeData = const_cast<LPWSTR>(createNestedFolderStr.GetString());
sub.InsertMenuItem(2, true, &mi);

sub.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, ScreenPoint.x, ScreenPoint.y, m_hWnd);
sub.AppendMenu(MFT_STRING | copyFolderIdFlag, ID_COPYFOLDERID, TR("Copy folder's ID"));

sub.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, screenPoint.x, screenPoint.y, m_hWnd);
return 0;
}

Expand Down Expand Up @@ -356,6 +376,26 @@ LRESULT CServerFolderSelect::OnOpenInBrowser(WORD wNotifyCode, WORD wID, HWND hW
return 0;
}

LRESULT CServerFolderSelect::OnCopyFolderId(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
HTREEITEM item = m_FolderTree.GetSelectedItem();

if (!item)
return 0;
int nIndex = m_FolderTree.GetItemData(item);

if (nIndex <0 || nIndex >= m_FolderList.GetCount()) {
return 0;
}
CFolderItem& folder = m_FolderList[nIndex];

if (!folder.getId().empty() && folder.getId() != CFolderItem::NewFolderMark) {
CString str = U2W(folder.getId());

WinUtils::CopyTextToClipboard(str);
}
return 0;
}

LRESULT CServerFolderSelect::OnCreateNestedFolder(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
HTREEITEM item = m_FolderTree.GetSelectedItem();
Expand Down
5 changes: 4 additions & 1 deletion Source/Gui/Dialogs/ServerFolderSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define ID_EDITFOLDER 10001
#define ID_OPENINBROWSER 10002
#define ID_CREATENESTEDFOLDER 10003
#define ID_COPYFOLDERID 10004

class UploadEngineManager;
class ServerProfile;
Expand All @@ -62,6 +63,7 @@ class CServerFolderSelect :
COMMAND_HANDLER(ID_CREATENESTEDFOLDER, BN_CLICKED, OnCreateNestedFolder)
COMMAND_HANDLER(IDC_NEWFOLDERBUTTON, BN_CLICKED, OnBnClickedNewfolderbutton)
COMMAND_ID_HANDLER(ID_EDITFOLDER, OnEditFolder)
COMMAND_HANDLER(ID_COPYFOLDERID, BN_CLICKED, OnCopyFolderId)
NOTIFY_HANDLER(IDC_FOLDERTREE, NM_DBLCLK, OnFolderlistLbnDblclk)
CHAIN_MSG_MAP(CDialogResize<CServerFolderSelect>)
END_MSG_MAP()
Expand All @@ -88,6 +90,7 @@ class CServerFolderSelect :
LRESULT OnBnClickedNewfolderbutton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEditFolder(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnCopyFolderId(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

void onTaskFinished(UploadTask* task, bool success);
void OnLoadFinished();
Expand Down Expand Up @@ -120,4 +123,4 @@ class CServerFolderSelect :
void BuildFolderTree(std::vector<CFolderItem> &list,const CString& parentFolderId);
};

#endif // SERVERFOLDERSELECT_H
#endif // SERVERFOLDERSELECT_H
31 changes: 22 additions & 9 deletions Source/Gui/Dialogs/UploadSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,16 +944,17 @@ void CUploadSettings::OnFolderButtonContextMenu(POINT pt, bool isImageServerTool
ServerProfile & serverProfile = isImageServerToolbar ? getSessionImageServerItem() : getSessionFileServerItem();

CMenu sub;
MENUITEMINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;

sub.CreatePopupMenu();
mi.wID = IDC_NEWFOLDER + static_cast<int>(isImageServerToolbar);
CString newFolderStr = TR("New folder");
mi.dwTypeData = const_cast<LPWSTR>(newFolderStr.GetString());
sub.InsertMenuItem(0, true, &mi);

sub.AppendMenu(MFT_STRING, IDC_NEWFOLDER + static_cast<int>(isImageServerToolbar), TR("New folder"));

if (!serverProfile.folderId().empty()) {
UINT flags = MFT_STRING;
if (serverProfile.folderId().empty() || serverProfile.folderId() == CFolderItem::NewFolderMark) {
flags |= MFS_DISABLED;
}
sub.AppendMenu(flags, IDC_COPYFOLDERID + static_cast<int>(isImageServerToolbar), TR("Copy folder's ID"));
}

if (!serverProfile.folderUrl().empty()) {
sub.AppendMenu(MFT_STRING, IDC_OPENINBROWSER + static_cast<int>(isImageServerToolbar), TR("Open in Web Browser"));
Expand Down Expand Up @@ -1009,6 +1010,18 @@ LRESULT CUploadSettings::OnOpenInBrowser(WORD /*wNotifyCode*/, WORD wID, HWND /*
}
return 0;
}

LRESULT CUploadSettings::OnCopyFolderId(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
bool ImageServer = (wID % 2) != 0;
ServerProfile& serverProfile = ImageServer ? getSessionImageServerItem() : getSessionFileServerItem();
std::string folderId = serverProfile.folderId();
if (!folderId.empty() && folderId != CFolderItem::NewFolderMark) {
CString str = U2W(folderId);

WinUtils::CopyTextToClipboard(str);
}
return 0;
}

void CUploadSettings::OnServerButtonContextMenu(POINT pt, bool isImageServerToolbar)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/Gui/Dialogs/UploadSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ constexpr unsigned int IDC_OPENINBROWSER = 4014;
constexpr unsigned int IDC_SERVERPARAMS = 4016;
constexpr unsigned int IDC_OPENREGISTERURL = 4018;
constexpr unsigned int IDC_LOGINTOOLBUTTON = 4020;
constexpr unsigned int IDC_COPYFOLDERID = 4022;

constexpr unsigned int IDC_TOOLBARSEPARATOR1 = 4002;
constexpr unsigned int IDC_TOOLBARSEPARATOR2 = 4003;
Expand Down Expand Up @@ -95,6 +96,9 @@ class CUploadSettings:
COMMAND_HANDLER(IDC_NEWFOLDER+1, BN_CLICKED, OnNewFolder)
COMMAND_HANDLER(IDC_OPENINBROWSER, BN_CLICKED, OnOpenInBrowser)
COMMAND_HANDLER(IDC_OPENINBROWSER+1, BN_CLICKED, OnOpenInBrowser)
COMMAND_HANDLER(IDC_COPYFOLDERID, BN_CLICKED, OnCopyFolderId)
COMMAND_HANDLER(IDC_COPYFOLDERID + 1, BN_CLICKED, OnCopyFolderId)

COMMAND_HANDLER(IDC_OPENREGISTERURL, BN_CLICKED, OnOpenSignupPage)
COMMAND_HANDLER(IDC_OPENREGISTERURL+1, BN_CLICKED, OnOpenSignupPage)
COMMAND_HANDLER(IDC_SERVERPARAMS, BN_CLICKED, OnServerParamsClicked)
Expand Down Expand Up @@ -149,6 +153,7 @@ class CUploadSettings:
LRESULT OnFileServerSelect(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnNewFolder(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnOpenInBrowser(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnCopyFolderId(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnServerParamsClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnServerDropDown(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
LRESULT OnOpenSignupPage(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
Expand Down
31 changes: 28 additions & 3 deletions Source/Gui/Dialogs/WizardDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,9 +1740,34 @@ LRESULT CWizardDlg::OnEnable(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/

void CWizardDlg::CloseWizard()
{
if(CurPage!= wpWelcomePage && CurPage!= wpUploadPage && Settings.ConfirmOnExit)
if(LocalizedMessageBox(TR("Are you sure to quit?"),APPNAME, MB_YESNO|MB_ICONQUESTION) != IDYES) return ;

if(CurPage!= wpWelcomePage && CurPage!= wpUploadPage && Settings.ConfirmOnExit) {
int buttonPressed{};
CTaskDialog dlg;
CString verText = TR("Do not ask again");
dlg.SetVerificationText(verText);
CString contentText = TR("Are you sure to quit?");
dlg.SetContentText(contentText);
CString windowTitle = APPNAME;
dlg.SetWindowTitle(windowTitle);
dlg.SetCommonButtons(TDCBF_YES_BUTTON | TDCBF_NO_BUTTON);
// From the official Win32 style guide: don't use the question mark icon to ask questions. Don't routinely replace
// question mark icons with warning icons. Replace a question mark icon with a warning icon only if the question
// has significant consequences. Otherwise, use no icon.
//dlg.SetMainIcon(TD_WARNING_ICON);
DWORD flags = TDF_POSITION_RELATIVE_TO_WINDOW | TDF_ALLOW_DIALOG_CANCELLATION;
if (ServiceLocator::instance()->translator()->isRTL()) {
flags |= TDF_RTL_LAYOUT;
}
dlg.ModifyFlags(0, flags);
BOOL verificationFlagChecked = FALSE;
int res = dlg.DoModal(m_hWnd, &buttonPressed, nullptr, &verificationFlagChecked);
if (verificationFlagChecked) {
Settings.ConfirmOnExit = false;
}
if (SUCCEEDED(res) && buttonPressed != IDYES) {
return;
}
}
CloseDialog(0);
}

Expand Down
3 changes: 2 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- Convert korean.lng and farsi.lng ?
- Proxy provided by DefaultProxyProvider not being changed on redirects
- Fix log window buttons moving when RTL is on
- Fix function names in docs (CSelection etc.)
- Fix function names in docs (CSelection etc.)
- File name conflict when uploading to Yandex.disk

0 comments on commit afcb1ab

Please sign in to comment.