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"
25 #include "UnicodeUtils.h"
27 IMPLEMENT_DYNAMIC(CSubmoduleUpdateDlg
, CStandAloneDialog
)
29 CSubmoduleUpdateDlg::CSubmoduleUpdateDlg(CWnd
* pParent
/*=NULL*/)
30 : CStandAloneDialog(CSubmoduleUpdateDlg::IDD
, pParent
)
40 CSubmoduleUpdateDlg::~CSubmoduleUpdateDlg()
44 void CSubmoduleUpdateDlg::DoDataExchange(CDataExchange
* pDX
)
46 CStandAloneDialog::DoDataExchange(pDX
);
47 DDX_Control(pDX
, IDC_LIST_PATH
, m_PathListBox
);
48 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_INIT
, m_bInit
);
49 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_RECURSIVE
, m_bRecursive
);
50 DDX_Check(pDX
, IDC_FORCE
, m_bForce
);
51 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_NOFETCH
, m_bNoFetch
);
52 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_MERGE
, m_bMerge
);
53 DDX_Check(pDX
, IDC_CHECK_SUBMODULE_REBASE
, m_bRebase
);
57 BEGIN_MESSAGE_MAP(CSubmoduleUpdateDlg
, CStandAloneDialog
)
58 ON_BN_CLICKED(IDOK
, &CSubmoduleUpdateDlg::OnBnClickedOk
)
59 ON_BN_CLICKED(IDHELP
, &CSubmoduleUpdateDlg::OnBnClickedHelp
)
60 ON_LBN_SELCHANGE(IDC_LIST_PATH
, &CSubmoduleUpdateDlg::OnLbnSelchangeListPath
)
63 static int SubmoduleCallback(git_submodule
*sm
, const char * /*name*/, void *payload
)
65 STRING_VECTOR
*list
= *(STRING_VECTOR
**)payload
;
66 STRING_VECTOR
*prefixList
= *((STRING_VECTOR
**)payload
+ 1);
67 CString path
= CUnicodeUtils::GetUnicode(git_submodule_path(sm
));
68 if (prefixList
->empty())
70 list
->push_back(path
);
74 for (size_t i
= 0; i
< prefixList
->size(); ++i
)
76 CString prefix
= prefixList
->at(i
) + _T("/");
77 if (path
.Left(prefix
.GetLength()) == prefix
)
78 list
->push_back(path
);
84 static void GetSubmodulePathList(STRING_VECTOR
&list
, STRING_VECTOR
&prefixList
)
87 if (git_repository_open(&repo
, CUnicodeUtils::GetUTF8(g_Git
.m_CurrentDir
)))
89 MessageBox(NULL
, CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR
);
93 STRING_VECTOR
*listParams
[] = { &list
, &prefixList
};
94 if (git_submodule_foreach(repo
, SubmoduleCallback
, &listParams
))
96 MessageBox(NULL
, CGit::GetLibGit2LastErr(_T("Could not get submodule list.")), _T("TortoiseGit"), MB_ICONERROR
);
100 git_repository_free(repo
);
101 std::sort(list
.begin(), list
.end());
104 BOOL
CSubmoduleUpdateDlg::OnInitDialog()
106 CStandAloneDialog::OnInitDialog();
107 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
109 CString sWindowTitle
;
110 GetWindowText(sWindowTitle
);
111 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
113 AdjustControlSize(IDC_CHECK_SUBMODULE_INIT
);
114 AdjustControlSize(IDC_CHECK_SUBMODULE_RECURSIVE
);
115 AdjustControlSize(IDC_CHECK_SUBMODULE_NOFETCH
);
116 AdjustControlSize(IDC_CHECK_SUBMODULE_MERGE
);
117 AdjustControlSize(IDC_CHECK_SUBMODULE_REBASE
);
119 CString WorkingDir
= g_Git
.m_CurrentDir
;
120 WorkingDir
.Replace(_T(':'), _T('_'));
122 m_regPath
= CRegString(CString(_T("Software\\TortoiseGit\\History\\SubmoduleUpdatePath\\") + WorkingDir
));
123 CString path
= m_regPath
;
125 GetSubmodulePathList(list
, m_PathFilterList
);
126 STRING_VECTOR selected
;
130 CString part
= path
.Tokenize(_T("|"), pos
);
132 selected
.push_back(part
);
134 for (size_t i
= 0; i
< list
.size(); ++i
)
136 m_PathListBox
.AddString(list
[i
]);
137 if (selected
.size() == 0)
138 m_PathListBox
.SetSel((int)i
);
141 for (int j
= 0; j
< selected
.size(); ++j
)
143 if (selected
[j
] == list
[i
])
144 m_PathListBox
.SetSel((int)i
);
154 void CSubmoduleUpdateDlg::OnBnClickedOk()
156 CStandAloneDialog::UpdateData(TRUE
);
159 for (int i
= 0; i
< m_PathListBox
.GetCount(); ++i
)
161 if (m_PathListBox
.GetSel(i
))
163 if (!selected
.IsEmpty())
164 selected
.Append(_T("|"));
166 m_PathListBox
.GetText(i
, text
);
167 m_PathList
.push_back(text
);
168 selected
.Append(text
);
171 m_regPath
= selected
;
173 CStandAloneDialog::OnOK();
176 void CSubmoduleUpdateDlg::OnBnClickedHelp()
181 void CSubmoduleUpdateDlg::OnLbnSelchangeListPath()
183 GetDlgItem(IDOK
)->EnableWindow(m_PathListBox
.GetSelCount() > 0 ? TRUE
: FALSE
);