Ejemplo n.º 1
0
        public void OpenGroup(DocumentGroup group)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (group == null)
            {
                return;
            }

            if (group.Positions != null)
            {
                using (var stream = new VsOleStream())
                {
                    stream.Write(group.Positions, 0, group.Positions.Length);
                    stream.Seek(0, SeekOrigin.Begin);

                    var hr = DocumentWindowMgr.ReopenDocumentWindows(stream);
                    if (hr != VSConstants.S_OK)
                    {
                        Debug.Assert(false, "ReopenDocumentWindows", String.Empty, hr);
                    }
                }
            }

            try
            {
                var missingFiles = new List <string>();
                var openFiles    = Package.Environment.GetDocumentFiles();
                foreach (var file in group.Files)
                {
                    if (File.Exists(file))
                    {
                        if (!openFiles.Any(f => string.Compare(f, file, true) == 0))
                        {
                            OpenFile(file);
                        }
                    }
                    else
                    {
                        missingFiles.Add(file);
                    }
                }

                if (missingFiles.Count > 0)
                {
                    MessageBox.Show("The following files could not be found and were not restored:\n\n"
                                    + String.Join("\n", missingFiles), "SaveAllTheTabs");
                }
            }
            catch (Exception ex)
            {
                Debug.Assert(false, "Windows for the solution were restored, but an error occurred while opening external files.\n\n" + nameof(OpenGroup), ex.ToString());
            }
        }
Ejemplo n.º 2
0
        public void OpenGroup(DocumentGroup group)
        {
            if (group == null)
            {
                return;
            }

            using (var stream = new VsOleStream())
            {
                stream.Write(group.Positions, 0, group.Positions.Length);
                stream.Seek(0, SeekOrigin.Begin);

                var hr = DocumentWindowMgr.ReopenDocumentWindows(stream);
                if (hr != VSConstants.S_OK)
                {
                    Debug.Assert(false, "ReopenDocumentWindows", String.Empty, hr);
                }
            }
        }
Ejemplo n.º 3
0
        public void SaveGroup(string name, int?slot = null)
        {
            if (DocumentWindowMgr == null)
            {
                Debug.Assert(false, "IVsUIShellDocumentWindowMgr", String.Empty, 0);
                return;
            }

            if (!Package.Environment.GetDocumentWindows().Any())
            {
                return;
            }

            var isBuiltIn = IsBuiltInGroup(name);

            if (isBuiltIn)
            {
                slot = null;
            }

            var group = Groups.FindByName(name);

            var files = new DocumentFilesHashSet(Package.Environment.GetDocumentFiles().OrderBy(Path.GetFileName));

            //var bps = Package.Environment.GetMatchingBreakpoints(files, StringComparer.OrdinalIgnoreCase));

            using (var stream = new VsOleStream())
            {
                var hr = DocumentWindowMgr.SaveDocumentWindowPositions(0, stream);
                if (hr != VSConstants.S_OK)
                {
                    Debug.Assert(false, "SaveDocumentWindowPositions", String.Empty, hr);

                    if (group != null)
                    {
                        Groups.Remove(group);
                    }
                    return;
                }
                stream.Seek(0, SeekOrigin.Begin);

                var documents = String.Join(", ", files.Select(Path.GetFileName));

                if (group == null)
                {
                    group = new DocumentGroup
                    {
                        Name        = name,
                        Description = documents,
                        Files       = files,
                        Positions   = stream.ToArray()
                    };

                    TrySetSlot(group, slot);
                    if (isBuiltIn)
                    {
                        Groups.Insert(0, group);
                    }
                    else
                    {
                        Groups.Add(group);
                    }
                }
                else
                {
                    SaveUndoGroup(group);

                    group.Description = documents;
                    group.Files       = files;
                    group.Positions   = stream.ToArray();

                    TrySetSlot(group, slot);
                }
            }
        }