Пример #1
0
        void JSBeautifierProjectItem(EnvDTE.ProjectItem item)
        {
            if (!_package.OptionsPage.AllowDenyFilter.IsAllowed(item.Name))
            {
                return;
            }

            EnvDTE.Window documentWindow = null;
            try
            {
                if (!item.IsOpen[EnvDTE.Constants.vsViewKindTextView])
                {
                    documentWindow = item.Open(EnvDTE.Constants.vsViewKindTextView);
                    if (documentWindow == null)
                    {
                        return;
                    }
                }

                if (_package.JSBeautifier(item.Document))
                {
                    item.Document.Save();
                }
            }
            catch (COMException)
            {
                _package.OutputString($"Failed to process {item.Name}.");
            }
            finally
            {
                documentWindow?.Close();
            }
        }
Пример #2
0
        public void ValidateNewFileOpenedWithEditor()
        {
            UIThreadInvoker.Invoke((ThreadInvoker) delegate() {
                TestUtils testUtils = new TestUtils();
                testUtils.CloseCurrentSolution(__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave);
                testUtils.CreateEmptySolution(TestContext.TestDir, "CreateEmptySolution");

                //Add new file to the solution and save all
                string name       = "mynewfile";
                EnvDTE.DTE dte    = VsIdeTestHostContext.Dte;
                EnvDTE.Window win = dte.ItemOperations.NewFile(@"Haskell editor Files\Haskell editor", name, EnvDTE.Constants.vsViewKindPrimary);
                Assert.IsNotNull(win);
                dte.ExecuteCommand("File.SaveAll", string.Empty);

                //get the currect misc files state
                object OriginalValueMiscFilesSavesLastNItems = dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value;
                if ((int)OriginalValueMiscFilesSavesLastNItems == 0)
                {
                    dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value = 5;
                }

                //get a handle to the project item in the solution explorer
                EnvDTE.ProjectItem item = win.Document.ProjectItem;
                Assert.IsNotNull(item);

                //close window
                win.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);

                //reset the miscfiles property if it was modified
                if (OriginalValueMiscFilesSavesLastNItems != dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value)
                {
                    dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value = OriginalValueMiscFilesSavesLastNItems;
                }
            });
        }
Пример #3
0
        static void ShowGraphInVS <S>(int k, IAutomaton <S> fa, string name, Func <S, string> describeS = null)
        {
            string filename = name + (name.EndsWith(".dgml") ? "" : ".dgml");

            //Access the top-level VS automation object model
            EnvDTE.DTE dte = (EnvDTE.DTE)VS;
            #region Close the dgml file if it is open
            try
            {
                System.Collections.IEnumerator wins = dte.Windows.GetEnumerator();
                while (wins.MoveNext() == true)
                {
                    EnvDTE.Window w = wins.Current as EnvDTE.Window;
                    if (filename.Equals(w.Caption))
                    {
                        w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                        break;
                    }
                }
            }
            catch
            {
                //the operation dte.Windows.GetEnumerator()
                //may sometimes cause COMException
                //Ignore this exception,
                //then the window with given filename may still be open
                //and VS may ask to save changes, instead of ignoring
                //when the file is subsequently changed on disk
            }
            #endregion
            SaveGraph(k, fa, name, describeS);
            #region Open the dgml file in VS
            try
            {
                var dir          = System.Environment.CurrentDirectory;
                var fullfilename = dir + "/" + filename;
                dte.ExecuteCommand("File.OpenFile", dir + "/" + filename);
            }
            catch
            {
                OpenFileInNewProcess(filename);
            }
            #endregion
        }
        /// <summary>
        /// Loops through each of the items in the project, attempting to extract any sections of code
        /// marked.
        /// </summary>
        /// <param name="dte"> Pointer to Object Model in which all actions should be performed </param>
        private bool ExtractItems(EnvDTE.ProjectItems projSourceItems, EnvDTE._DTE dte, EnvDTE.ProjectItems projDestItems)
        {
            EnvDTE.ProjectItem  projItem            = null;
            EnvDTE.TextDocument textDoc             = null;
            EnvDTE.Properties   extractorProperties = null;
            Extensions          extensions          = null;
            CommentPair         comments            = null;

            EnvDTE.Window w = null;

            bool   fSuccess = true;
            int    i, nItems, nLastIndex;
            string strExtension;

            extractorProperties = m_application.get_Properties("Assignment Manager", "Code Extractor");
            if (extractorProperties == null)
            {
                throw new Exception("The Academic Code Extractor is not properly installed and configured.");
            }
            extensions = extractorProperties.Item("Extensions").Object as Extensions;
            if (extensions == null)
            {
                throw new Exception("The Academic Code Extractor is not properly installed and configured.");
            }

            nItems = projDestItems.Count;
            for (i = 1; i <= nItems; i++)
            {
                projItem = projDestItems.Item(i);
                try
                {
                    if (projItem.ProjectItems.Count > 0)
                    {
                        ExtractItems(projSourceItems.Item(i).ProjectItems, dte, projItem.ProjectItems);
                    }
                    // Note that this will *actually* be happening in an invisible
                    // out-of-process instance of VS, so the user will not be
                    // subjected to appearing / disappearing windows.
                    w       = projItem.Open(EnvDTE.Constants.vsViewKindTextView);
                    textDoc = w.Document.Object("TextDocument") as EnvDTE.TextDocument;

                    strExtension = projItem.get_FileNames(1);

                    nLastIndex = strExtension.LastIndexOf('.');
                    if (nLastIndex == -1)
                    {
                        w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                        continue;                                          // We have no capacity for files with no extension.
                    }
                    strExtension = strExtension.Remove(0, nLastIndex + 1); // Trim off the 'name.' part of 'name.ext'

                    comments = extensions[strExtension];
                    if (comments == null)
                    {
                        w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                        continue;                         // This file has no associated extension type. Ignore it.
                    }

                    fSuccess &= ExtractText(textDoc, comments.BeginComment, comments.EndComment, projSourceItems);

                    w.Close(EnvDTE.vsSaveChanges.vsSaveChangesYes);
                }
                catch (Exception /*e*/)
                {
                    // If we end up here, that simply means that the file
                    // has no text. Since we obviously don't want to remove the
                    // textual tags from a file with no comments...
                    if (w != null)
                    {
                        w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                    }
                }
            }

            return(fSuccess);
        }