OSDN Git Service

a92d4ef5c7a76477d1dfde638cac5dea87033b55
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / SendMailDlg.cpp
1 // SendMailDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "SendMailDlg.h"\r
7 #include "MessageBox.h"\r
8 #include "commonresource.h"\r
9 #include "AppUtils.h"\r
10 // CSendMailDlg dialog\r
11 \r
12 IMPLEMENT_DYNAMIC(CSendMailDlg, CResizableStandAloneDialog)\r
13 \r
14 CSendMailDlg::CSendMailDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CSendMailDlg::IDD, pParent)\r
16         , m_To(_T(""))\r
17         , m_CC(_T(""))\r
18         , m_Subject(_T(""))\r
19         , m_bAttachment(FALSE)\r
20         , m_bCombine(FALSE)\r
21 {\r
22 \r
23 }\r
24 \r
25 CSendMailDlg::~CSendMailDlg()\r
26 {\r
27 }\r
28 \r
29 void CSendMailDlg::DoDataExchange(CDataExchange* pDX)\r
30 {\r
31         CDialog::DoDataExchange(pDX);\r
32         DDX_Text(pDX, IDC_SENDMAIL_TO, m_To);\r
33         DDX_Text(pDX, IDC_SENDMAIL_CC, m_CC);\r
34         DDX_Check(pDX, IDC_SENDMAIL_ATTACHMENT, m_bAttachment);\r
35         DDX_Check(pDX, IDC_SENDMAIL_COMBINE, m_bCombine);\r
36         DDX_Control(pDX, IDC_SENDMAIL_PATCHS, m_ctrlList);\r
37         DDX_Control(pDX,IDC_SENDMAIL_SETUP, this->m_SmtpSetup);\r
38         DDX_Control(pDX,IDC_SENDMAIL_TO,m_ctrlTO);\r
39         DDX_Control(pDX,IDC_SENDMAIL_CC,m_ctrlCC);\r
40 }\r
41 \r
42 \r
43 BEGIN_MESSAGE_MAP(CSendMailDlg, CResizableStandAloneDialog)\r
44         ON_BN_CLICKED(IDC_SENDMAIL_COMBINE, &CSendMailDlg::OnBnClickedSendmailCombine)\r
45         ON_BN_CLICKED(IDOK, &CSendMailDlg::OnBnClickedOk)\r
46         ON_NOTIFY(LVN_ITEMCHANGED, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnLvnItemchangedSendmailPatchs)\r
47         ON_NOTIFY(NM_DBLCLK, IDC_SENDMAIL_PATCHS, &CSendMailDlg::OnNMDblclkSendmailPatchs)\r
48         ON_EN_CHANGE(IDC_SENDMAIL_SUBJECT, &CSendMailDlg::OnEnChangeSendmailSubject)\r
49 END_MESSAGE_MAP()\r
50 \r
51 \r
52 // CSendMailDlg message handlers\r
53 \r
54 BOOL CSendMailDlg::OnInitDialog()\r
55 {\r
56         CResizableStandAloneDialog::OnInitDialog();\r
57 \r
58         AddAnchor(IDC_SENDMAIL_GROUP,TOP_LEFT,TOP_RIGHT);\r
59         AddAnchor(IDC_SENDMAIL_TO,TOP_LEFT,TOP_RIGHT);\r
60         AddAnchor(IDC_SENDMAIL_CC,TOP_LEFT,TOP_RIGHT);\r
61         AddAnchor(IDC_SENDMAIL_SUBJECT,TOP_LEFT,TOP_RIGHT);\r
62         AddAnchor(IDC_SENDMAIL_SETUP,TOP_RIGHT);\r
63 \r
64         AddAnchor(IDC_SENDMAIL_PATCHS,TOP_LEFT,BOTTOM_RIGHT);\r
65         AddAnchor(IDOK,BOTTOM_RIGHT);\r
66         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
67 \r
68         this->AddOthersToAnchor();\r
69         EnableSaveRestore(_T("SendMailDlg"));\r
70 \r
71         m_ctrlCC.Init();\r
72         m_ctrlTO.Init();\r
73 \r
74         m_ctrlCC.SetSeparator(_T(";"));\r
75         m_ctrlTO.SetSeparator(_T(";"));\r
76 \r
77         m_AddressReg.SetMaxHistoryItems(0xFFFF);\r
78 \r
79         m_AddressReg.Load(_T("Software\\TortoiseGit\\TortoiseProc\\EmailAddress\\"),_T("email"));\r
80         for(int i=0;i<m_AddressReg.GetCount();i++)\r
81         {\r
82                 m_ctrlCC.AddSearchString(m_AddressReg.GetEntry(i));\r
83                 m_ctrlTO.AddSearchString(m_AddressReg.GetEntry(i));\r
84         }\r
85 \r
86         m_ctrlList.SetExtendedStyle( m_ctrlList.GetExtendedStyle()| LVS_EX_CHECKBOXES );\r
87 \r
88         for(int i=0;i<m_PathList.GetCount();i++)\r
89         {\r
90                 m_ctrlList.InsertItem(i,m_PathList[i].GetWinPathString());\r
91                 m_ctrlList.SetCheck(i,true);\r
92         }\r
93         \r
94 //      m_ctrlCC.AddSearchString(_T("Tortoisegit-dev@google.com"));\r
95 //      m_ctrlTO.AddSearchString(_T("Tortoisegit-dev@google.com"));\r
96         this->UpdateData(FALSE);\r
97         OnBnClickedSendmailCombine();\r
98         return TRUE;\r
99 }\r
100 void CSendMailDlg::OnBnClickedSendmailCombine()\r
101 {\r
102         // TODO: Add your control notification handler code here\r
103         this->UpdateData();\r
104         this->GetDlgItem(IDC_SENDMAIL_SUBJECT)->EnableWindow(this->m_bCombine);\r
105         if(m_bCombine)\r
106                 GetDlgItem(IDC_SENDMAIL_SUBJECT)->SetWindowText(this->m_Subject);\r
107 }\r
108 \r
109 void CSendMailDlg::OnBnClickedOk()\r
110 {\r
111         \r
112         this->UpdateData();\r
113         if(this->m_To.IsEmpty() && this->m_CC.IsEmpty())\r
114         {\r
115                 CMessageBox::Show(NULL,IDS_ERR_ADDRESS_NO_EMPTY,IDS_APPNAME,MB_OK|MB_ICONERROR);\r
116                 return;\r
117         }\r
118         int start =0;\r
119         CString Address;\r
120         while(start>=0)\r
121         {\r
122                 Address=this->m_CC.Tokenize(_T(";"),start);\r
123                 m_AddressReg.AddEntry(Address);\r
124                 m_AddressReg.Save();\r
125         }\r
126         start =0;\r
127         while(start>=0)\r
128         {\r
129                 Address=this->m_To.Tokenize(_T(";"),start);\r
130                 m_AddressReg.AddEntry(Address);\r
131                 m_AddressReg.Save();\r
132         }       \r
133         \r
134         OnOK();\r
135         // TODO: Add your control notification handler code here\r
136 }\r
137 \r
138 void CSendMailDlg::OnLvnItemchangedSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)\r
139 {\r
140         LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);\r
141         // TODO: Add your control notification handler code here\r
142         \r
143         *pResult = 0;\r
144 }\r
145 \r
146 void CSendMailDlg::OnNMDblclkSendmailPatchs(NMHDR *pNMHDR, LRESULT *pResult)\r
147 {\r
148         LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);\r
149         // TODO: Add your control notification handler code here\r
150         CString path=this->m_ctrlList.GetItemText(pNMItemActivate->iItem,0);\r
151         CTGitPath gitpath;\r
152         gitpath.SetFromWin(path);\r
153         \r
154         CAppUtils::StartUnifiedDiffViewer(path,gitpath.GetFilename());\r
155 \r
156         *pResult = 0;\r
157 }\r
158 \r
159 void CSendMailDlg::OnEnChangeSendmailSubject()\r
160 {\r
161         // TODO:  If this is a RICHEDIT control, the control will not\r
162         // send this notification unless you override the CResizableStandAloneDialog::OnInitDialog()\r
163         // function and call CRichEditCtrl().SetEventMask()\r
164         // with the ENM_CHANGE flag ORed into the mask.\r
165 \r
166         // TODO:  Add your control notification handler code here\r
167         GetDlgItem(IDC_SENDMAIL_SUBJECT)->GetWindowText(this->m_Subject);\r
168 }\r