Git Property Page: get latest change in new thread
[TortoiseGit.git] / src / TortoiseProc / SendMailDlg.cpp
blobd02cb792cfed69cb5dffc9e86c9f8340e02011fc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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"
28 #include "MailMsg.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(""))
39 , m_regAttach(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Attach"),0)
40 , m_regCombine(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\Combine"),0)
41 , m_regUseMAPI(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI"),0)
43 m_bAttachment = m_regAttach;
44 m_bCombine = m_regCombine;
45 m_bUseMAPI = m_regUseMAPI;
46 this->m_ctrlList.m_ContextMenuMask &=~ m_ctrlList.GetMenuMask(CPatchListCtrl::MENU_SENDMAIL);
49 CSendMailDlg::~CSendMailDlg()
53 void CSendMailDlg::DoDataExchange(CDataExchange* pDX)
55 CDialog::DoDataExchange(pDX);
56 DDX_Text(pDX, IDC_SENDMAIL_TO, m_To);
57 DDX_Text(pDX, IDC_SENDMAIL_CC, m_CC);
58 DDX_Check(pDX, IDC_SENDMAIL_ATTACHMENT, m_bAttachment);
59 DDX_Check(pDX, IDC_SENDMAIL_COMBINE, m_bCombine);
60 DDX_Check(pDX, IDC_SENDMAIL_MAPI, m_bUseMAPI);
61 DDX_Control(pDX, IDC_SENDMAIL_PATCHS, m_ctrlList);
62 DDX_Control(pDX,IDC_SENDMAIL_SETUP, this->m_SmtpSetup);
63 DDX_Control(pDX,IDC_SENDMAIL_TO,m_ctrlTO);
64 DDX_Control(pDX,IDC_SENDMAIL_CC,m_ctrlCC);
68 BEGIN_MESSAGE_MAP(CSendMailDlg, CResizableStandAloneDialog)
69 ON_BN_CLICKED(IDC_SENDMAIL_COMBINE, &CSendMailDlg::OnBnClickedSendmailCombine)
70 ON_BN_CLICKED(IDOK, &CSendMailDlg::OnBnClickedOk)
71 ON_NOTIFY(LVN_ITEMCHANGED, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnLvnItemchangedSendmailPatchs)
72 ON_NOTIFY(NM_DBLCLK, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnNMDblclkSendmailPatchs)
73 ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT, &CSendMailDlg::OnEnChangeSendmailSubject)
74 ON_BN_CLICKED(IDC_SENDMAIL_MAPI, &CSendMailDlg::OnBnClickedSendmailMapi)
75 END_MESSAGE_MAP()
77 // CSendMailDlg message handlers
79 BOOL CSendMailDlg::PreTranslateMessage(MSG* pMsg)
81 m_ToolTip.RelayEvent(pMsg);
83 return CDialog::PreTranslateMessage(pMsg);
86 BOOL CSendMailDlg::OnInitDialog()
88 CResizableStandAloneDialog::OnInitDialog();
89 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
91 AddAnchor(IDC_SENDMAIL_GROUP,TOP_LEFT,TOP_RIGHT);
92 AddAnchor(IDC_SENDMAIL_TO,TOP_LEFT,TOP_RIGHT);
93 AddAnchor(IDC_SENDMAIL_CC,TOP_LEFT,TOP_RIGHT);
94 AddAnchor(IDC_SENDMAIL_SUBJECT,TOP_LEFT,TOP_RIGHT);
95 AddAnchor(IDC_SENDMAIL_SETUP,TOP_RIGHT);
97 AddAnchor(IDC_SENDMAIL_PATCHS,TOP_LEFT,BOTTOM_RIGHT);
98 AddAnchor(IDOK,BOTTOM_RIGHT);
99 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
100 AddAnchor(IDHELP, BOTTOM_RIGHT);
102 this->AddOthersToAnchor();
104 AdjustControlSize(IDC_SENDMAIL_ATTACHMENT);
105 AdjustControlSize(IDC_SENDMAIL_COMBINE);
106 AdjustControlSize(IDC_SENDMAIL_MAPI);
107 AdjustControlSize(IDC_SENDMAIL_SETUP);
109 EnableSaveRestore(_T("SendMailDlg"));
111 CString sWindowTitle;
112 GetWindowText(sWindowTitle);
113 CAppUtils::SetWindowTitle(m_hWnd, m_PathList.GetCommonRoot().GetUIPathString(), sWindowTitle);
115 CString mailCient;
116 CMailMsg::DetectMailClient(mailCient);
117 if (mailCient.IsEmpty()) {
118 m_bUseMAPI = false;
119 GetDlgItem(IDC_SENDMAIL_MAPI)->EnableWindow(false);
120 GetDlgItem(IDC_SENDMAIL_MAPI)->SendMessage(BM_SETCHECK, BST_UNCHECKED);
123 m_ctrlCC.Init();
124 m_ctrlTO.Init();
126 m_ctrlCC.SetSeparator(_T(";"));
127 m_ctrlTO.SetSeparator(_T(";"));
129 m_AddressReg.SetMaxHistoryItems(0xFFFF);
131 m_AddressReg.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));
132 for(int i=0;i<m_AddressReg.GetCount();i++)
134 m_ctrlCC.AddSearchString(m_AddressReg.GetEntry(i));
135 m_ctrlTO.AddSearchString(m_AddressReg.GetEntry(i));
138 m_ctrlList.SetExtendedStyle( m_ctrlList.GetExtendedStyle()| LVS_EX_CHECKBOXES );
140 for(int i=0;i<m_PathList.GetCount();i++)
142 m_ctrlList.InsertItem(i,m_PathList[i].GetWinPathString());
143 m_ctrlList.SetCheck(i,true);
146 // m_ctrlCC.AddSearchString(_T("Tortoisegit-dev@google.com"));
147 // m_ctrlTO.AddSearchString(_T("Tortoisegit-dev@google.com"));
148 this->UpdateData(FALSE);
149 OnBnClickedSendmailCombine();
151 //Create the ToolTip control
152 if( !m_ToolTip.Create(this))
154 TRACE0("Unable to create the ToolTip!");
156 else
158 m_ToolTip.SetMaxTipWidth(1024*8); // make multiline tooltips possible
159 m_ToolTip.AddTool(GetDlgItem(IDC_SENDMAIL_MAPI), CString(MAKEINTRESOURCE(IDS_PROC_SENDMAIL_WRAPTOOLTIP)));
160 m_ToolTip.Activate(TRUE);
163 return TRUE;
165 void CSendMailDlg::OnBnClickedSendmailCombine()
167 this->UpdateData();
168 this->GetDlgItem(IDC_SENDMAIL_SUBJECT)->EnableWindow(this->m_bCombine);
169 if(m_bCombine)
170 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(this->m_Subject);
172 UpdateSubject();
175 void CSendMailDlg::OnBnClickedOk()
177 this->UpdateData();
179 if(this->m_To.IsEmpty() && this->m_CC.IsEmpty())
181 CMessageBox::Show(NULL,IDS_ERR_ADDRESS_NO_EMPTY,IDS_APPNAME,MB_OK|MB_ICONERROR);
182 return;
184 int start =0;
185 CString Address;
186 while(start>=0)
188 Address=this->m_CC.Tokenize(_T(";"),start);
189 m_AddressReg.AddEntry(Address);
190 m_AddressReg.Save();
192 start =0;
193 while(start>=0)
195 Address=this->m_To.Tokenize(_T(";"),start);
196 m_AddressReg.AddEntry(Address);
197 m_AddressReg.Save();
200 this->m_PathList.Clear();
201 for(int i=0;i<m_ctrlList.GetItemCount();i++)
203 CTGitPath path;
204 if(m_ctrlList.GetCheck(i))
206 path.SetFromWin(m_ctrlList.GetItemText(i,0));
207 this->m_PathList.AddPath(path);
211 m_regAttach=m_bAttachment;
212 m_regCombine=m_bCombine;
213 m_regUseMAPI=m_bUseMAPI;
215 OnOK();
218 void CSendMailDlg::UpdateSubject()
220 this->UpdateData();
222 if(!this->m_bCombine)
224 if(m_ctrlList.GetSelectedCount()==1)
226 POSITION pos=m_ctrlList.GetFirstSelectedItemPosition();
227 int index=m_ctrlList.GetNextSelectedItem(pos);
228 if(this->m_MapPatch.find(index) == m_MapPatch.end() )
230 CString pathfile=m_ctrlList.GetItemText(index,0);
231 m_MapPatch[index].Parser(pathfile);
233 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(m_MapPatch[index].m_Subject);
235 else
237 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(_T(""));
242 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)
244 UNREFERENCED_PARAMETER(pNMHDR);
245 UpdateSubject();
247 *pResult = 0;
250 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)
252 LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
254 CString path=this->m_ctrlList.GetItemText(pNMItemActivate->iItem,0);
255 CTGitPath gitpath;
256 gitpath.SetFromWin(path);
258 CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());
260 *pResult = 0;
263 void CSendMailDlg::OnEnChangeSendmailSubject()
265 this->UpdateData();
266 if(this->m_bCombine)
267 GetDlgItem(IDC_SENDMAIL_SUBJECT)->GetWindowText(this->m_Subject);
270 void CSendMailDlg::OnBnClickedSendmailMapi()
272 this->UpdateData();