Add icon for fetch post action reset
[TortoiseGit.git] / src / TortoiseProc / SendMailDlg.cpp
blobb4661ea56e5bad7137bd98c7435b29d53ab3d9be
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SendMailDlg.h"
25 #include "MessageBox.h"
26 #include "AppUtils.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_To(_T(""))
36 , m_CC(_T(""))
37 , m_Subject(_T(""))
38 , m_bCustomSubject(FALSE)
40 , m_regAttach(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Attach"),0)
41 , m_regCombine(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Combine"),0)
43 m_bAttachment = m_regAttach;
44 m_bCombine = m_regCombine;
45 this->m_ctrlList.m_ContextMenuMask &=~ m_ctrlList.GetMenuMask(CPatchListCtrl::MENU_SENDMAIL);
48 CSendMailDlg::~CSendMailDlg()
52 void CSendMailDlg::DoDataExchange(CDataExchange* pDX)
54 CDialog::DoDataExchange(pDX);
55 DDX_Text(pDX, IDC_SENDMAIL_TO, m_To);
56 DDX_Text(pDX, IDC_SENDMAIL_CC, m_CC);
57 DDX_Check(pDX, IDC_SENDMAIL_ATTACHMENT, m_bAttachment);
58 DDX_Check(pDX, IDC_SENDMAIL_COMBINE, m_bCombine);
59 DDX_Control(pDX, IDC_SENDMAIL_PATCHS, m_ctrlList);
60 DDX_Control(pDX,IDC_SENDMAIL_SETUP, this->m_SmtpSetup);
61 DDX_Control(pDX,IDC_SENDMAIL_TO,m_ctrlTO);
62 DDX_Control(pDX,IDC_SENDMAIL_CC,m_ctrlCC);
66 BEGIN_MESSAGE_MAP(CSendMailDlg, CResizableStandAloneDialog)
67 ON_BN_CLICKED(IDC_SENDMAIL_COMBINE, &CSendMailDlg::OnBnClickedSendmailCombine)
68 ON_BN_CLICKED(IDOK, &CSendMailDlg::OnBnClickedOk)
69 ON_NOTIFY(LVN_ITEMCHANGED, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnLvnItemchangedSendmailPatchs)
70 ON_NOTIFY(NM_DBLCLK, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnNMDblclkSendmailPatchs)
71 ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT, &CSendMailDlg::OnEnChangeSendmailSubject)
72 ON_STN_CLICKED(IDC_SENDMAIL_SETUP, &CSendMailDlg::OnStnClickedSendmailSetup)
73 END_MESSAGE_MAP()
75 // CSendMailDlg message handlers
77 BOOL CSendMailDlg::OnInitDialog()
79 CResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
82 AddAnchor(IDC_SENDMAIL_GROUP,TOP_LEFT,TOP_RIGHT);
83 AddAnchor(IDC_SENDMAIL_TO,TOP_LEFT,TOP_RIGHT);
84 AddAnchor(IDC_SENDMAIL_CC,TOP_LEFT,TOP_RIGHT);
85 AddAnchor(IDC_SENDMAIL_SUBJECT,TOP_LEFT,TOP_RIGHT);
86 AddAnchor(IDC_SENDMAIL_SETUP,TOP_RIGHT);
88 AddAnchor(IDC_SENDMAIL_PATCHS,TOP_LEFT,BOTTOM_RIGHT);
89 AddAnchor(IDOK,BOTTOM_RIGHT);
90 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
91 AddAnchor(IDHELP, BOTTOM_RIGHT);
93 this->AddOthersToAnchor();
95 AdjustControlSize(IDC_SENDMAIL_ATTACHMENT);
96 AdjustControlSize(IDC_SENDMAIL_COMBINE);
97 AdjustControlSize(IDC_SENDMAIL_SETUP);
99 EnableSaveRestore(_T("SendMailDlg"));
101 CString sWindowTitle;
102 GetWindowText(sWindowTitle);
103 CAppUtils::SetWindowTitle(m_hWnd, m_PathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
105 m_ctrlCC.Init();
106 m_ctrlTO.Init();
108 m_ctrlCC.SetSeparator(_T(";"));
109 m_ctrlTO.SetSeparator(_T(";"));
111 m_AddressReg.SetMaxHistoryItems(0xFFFF);
113 m_AddressReg.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));
114 for (size_t i = 0; i < m_AddressReg.GetCount(); ++i)
116 m_ctrlCC.AddSearchString(m_AddressReg.GetEntry(i));
117 m_ctrlTO.AddSearchString(m_AddressReg.GetEntry(i));
120 m_ctrlList.SetExtendedStyle( m_ctrlList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
122 for (int i = 0; i < m_PathList.GetCount(); ++i)
124 m_ctrlList.InsertItem(i,m_PathList[i].GetWinPathString());
125 m_ctrlList.SetCheck(i,true);
128 if (m_PathList.GetCount() == 1)
129 m_ctrlList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
131 this->UpdateData(FALSE);
132 OnBnClickedSendmailCombine();
134 m_SmtpSetup.SetURL(CString());
136 return TRUE;
138 void CSendMailDlg::OnBnClickedSendmailCombine()
140 this->UpdateData();
142 if (m_bCustomSubject)
143 return;
145 this->GetDlgItem(IDC_SENDMAIL_SUBJECT)->EnableWindow(this->m_bCombine);
146 if(m_bCombine)
147 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(this->m_Subject);
149 UpdateSubject();
152 void CSendMailDlg::OnBnClickedOk()
154 this->UpdateData();
156 if(this->m_To.IsEmpty() && this->m_CC.IsEmpty())
158 CMessageBox::Show(NULL,IDS_ERR_ADDRESS_NO_EMPTY,IDS_APPNAME,MB_OK|MB_ICONERROR);
159 return;
161 int start =0;
162 CString Address;
163 while(start>=0)
165 Address=this->m_CC.Tokenize(_T(";"),start);
166 m_AddressReg.AddEntry(Address);
167 m_AddressReg.Save();
169 start =0;
170 while(start>=0)
172 Address=this->m_To.Tokenize(_T(";"),start);
173 m_AddressReg.AddEntry(Address);
174 m_AddressReg.Save();
177 this->m_PathList.Clear();
178 for (int i = 0; i < m_ctrlList.GetItemCount(); ++i)
180 CTGitPath path;
181 if(m_ctrlList.GetCheck(i))
183 path.SetFromWin(m_ctrlList.GetItemText(i,0));
184 this->m_PathList.AddPath(path);
188 m_regAttach=m_bAttachment;
189 m_regCombine=m_bCombine;
191 OnOK();
194 void CSendMailDlg::UpdateSubject()
196 this->UpdateData();
198 if(!this->m_bCombine)
200 if(m_ctrlList.GetSelectedCount()==1)
202 POSITION pos=m_ctrlList.GetFirstSelectedItemPosition();
203 int index=m_ctrlList.GetNextSelectedItem(pos);
204 if(this->m_MapPatch.find(index) == m_MapPatch.end() )
206 CString pathfile=m_ctrlList.GetItemText(index,0);
207 m_MapPatch[index].Parse(pathfile);
209 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(m_MapPatch[index].m_Subject);
211 else
213 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(_T(""));
218 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR * /*pNMHDR*/, LRESULT *pResult)
220 if (!m_bCustomSubject)
221 UpdateSubject();
223 *pResult = 0;
226 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)
228 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
230 CString path=this->m_ctrlList.GetItemText(pNMItemActivate->iItem,0);
231 CTGitPath gitpath;
232 gitpath.SetFromWin(path);
234 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
236 *pResult = 0;
239 void CSendMailDlg::OnEnChangeSendmailSubject()
241 this->UpdateData();
242 if (m_bCombine || m_bCustomSubject)
243 GetDlgItem(IDC_SENDMAIL_SUBJECT)->GetWindowText(this->m_Subject);
246 void CSendMailDlg::OnStnClickedSendmailSetup()
248 CCommonAppUtils::RunTortoiseGitProc(_T("/command:settings /page:smtp"));