public static void ShelveFiles(IList<string> files, P4ScmProvider Scm, bool ShowUi) { Dictionary<int, IDictionary<string, P4.FileMetaData>> changeLists = new Dictionary<int, IDictionary<string, P4.FileMetaData>>(); bool shelvedFiles = false; for (int idx = 0; idx < files.Count; idx++) { int changeListId = -1; if (files[idx] != null && (files[idx].EndsWith("...") || files[idx].EndsWith("*"))) { List<P4.FileSpec> fileSpecs = new List<P4.FileSpec>(); fileSpecs.Add(P4.FileSpec.DepotSpec(files[idx])); IList<P4.File> opened = Scm.Connection.Repository.GetOpenedFiles(fileSpecs, null); IList<P4.FileSpec> openedSpecs = new List<P4.FileSpec>(); foreach (P4.File f in opened) { if ((f != null) && (f.DepotPath != null)) { openedSpecs.Add(P4.FileSpec.ClientSpec(f.ClientPath.Path)); } } IList<P4.FileMetaData> metadata = Scm.ListFileMetaData(null, openedSpecs); foreach (P4.FileMetaData f in metadata) { if (f != null) { changeListId = f.Change; if (changeLists.ContainsKey(changeListId) == false) { changeLists.Add(changeListId, new Dictionary<string, P4.FileMetaData>()); } if (changeLists[changeListId].ContainsKey(f.LocalPath.Path) == false) { changeLists[changeListId].Add(f.LocalPath.Path, f); } if (f.MovedFile != null) { P4.FileMetaData movedFmd = Scm.GetFileMetaData(f.MovedFile.Path); if ((movedFmd != null) && (movedFmd.LocalPath != null) && (changeLists[changeListId].ContainsKey(movedFmd.LocalPath.Path) == false)) { changeLists[changeListId].Add(movedFmd.LocalPath.Path, movedFmd); } } } } continue; } P4.FileMetaData fmd = null; fmd = Scm.Fetch(files[idx]); if (fmd == null) { continue; } SourceControlStatus status = Scm.GetFileStatus(files[idx]); if (status == SourceControlStatus.scsCheckedIn) { continue; } changeListId = fmd.Change; // describe cl here and see if it is shelved if (changeListId > 0) { Options opts = new Options(); opts["-S"] = null; Changelist isChangeShelved = Scm.GetChangelist(changeListId, opts); if (isChangeShelved.Shelved) { shelvedFiles = true; } } if (changeLists.ContainsKey(changeListId) == false) { changeLists.Add(changeListId, new Dictionary<string, P4.FileMetaData>()); } if (changeLists[changeListId].ContainsKey(fmd.LocalPath.Path) == false) { changeLists[changeListId].Add(fmd.LocalPath.Path, fmd); } if (fmd.MovedFile != null) { P4.FileMetaData movedFmd = Scm.GetFileMetaData(fmd.MovedFile.Path); if ((movedFmd != null) && (movedFmd.LocalPath != null) && (changeLists[changeListId].ContainsKey(movedFmd.LocalPath.Path) == false)) { changeLists[changeListId].Add(movedFmd.LocalPath.Path, movedFmd); } } } bool dlgShown = false; foreach (int changeListId in changeLists.Keys) { ShelveFileDlg dlg = new ShelveFileDlg(Scm); if (!(shelvedFiles)) { dlg.ClearChangelistTB.Checked = false; dlg.ClearChangelistTB.Enabled = false; } dlg.ChangelistId = changeListId; dlg.SelectedFileList = changeLists[changeListId].Values.ToList(); if (dlg.SelectedFileList.Count <= 0) { continue; } dlgShown = true; DialogResult res = DialogResult.OK; dlg.Description = Resources.ShelveFileDlg_FilesShelvedFromDefaultChangelist; if (changeListId > 0) { dlg.Description = string.Format( Resources.ShelveFileDlg_FilesShelvedFromNumberedChangelist, changeListId); } if (ShowUi) { res = dlg.ShowDialog(); } if (res == DialogResult.Cancel) { return; } // If requested delete the existing shelved flags if ((changeListId > 0) && (dlg.ReplaceExistingShelvedFiles)) { if (Scm.ShelveFiles(changeListId, null, P4.ShelveFilesCmdFlags.Delete, true, null) == false) { return; } } P4.ShelveFilesCmdFlags flags = P4.ShelveFilesCmdFlags.Force; if (dlg.DontShelveUnchangedFiles) { flags |= ShelveFilesCmdFlags.LeaveUnchanged; } // Shelve the files if (Scm.ShelveFiles(changeListId, dlg.Description, flags, dlg.SelectedFileList) == false) { return; } // If requested, revert the files after shelving if (dlg.RevertAfterShelving) { IList<string> selection = dlg.GetSelectedFiles(); string[] selected = selection.ToArray(); Scm.RevertFiles(false, true, null, selected); } Scm.BroadcastChangelistUpdate(null, new P4ScmProvider.ChangelistUpdateArgs(changeListId, P4ScmProvider.ChangelistUpdateArgs.UpdateType.ContentUpdate)); } if (dlgShown == false) { MessageBox.Show(Resources.ShelveFileDlg_NoShelveableFilesWarning, Resources.PerforceSCM, MessageBoxButtons.OK, MessageBoxIcon.Error); } }