1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : gitDiffDlg.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "editor_config.h"
#include "gitDiffDlg.h"
#include "gitentry.h"
#include "windowattrmanager.h"
#include "GitDiffOutputParser.h"
#include "asyncprocess.h"
#include "cl_config.h"
#include "git.h"
#include "gitCommitEditor.h"
#include "gitdiffchoosecommitishdlg.h"
#include "globals.h"
#include "processreaderthread.h"
#include <wx/tokenzr.h>
BEGIN_EVENT_TABLE(GitDiffDlg, wxDialog)
END_EVENT_TABLE()
GitDiffDlg::GitDiffDlg(wxWindow* parent, const wxString& workingDir, GitPlugin* plugin)
: GitDiffDlgBase(parent)
, m_workingDir(workingDir)
, m_plugin(plugin)
{
clConfig conf("git.conf");
GitEntry data;
conf.ReadItem(&data);
SetName("GitDiffDlg");
WindowAttrManager::Load(this);
m_splitter->SetSashPosition(data.GetGitDiffDlgSashPos());
Bind(wxEVT_ASYNC_PROCESS_OUTPUT, &GitDiffDlg::OnProcessOutput, this);
Bind(wxEVT_ASYNC_PROCESS_TERMINATED, &GitDiffDlg::OnProcessTerminated, this);
CreateDiff();
::clSetDialogBestSizeAndPosition(this);
}
/*******************************************************************************/
GitDiffDlg::~GitDiffDlg()
{
clConfig conf("git.conf");
GitEntry data;
conf.ReadItem(&data);
data.SetGitDiffDlgSashPos(m_splitter->GetSashPosition());
conf.WriteItem(&data);
}
/*******************************************************************************/
void GitDiffDlg::CreateDiff()
{
m_commandOutput.Empty(); // There might be stale contents from a previous run
wxString command = PrepareCommand();
m_plugin->DisplayMessage("GitDiff: " + command);
m_process = m_plugin->AsyncRunGit(this, command, IProcessCreateDefault | IProcessWrapInShell,
m_plugin->GetRepositoryPath());
}
wxString GitDiffDlg::PrepareCommand() const
{
wxString commitsString = m_commits;
if(commitsString.empty()) {
// Standard diff of changes against HEAD, but which sort?
switch(m_radioBoxStaged->GetSelection()) {
case 0:
commitsString = "";
break; // Unstaged only
case 1:
commitsString = "--cached ";
break; // Staged only
default:
commitsString = "HEAD "; // Both
}
}
wxString command(" --no-pager diff ");
if(m_checkIgnoreSpace->GetValue()) {
command << "--ignore-all-space "; // -w
}
return command + commitsString;
}
void GitDiffDlg::SetDiff(const wxString& diff)
{
wxString commandOutput = diff;
m_fileListBox->Clear();
m_diffMap.clear();
commandOutput.Replace(wxT("\r"), wxT(""));
GitDiffOutputParser diff_parser;
diff_parser.GetDiffMap(m_commandOutput, m_diffMap);
for(wxStringMap_t::iterator it = m_diffMap.begin(); it != m_diffMap.end(); ++it) {
m_fileListBox->Append((*it).first);
}
m_editor->SetReadOnly(false);
m_editor->SetText(wxT(""));
if(m_diffMap.size() != 0) {
wxStringMap_t::iterator it = m_diffMap.begin();
m_editor->SetText((*it).second);
m_fileListBox->Select(0);
m_editor->SetReadOnly(true);
}
}
/*******************************************************************************/
void GitDiffDlg::OnChangeFile(wxCommandEvent& e)
{
int sel = m_fileListBox->GetSelection();
wxString file = m_fileListBox->GetString(sel);
m_editor->SetReadOnly(false);
m_editor->SetText(m_diffMap[file]);
m_editor->SetReadOnly(true);
}
void GitDiffDlg::OnChoseCommits(wxCommandEvent& event)
{
GitDiffChooseCommitishDlg dlg(this, m_plugin);
if(dlg.ShowModal() == wxID_OK) {
wxString commit1 = dlg.GetFirstCommit();
wxString joiner = dlg.GetJoiner(); // May be ' ' or '...'
wxString commit2 = dlg.GetSecondCommit();
m_commits = commit1 + joiner + commit2;
CreateDiff();
}
}
void GitDiffDlg::OnProcessOutput(clProcessEvent& event) { m_commandOutput.Append(event.GetOutput()); }
void GitDiffDlg::OnProcessTerminated(clProcessEvent& event)
{
wxUnusedVar(event);
wxDELETE(m_process);
SetDiff(m_commandOutput);
}
void GitDiffDlg::OnOptionsChanged(wxCommandEvent& event) { CreateDiff(); }
|