public void InitView(P4ScmProvider _scm, IList <string> files, IList <object> fields) { listItemMap = new Dictionary <string, P4ObjectTreeListViewItem>(); IList <P4.FileSpec> fs = P4.FileSpec.LocalSpecList(files.ToArray()); Files = _scm.GetFileMetaData(fs, null); Fields = fields; foreach (P4.FileMetaData file in Files) { P4FileTreeListViewItem it = new P4FileTreeListViewItem(null, file, (IList <object>)Fields); listItemMap.Add(file.DepotPath.Path, it); this.Items.Add(it); } }
public P4ChangeTreeListViewItem(TreeListViewItem parentItem, P4.Changelist changeData, P4ScmProvider scm, IList <object> fields) : base() { ParentItem = parentItem; Fields = fields; NodeType = nodeType.Pending; // default Scm = scm; Tag = changeData; Ours = (changeData.ClientId == Scm.Connection.Workspace); if (Ours) { P4.Options opts = new P4.Options(); if (changeData.Id > 0) { opts["-e"] = changeData.Id.ToString(); } else { opts["-e"] = "default"; NodeType.Set(nodeType.Default); } opts["-Ru"] = null; opts["-m"] = "1"; P4.FileSpec fs = new P4.FileSpec(new P4.ClientPath(@"//" + Scm.Connection.Workspace + @"/..."), null); List <P4.FileSpec> lfs = new List <P4.FileSpec>(); lfs.Add(fs); IList <P4.FileMetaData> unresolved = Scm.GetFileMetaData(lfs, opts); if ((unresolved != null) && (unresolved.Count > 0)) { NeedsResolve = true; } } _changeData = changeData; // don't call InitSubitems() or SelectImagesFromMetaData() yet if (changeData.Id > 0) { _reviewData = Scm.Connection.Swarm.IsChangelistAttachedToReview(changeData.Id); } InitSubitems(); SelectImagesFromMetaData(); }
public static void ChangeFileType(P4ScmProvider scm, IList <string> paths) { FileAttributesDlg dlg = new FileAttributesDlg(scm); int changelistId = 0; IList <string> CheckedinFiles = new List <string>(); IList <string> CheckedoutFiles = new List <string>(); IList <P4.FileMetaData> fmd = scm.GetFileMetaData(paths, null); P4.FileType ft = null; if (fmd != null) { foreach (P4.FileMetaData md in fmd) { if (ft == null) { ft = md.Type; if (md.Change > 0) { changelistId = md.Change; } } else { // only keep the base type if all the same if (ft.BaseType != md.Type.BaseType) { ft.BaseType = P4.BaseFileType.Unspecified; } // only keep fags that are the same ft.Modifiers &= md.Type.Modifiers; if (changelistId != md.Change) { changelistId = 0; } } if (md.Action == P4.FileAction.None) { CheckedinFiles.Add(md.LocalPath.Path); } else { CheckedoutFiles.Add(md.LocalPath.Path); } } } dlg.FileType = ft; dlg.TargetChangelistId = changelistId; if (dlg.ShowDialog() == DialogResult.Cancel) { return; } int targetChangelist = dlg.TargetChangelistId; P4.Options options = null; if (targetChangelist < 0) { // if selected, create a new numbered changelist with the files. P4.Changelist change = scm.Connection.Repository.NewChangelist(); change.Description = "<P4VS Change FileType>"; change.ClientId = scm.Connection.Repository.Connection.Client.Name; change.OwnerName = scm.Connection.Repository.Connection.UserName; change.Files = null; // new List<P4.FileMetaData>(); P4.Changelist newChange = scm.Connection.Repository.CreateChangelist(change); targetChangelist = newChange.Id; } if (CheckedoutFiles.Count > 0) { options = new P4.ReopenCmdOptions(targetChangelist, dlg.FileType); if ((options.ContainsKey("-t")) && (string.IsNullOrEmpty(options["-t"]) == false)) { scm.ReopenFiles(P4.FileSpec.LocalSpecList(CheckedoutFiles), options); } } if (CheckedinFiles.Count > 0) { options = new P4.EditCmdOptions(P4.EditFilesCmdFlags.None, targetChangelist, dlg.FileType); if ((options.ContainsKey("-t")) && (string.IsNullOrEmpty(options["-t"]) == false)) { scm.EditFiles(P4.FileSpec.LocalSpecList(CheckedinFiles), options); } } scm.BroadcastChangelistUpdate(null, new P4ScmProvider.ChangelistUpdateArgs(targetChangelist, P4ScmProvider.ChangelistUpdateArgs.UpdateType.Edit)); }
/// <summary> /// Expand the directory by filling in the list of child directories /// and file within the directory. /// </summary> /// <returns>false if an error prevented completion</returns> public bool Expand(bool filtered) { if (String.IsNullOrEmpty(depotPath)) { return(false); } if (_scm.ServerVersion >= Versions.V12_1) { if (!String.IsNullOrEmpty(depotPath)) { IList <string> subdirs = new List <string>(); IList <FileMetaData> fileList = new List <FileMetaData>(); Options options = new Options(); options["-Ol"] = null; options["-D"] = null; options["-F"] = "^headAction=delete & ^headAction=move/delete"; options["-T"] = "depotFile, dir"; if (filtered) { options = new Options(); options["-Ol"] = null; options["-Dlc"] = null; options["-Rc"] = null; options["-F"] = "^headAction=delete & ^headAction=move/delete"; options["-T"] = "depotFile, dir"; } IList <FileMetaData> fmd = _scm.GetFileMetaData(options, DepotPath + "/*"); foreach (FileMetaData f in fmd) { if (f.DepotPath != null) { fileList.Add(f); } if (f.Directory != null) { subdirs.Add(f.Directory); } } if ((subdirs != null) && (subdirs.Count > 0)) { subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs); foreach (P4Directory dir in subdirectories.Values) { dir.InDepot = true; } } if (fileList != null) { files = P4FileMap.FromFstatOutput(fileList); // if the directory contains files from the depot, we can use // the local path of one of those files to determine the local // path for this directory if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0)) { foreach (FileMetaData f in files.Values) { if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path)) { localPath = f.LocalPath.GetDirectoryName(); break; } } } } } } else { // old tree builder using dirs and fstat //***************************************************************************************** // if we have the depot path, get a list of the subdirectories from the depot if (!String.IsNullOrEmpty(depotPath)) { IList <string> subdirs = _scm.GetDepotDirs(null, String.Format("{0}/*", depotPath)); if ((subdirs != null) && (subdirs.Count > 0)) { subdirectories = P4DirectoryMap.FromDirsOutput(_scm, Workspace, this, subdirs); foreach (P4Directory dir in subdirectories.Values) { dir.InDepot = true; } } IList <FileMetaData> fileList = _scm.GetFileMetaData(null, String.Format("{0}/*", depotPath)); // get a list of the files in the directory if (fileList != null) { files = P4FileMap.FromFstatOutput(fileList); // if the directory contains files from the depot, we can use // the local path of one of those files to determine the local // path for this directory if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0)) { foreach (FileMetaData f in files.Values) { if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path)) { localPath = f.LocalPath.GetDirectoryName(); break; } } } } } //***************************************************************************************** } // if we have a workspace and a local path, match the files and // subdirectories in the depot with the files in the file system if ((!String.IsNullOrEmpty(localPath)) && (Workspace != null)) { DirectoryInfo[] directoryList = null; FileInfo[] fileList = null; try { DirectoryInfo di = new DirectoryInfo(localPath); directoryList = di.GetDirectories(); fileList = di.GetFiles(); } catch { //LogFile.LogException( "Initializing Directory from Workspace", ex ); } // get the subdirectories listed in the file and match them up // with the one in the list from the depot if ((directoryList != null) && (directoryList.Length > 0)) { foreach (DirectoryInfo di in directoryList) { string itemName = di.Name; if (subdirectories.ContainsKey(itemName)) { subdirectories[itemName].InWorkspace = true; } else { P4Directory subDir = new P4Directory(_scm, Workspace, itemName, null, di.FullName, parentDirectory); subDir.InDepot = false; subDir.InWorkspace = true; subdirectories[itemName] = subDir; } } } // get the files listed in the subdirectory and match them up // with the one in the list from the depot if ((fileList != null) && (fileList.Length > 0)) { foreach (FileInfo fi in fileList) { string itemName = fi.Name; if (files != null && files.ContainsKey(itemName) == false) { FileMetaData file = new FileMetaData(); file.LocalPath = new LocalPath(fi.FullName); file.DepotPath = null; file.FileSize = fi.Length; files[itemName] = file; } } } } return(true); }
//private P4.Label _labelToAdd = null; public static List <P4.FileSpec> Show(IList <string> paths, string specifier, string value, P4ScmProvider scm) { List <P4.FileSpec> files = new List <P4.FileSpec>(); DiffDlg dlg = null; try { dlg = new DiffDlg(paths, specifier, value, scm); } catch { return(null); } if (dlg.ShowDialog() != DialogResult.Cancel) { if (dlg.DialogResult == DialogResult.OK) { // get the strings to diff string path1 = dlg.path1TB.Text; string path2 = dlg.path2TB.Text; // create the 2 filespecs P4.FileSpec spec1 = new P4.FileSpec(); P4.FileSpec spec2 = new P4.FileSpec(); if (path1.StartsWith("//")) { spec1.DepotPath = new P4.DepotPath(path1); } else { spec1.LocalPath = new P4.LocalPath(path1); } if (path2.StartsWith("//")) { spec2.DepotPath = new P4.DepotPath(path2); } else { spec2.LocalPath = new P4.LocalPath(path2); } // build spec one if (dlg.specifier1stRB.Checked == true) { // #revision if (dlg.specifier1stCB.SelectedIndex == 0) { if (dlg.path1ValueTB.Text == string.Empty) { spec1.Version = null; } else { try { int rev1 = Convert.ToInt32(dlg.path1ValueTB.Text); spec1.Version = new P4.Revision(rev1); } catch (Exception) { MessageBox.Show(string.Format(Resources.DiffDlg_InvalidRevisionSpecifier, dlg.path1ValueTB.Text), Resources.PerforceSCM, MessageBoxButtons.OK); Show(paths, specifier, value, scm); return(files); } } } // @workspace if (dlg.specifier1stCB.SelectedIndex == 4) { if (dlg.path1ValueTB.Text == string.Empty) { spec1.Version = null; } else { string ws1 = dlg.path1ValueTB.Text; spec1.Version = new P4.ClientNameVersion(ws1); } } // @date/time if (dlg.specifier1stCB.SelectedIndex == 2) { DateTime dt1 = dlg.path1dateTimePicker.Value; spec1.Version = new P4.DateTimeVersion(dt1); } // @changelist if (dlg.specifier1stCB.SelectedIndex == 1) { if (dlg.path1ValueTB.Text == string.Empty) { spec1.Version = null; } else { try { int cl1 = Convert.ToInt32(dlg.path1ValueTB.Text); spec1.Version = new P4.ChangelistIdVersion(cl1); } catch (Exception) { MessageBox.Show(string.Format(Resources.DiffDlg_InvalidChangelistSpecifier, dlg.path1ValueTB.Text), Resources.PerforceSCM, MessageBoxButtons.OK); Show(paths, specifier, value, scm); return(files); } } } // @label if (dlg.specifier1stCB.SelectedIndex == 3) { if (dlg.path1ValueTB.Text == string.Empty) { spec1.Version = null; } else { string lb1 = dlg.path1ValueTB.Text; spec1.Version = new P4.LabelNameVersion(lb1); } } } if (dlg.workspace1stRB.Checked == true) { // if diffing with local path, get that from the file metadata // and null out the spec's depot path if (spec1.DepotPath != null) { P4.FileMetaData fmd = scm.GetFileMetaData(spec1.DepotPath.Path); if (fmd != null) { spec1.LocalPath = fmd.LocalPath; spec1.DepotPath = null; } } } if (dlg.latest1stRB.Checked == true) { spec1.Version = new P4.HeadRevision(); } if (dlg.have1stRB.Checked == true) { spec1.Version = new P4.HaveRevision(); } // build spec 2 if (dlg.specifier2ndRB.Checked == true) { // #revision if (dlg.specifier2ndCB.SelectedIndex == 0) { if (dlg.path2ValueTB.Text == string.Empty) { spec2.Version = null; } else { try { int rev2 = Convert.ToInt32(dlg.path2ValueTB.Text); spec2.Version = new P4.Revision(rev2); } catch (Exception) { MessageBox.Show(string.Format(Resources.DiffDlg_InvalidRevisionSpecifier, dlg.path1ValueTB.Text), Resources.PerforceSCM, MessageBoxButtons.OK); Show(paths, specifier, value, scm); return(files); } } } // @workspace if (dlg.specifier2ndCB.SelectedIndex == 4) { if (dlg.path2ValueTB.Text == string.Empty) { spec2.Version = null; } else { string ws2 = dlg.path2ValueTB.Text; spec2.Version = new P4.ClientNameVersion(ws2); } } // @date/time if (dlg.specifier2ndCB.SelectedIndex == 2) { DateTime dt2 = dlg.path2dateTimePicker.Value; spec2.Version = new P4.DateTimeVersion(dt2); } // @changelist if (dlg.specifier2ndCB.SelectedIndex == 1) { if (dlg.path2ValueTB.Text == string.Empty) { spec2.Version = null; } else { try { int cl2 = Convert.ToInt32(dlg.path2ValueTB.Text); spec2.Version = new P4.ChangelistIdVersion(cl2); } catch (Exception) { MessageBox.Show(string.Format(Resources.DiffDlg_InvalidChangelistSpecifier, dlg.path1ValueTB.Text), Resources.PerforceSCM, MessageBoxButtons.OK); Show(paths, specifier, value, scm); return(files); } } } // @label if (dlg.specifier2ndCB.SelectedIndex == 3) { if (dlg.path2ValueTB.Text == string.Empty) { spec2.Version = null; } else { string lb2 = dlg.path2ValueTB.Text; spec2.Version = new P4.LabelNameVersion(lb2); } } } if (dlg.workspace2ndRB.Checked == true) { // if diffing with local path, get that from the file metadata // and null out the spec's depot path if (spec2.DepotPath != null) { P4.FileMetaData fmd = scm.GetFileMetaData(spec2.DepotPath.Path); if (fmd != null) { spec2.LocalPath = fmd.LocalPath; spec2.DepotPath = null; } } } if (dlg.latest2ndRB.Checked == true) { spec2.Version = new P4.HeadRevision(); } if (dlg.have2ndRB.Checked == true) { spec2.Version = new P4.HaveRevision(); } files.Add(spec1); files.Add(spec2); IList <P4.FileMetaData> checkForValid = scm.GetFileMetaData(files, null); if (checkForValid == null || (checkForValid != null && checkForValid.Count < 2)) { if (scm.Connection.Repository.Connection.LastResults.ErrorList != null) { P4.P4ClientErrorList invalid = scm.Connection.Repository.Connection.LastResults.ErrorList; string message = string.Empty; foreach (P4ClientError error in invalid) { message = message + error.ErrorMessage; } MessageBox.Show(message); Show(paths, specifier, value, scm); return(files); } } if (files != null) { scm.Diff2Files(files); } return(files); } } return(null); }
public DiffDlg(IList <string> paths, string specifier, string value, P4ScmProvider scm) { PreferenceKey = "DiffDlg"; _scm = scm; _paths = paths; InitializeComponent(); this.Icon = Images.icon_p4vs_16px; if (components == null) { components = new System.ComponentModel.Container(); } // // imageList1 // imageList1 = new System.Windows.Forms.ImageList(components); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; this.imageList1.Images.Add("revision_icon_base.png", Images.revision_icon_base); this.imageList1.Images.Add("submitted_change_icon.png", Images.submitted_change_icon); this.imageList1.Images.Add("datetime.png", Images.datetime); this.imageList1.Images.Add("labels_icon.png", Images.labels_icon); this.imageList1.Images.Add("clients_icon.png", Images.clients_icon); this.imageList1.Images.Add("portrait.png", Images.portrait); this.imageList1.Images.Add("client_folder.png", Images.client_folder); this.imageList1.Images.Add("depot_folder.png", Images.depot_folder); latest1stRBFmt = latest1stRB.Text; have1stRBFmt = have1stRB.Text; latest2ndRBFmt = latest2ndRB.Text; have2ndRBFmt = have2ndRB.Text; // dialog called from workspace tool window if (specifier == "workspace") { } // dialog called from solution explorer or VS menu if (specifier == "revision" || specifier == "explorer") { int latest = 0; int have = 0; // set up top path path1TB.Text = paths[0]; P4.FileMetaData file1 = scm.GetFileMetaData(paths[0]); if (file1 != null) { latest = file1.HeadRev; have = file1.HaveRev; latest1stRB.Text = string.Format(latest1stRBFmt, latest); have1stRB.Text = string.Format(have1stRBFmt, have); specifier1stCB.SelectedIndex = 0; latest1stRB.Checked = true; specifier1stCB.SelectedIndex = 0; if ((string.IsNullOrEmpty(path1ValueTB.Text) == true || string.IsNullOrEmpty(path1ValueTB.Text) == true) && (specifier1stRB.Checked == true)) { diffBtn.Enabled = false; } else { diffBtn.Enabled = true; } // set up bottom path path2TB.Text = paths[0]; latest2ndRB.Text = string.Format(latest2ndRBFmt, latest); have2ndRB.Text = string.Format(have2ndRBFmt, have); specifier2ndCB.SelectedIndex = 0; have2ndRB.Checked = true; if ((string.IsNullOrEmpty(path2ValueTB.Text) == true || string.IsNullOrEmpty(path2ValueTB.Text) == true) && (specifier2ndRB.Checked == true)) { diffBtn.Enabled = false; } else { diffBtn.Enabled = true; } } else { string msg = string.Format(Resources.DiffDlg_MissingFileError, paths[0]); MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ArgumentException(msg); } } // dialog called from history if (specifier == "history") { int latest = 0; int have = 0; // set up top path path1TB.Text = paths[0]; P4.FileMetaData file1 = scm.GetFileMetaData(paths[0]); if (file1 != null) { latest = file1.HeadRev; have = file1.HaveRev; latest1stRB.Text = string.Format(latest1stRBFmt, latest); have1stRB.Text = string.Format(have1stRBFmt, have); specifier1stCB.SelectedIndex = 0; if (value == "local") { workspace1stRB.Checked = true; } else { specifier1stRB.Checked = true; path1ValueTB.Text = value; } specifier1stCB.SelectedIndex = 0; if ((string.IsNullOrEmpty(path1ValueTB.Text) == true || string.IsNullOrEmpty(path1ValueTB.Text) == true) && (specifier1stRB.Checked == true)) { diffBtn.Enabled = false; } else { diffBtn.Enabled = true; } // set up bottom path path2TB.Text = paths[0]; latest2ndRB.Text = string.Format(latest2ndRBFmt, latest); have2ndRB.Text = string.Format(have2ndRBFmt, have); specifier2ndCB.SelectedIndex = 0; specifier2ndRB.Checked = true; if ((string.IsNullOrEmpty(path2ValueTB.Text) == true || string.IsNullOrEmpty(path2ValueTB.Text) == true) && (specifier2ndRB.Checked == true)) { diffBtn.Enabled = false; } else { diffBtn.Enabled = true; } } else { string msg = string.Format(Resources.DiffDlg_MissingFileError, paths[0]); MessageBox.Show(msg, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error); throw new ArgumentException(msg); } } // dialog called from submitted changelists tool window if (specifier == "changelist") { // set up top path path1TB.Text = string.Empty; specifier1stCB.SelectedIndex = 1; specifier1stRB.Checked = true; path1ValueTB.Text = value; diffBtn.Enabled = false; // set up bottom path path2TB.Text = string.Empty; specifier2ndCB.SelectedIndex = 0; specifier2ndRB.Checked = true; diffBtn.Enabled = false; } // dialog called from labels tool window if (specifier == "label") { } }
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); } }
public static void ShelveFiles(IList<P4.FileMetaData> files, P4.Changelist changelist, P4ScmProvider ScmProvider, bool ShowUi) { ShelveFileDlg dlg = new ShelveFileDlg(ScmProvider); bool shelvedFiles = changelist.Shelved; dlg.ChangelistId = changelist.Id; if ((files != null) && (files.Count > 0)) { List<P4.FileMetaData> linkedFiles = new List<P4.FileMetaData>(); foreach (P4.FileMetaData fmd in files) { if (fmd.MovedFile != null) { P4.FileMetaData movedFmd = ScmProvider.GetFileMetaData(fmd.MovedFile.Path); linkedFiles.Add(movedFmd); } } foreach (P4.FileMetaData fmd in linkedFiles) { files.Add(fmd); } dlg.SelectedFileList = files; } if (dlg.SelectedFileList.Count <= 0) { dlg.SelectAllCB.Checked = true; } if (!(shelvedFiles)) { dlg.ClearChangelistTB.Checked = false; dlg.ClearChangelistTB.Enabled = false; } DialogResult res = DialogResult.OK; dlg.Description = Resources.ShelveFileDlg_FilesShelvedFromDefaultChangelist; if (changelist.Id > 0) { dlg.Description = string.Format( Resources.ShelveFileDlg_FilesShelvedFromNumberedChangelist, changelist.Id); } if (ShowUi) { res = dlg.ShowDialog(); } if (res == DialogResult.Cancel) { return; } // If requested delete the existing shelved flags if ((changelist.Id > 0) && (dlg.ReplaceExistingShelvedFiles)) { if (ScmProvider.ShelveFiles(changelist.Id, null, P4.ShelveFilesCmdFlags.Delete, true, null) == false) { return; } } P4.ShelveFilesCmdFlags flags = P4.ShelveFilesCmdFlags.Force; if (dlg.DontShelveUnchangedFiles) { flags |= ShelveFilesCmdFlags.LeaveUnchanged; } // Shelve the files if (ScmProvider.ShelveFiles(changelist.Id, dlg.Description, flags, dlg.SelectedFileList) == false) { return; } // If requested, revert the files after shelving if (dlg.RevertAfterShelving) { ScmProvider.RevertFiles(false, true, null, dlg.GetSelectedFiles().ToArray()); } ScmProvider.BroadcastChangelistUpdate(null, new P4ScmProvider.ChangelistUpdateArgs(changelist.Id, P4ScmProvider.ChangelistUpdateArgs.UpdateType.ContentUpdate)); }
public GetRevisionDlg(IList <P4.FileSpec> files, string specifier, string value, P4ScmProvider scm, bool isSolutionIncluded) { PreferenceKey = "GetRevisionDlg"; _scm = scm; _files = files; _isSolutionIncluded = isSolutionIncluded; InitializeComponent(); this.Icon = Images.icon_p4vs_16px; // adding a header with header style set to none so that this // behaves as a single column list. ColumnHeader h = new ColumnHeader(); h.Width = -2; filesListView.Columns.Add(h); IList <P4.FileMetaData> mdl = new List <P4.FileMetaData>(); if (files != null) { foreach (FileSpec fs in files) { // if LocalPath is null, it is likely that this was // launched from somewhere only providing depot paths // in that case, assume all LocalPaths for files will // be null and break. if (fs.LocalPath == null) { break; } if (fs.LocalPath.Path.EndsWith("...")) { mdl.Add(fs); } else { FileMetaData fmd = _scm.GetCachedFile(fs.LocalPath.Path); if (fmd == null) { fmd = _scm.UpdateFileInCache(fs.LocalPath.Path, true); } // if it is still null, it is likely not in Perforce if (fmd != null) { mdl.Add(fmd); } } } if (mdl.Count == 0) { mdl = scm.GetFileMetaData(files, null); } } IList <object> fields = new List <object>(); fields.Add(P4FileTreeListViewItem.SubItemFlag.DepotFullPath); if ((mdl != null) && (mdl.Count > 0)) { foreach (P4.FileMetaData file in mdl) { P4FileTreeListViewItem item = new P4FileTreeListViewItem(null, file, fields); P4FileTreeListViewItem dupe = (P4FileTreeListViewItem)filesListView.FindItemWithText(item.Text); if (dupe != item) { item.Tag = file; item.FileData = file; filesListView.Items.Add(item); } } } // dialog called from workspace tool window if (specifier == "workspace") { specifierCB.SelectedIndex = 4; specifierRB.Checked = true; if (value != null) { ValueTB.Text = value; } } // dialog called from solution explorer or VS menu if (specifier == "revision" || specifier == "explorer") { specifierCB.SelectedIndex = 0; getLatestRB.Checked = true; } // dialog called from submitted changelists tool window if (specifier == "changelist") { specifierCB.SelectedIndex = 1; specifierRB.Checked = true; changelistFilesChk.Enabled = true; if (value != null) { ValueTB.Text = value; } } // dialog called from labels tool window if (specifier == "label") { specifierCB.SelectedIndex = 3; specifierRB.Checked = true; removeChk.Enabled = true; if (value != null) { ValueTB.Text = value; } } }