Example #1
0
        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));
        }