1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2016 - 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 // RefLogDlg.cpp : implementation file
24 #include "RefLogDlg.h"
27 #include "MessageBox.h"
28 #include "UnicodeUtils.h"
32 IMPLEMENT_DYNAMIC(CRefLogDlg
, CResizableStandAloneDialog
)
34 UINT
CRefLogDlg::m_FindDialogMessage
= ::RegisterWindowMessage(FINDMSGSTRING
);
36 CRefLogDlg::CRefLogDlg(CWnd
* pParent
/*=nullptr*/)
37 : CResizableStandAloneDialog(CRefLogDlg::IDD
, pParent
)
38 , m_pFindDialog(nullptr)
43 CRefLogDlg::~CRefLogDlg()
47 void CRefLogDlg::DoDataExchange(CDataExchange
* pDX
)
49 CDialog::DoDataExchange(pDX
);
50 DDX_Control(pDX
, IDC_COMBOBOXEX_REF
, m_ChooseRef
);
51 DDX_Control(pDX
, IDC_REFLOG_LIST
, m_RefList
);
55 BEGIN_MESSAGE_MAP(CRefLogDlg
, CResizableStandAloneDialog
)
56 ON_BN_CLICKED(IDOK
, &CRefLogDlg::OnBnClickedOk
)
57 ON_BN_CLICKED(IDC_REFLOG_BUTTONCLEARSTASH
, &CRefLogDlg::OnBnClickedClearStash
)
58 ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REF
, &CRefLogDlg::OnCbnSelchangeRef
)
59 ON_MESSAGE(MSG_REFLOG_CHANGED
,OnRefLogChanged
)
60 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
63 LRESULT
CRefLogDlg::OnRefLogChanged(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
65 m_RefList
.m_RevCache
.clear();
70 BOOL
CRefLogDlg::OnInitDialog()
72 CResizableStandAloneDialog::OnInitDialog();
73 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
75 AddAnchor(IDOK
,BOTTOM_RIGHT
);
76 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
77 AddAnchor(IDC_REFLOG_BUTTONCLEARSTASH
, BOTTOM_LEFT
);
78 AddAnchor(IDC_REFLOG_LIST
,TOP_LEFT
,BOTTOM_RIGHT
);
79 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
80 AddAnchor(IDC_COMBOBOXEX_REF
, TOP_LEFT
, TOP_RIGHT
);
83 this->EnableSaveRestore(_T("RefLogDlg"));
86 GetWindowText(sWindowTitle
);
87 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
89 m_ChooseRef
.SetMaxHistoryItems(0x7FFFFFFF);
91 m_RefList
.m_hasWC
= !GitAdminDir::IsBareRepo(g_Git
.m_CurrentDir
);
93 this->m_RefList
.InsertRefLogColumn();
99 // CRefLogDlg message handlers
101 void CRefLogDlg::OnBnClickedOk()
103 if (m_RefList
.GetSelectedCount() == 1)
105 // get the selected row
106 POSITION pos
= m_RefList
.GetFirstSelectedItemPosition();
107 size_t selIndex
= m_RefList
.GetNextSelectedItem(pos
);
108 if (selIndex
< m_RefList
.m_arShownList
.size())
110 // all ok, pick up the revision
111 GitRev
* pLogEntry
= m_RefList
.m_arShownList
.SafeGetAt(selIndex
);
113 m_SelectedHash
= pLogEntry
->m_CommitHash
;
119 void CRefLogDlg::OnBnClickedClearStash()
121 size_t count
= m_RefList
.m_arShownList
.size();
123 msg
.Format(IDS_PROC_DELETEALLSTASH
, count
);
124 if (CMessageBox::Show(this->GetSafeHwnd(), msg
, _T("TortoiseGit"), 2, IDI_QUESTION
, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
127 if (g_Git
.Run(_T("git.exe stash clear"), &cmdOut
, CP_UTF8
))
129 MessageBox(cmdOut
, _T("TortoiseGit"), MB_ICONERROR
);
133 m_RefList
.m_RevCache
.clear();
139 void CRefLogDlg::OnCbnSelchangeRef()
141 CString ref
=m_ChooseRef
.GetString();
142 m_RefList
.ClearText();
144 m_RefList
.SetRedraw(false);
147 if (GitRevLoglist::GetRefLog(ref
, m_RefList
.m_RevCache
, err
))
148 MessageBox(_T("Error while loading reflog.\n") + err
, _T("TortoiseGit"), MB_ICONERROR
);
150 m_RefList
.SetItemCountEx((int)m_RefList
.m_RevCache
.size());
152 this->m_RefList
.m_arShownList
.clear();
154 for (unsigned int i
= 0; i
< m_RefList
.m_RevCache
.size(); ++i
)
156 GitRevLoglist
* rev
= &m_RefList
.m_RevCache
[i
];
157 rev
->m_IsFull
= TRUE
;
158 this->m_RefList
.m_arShownList
.SafeAdd(rev
);
161 m_RefList
.SetRedraw(true);
163 m_RefList
.Invalidate();
165 if (ref
== _T("refs/stash"))
167 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->ShowWindow(SW_SHOW
);
168 BOOL enabled
= !m_RefList
.m_arShownList
.empty();
169 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->EnableWindow(enabled
);
171 GetDlgItem(IDOK
)->SetFocus();
174 GetDlgItem(IDC_REFLOG_BUTTONCLEARSTASH
)->ShowWindow(SW_HIDE
);
177 BOOL
CRefLogDlg::PreTranslateMessage(MSG
* pMsg
)
179 if (pMsg
->message
== WM_KEYDOWN
&& pMsg
->wParam
== VK_F5
)
181 else if (pMsg
->message
== WM_KEYDOWN
&& (pMsg
->wParam
== VK_F3
|| (pMsg
->wParam
== 'F' && (GetAsyncKeyState(VK_CONTROL
) & 0x8000))))
184 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
187 void CRefLogDlg::Refresh()
190 list
.push_back(_T("HEAD"));
191 if (g_Git
.GetRefList(list
))
192 MessageBox(g_Git
.GetGitLastErr(_T("Could not get all refs.")), _T("TortoiseGit"), MB_ICONERROR
);
194 m_ChooseRef
.SetList(list
);
196 if (m_CurrentBranch
.IsEmpty())
198 m_CurrentBranch
.Format(_T("refs/heads/%s"), (LPCTSTR
)g_Git
.GetCurrentBranch());
199 m_ChooseRef
.SetCurSel(0); /* Choose HEAD */
204 for (int i
= 0; i
< (int)list
.size(); ++i
)
206 if(list
[i
] == m_CurrentBranch
)
208 m_ChooseRef
.SetCurSel(i
);
214 m_ChooseRef
.SetCurSel(0);
217 m_RefList
.m_RevCache
.clear();
222 void CRefLogDlg::OnFind()
225 m_pFindDialog
= new CFindReplaceDialog();
226 m_pFindDialog
->Create(TRUE
, _T(""), nullptr, FR_DOWN
| FR_HIDEWHOLEWORD
| FR_HIDEUPDOWN
, this);
229 LRESULT
CRefLogDlg::OnFindDialogMessage(WPARAM
/*wParam*/, LPARAM
/*lParam*/)
231 ASSERT(m_pFindDialog
);
233 if (m_RefList
.m_arShownList
.empty())
236 // If the FR_DIALOGTERM flag is set,
237 // invalidate the handle identifying the dialog box.
238 if (m_pFindDialog
->IsTerminating())
240 m_pFindDialog
= nullptr;
244 // If the FR_FINDNEXT flag is set,
245 // call the application-defined search routine
246 // to search for the requested string.
247 if (m_pFindDialog
->FindNext())
249 //read data from dialog
250 CString findString
= m_pFindDialog
->GetFindString();
253 bool bCaseSensitive
= !!(m_pFindDialog
->m_nFlags
& FR_MATCHCASE
);
256 findString
.MakeLower();
258 size_t i
= m_nSearchLine
;
259 if (i
>= m_RefList
.m_arShownList
.size())
264 GitRevLoglist
* data
= m_RefList
.m_arShownList
.SafeGetAt(i
);
269 str
+= data
->m_RefAction
;
271 str
+= data
->m_CommitHash
.ToString();
273 str
+= data
->GetSubject();
275 str
+= data
->GetBody();
281 if (str
.Find(findString
) >= 0)
285 if(!bFound
&& i
>= m_RefList
.m_arShownList
.size())
287 } while (i
!= m_nSearchLine
&& (!bFound
));
291 m_RefList
.SetHotItem((int)i
- 1);
292 m_RefList
.EnsureVisible((int)i
- 1, FALSE
);
296 MessageBox(_T("\"") + findString
+ _T("\" ") + CString(MAKEINTRESOURCE(IDS_NOTFOUND
)), _T("TortoiseGit"), MB_ICONINFORMATION
);