private void actionBtn_Click(object sender, EventArgs e) { previewTB.Clear(); string sourceSelection = string.Empty; if (sourceCB.Enabled) { sourceSelection = this.sourceCB.SelectedItem.ToString(); } else if (sourceTB.Enabled) { sourceSelection = this.sourceTB.Text; } P4.Stream effectiveTarget = _scm.GetStream(_target, null, null); P4.Stream effectiveSource = _scm.GetStream(sourceSelection, null, null); if (effectiveSource == null || effectiveTarget == null) { return; } if (effectiveTarget.Type == P4.StreamType.Virtual) { if (effectiveTarget.BaseParent != null) { effectiveTarget = _scm.GetStream(effectiveTarget.BaseParent.Path, null, null); } else if (effectiveTarget.Parent != null) { effectiveTarget = _scm.GetStream(effectiveTarget.Parent.Path, null, null); } } if (effectiveSource.Type == P4.StreamType.Virtual) { if (effectiveSource.BaseParent != null) { effectiveSource = _scm.GetStream(effectiveSource.BaseParent.Path, null, null); } else if (effectiveSource.Parent != null) { effectiveSource = _scm.GetStream(effectiveSource.Parent.Path, null, null); } } P4.Options opts = new P4.Options(); IList <P4.FileSpec> files = new List <P4.FileSpec>(); if ((effectiveSource.Parent != null && effectiveSource.Parent.Path == effectiveTarget.Id) || (effectiveSource.BaseParent != null && effectiveSource.BaseParent.Path == effectiveTarget.Id)) { opts["-S"] = effectiveSource.Id; } else if ((effectiveTarget.Parent != null && effectiveTarget.Parent.Path == effectiveSource.Id) || (effectiveTarget.BaseParent != null && effectiveTarget.BaseParent.Path == effectiveSource.Id)) { opts["-S"] = effectiveTarget.Id; opts["-r"] = null; } if (_action == "merge") { files = _scm.MergeFiles(opts); } else if (_action == "copy") { files = _scm.CopyFiles(opts); } P4.P4CommandResult results = _scm.Connection.Repository.Connection.LastResults; string preview = null; if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null) { previewTB.Text = preview; foreach (P4.P4ClientError error in _scm.Connection.Repository.Connection.LastResults.ErrorList) { previewTB.AppendText(error.ErrorMessage); } DialogResult = DialogResult.None; return; } if (files != null) { // if there are files to merge or copy, offer // changelist selection and submit or save int count = files.Count(); string target = targetTB.Text; string action = null; string summary = string.Empty; P4.Changelist getDesc = _scm.GetChangelist(-1); string newChangeDescription = getDesc.Description; IList <P4.Changelist> changes = _scm.GetAvailibleChangelists(-1); if (count > 1) { if (_action == "merge") { summary = string.Format(Resources.P4VsProviderService_MergeSummary, count); if (newChangeDescription == null || newChangeDescription == Resources.DefaultChangeListDescription) { newChangeDescription = string.Format( Resources.P4VsProviderService_MergeChangeDescription, target); } } else if (_action == "copy") { summary = string.Format(Resources.P4VsProviderService_CopySummary, count); if (newChangeDescription == null || newChangeDescription == Resources.DefaultChangeListDescription) { newChangeDescription = string.Format( Resources.P4VsProviderService_CopyChangeDescription, target); } if (submitCopiedRB.Checked) { string[] fileStringArray = new string[count]; for (int idx = 0; idx < count; idx++) { fileStringArray[idx] = files[idx].LocalPath.Path; } _scm.SubmitFiles(newChangeDescription, null, false, fileStringArray); return; } } } else { if (_action == "merge") { summary = Resources.P4VsProviderService_Merge1Summary; if (newChangeDescription == null || newChangeDescription == Resources.DefaultChangeListDescription) { newChangeDescription = string.Format( Resources.P4VsProviderService_Merge1ChangeDescription, target); } } else if (_action == "copy") { summary = Resources.P4VsProviderService_Copy1Summary; if (newChangeDescription == null || newChangeDescription == Resources.DefaultChangeListDescription) { newChangeDescription = string.Format( Resources.P4VsProviderService_Copy1ChangeDescription, target); } if (submitCopiedRB.Checked) { _scm.SubmitFiles(newChangeDescription, null, false, files[0].LocalPath.Path); return; } } } int changeListId = -1; P4.Changelist changelist = SelectChangelistDlg.ShowChooseChangelistSubmit( summary, changes, ref newChangeDescription, out action, true, true, _scm); changeListId = changelist.Id; if (changeListId == -2) { // user hit 'No' return; } opts = new P4.Options(); if (changeListId > 0) { opts["-c"] = changeListId.ToString(); } P4.Changelist changeToSubmit = _scm.Connection.Repository.NewChangelist(); if (changeListId == -1) { // Overwrite new changelist files. If default has files in it, a new // changelist will automatically get those files. changeToSubmit.Files = files as IList <P4.FileMetaData>; changeToSubmit.Description = changelist.Description; changeToSubmit = _scm.SaveChangelist(changeToSubmit, null); opts["-c"] = changeToSubmit.Id.ToString(); changeListId = changeToSubmit.Id; } if (opts.ContainsKey("-c")) { Int32 c = Convert.ToInt32(opts["-c"]); changeToSubmit = _scm.GetChangelist(c); _scm.MoveFilesToChangeList(c, changelist.Description, files); changeListId = changeToSubmit.Id; } // done, unless submit was hit if (action == "submit") { changeToSubmit.Description = changelist.Description; if (changeListId > 0) { SubmitDlg.SubmitPendingChanglist(changeToSubmit, changeToSubmit.Files, _scm); } else { IList <string> list = new List <string>(); foreach (P4.FileSpec fs in files) { list.Add(fs.LocalPath.Path.ToString()); } SubmitDlg.SubmitFiles(list, _scm, false, changeToSubmit.Description); } } } returnedFiles = files; DialogResult = DialogResult.OK; return; }