| 1 |
#ifndef GITBLAMEDLG_H |
| 2 |
#define GITBLAMEDLG_H |
| 3 |
#include "clEditorEditEventsHandler.h" |
| 4 |
#include "cl_command_event.h" |
| 5 |
#include "gitui.h" |
| 6 |
#include "macros.h" |
| 7 |
#include <map> |
| 8 |
#include <wx/arrstr.h> |
| 9 |
#include <wx/choice.h> |
| 10 |
#include <wx/stc/stc.h> |
| 11 |
|
| 12 |
class IProcess; |
| 13 |
class GitPlugin; |
| 14 |
|
| 15 |
class CommitStore |
| 16 |
{ |
| 17 |
public: |
| 18 |
CommitStore() |
| 19 |
: m_index(-1) |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
void Clear() |
| 24 |
{ |
| 25 |
m_visitedCommits.Clear(); |
| 26 |
m_index = -1; |
| 27 |
m_revlistOutput.Clear(); |
| 28 |
} |
| 29 |
|
| 30 |
void AddCommit(const wxString& commit) |
| 31 |
{ |
| 32 |
wxCHECK_RET(!commit.empty(), "Passed an empty commit"); |
| 33 |
m_index = m_visitedCommits.Index(commit); // See if it's already here |
| 34 |
if(m_index == wxNOT_FOUND) { |
| 35 |
m_index = m_visitedCommits.Add(commit); |
| 36 |
} |
| 37 |
} |
| 38 |
wxString GetPreviousCommit() { return CanGoBack() ? m_visitedCommits.Item(++m_index) : ""; } |
| 39 |
wxString GetNextCommit() { return CanGoForward() ? m_visitedCommits.Item(--m_index) : ""; } |
| 40 |
wxString GetCurrentlyDisplayedCommit() const { return (m_index < 0) ? "" : m_visitedCommits.Item(m_index); } |
| 41 |
void SetCurrentlyDisplayedCommit(const wxString& commit) |
| 42 |
{ |
| 43 |
wxCHECK_RET(!commit.empty(), "Passed an empty commit"); |
| 44 |
m_index = m_visitedCommits.Index(commit); |
| 45 |
wxASSERT(m_index != wxNOT_FOUND); |
| 46 |
} |
| 47 |
wxString GetCommit(size_t n) const { return (n < m_visitedCommits.GetCount()) ? m_visitedCommits.Item(n) : ""; } |
| 48 |
bool CanGoBack() const { return m_index >= 0 && m_index < (int)(m_visitedCommits.GetCount() - 1); } |
| 49 |
bool CanGoForward() const { return m_index > 0; } |
| 50 |
void LoadChoice(wxChoice* choice) const |
| 51 |
{ |
| 52 |
choice->Clear(); |
| 53 |
choice->Append(m_visitedCommits); |
| 54 |
choice->SetSelection(m_index); |
| 55 |
} |
| 56 |
void SetRevlistOutput(const wxArrayString& commits) { m_revlistOutput = commits; } |
| 57 |
const wxArrayString& GetRevlistOutput() const { return m_revlistOutput; } |
| 58 |
wxString GetCommitParent(const wxString& commit) |
| 59 |
{ |
| 60 |
wxString parent; |
| 61 |
for(size_t n = 0; n < m_revlistOutput.GetCount(); ++n) { |
| 62 |
if(m_revlistOutput.Item(n).Left(8) == commit) { |
| 63 |
wxString parentHash = m_revlistOutput.Item(n).AfterFirst(' '); |
| 64 |
if(!parentHash.empty()) { |
| 65 |
parent = parentHash.Left(8); |
| 66 |
break; |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
return parent; |
| 71 |
} |
| 72 |
|
| 73 |
protected: |
| 74 |
wxArrayString m_visitedCommits; |
| 75 |
int m_index; |
| 76 |
wxArrayString m_revlistOutput; |
| 77 |
}; |
| 78 |
|
| 79 |
class GitBlameDlg : public GitBlameDlgBase |
| 80 |
{ |
| 81 |
public: |
| 82 |
GitBlameDlg(wxWindow* parent, GitPlugin* plugin); |
| 83 |
virtual ~GitBlameDlg(); |
| 84 |
|
| 85 |
void SetBlame(const wxString& blame, const wxString& args); |
| 86 |
void OnRevListOutput(const wxString& output, const wxString& Arguments); |
| 87 |
void Show(); |
| 88 |
|
| 89 |
protected: |
| 90 |
virtual void OnExtraArgsTextEnter(wxCommandEvent& event); |
| 91 |
virtual void OnRefreshBlame(wxCommandEvent& event); |
| 92 |
virtual void OnHistoryItemSelected(wxCommandEvent& event); |
| 93 |
virtual void OnBackUpdateUI(wxUpdateUIEvent& event); |
| 94 |
virtual void OnForwardUpdateUI(wxUpdateUIEvent& event); |
| 95 |
virtual void OnNextBlame(wxCommandEvent& event); |
| 96 |
virtual void OnPreviousBlame(wxCommandEvent& event); |
| 97 |
virtual void OnSettings(wxCommandEvent& event); |
| 98 |
virtual void OnStcblameLeftDclick(wxMouseEvent& event); |
| 99 |
virtual void OnCloseDialog(wxCommandEvent& event); |
| 100 |
virtual void OnCharHook(wxKeyEvent& event); |
| 101 |
void GetNewCommitBlame(const wxString& commit); |
| 102 |
void ClearLogControls(); |
| 103 |
void UpdateLogControls(const wxString& commit); |
| 104 |
|
| 105 |
void OnProcessTerminated(clProcessEvent& event); |
| 106 |
void OnProcessOutput(clProcessEvent& event); |
| 107 |
void OnChangeFile(wxCommandEvent& event); |
| 108 |
|
| 109 |
void DoCloseDialog(); |
| 110 |
|
| 111 |
GitPlugin* m_plugin; |
| 112 |
clEditEventsHandler::Ptr_t m_editEventsHandler; |
| 113 |
|
| 114 |
CommitStore m_commitStore; |
| 115 |
bool m_showParentCommit; |
| 116 |
bool m_showLogControls; |
| 117 |
wxStringMap_t m_diffMap; |
| 118 |
int m_sashPositionMain; |
| 119 |
int m_sashPositionV; |
| 120 |
int m_sashPositionH; |
| 121 |
|
| 122 |
wxString m_commandOutput; |
| 123 |
IProcess* m_process; |
| 124 |
}; |
| 125 |
|
| 126 |
class GitBlameSettingsDlg : public GitBlameSettingsDlgBase |
| 127 |
{ |
| 128 |
public: |
| 129 |
GitBlameSettingsDlg(wxWindow* parent, bool showParentCommit, bool showLogControls); |
| 130 |
virtual ~GitBlameSettingsDlg() {} |
| 131 |
|
| 132 |
protected: |
| 133 |
}; |
| 134 |
#endif // GITBLAMEDLG_H |