1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // SendMailDlg.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "SendMailDlg.h"
25 #include "MessageBox.h"
27 #include "PatchListCtrl.h"
29 // CSendMailDlg dialog
31 IMPLEMENT_DYNAMIC(CSendMailDlg
, CResizableStandAloneDialog
)
33 CSendMailDlg::CSendMailDlg(CWnd
* pParent
/*=NULL*/)
34 : CResizableStandAloneDialog(CSendMailDlg::IDD
, pParent
)
35 , m_bCustomSubject(FALSE
)
37 , m_regAttach(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Attach"),0)
38 , m_regCombine(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Combine"),0)
40 m_bAttachment
= m_regAttach
;
41 m_bCombine
= m_regCombine
;
42 this->m_ctrlList
.m_ContextMenuMask
&=~ m_ctrlList
.GetMenuMask(CPatchListCtrl::MENU_SENDMAIL
);
45 CSendMailDlg::~CSendMailDlg()
49 void CSendMailDlg::DoDataExchange(CDataExchange
* pDX
)
51 CDialog::DoDataExchange(pDX
);
52 DDX_Text(pDX
, IDC_SENDMAIL_TO
, m_To
);
53 DDX_Text(pDX
, IDC_SENDMAIL_CC
, m_CC
);
54 DDX_Check(pDX
, IDC_SENDMAIL_ATTACHMENT
, m_bAttachment
);
55 DDX_Check(pDX
, IDC_SENDMAIL_COMBINE
, m_bCombine
);
56 DDX_Control(pDX
, IDC_SENDMAIL_PATCHS
, m_ctrlList
);
57 DDX_Control(pDX
,IDC_SENDMAIL_SETUP
, this->m_SmtpSetup
);
58 DDX_Control(pDX
,IDC_SENDMAIL_TO
,m_ctrlTO
);
59 DDX_Control(pDX
,IDC_SENDMAIL_CC
,m_ctrlCC
);
63 BEGIN_MESSAGE_MAP(CSendMailDlg
, CResizableStandAloneDialog
)
64 ON_BN_CLICKED(IDC_SENDMAIL_COMBINE
, &CSendMailDlg::OnBnClickedSendmailCombine
)
65 ON_BN_CLICKED(IDOK
, &CSendMailDlg::OnBnClickedOk
)
66 ON_NOTIFY(LVN_ITEMCHANGED
, IDC_SENDMAIL_PATCHS
, &CSendMailDlg::OnLvnItemchangedSendmailPatchs
)
67 ON_NOTIFY(NM_DBLCLK
, IDC_SENDMAIL_PATCHS
, &CSendMailDlg::OnNMDblclkSendmailPatchs
)
68 ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT
, &CSendMailDlg::OnEnChangeSendmailSubject
)
69 ON_STN_CLICKED(IDC_SENDMAIL_SETUP
, &CSendMailDlg::OnStnClickedSendmailSetup
)
72 // CSendMailDlg message handlers
74 BOOL
CSendMailDlg::OnInitDialog()
76 CResizableStandAloneDialog::OnInitDialog();
77 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
79 AddAnchor(IDC_SENDMAIL_GROUP
,TOP_LEFT
,TOP_RIGHT
);
80 AddAnchor(IDC_SENDMAIL_TO
,TOP_LEFT
,TOP_RIGHT
);
81 AddAnchor(IDC_SENDMAIL_CC
,TOP_LEFT
,TOP_RIGHT
);
82 AddAnchor(IDC_SENDMAIL_SUBJECT
,TOP_LEFT
,TOP_RIGHT
);
83 AddAnchor(IDC_SENDMAIL_SETUP
,TOP_RIGHT
);
85 AddAnchor(IDC_SENDMAIL_PATCHS
,TOP_LEFT
,BOTTOM_RIGHT
);
86 AddAnchor(IDOK
,BOTTOM_RIGHT
);
87 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
88 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
90 this->AddOthersToAnchor();
92 AdjustControlSize(IDC_SENDMAIL_ATTACHMENT
);
93 AdjustControlSize(IDC_SENDMAIL_COMBINE
);
94 AdjustControlSize(IDC_SENDMAIL_SETUP
);
96 EnableSaveRestore(_T("SendMailDlg"));
99 GetWindowText(sWindowTitle
);
100 CAppUtils::SetWindowTitle(m_hWnd
, m_PathList
.GetCommonRoot().GetUIPathString(), sWindowTitle
);
105 m_ctrlCC
.SetSeparator(_T(";"));
106 m_ctrlTO
.SetSeparator(_T(";"));
108 m_AddressReg
.SetMaxHistoryItems(0xFFFF);
110 m_AddressReg
.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));
111 for (size_t i
= 0; i
< m_AddressReg
.GetCount(); ++i
)
113 m_ctrlCC
.AddSearchString(m_AddressReg
.GetEntry(i
));
114 m_ctrlTO
.AddSearchString(m_AddressReg
.GetEntry(i
));
117 m_ctrlList
.SetExtendedStyle( m_ctrlList
.GetExtendedStyle()| LVS_EX_CHECKBOXES
);
119 for (int i
= 0; i
< m_PathList
.GetCount(); ++i
)
121 m_ctrlList
.InsertItem(i
,m_PathList
[i
].GetWinPathString());
122 m_ctrlList
.SetCheck(i
,true);
125 if (m_PathList
.GetCount() == 1)
126 m_ctrlList
.SetItemState(0, LVIS_SELECTED
, LVIS_SELECTED
);
128 this->UpdateData(FALSE
);
129 OnBnClickedSendmailCombine();
131 m_SmtpSetup
.SetURL(CString());
135 void CSendMailDlg::OnBnClickedSendmailCombine()
139 if (m_bCustomSubject
)
142 this->GetDlgItem(IDC_SENDMAIL_SUBJECT
)->EnableWindow(this->m_bCombine
);
144 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(this->m_Subject
);
149 void CSendMailDlg::OnBnClickedOk()
153 if (m_To
.IsEmpty() && m_CC
.IsEmpty() && CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType"), SEND_MAIL_MAPI
) != SEND_MAIL_MAPI
)
155 CMessageBox::Show(NULL
,IDS_ERR_ADDRESS_NO_EMPTY
,IDS_APPNAME
,MB_OK
|MB_ICONERROR
);
162 Address
=this->m_CC
.Tokenize(_T(";"),start
);
163 m_AddressReg
.AddEntry(Address
);
169 Address
=this->m_To
.Tokenize(_T(";"),start
);
170 m_AddressReg
.AddEntry(Address
);
174 this->m_PathList
.Clear();
175 for (int i
= 0; i
< m_ctrlList
.GetItemCount(); ++i
)
178 if(m_ctrlList
.GetCheck(i
))
180 path
.SetFromWin(m_ctrlList
.GetItemText(i
,0));
181 this->m_PathList
.AddPath(path
);
185 m_regAttach
=m_bAttachment
;
186 m_regCombine
=m_bCombine
;
191 void CSendMailDlg::UpdateSubject()
195 if(!this->m_bCombine
)
197 if(m_ctrlList
.GetSelectedCount()==1)
199 POSITION pos
=m_ctrlList
.GetFirstSelectedItemPosition();
200 int index
=m_ctrlList
.GetNextSelectedItem(pos
);
201 if(this->m_MapPatch
.find(index
) == m_MapPatch
.end() )
203 CString pathfile
=m_ctrlList
.GetItemText(index
,0);
204 m_MapPatch
[index
].Parse(pathfile
);
206 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(m_MapPatch
[index
].m_Subject
);
210 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->SetWindowText(_T(""));
215 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR
* /*pNMHDR*/, LRESULT
*pResult
)
217 if (!m_bCustomSubject
)
223 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR
*pNMHDR
, LRESULT
*pResult
)
225 LPNMITEMACTIVATE pNMItemActivate
= reinterpret_cast<LPNMITEMACTIVATE
>(pNMHDR
);
227 CString path
=this->m_ctrlList
.GetItemText(pNMItemActivate
->iItem
,0);
229 gitpath
.SetFromWin(path
);
231 CAppUtils::StartUnifiedDiffViewer(path
,gitpath
.GetFilename());
236 void CSendMailDlg::OnEnChangeSendmailSubject()
239 if (m_bCombine
|| m_bCustomSubject
)
240 GetDlgItem(IDC_SENDMAIL_SUBJECT
)->GetWindowText(this->m_Subject
);
243 void CSendMailDlg::OnStnClickedSendmailSetup()
245 CCommonAppUtils::RunTortoiseGitProc(_T("/command:settings /page:smtp"));