private void UpdateSubmodulesList()
{
RemoveSubmoduleButtons();
_previousUpdateTime = DateTime.Now;
_submodulesStatusImagesCTS = new CancellationTokenSource();
foreach (var submodule in Module.GetSubmodulesLocalPathes().OrderBy(submoduleName => submoduleName))
{
var name = submodule;
string path = Module.GetSubmoduleFullPath(submodule);
if (Settings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path))
name = name + " " + GetModuleBranch(path);
var smi = AddSubmoduleToMenu(name, path);
var module = Module.GetSubmodule(submodule);
var submoduleName = module.GetCurrentSubmoduleLocalPath();
GetSubmoduleStatusImageAsync(smi, module.SuperprojectModule, submoduleName);
}
bool containSubmodules = toolStripButtonLevelUp.DropDownItems.Count != 0;
if (!containSubmodules)
toolStripButtonLevelUp.DropDownItems.Add(_noSubmodulesPresent.Text);
string currentSubmoduleName = null;
if (Module.SuperprojectModule != null)
{
var superprojectSeparator = new ToolStripSeparator();
toolStripButtonLevelUp.DropDownItems.Add(superprojectSeparator);
GitModule supersuperproject = Module.FindTopProjectModule();
if (Module.SuperprojectModule.WorkingDir != supersuperproject.WorkingDir)
{
var name = "Top project: " + Path.GetFileName(Path.GetDirectoryName(supersuperproject.WorkingDir));
string path = supersuperproject.WorkingDir;
if (Settings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path))
name = name + " " + GetModuleBranch(path);
var smi = AddSubmoduleToMenu(name, supersuperproject);
smi.Image = Resources.IconFolderSubmodule;
}
{
var name = "Superproject: ";
GitModule parentModule = Module.SuperprojectModule;
string localpath = "";
if (Module.SuperprojectModule.WorkingDir != supersuperproject.WorkingDir)
{
parentModule = supersuperproject;
localpath = Module.SuperprojectModule.WorkingDir.Substring(supersuperproject.WorkingDir.Length);
localpath = PathUtil.GetDirectoryName(localpath.ToPosixPath());
name = name + localpath;
}
else
name = name + Path.GetFileName(Path.GetDirectoryName(supersuperproject.WorkingDir));
string path = Module.SuperprojectModule.WorkingDir;
if (Settings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path))
name = name + " " + GetModuleBranch(path);
var smi = AddSubmoduleToMenu(name, Module.SuperprojectModule);
GetSubmoduleStatusImageAsync(smi, parentModule, localpath);
}
var submodules = supersuperproject.GetSubmodulesLocalPathes().OrderBy(submoduleName => submoduleName);
if (submodules.Any())
{
string localpath = Module.WorkingDir.Substring(supersuperproject.WorkingDir.Length);
localpath = PathUtil.GetDirectoryName(localpath.ToPosixPath());
foreach (var submodule in submodules)
{
var name = submodule;
string path = supersuperproject.GetSubmoduleFullPath(submodule);
if (Settings.DashboardShowCurrentBranch && !GitModule.IsBareRepository(path))
name = name + " " + GetModuleBranch(path);
var submenu = AddSubmoduleToMenu(name, path);
if (submodule == localpath)
{
currentSubmoduleName = Module.GetCurrentSubmoduleLocalPath();
submenu.Font = new Font(submenu.Font, FontStyle.Bold);
}
var module = supersuperproject.GetSubmodule(submodule);
var submoduleName = module.GetCurrentSubmoduleLocalPath();
GetSubmoduleStatusImageAsync(submenu, module.SuperprojectModule, submoduleName);
}
}
}
var separator = new ToolStripSeparator();
toolStripButtonLevelUp.DropDownItems.Add(separator);
var mi = new ToolStripMenuItem(updateAllSubmodulesToolStripMenuItem.Text);
mi.Click += UpdateAllSubmodulesToolStripMenuItemClick;
toolStripButtonLevelUp.DropDownItems.Add(mi);
if (currentSubmoduleName != null)
{
var usmi = new ToolStripMenuItem(_updateCurrentSubmodule.Text);
usmi.Tag = currentSubmoduleName;
usmi.Click += UpdateSubmoduleToolStripMenuItemClick;
toolStripButtonLevelUp.DropDownItems.Add(usmi);
}
}