Allow to use libgit2 for unified diff
[TortoiseGit.git] / src / TortoiseProc / InputLogDlg.cpp
bloba793246ba334a80305e231aa3cfb925885d7b3eb
1 // TortoiseGit - 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 "InputLogDlg.h"
22 #include "registry.h"
23 #include "HistoryDlg.h"
24 #include "RegHistory.h"
27 // CInputLogDlg dialog
29 IMPLEMENT_DYNAMIC(CInputLogDlg, CResizableStandAloneDialog)
31 CInputLogDlg::CInputLogDlg(CWnd* pParent /*=NULL*/)
32 : CResizableStandAloneDialog(CInputLogDlg::IDD, pParent)
33 , m_pProjectProperties(NULL)
38 CInputLogDlg::~CInputLogDlg()
42 void CInputLogDlg::DoDataExchange(CDataExchange* pDX)
44 CResizableStandAloneDialog::DoDataExchange(pDX);
45 DDX_Control(pDX, IDC_INPUTTEXT, m_cInput);
49 BEGIN_MESSAGE_MAP(CInputLogDlg, CResizableStandAloneDialog)
50 ON_EN_CHANGE(IDC_INPUTTEXT, OnEnChangeLogmessage)
51 ON_BN_CLICKED(IDC_HISTORY, &CInputLogDlg::OnBnClickedHistory)
52 END_MESSAGE_MAP()
55 BOOL CInputLogDlg::OnInitDialog()
57 CResizableStandAloneDialog::OnInitDialog();
59 #ifdef DEBUG
60 if (m_pProjectProperties == NULL)
61 TRACE("InputLogDlg: project properties not set\n");
62 if (m_sActionText.IsEmpty())
63 TRACE("InputLogDlg: action text not set\n");
64 if (m_sUUID.IsEmpty())
65 TRACE("InputLogDlg: repository UUID not set\n");
66 #endif
68 if (m_pProjectProperties)
69 m_cInput.Init(*m_pProjectProperties);
70 else
71 m_cInput.Init();
73 m_cInput.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
75 if (m_pProjectProperties)
77 if (m_pProjectProperties->nLogWidthMarker)
79 m_cInput.Call(SCI_SETWRAPMODE, SC_WRAP_NONE);
80 m_cInput.Call(SCI_SETEDGEMODE, EDGE_LINE);
81 m_cInput.Call(SCI_SETEDGECOLUMN, m_pProjectProperties->nLogWidthMarker);
83 else
85 m_cInput.Call(SCI_SETEDGEMODE, EDGE_NONE);
86 m_cInput.Call(SCI_SETWRAPMODE, SC_WRAP_WORD);
88 m_cInput.SetText(m_pProjectProperties->sLogTemplate);
91 SetDlgItemText(IDC_ACTIONLABEL, m_sActionText);
93 AddAnchor(IDC_ACTIONLABEL, TOP_LEFT, TOP_RIGHT);
94 AddAnchor(IDC_GROUPBOX, TOP_LEFT, BOTTOM_RIGHT);
95 AddAnchor(IDC_HISTORY, TOP_LEFT);
96 AddAnchor(IDC_INPUTTEXT, TOP_LEFT, BOTTOM_RIGHT);
97 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
98 AddAnchor(IDOK, BOTTOM_RIGHT);
99 EnableSaveRestore(_T("InputDlg"));
100 if (hWndExplorer)
101 CenterWindow(CWnd::FromHandle(hWndExplorer));
102 GetDlgItem(IDC_INPUTTEXT)->SetFocus();
103 return FALSE;
106 void CInputLogDlg::OnOK()
108 UpdateData();
109 m_sLogMsg = m_cInput.GetText();
111 CString reg;
112 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_sUUID);
114 CRegHistory history;
115 history.Load(reg, _T("logmsgs"));
116 history.AddEntry(m_sLogMsg);
117 history.Save();
119 CResizableStandAloneDialog::OnOK();
122 BOOL CInputLogDlg::PreTranslateMessage(MSG* pMsg)
124 if (pMsg->message == WM_KEYDOWN)
126 switch (pMsg->wParam)
128 case VK_RETURN:
130 if (GetAsyncKeyState(VK_CONTROL)&0x8000)
132 if ( GetDlgItem(IDOK)->IsWindowEnabled() )
134 PostMessage(WM_COMMAND, IDOK);
138 break;
142 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
145 void CInputLogDlg::OnEnChangeLogmessage()
147 UpdateOKButton();
150 void CInputLogDlg::UpdateOKButton()
152 CString sTemp = m_cInput.GetText();
153 if (((m_pProjectProperties==NULL)||(sTemp.GetLength() >= m_pProjectProperties->nMinLogSize)))
155 DialogEnableWindow(IDOK, TRUE);
157 else
159 DialogEnableWindow(IDOK, FALSE);
163 void CInputLogDlg::OnBnClickedHistory()
165 CString reg;
166 reg.Format(_T("Software\\TortoiseGit\\History\\commit%s"), (LPCTSTR)m_sUUID);
167 CRegHistory history;
168 history.Load(reg, _T("logmsgs"));
169 CHistoryDlg HistoryDlg;
170 HistoryDlg.SetHistory(history);
171 if (HistoryDlg.DoModal()==IDOK)
173 if (HistoryDlg.GetSelectedText().Compare(m_cInput.GetText().Left(HistoryDlg.GetSelectedText().GetLength()))!=0)
175 if ((m_pProjectProperties)&&(m_pProjectProperties->sLogTemplate.Compare(m_cInput.GetText())!=0))
176 m_cInput.InsertText(HistoryDlg.GetSelectedText(), !m_cInput.GetText().IsEmpty());
177 else
178 m_cInput.SetText(HistoryDlg.GetSelectedText());
181 UpdateOKButton();
182 GetDlgItem(IDC_INPUTTEXT)->SetFocus();