source: filezilla/trunk/fuentes/src/interface/defaultfileexistsdlg.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 2.9 KB
Line 
1#include <filezilla.h>
2#include "defaultfileexistsdlg.h"
3
4enum CFileExistsNotification::OverwriteAction CDefaultFileExistsDlg::m_defaults[2] = {CFileExistsNotification::unknown, CFileExistsNotification::unknown};
5
6CDefaultFileExistsDlg::CDefaultFileExistsDlg()
7{
8}
9
10bool CDefaultFileExistsDlg::Load(wxWindow *parent, bool fromQueue)
11{
12        if (!wxDialogEx::Load(parent, _T("ID_DEFAULTFILEEXISTSDLG")))
13                return false;
14
15        if (fromQueue)
16                XRCCTRL(*this, "ID_DESCRIPTION", wxStaticText)->SetLabel(_("Select default file exists action only for the currently selected files in the queue."));
17        else
18                XRCCTRL(*this, "ID_DESCRIPTION", wxStaticText)->SetLabel(_("Select default file exists action if the target file already exists. This selection is valid only for the current session."));
19
20        WrapRecursive(this, 1.8, "DEFAULTFILEEXISTS");
21        GetSizer()->Fit(this);
22        GetSizer()->SetSizeHints(this);
23
24        if (fromQueue)
25                return true;
26
27        SelectDefaults(&m_defaults[0], &m_defaults[1]);
28
29        return true;
30}
31
32void CDefaultFileExistsDlg::SelectDefaults(enum CFileExistsNotification::OverwriteAction* downloadAction, enum CFileExistsNotification::OverwriteAction* uploadAction)
33{
34        if (downloadAction)
35                XRCCTRL(*this, "ID_DOWNLOAD_ACTION", wxChoice)->SetSelection(*downloadAction + 1);
36        if (uploadAction)
37                XRCCTRL(*this, "ID_UPLOAD_ACTION", wxChoice)->SetSelection(*uploadAction + 1);
38}
39
40enum CFileExistsNotification::OverwriteAction CDefaultFileExistsDlg::GetDefault(bool download)
41{
42        return m_defaults[download ? 0 : 1];
43}
44
45bool CDefaultFileExistsDlg::Run(enum CFileExistsNotification::OverwriteAction *downloadAction, enum CFileExistsNotification::OverwriteAction *uploadAction)
46{
47        SelectDefaults(downloadAction, uploadAction);
48
49        // Remove one side of the dialog if not needed
50        if (!downloadAction && uploadAction)
51        {
52                XRCCTRL(*this, "ID_DOWNLOAD_ACTION_DESC", wxWindow)->Hide();
53                XRCCTRL(*this, "ID_DOWNLOAD_ACTION", wxWindow)->Hide();
54        }
55        else if (downloadAction && !uploadAction)
56        {
57                XRCCTRL(*this, "ID_UPLOAD_ACTION_DESC", wxStaticText)->Hide();
58                XRCCTRL(*this, "ID_UPLOAD_ACTION", wxWindow)->Hide();
59        }
60        Layout();
61        GetSizer()->Fit(this);
62
63        if (ShowModal() != wxID_OK)
64                return false;
65
66        if (downloadAction || !uploadAction)
67        {
68                int dl = XRCCTRL(*this, "ID_DOWNLOAD_ACTION", wxChoice)->GetSelection();
69                if (dl >= 0)
70                        dl--;
71                enum CFileExistsNotification::OverwriteAction action = (enum CFileExistsNotification::OverwriteAction)dl;
72
73                if (downloadAction)
74                        *downloadAction = action;
75                else
76                        m_defaults[0] = action;
77        }
78
79        if (!downloadAction || uploadAction)
80        {
81                int ul = XRCCTRL(*this, "ID_UPLOAD_ACTION", wxChoice)->GetSelection();
82                if (ul >= 0)
83                        ul--;
84                enum CFileExistsNotification::OverwriteAction action = (enum CFileExistsNotification::OverwriteAction)ul;
85
86                if (uploadAction)
87                        *uploadAction = action;
88                else
89                        m_defaults[1] = action;
90        }
91
92        return true;
93}
94
95void CDefaultFileExistsDlg::SetDefault(bool download, enum CFileExistsNotification::OverwriteAction action)
96{
97        m_defaults[download ? 0 : 1] = action;
98}
Note: See TracBrowser for help on using the repository browser.