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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2017 Eran Ifrah
// file name : gitdiffchoosecommitishdlg.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 "asyncprocess.h"
#include "cl_config.h"
#include "git.h"
#include "gitdiffchoosecommitishdlg.h"
#include "gitentry.h"
#include "globals.h"
#include "processreaderthread.h"
#include "windowattrmanager.h"
#include <wx/tokenzr.h>
GitDiffChooseCommitishDlg::GitDiffChooseCommitishDlg(wxWindow* parent, GitPlugin* plugin)
: GitDiffChooseCommitishDlgBase(parent)
, m_plugin(plugin)
, m_selectedRadio1(3)
, m_selectedRadio2(3)
, m_activeChoice1(m_choiceCommit1)
, m_activeChoice2(m_choiceCommit2)
{
WindowAttrManager::Load(this);
// Set a max width for these, else selecting a commit with a long message will break the layout
m_choiceCommit1->SetMaxSize(wxSize(60, -1));
m_choiceCommit2->SetMaxSize(wxSize(60, -1));
clConfig conf("git.conf");
GitEntry data;
conf.ReadItem(&data);
m_selectedRadio1 = data.GetGitDiffChooseDlgRadioSel1();
m_selectedRadio2 = data.GetGitDiffChooseDlgRadioSel2();
wxRadioButton* radiosL[] = { m_radioBranch1, m_radioTag1, m_radioCommit1, m_radioUserEntered1 };
wxRadioButton* radiosR[] = { m_radioBranch2, m_radioTag2, m_radioCommit2, m_radioUserEntered2 };
wxItemContainerImmutable* choicesL[] = { m_choiceBranch1, m_choiceTag1, m_choiceCommit1, m_comboCommitish1 };
wxItemContainerImmutable* choicesR[] = { m_choiceBranch2, m_choiceTag2, m_choiceCommit2, m_comboCommitish2 };
if(m_selectedRadio1 > -1 && m_selectedRadio1 < 4) {
radiosL[m_selectedRadio1]->SetValue(1);
m_activeChoice1 = choicesL[m_selectedRadio1];
}
if(m_selectedRadio2 > -1 && m_selectedRadio2 < 4) {
radiosR[m_selectedRadio2]->SetValue(1);
m_activeChoice2 = choicesR[m_selectedRadio2];
}
m_comboCommitish1->Append(data.GetGitDiffChooseDlgCBoxValues1());
m_comboCommitish2->Append(data.GetGitDiffChooseDlgCBoxValues2());
m_plugin->AsyncRunGitWithCallback(
" --no-pager branch -a --no-color",
[this](const wxString& output) {
wxArrayString items = wxStringTokenize(output, "\n", wxTOKEN_STRTOK);
m_choiceBranch1->Set(items);
m_choiceBranch1->Set(items);
},
IProcessCreateDefault | IProcessWrapInShell, m_plugin->GetRepositoryPath());
m_plugin->AsyncRunGitWithCallback(
" --no-pager tag",
[this](const wxString& output) {
wxArrayString items = wxStringTokenize(output, "\n", wxTOKEN_STRTOK);
m_choiceTag1->Set(items);
m_choiceTag2->Set(items);
},
IProcessCreateDefault | IProcessWrapInShell, m_plugin->GetRepositoryPath());
// Restrict the commits to 1000: filling a wxChoice with many more froze CodeLite for several minutes
// and in any case, selecting one particular commit out of hundreds is not easy!
m_plugin->AsyncRunGitWithCallback(
" --no-pager log -1000 --format=\"%h %<(60,trunc)%s\"",
[this](const wxString& output) {
wxArrayString items = wxStringTokenize(output, "\n", wxTOKEN_STRTOK);
m_choiceCommit1->Set(items);
m_choiceCommit2->Set(items);
},
IProcessCreateDefault | IProcessWrapInShell, m_plugin->GetRepositoryPath());
}
GitDiffChooseCommitishDlg::~GitDiffChooseCommitishDlg()
{
wxArrayString comboCommitish1Strings = m_comboCommitish1->GetStrings();
if(m_selectedRadio1 == 3) {
wxString sel = m_comboCommitish1->GetValue();
if(!sel.empty()) {
if(comboCommitish1Strings.Index(sel) != wxNOT_FOUND) {
comboCommitish1Strings.Remove(sel);
}
comboCommitish1Strings.Insert(sel, 0);
}
}
wxArrayString comboCommitish2Strings = m_comboCommitish2->GetStrings();
if(m_selectedRadio1 == 3) {
wxString sel = m_comboCommitish2->GetValue();
if(!sel.empty()) {
if(comboCommitish2Strings.Index(sel) != wxNOT_FOUND) {
comboCommitish2Strings.Remove(sel);
}
comboCommitish2Strings.Insert(sel, 0);
}
}
clConfig conf("git.conf");
GitEntry data;
conf.ReadItem(&data);
data.SetGitDiffChooseDlgRadioSel1(m_selectedRadio1);
data.SetGitDiffChooseDlgRadioSel2(m_selectedRadio2);
data.SetGitDiffChooseDlgCBoxValues1(comboCommitish1Strings);
data.SetGitDiffChooseDlgCBoxValues2(comboCommitish2Strings);
conf.WriteItem(&data);
}
wxString GitDiffChooseCommitishDlg::GetAncestorSetting(wxSpinCtrl* spin) const
{
wxString setting;
if(spin) {
int value = spin->GetValue();
if(value > 0) {
setting = wxString::Format("~%i", value);
}
}
return setting;
}
void GitDiffChooseCommitishDlg::OnUpdateUIBranch1(wxUpdateUIEvent& event) { event.Enable(m_radioBranch1->GetValue()); }
void GitDiffChooseCommitishDlg::OnUpdateUIBranch2(wxUpdateUIEvent& event) { event.Enable(m_radioBranch2->GetValue()); }
void GitDiffChooseCommitishDlg::OnUpdateUICommit1(wxUpdateUIEvent& event) { event.Enable(m_radioCommit1->GetValue()); }
void GitDiffChooseCommitishDlg::OnUpdateUICommit2(wxUpdateUIEvent& event) { event.Enable(m_radioCommit2->GetValue()); }
void GitDiffChooseCommitishDlg::OnUpdateUICommitish1(wxUpdateUIEvent& event)
{
event.Enable(m_radioUserEntered1->GetValue());
}
void GitDiffChooseCommitishDlg::OnUpdateUICommitish2(wxUpdateUIEvent& event)
{
event.Enable(m_radioUserEntered2->GetValue());
}
void GitDiffChooseCommitishDlg::OnUpdateUITags1(wxUpdateUIEvent& event) { event.Enable(m_radioTag1->GetValue()); }
void GitDiffChooseCommitishDlg::OnUpdateUITags2(wxUpdateUIEvent& event) { event.Enable(m_radioTag2->GetValue()); }
void GitDiffChooseCommitishDlg::OnRadioBranch1Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice1 = m_choiceBranch1;
m_selectedRadio1 = 0;
}
void GitDiffChooseCommitishDlg::OnRadioBranch2Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice2 = m_choiceBranch2;
m_selectedRadio2 = 0;
}
void GitDiffChooseCommitishDlg::OnRadioTag1Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice1 = m_choiceTag1;
m_selectedRadio1 = 1;
}
void GitDiffChooseCommitishDlg::OnRadioTag2Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice2 = m_choiceTag2;
m_selectedRadio2 = 1;
}
void GitDiffChooseCommitishDlg::OnRadioCommit1Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice1 = m_choiceCommit1;
m_selectedRadio1 = 2;
}
void GitDiffChooseCommitishDlg::OnRadioCommit2Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice2 = m_choiceCommit2;
m_selectedRadio2 = 2;
}
void GitDiffChooseCommitishDlg::OnRadioUser1Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice1 = m_comboCommitish1;
m_selectedRadio1 = 3;
}
void GitDiffChooseCommitishDlg::OnRadioUser2Selected(wxCommandEvent& WXUNUSED(event))
{
m_activeChoice2 = m_comboCommitish2;
m_selectedRadio2 = 3;
}
void GitDiffChooseCommitishDlg::OnTextFirstUI(wxUpdateUIEvent& event)
{
wxString text =
(m_activeChoice1 == m_comboCommitish1) ? m_comboCommitish1->GetValue() : m_activeChoice1->GetStringSelection();
if(text.StartsWith("* ")) {
text = text.Mid(2); // Remove the 'active branch' marker
}
if(m_activeChoice1 == m_choiceCommit1) {
text = text.BeforeFirst(' '); // We want only the commit hash, not the message
}
static_cast<wxTextCtrl*>(event.GetEventObject())->ChangeValue(text.Trim().Trim(false));
}
void GitDiffChooseCommitishDlg::OnTextSecondUI(wxUpdateUIEvent& event)
{
wxString text =
(m_activeChoice2 == m_comboCommitish2) ? m_comboCommitish2->GetValue() : m_activeChoice2->GetStringSelection();
if(text.StartsWith("* ")) {
text = text.Mid(2); // Remove the 'active branch' marker
}
if(m_activeChoice2 == m_choiceCommit2) {
text = text.BeforeFirst(' '); // We want only the commit hash, not the message
}
static_cast<wxTextCtrl*>(event.GetEventObject())->ChangeValue(text.Trim().Trim(false));
}
void GitDiffChooseCommitishDlg::OnBranch1Changed(wxCommandEvent& event)
{
wxString newBranch = m_choiceBranch1->GetString(event.GetInt());
if(newBranch.StartsWith("* ")) {
newBranch = newBranch.Mid(2); // Remove the 'active branch' marker
}
m_plugin->AsyncRunGitWithCallback(
" --no-pager log -1000 --format=\"%h %<(60,trunc)%s\" " + newBranch,
[this](const wxString& output) {
wxArrayString items = wxStringTokenize(output, "\n", wxTOKEN_STRTOK);
m_choiceCommit1->Set(items);
},
IProcessCreateDefault | IProcessWrapInShell, m_plugin->GetRepositoryPath());
}
void GitDiffChooseCommitishDlg::OnBranch2Changed(wxCommandEvent& event)
{
wxString newBranch = m_choiceBranch2->GetString(event.GetInt());
if(newBranch.StartsWith("* ")) {
newBranch = newBranch.Mid(2); // Remove the 'active branch' marker
}
m_plugin->AsyncRunGitWithCallback(
" --no-pager log -1000 --format=\"%h %<(60,trunc)%s\" " + newBranch,
[this](const wxString& output) {
wxArrayString items = wxStringTokenize(output, "\n", wxTOKEN_STRTOK);
m_choiceCommit2->Set(items);
},
IProcessCreateDefault | IProcessWrapInShell, m_plugin->GetRepositoryPath());
}
|