BrowseRefs: Context menu enhancements
[TortoiseGit.git] / src / TortoiseProc / EditPropertyValueDlg.cpp
blobfb4e03c992cd31436b78db448888949397355baa
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
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 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "SVNProperties.h"
22 #include "UnicodeUtils.h"
23 #include "AppUtils.h"
24 #include "StringUtils.h"
25 #include "EditPropertyValueDlg.h"
28 IMPLEMENT_DYNAMIC(CEditPropertyValueDlg, CResizableStandAloneDialog)
30 CEditPropertyValueDlg::CEditPropertyValueDlg(CWnd* pParent /*=NULL*/)
31 : CResizableStandAloneDialog(CEditPropertyValueDlg::IDD, pParent)
32 , m_sPropValue(_T(""))
33 , m_bRecursive(FALSE)
34 , m_bFolder(false)
35 , m_bMultiple(false)
36 , m_bIsBinary(false)
37 , m_bRevProps(false)
41 CEditPropertyValueDlg::~CEditPropertyValueDlg()
45 void CEditPropertyValueDlg::DoDataExchange(CDataExchange* pDX)
47 CResizableStandAloneDialog::DoDataExchange(pDX);
48 DDX_Control(pDX, IDC_PROPNAMECOMBO, m_PropNames);
49 DDX_Text(pDX, IDC_PROPVALUE, m_sPropValue);
50 DDX_Check(pDX, IDC_PROPRECURSIVE, m_bRecursive);
54 BEGIN_MESSAGE_MAP(CEditPropertyValueDlg, CResizableStandAloneDialog)
55 ON_BN_CLICKED(IDHELP, &CEditPropertyValueDlg::OnBnClickedHelp)
56 ON_CBN_SELCHANGE(IDC_PROPNAMECOMBO, &CEditPropertyValueDlg::CheckRecursive)
57 ON_CBN_EDITCHANGE(IDC_PROPNAMECOMBO, &CEditPropertyValueDlg::CheckRecursive)
58 ON_BN_CLICKED(IDC_LOADPROP, &CEditPropertyValueDlg::OnBnClickedLoadprop)
59 ON_EN_CHANGE(IDC_PROPVALUE, &CEditPropertyValueDlg::OnEnChangePropvalue)
60 END_MESSAGE_MAP()
62 BOOL CEditPropertyValueDlg::OnInitDialog()
64 CResizableStandAloneDialog::OnInitDialog();
65 CString resToken;
66 int curPos = 0;
68 // get the property values for user defined property files
69 m_ProjectProperties.ReadPropsPathList(m_pathList);
71 bool bFound = false;
73 // fill the combobox control with all the
74 // known properties
75 if (!m_bRevProps)
77 m_PropNames.AddString(_T("svn:eol-style"));
78 m_PropNames.AddString(_T("svn:executable"));
79 if ((m_bFolder)||(m_bMultiple))
80 m_PropNames.AddString(_T("svn:externals"));
81 if ((m_bFolder)||(m_bMultiple))
82 m_PropNames.AddString(_T("svn:ignore"));
83 m_PropNames.AddString(_T("svn:keywords"));
84 m_PropNames.AddString(_T("svn:needs-lock"));
85 m_PropNames.AddString(_T("svn:mime-type"));
86 if ((m_bFolder)||(m_bMultiple))
87 m_PropNames.AddString(_T("svn:mergeinfo"));
88 if (!m_ProjectProperties.sFPPath.IsEmpty())
90 resToken = m_ProjectProperties.sFPPath.Tokenize(_T("\n"),curPos);
91 while (resToken != "")
93 m_PropNames.AddString(resToken);
94 resToken = m_ProjectProperties.sFPPath.Tokenize(_T("\n"),curPos);
98 if ((m_bFolder)||(m_bMultiple))
100 m_PropNames.AddString(_T("bugtraq:url"));
101 m_PropNames.AddString(_T("bugtraq:logregex"));
102 m_PropNames.AddString(_T("bugtraq:label"));
103 m_PropNames.AddString(_T("bugtraq:message"));
104 m_PropNames.AddString(_T("bugtraq:number"));
105 m_PropNames.AddString(_T("bugtraq:warnifnoissue"));
106 m_PropNames.AddString(_T("bugtraq:append"));
108 m_PropNames.AddString(_T("tsvn:logtemplate"));
109 m_PropNames.AddString(_T("tsvn:logwidthmarker"));
110 m_PropNames.AddString(_T("tsvn:logminsize"));
111 m_PropNames.AddString(_T("tsvn:lockmsgminsize"));
112 m_PropNames.AddString(_T("tsvn:logfilelistenglish"));
113 m_PropNames.AddString(_T("tsvn:logsummary"));
114 m_PropNames.AddString(_T("tsvn:projectlanguage"));
115 m_PropNames.AddString(_T("tsvn:userfileproperties"));
116 m_PropNames.AddString(_T("tsvn:userdirproperties"));
117 m_PropNames.AddString(_T("tsvn:autoprops"));
119 m_PropNames.AddString(_T("webviewer:revision"));
120 m_PropNames.AddString(_T("webviewer:pathrevision"));
122 if (!m_ProjectProperties.sDPPath.IsEmpty())
124 curPos = 0;
125 resToken = m_ProjectProperties.sDPPath.Tokenize(_T("\n"),curPos);
127 while (resToken != "")
129 m_PropNames.AddString(resToken);
130 resToken = m_ProjectProperties.sDPPath.Tokenize(_T("\n"),curPos);
134 else
135 GetDlgItem(IDC_PROPRECURSIVE)->EnableWindow(FALSE);
137 // select the pre-set property in the combobox
138 for (int i=0; i<m_PropNames.GetCount(); ++i)
140 CString sText;
141 m_PropNames.GetLBText(i, sText);
142 if (m_sPropName.Compare(sText)==0)
144 m_PropNames.SetCurSel(i);
145 bFound = true;
146 break;
150 if (!bFound)
152 m_PropNames.SetWindowText(m_sPropName);
155 GetDlgItem(IDC_PROPNAMECOMBO)->EnableToolTips();
157 m_tooltips.Create(this);
159 UpdateData(FALSE);
160 CheckRecursive();
162 if (!m_sTitle.IsEmpty())
163 SetWindowText(m_sTitle);
165 AdjustControlSize(IDC_PROPRECURSIVE);
167 GetDlgItem(IDC_PROPRECURSIVE)->ShowWindow(m_bRevProps ? SW_HIDE : SW_SHOW);
169 AddAnchor(IDC_PROPNAME, TOP_LEFT, TOP_CENTER);
170 AddAnchor(IDC_PROPNAMECOMBO, TOP_CENTER, TOP_RIGHT);
171 AddAnchor(IDC_PROPVALUEGROUP, TOP_LEFT, BOTTOM_RIGHT);
172 AddAnchor(IDC_PROPVALUE, TOP_LEFT, BOTTOM_RIGHT);
173 AddAnchor(IDC_LOADPROP, BOTTOM_RIGHT);
174 AddAnchor(IDC_PROPRECURSIVE, BOTTOM_LEFT);
175 AddAnchor(IDOK, BOTTOM_RIGHT);
176 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
177 AddAnchor(IDHELP, BOTTOM_RIGHT);
178 EnableSaveRestore(_T("EditPropertyValueDlg"));
179 return TRUE;
182 void CEditPropertyValueDlg::SetPropertyValue(const std::string& sValue)
184 if (SVNProperties::IsBinary(sValue))
186 m_bIsBinary = true;
187 m_sPropValue.LoadString(IDS_EDITPROPS_BINVALUE);
189 else
191 m_bIsBinary = false;
192 m_sPropValue = MultibyteToWide(sValue.c_str()).c_str();
196 void CEditPropertyValueDlg::OnBnClickedHelp()
198 OnHelp();
201 void CEditPropertyValueDlg::OnCancel()
203 m_sPropName.Empty();
204 CDialog::OnCancel();
207 void CEditPropertyValueDlg::OnOK()
209 UpdateData();
210 if (!m_bIsBinary)
212 m_PropValue = WideToMultibyte((LPCTSTR)m_sPropValue);
214 m_PropNames.GetWindowText(m_sPropName);
215 CDialog::OnOK();
218 void CEditPropertyValueDlg::CheckRecursive()
220 // some properties can only be applied to files
221 // if the properties are edited for a folder or
222 // multiple items, then such properties must be
223 // applied recursively.
224 // Here, we check the property the user selected
225 // and check the "recursive" checkbox automatically
226 // if it needs to be set.
227 int idx = m_PropNames.GetCurSel();
228 if (idx >= 0)
230 CString sName;
231 m_PropNames.GetLBText(idx, sName);
232 if ((m_bFolder)||(m_bMultiple))
234 // folder or multiple, now check for file-only props
235 if (sName.Compare(_T("svn:eol-style"))==0)
236 m_bRecursive = TRUE;
237 if (sName.Compare(_T("svn:executable"))==0)
238 m_bRecursive = TRUE;
239 if (sName.Compare(_T("svn:keywords"))==0)
240 m_bRecursive = TRUE;
241 if (sName.Compare(_T("svn:needs-lock"))==0)
242 m_bRecursive = TRUE;
243 if (sName.Compare(_T("svn:mime-type"))==0)
244 m_bRecursive = TRUE;
246 UINT nText = 0;
247 if (sName.Compare(_T("svn:externals"))==0)
248 nText = IDS_PROP_TT_EXTERNALS;
249 if (sName.Compare(_T("svn:executable"))==0)
250 nText = IDS_PROP_TT_EXECUTABLE;
251 if (sName.Compare(_T("svn:needs-lock"))==0)
252 nText = IDS_PROP_TT_NEEDSLOCK;
253 if (sName.Compare(_T("svn:mime-type"))==0)
254 nText = IDS_PROP_TT_MIMETYPE;
255 if (sName.Compare(_T("svn:ignore"))==0)
256 nText = IDS_PROP_TT_IGNORE;
257 if (sName.Compare(_T("svn:keywords"))==0)
258 nText = IDS_PROP_TT_KEYWORDS;
259 if (sName.Compare(_T("svn:eol-style"))==0)
260 nText = IDS_PROP_TT_EOLSTYLE;
261 if (sName.Compare(_T("svn:mergeinfo"))==0)
262 nText = IDS_PROP_TT_MERGEINFO;
264 if (sName.Compare(_T("bugtraq:label"))==0)
265 nText = IDS_PROP_TT_BQLABEL;
266 if (sName.Compare(_T("bugtraq:logregex"))==0)
267 nText = IDS_PROP_TT_BQLOGREGEX;
268 if (sName.Compare(_T("bugtraq:message"))==0)
269 nText = IDS_PROP_TT_BQMESSAGE;
270 if (sName.Compare(_T("bugtraq:number"))==0)
271 nText = IDS_PROP_TT_BQNUMBER;
272 if (sName.Compare(_T("bugtraq:url"))==0)
273 nText = IDS_PROP_TT_BQURL;
274 if (sName.Compare(_T("bugtraq:warnifnoissue"))==0)
275 nText = IDS_PROP_TT_BQWARNNOISSUE;
276 if (sName.Compare(_T("bugtraq:append"))==0)
277 nText = IDS_PROP_TT_BQAPPEND;
279 if (sName.Compare(_T("tsvn:logtemplate"))==0)
280 nText = IDS_PROP_TT_TSVNLOGTEMPLATE;
281 if (sName.Compare(_T("tsvn:logwidthmarker"))==0)
282 nText = IDS_PROP_TT_TSVNLOGWIDTHMARKER;
283 if (sName.Compare(_T("tsvn:logminsize"))==0)
284 nText = IDS_PROP_TT_TSVNLOGMINSIZE;
285 if (sName.Compare(_T("tsvn:lockmsgminsize"))==0)
286 nText = IDS_PROP_TT_TSVNLOCKMSGMINSIZE;
287 if (sName.Compare(_T("tsvn:logfilelistenglish"))==0)
288 nText = IDS_PROP_TT_TSVNLOGFILELISTENGLISH;
289 if (sName.Compare(_T("tsvn:logsummary"))==0)
290 nText = IDS_PROP_TT_TSVNLOGSUMMARY;
291 if (sName.Compare(_T("tsvn:projectlanguage"))==0)
292 nText = IDS_PROP_TT_TSVNPROJECTLANGUAGE;
293 if (sName.Compare(_T("tsvn:userfileproperties"))==0)
294 nText = IDS_PROP_TT_TSVNUSERFILEPROPERTIES;
295 if (sName.Compare(_T("tsvn:userfolderproperties"))==0)
296 nText = IDS_PROP_TT_TSVNUSERFOLDERPROPERTIES;
297 if (sName.Compare(_T("tsvn:autoprops"))==0)
298 nText = IDS_PROP_TT_TSVNAUTOPROPS;
300 if (sName.Compare(_T("webviewer:revision"))==0)
301 nText = IDS_PROP_TT_WEBVIEWERREVISION;
302 if (sName.Compare(_T("webviewer:pathrevision"))==0)
303 nText = IDS_PROP_TT_WEBVIEWERPATHREVISION;
305 if (nText)
307 m_tooltips.AddTool(GetDlgItem(IDC_PROPNAMECOMBO), nText);
308 m_tooltips.AddTool(GetDlgItem(IDC_PROPNAMECOMBO)->GetWindow(GW_CHILD), nText);
309 m_tooltips.AddTool(GetDlgItem(IDC_PROPVALUE), nText);
311 else
313 // if no match is found then remove the tool tip so that the last tooltip is not wrongly shown
314 m_tooltips.DelTool(GetDlgItem(IDC_PROPNAMECOMBO)->GetWindow(GW_CHILD));
319 BOOL CEditPropertyValueDlg::PreTranslateMessage(MSG* pMsg)
321 if (pMsg->message == WM_KEYDOWN)
323 switch (pMsg->wParam)
325 case VK_RETURN:
327 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
329 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
331 PostMessage(WM_COMMAND, IDOK);
335 break;
336 default:
337 break;
341 m_tooltips.RelayEvent(pMsg);
342 return __super::PreTranslateMessage(pMsg);
345 void CEditPropertyValueDlg::OnBnClickedLoadprop()
347 CString openPath;
348 if (!CAppUtils::FileOpenSave(openPath, NULL, IDS_REPOBROWSE_OPEN, IDS_COMMONFILEFILTER, true, m_hWnd))
350 return;
352 // first check the size of the file
353 HANDLE hFile = CreateFile(openPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
354 if (hFile != INVALID_HANDLE_VALUE)
356 DWORD size = GetFileSize(hFile, NULL);
357 FILE * stream;
358 _tfopen_s(&stream, openPath, _T("rbS"));
359 char * buf = new char[size];
360 if (fread(buf, sizeof(char), size, stream)==size)
362 m_PropValue.assign(buf, size);
364 delete [] buf;
365 fclose(stream);
366 // see if the loaded file contents are binary
367 SetPropertyValue(m_PropValue);
368 UpdateData(FALSE);
369 CloseHandle(hFile);
374 void CEditPropertyValueDlg::OnEnChangePropvalue()
376 UpdateData();
377 CString sTemp;
378 sTemp.LoadString(IDS_EDITPROPS_BINVALUE);
379 if ((m_bIsBinary)&&(m_sPropValue.CompareNoCase(sTemp)!=0))
381 m_sPropValue.Empty();
382 m_PropValue.clear();
383 UpdateData(FALSE);
384 m_bIsBinary = false;