1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2012 Sven Strickroth, <email@cs-ware.de>
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.
21 #include "TortoiseProc.h"
22 #include "SubmoduleUpdateDlg.h"
24 #include "UnicodeUtils.h"
26 IMPLEMENT_DYNAMIC(CSubmoduleUpdateDlg
, CStandAloneDialog
)
28 CSubmoduleUpdateDlg::CSubmoduleUpdateDlg(CWnd
* pParent
/*=NULL*/)
29 : CStandAloneDialog(CSubmoduleUpdateDlg::IDD
, pParent
)
39 CSubmoduleUpdateDlg::~CSubmoduleUpdateDlg()
43 void CSubmoduleUpdateDlg::DoDataExchange(CDataExchange
* pDX
)
45 CStandAloneDialog::DoDataExchange(pDX
);
46 DDX_Control(pDX
, IDC_LIST_PATH
, m_PathListBox
);
47 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_INIT
, m_bInit
);
48 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_RECURSIVE
, m_bRecursive
);
49 DDX_Check(pDX
, IDC_FORCE
, m_bForce
);
50 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_NOFETCH
, m_bNoFetch
);
51 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_MERGE
, m_bMerge
);
52 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_REBASE
, m_bRebase
);
56 BEGIN_MESSAGE_MAP(CSubmoduleUpdateDlg
, CStandAloneDialog
)
57 ON_BN_CLICKED(IDOK
, &CSubmoduleUpdateDlg::OnBnClickedOk
)
58 ON_BN_CLICKED(IDHELP
, &CSubmoduleUpdateDlg::OnBnClickedHelp
)
59 ON_LBN_SELCHANGE(IDC_LIST_PATH
, &CSubmoduleUpdateDlg::OnLbnSelchangeListPath
)
62 static int SubmoduleCallback(git_submodule
*sm
, const char * /*name*/, void *payload
)
64 STRING_VECTOR
*list
= *(STRING_VECTOR
**)payload
;
65 STRING_VECTOR
*prefixList
= *((STRING_VECTOR
**)payload
+ 1);
66 CString path
= CUnicodeUtils::GetUnicode(git_submodule_path(sm
));
67 if (prefixList
->empty())
69 list
->push_back(path
);
73 for (size_t i
= 0; i
< prefixList
->size(); ++i
)
75 CString prefix
= prefixList
->at(i
) + _T("/");
76 if (path
.Left(prefix
.GetLength()) == prefix
)
77 list
->push_back(path
);
83 static void GetSubmodulePathList(STRING_VECTOR
&list
, STRING_VECTOR
&prefixList
)
86 if (git_repository_open(&repo
, CUnicodeUtils::GetUTF8(g_Git
.m_CurrentDir
)))
88 MessageBox(NULL
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR
);
92 STRING_VECTOR
*listParams
[] = { &list
, &prefixList
};
93 if (git_submodule_foreach(repo
, SubmoduleCallback
, &listParams
))
95 MessageBox(NULL
, CGit::GetLibGit2LastErr(_T("Could not get submodule list.")), _T("TortoiseGit"), MB_ICONERROR
);
99 git_repository_free(repo
);
100 std::sort(list
.begin(), list
.end());
103 BOOL
CSubmoduleUpdateDlg::OnInitDialog()
105 CStandAloneDialog::OnInitDialog();
106 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
108 CString sWindowTitle
;
109 GetWindowText(sWindowTitle
);
110 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
112 AdjustControlSize(IDC_CHECK_SUBMODULE_INIT
);
113 AdjustControlSize(IDC_CHECK_SUBMODULE_RECURSIVE
);
114 AdjustControlSize(IDC_CHECK_SUBMODULE_NOFETCH
);
115 AdjustControlSize(IDC_CHECK_SUBMODULE_MERGE
);
116 AdjustControlSize(IDC_CHECK_SUBMODULE_REBASE
);
118 CString WorkingDir
= g_Git
.m_CurrentDir
;
119 WorkingDir
.Replace(_T(':'), _T('_'));
121 m_regPath
= CRegString(CString(_T("Software\\TortoiseGit\\History\\SubmoduleUpdatePath\\") + WorkingDir
));
122 CString path
= m_regPath
;
124 GetSubmodulePathList(list
, m_PathFilterList
);
125 STRING_VECTOR selected
;
126 if (m_PathList
.empty())
131 CString part
= path
.Tokenize(_T("|"), pos
);
133 selected
.push_back(part
);
138 for (size_t i
= 0; i
< m_PathList
.size(); ++i
)
139 selected
.push_back(m_PathList
[i
]);
142 for (size_t i
= 0; i
< list
.size(); ++i
)
144 m_PathListBox
.AddString(list
[i
]);
145 if (selected
.size() == 0)
146 m_PathListBox
.SetSel((int)i
);
149 for (int j
= 0; j
< selected
.size(); ++j
)
151 if (selected
[j
] == list
[i
])
152 m_PathListBox
.SetSel((int)i
);
162 void CSubmoduleUpdateDlg::OnBnClickedOk()
164 CStandAloneDialog::UpdateData(TRUE
);
167 for (int i
= 0; i
< m_PathListBox
.GetCount(); ++i
)
169 if (m_PathListBox
.GetSel(i
))
171 if (!selected
.IsEmpty())
172 selected
.Append(_T("|"));
174 m_PathListBox
.GetText(i
, text
);
175 m_PathList
.push_back(text
);
176 selected
.Append(text
);
179 m_regPath
= selected
;
181 CStandAloneDialog::OnOK();
184 void CSubmoduleUpdateDlg::OnBnClickedHelp()
189 void CSubmoduleUpdateDlg::OnLbnSelchangeListPath()
191 GetDlgItem(IDOK
)->EnableWindow(m_PathListBox
.GetSelCount() > 0 ? TRUE
: FALSE
);