Пример #1
0
        private bool RemoveItem(uint vsItemId)
        {
            IVsProject2 vsProject = hierarchy as IVsProject2;

            if (vsProject == null)
            {
                return(false);
            }
            int result = 0;
            int hr     = vsProject.RemoveItem(0, vsItemId, out result);

            return(hr == VSConstants.S_OK && result == 1);
        }
Пример #2
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnItem> toDelete = new List <SvnItem>(e.Selection.GetSelectedSvnItems(true));

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

            string body;

            // We do as if we are Visual Studio here: Same texts, same behavior (same chance on data loss)
            if (toDelete.Count == 1)
            {
                body = string.Format(CommandStrings.XWillBeDeletedPermanently, toDelete[0].Name);
            }
            else
            {
                body = CommandStrings.TheSelectedItemsWillBeDeletedPermanently;
            }

            if (DialogResult.OK != mb.Show(body, "", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation))
            {
                return; // No delete
            }
            int hr = VSErr.S_OK;

            foreach (SvnItem item in toDelete)
            {
                {
                    IVsUIHierarchy hier;
                    uint           id;
                    IVsWindowFrame frame;

                    if (VsShellUtilities.IsDocumentOpen(e.Context, item.FullPath, Guid.Empty, out hier, out id, out frame))
                    {
                        hr = frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);
                        if (!VSErr.Succeeded(hr))
                        {
                            break; // Show error and cancel further actions
                        }
                    }
                }

                try
                {
                    if (item.IsVersioned)
                    {
                        using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient())
                        {
                            SvnDeleteArgs da = new SvnDeleteArgs();
                            da.Force = true;
                            cl.Delete(item.FullPath, da);
                        }
                    }
                    else
                    {
                        SvnItem.DeleteNode(item.FullPath);
                    }
                }
                finally
                {
                    // TODO: Notify the working copy explorer here!
                    // (Maybe via one of these methods below)

                    e.GetService <ISvnStatusCache>().MarkDirtyRecursive(item.FullPath);
                    e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(item.FullPath);
                }

                // Ok, now remove the file from projects

                IProjectFileMapper pfm = e.GetService <IProjectFileMapper>();

                List <SccProject> projects = new List <SccProject>(pfm.GetAllProjectsContaining(item.FullPath));

                foreach (SccProject p in projects)
                {
                    IVsProject2 p2 = p.RawHandle as IVsProject2;

                    if (p2 == null)
                    {
                        continue;
                    }

                    VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                    int  found;
                    uint id;
                    if (!VSErr.Succeeded(p2.IsDocumentInProject(item.FullPath, out found, prio, out id)) || found == 0)
                    {
                        continue; // Probably already removed (mapping out of synch?)
                    }
                    hr = p2.RemoveItem(0, id, out found);

                    if (!VSErr.Succeeded(hr))
                    {
                        break;
                    }
                }
            }

            if (!VSErr.Succeeded(hr))
            {
                mb.Show(Marshal.GetExceptionForHR(hr).Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }