当前位置: 首页>>代码示例>>C#>>正文


C# Document.Activate方法代码示例

本文整理汇总了C#中Document.Activate方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Activate方法的具体用法?C# Document.Activate怎么用?C# Document.Activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Activate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cleanup

        /// <summary>
        /// Attempts to run code cleanup on the specified document.
        /// </summary>
        /// <param name="document">The document for cleanup.</param>
        /// <param name="textBuffer">The text buffer for the document.</param>
        internal void Cleanup(Document document, ITextBuffer textBuffer)
        {
            if (!_codeCleanupAvailabilityLogic.ShouldCleanup(document, true)) return;

            // Make sure the document to be cleaned up is active, required for some commands like format document.
            document.Activate();

            if (_package.IDE.ActiveDocument != document)
            {
                OutputWindowHelper.WriteLine(document.Name + " did not complete activation before cleaning started.");
            }

            _undoTransactionHelper.Run(
                delegate
                {
                    _package.IDE.StatusBar.Text = String.Format("EditorConfig is cleaning '{0}'...", document.Name);

                    // Perform the set of configured cleanups based on the language.
                    RunCodeCleanupGeneric(document, textBuffer);

                    _package.IDE.StatusBar.Text = String.Format("EditorConfig cleaned '{0}'.", document.Name);
                },
                delegate(Exception ex)
                {
                    OutputWindowHelper.WriteLine(String.Format("EditorConfig stopped cleaning '{0}': {1}", document.Name, ex));
                    _package.IDE.StatusBar.Text = String.Format("EditorConfig stopped cleaning '{0}'.  See output window for more details.", document.Name);
                });
        }
开发者ID:editorconfig,项目名称:editorconfig-visualstudio,代码行数:33,代码来源:CodeCleanupManager.cs

示例2: Read

        public override string Read(FileInfo fileInfo)
        {
            object nullobj = System.Reflection.Missing.Value;
            object readOnly = true;
            object noEncodingDialog = true;
            object confirmConversions = false;
            object visible = false;
            object filePath = fileInfo.FullName;
            object openAndRepair = false;

            object openFormat = WdOpenFormat.wdOpenFormatAuto;

            _wordDoc = WordApp.Documents.Open(
                ref filePath, ref confirmConversions, ref readOnly, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref openFormat,
                ref nullobj, ref visible, ref openAndRepair, ref nullobj, ref noEncodingDialog,
                ref nullobj);

            // Make this document the active document.
            _wordDoc.Activate();

            string result = WordApp.ActiveDocument.Content.Text;

            _wordDoc.Close(ref nullobj, ref nullobj, ref nullobj);

            return result;
        }
开发者ID:NecoMeco,项目名称:BookToVoice,代码行数:27,代码来源:DocReader.cs

示例3: Open

        // Open a new document
        public void Open()
        {
            object missing = System.Reflection.Missing.Value;
            oDoc = oWordApplic.Application.Documents.Add(ref missing, ref missing, ref missing, ref missing);

            oDoc.Activate();
        }
开发者ID:zwxscience,项目名称:Paper-management-system,代码行数:8,代码来源:ToWordDoc.cs

示例4: Open

        private void Open(string tempDoc)
        {
            object objTempDoc = tempDoc;
            object objMissing = System.Reflection.Missing.Value;

            objDocLast = objApp.Documents.Open(
                 ref objTempDoc,    //FileName
                 ref objMissing,   //ConfirmVersions
                 ref objMissing,   //ReadOnly
                 ref objMissing,   //AddToRecentFiles
                 ref objMissing,   //PasswordDocument
                 ref objMissing,   //PasswordTemplate
                 ref objMissing,   //Revert
                 ref objMissing,   //WritePasswordDocument
                 ref objMissing,   //WritePasswordTemplate
                 ref objMissing,   //Format
                 ref objMissing,   //Enconding
                 ref objMissing,   //Visible
                 ref objMissing,   //OpenAndRepair
                 ref objMissing,   //DocumentDirection
                 ref objMissing,   //NoEncodingDialog
                 ref objMissing    //XMLTransform
                 );

            objDocLast.Activate();
        }
开发者ID:honghaijei,项目名称:ProblemSetGenerator,代码行数:26,代码来源:Helper.cs

示例5: Format

        public void Format(Document document, IDocumentFilter filter)
        {
            var currentDoc = dte.ActiveDocument;

            document.Activate();

            if (dte.ActiveWindow.Kind == "Document")
            {
                if (filter.IsAllowed(document))
                    dte.ExecuteCommand(cmd.Command, cmd.Arguments);
            }

            currentDoc.Activate();
        }
开发者ID:Elders,项目名称:VSE-FormatDocumentOnSave,代码行数:14,代码来源:VisualStudioCommandFormatter.cs

示例6: SelectCodeItem

        /// <summary>
        /// Attempts to select the text of the specified code item.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="codeItem">The code item.</param>
        internal static void SelectCodeItem(Document document, BaseCodeItem codeItem)
        {
            var textDocument = document.GetTextDocument();
            if (textDocument == null) return;

            try
            {
                codeItem.RefreshCachedPositionAndName();
                textDocument.Selection.MoveToPoint(codeItem.StartPoint, false);
                textDocument.Selection.MoveToPoint(codeItem.EndPoint, true);

                textDocument.Selection.SwapAnchor();
            }
            catch (Exception)
            {
                // Select operation may fail if element is no longer available.
            }
            finally
            {
                // Always set focus within the code editor window.
                document.Activate();
            }
        }
开发者ID:Mediomondo,项目名称:codemaid,代码行数:28,代码来源:TextDocumentHelper.cs

示例7: MoveToCodeItem

        /// <summary>
        /// Attempts to move the cursor to the specified code item.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="codeItem">The code item.</param>
        /// <param name="centerOnWhole">True if the whole element should be used for centering.</param>
        internal static void MoveToCodeItem(Document document, BaseCodeItem codeItem, bool centerOnWhole)
        {
            var textDocument = document.GetTextDocument();
            if (textDocument == null) return;

            try
            {
                object viewRangeEnd = null;
                TextPoint navigatePoint = null;

                codeItem.RefreshCachedPositionAndName();
                textDocument.Selection.MoveToPoint(codeItem.StartPoint, false);

                if (centerOnWhole)
                {
                    viewRangeEnd = codeItem.EndPoint;
                }

                var codeItemElement = codeItem as BaseCodeItemElement;
                if (codeItemElement != null)
                {
                    navigatePoint = codeItemElement.CodeElement.GetStartPoint(vsCMPart.vsCMPartNavigate);
                }

                textDocument.Selection.AnchorPoint.TryToShow(vsPaneShowHow.vsPaneShowCentered, viewRangeEnd);

                if (navigatePoint != null)
                {
                    textDocument.Selection.MoveToPoint(navigatePoint, false);
                }
                else
                {
                    textDocument.Selection.FindText(codeItem.Name, (int)vsFindOptions.vsFindOptionsMatchInHiddenText);
                    textDocument.Selection.MoveToPoint(textDocument.Selection.AnchorPoint, false);
                }
            }
            catch (Exception)
            {
                // Move operation may fail if element is no longer available.
            }
            finally
            {
                // Always set focus within the code editor window.
                document.Activate();
            }
        }
开发者ID:Mediomondo,项目名称:codemaid,代码行数:52,代码来源:TextDocumentHelper.cs

示例8: FormatDocument

		/// <summary>
		/// Formats and re-saves a document.
		/// </summary>
		/// <param name="doc">The document to format.</param>
		/// <exception cref="System.ArgumentNullException">
		/// Thrown if <paramref name="doc" /> is <see langword="null" />.
		/// </exception>
		public static void FormatDocument(Document doc)
		{
			if (doc == null)
			{
				throw new ArgumentNullException("doc");
			}

			// You can only format the active document, so we have to temporarily
			// activate each document that needs formatting.
			Document active = CodeRush.Documents.Active;
			if (doc != active)
			{
				doc.Activate();
			}
			CodeRush.Documents.Format();
			doc.Save();
			if (doc != active)
			{
				active.Activate();
			}
		}
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:28,代码来源:FormatOnSavePlugin.cs

示例9: OnDocumentSaved

        /// <summary>
        /// Called when a document is saved.
        /// </summary>
        /// <param name="document">
        /// The document that was saved.
        /// </param>
        private void OnDocumentSaved(Document document)
        {
            if (this.docsInReformattingList.Remove(document))
            {
                return;
            }

            Window previouslyShownWindow = null;
            try
            {
                this.docsInReformattingList.Add(document);
                previouslyShownWindow = this.dte.ActiveWindow;
                document.Activate();
                this.dte.ExecuteCommand(ReSharperSilentCleanupCodeCommandName);
                if (!document.Saved)
                {
                    document.Save();
                }
            }
            finally
            {
                this.docsInReformattingList.Remove(document);
                if (previouslyShownWindow != null)
                {
                    previouslyShownWindow.Activate();
                }
            }
        }
开发者ID:salfab,项目名称:ReSharper.AutoFormatOnSave,代码行数:34,代码来源:ReSharper.AutoFormatOnSavePackage.cs

示例10: Cleanup

        /// <summary>
        /// Attempts to run code cleanup on the specified document.
        /// </summary>
        /// <param name="document">The document for cleanup.</param>
        /// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
        internal void Cleanup(Document document, bool isAutoSave = false)
        {
            if (!_codeCleanupAvailabilityLogic.ShouldCleanup(document, true)) return;

            // Make sure the document to be cleaned up is active, required for some commands like
            // format document.
            document.Activate();

            if (_package.ActiveDocument != document)
            {
                OutputWindowHelper.WarningWriteLine(
                    string.Format("Activation was not completed before cleaning began for '{0}'", document.Name));
            }

            // Conditionally start cleanup with reorganization.
            if (Settings.Default.Reorganizing_RunAtStartOfCleanup)
            {
                _codeReorderManager.Reorganize(document, isAutoSave);
            }

            _undoTransactionHelper.Run(
                () => !(isAutoSave && Settings.Default.General_SkipUndoTransactionsDuringAutoCleanupOnSave),
                delegate
                {
                    var cleanupMethod = FindCodeCleanupMethod(document);
                    if (cleanupMethod != null)
                    {
                        OutputWindowHelper.DiagnosticWriteLine(
                            string.Format("CodeCleanupManager.Cleanup started for '{0}'", document.FullName));

                        _package.IDE.StatusBar.Text = string.Format("CodeMaid is cleaning '{0}'...", document.Name);

                        // Perform the set of configured cleanups based on the language.
                        cleanupMethod(document, isAutoSave);

                        _package.IDE.StatusBar.Text = string.Format("CodeMaid cleaned '{0}'.", document.Name);

                        OutputWindowHelper.DiagnosticWriteLine(
                            string.Format("CodeCleanupManager.Cleanup completed for '{0}'", document.FullName));
                    }
                },
                delegate(Exception ex)
                {
                    OutputWindowHelper.ExceptionWriteLine(
                        string.Format("Stopped cleaning '{0}'", document.Name), ex);
                    _package.IDE.StatusBar.Text = string.Format("CodeMaid stopped cleaning '{0}'.  See output window for more details.", document.Name);
                });
        }
开发者ID:nhammadi,项目名称:codemaid,代码行数:53,代码来源:CodeCleanupManager.cs

示例11: Cleanup

        /// <summary>
        /// Attempts to run code cleanup on the specified document.
        /// </summary>
        /// <param name="document">The document for cleanup.</param>
        internal void Cleanup(Document document)
        {
            if (!_codeCleanupAvailabilityLogic.CanCleanupDocument(document, true)) return;

            // Make sure the document to be cleaned up is active, required for some commands like format document.
            document.Activate();

            // Check for designer windows being active, which should not proceed with cleanup as the code isn't truly active.
            if (document.ActiveWindow.Caption.EndsWith(" [Design]"))
            {
                return;
            }

            if (_package.ActiveDocument != document)
            {
                OutputWindowHelper.WarningWriteLine($"Activation was not completed before cleaning began for '{document.Name}'");
            }

            // Conditionally start cleanup with reorganization.
            if (Settings.Default.Reorganizing_RunAtStartOfCleanup)
            {
                _codeReorganizationManager.Reorganize(document);
            }

            new UndoTransactionHelper(_package, $"CodeMaid Cleanup for '{document.Name}'").Run(
                delegate
                {
                    var cleanupMethod = FindCodeCleanupMethod(document);
                    if (cleanupMethod != null)
                    {
                        OutputWindowHelper.DiagnosticWriteLine($"CodeCleanupManager.Cleanup started for '{document.FullName}'");
                        _package.IDE.StatusBar.Text = $"CodeMaid is cleaning '{document.Name}'...";

                        // Perform the set of configured cleanups based on the language.
                        cleanupMethod(document);

                        _package.IDE.StatusBar.Text = $"CodeMaid cleaned '{document.Name}'.";
                        OutputWindowHelper.DiagnosticWriteLine($"CodeCleanupManager.Cleanup completed for '{document.FullName}'");
                    }
                });
        }
开发者ID:reima,项目名称:codemaid,代码行数:45,代码来源:CodeCleanupManager.cs

示例12: Open

 public bool Open(string wordName, bool showApp)
 {
     bool result = false;
     if (string.IsNullOrEmpty(wordName)) return false;
     try
     {
         object fileName = wordName;
         object readOnly = false;
         object isVisible = true;
         object missing = Missing.Value;
         Document = wordApp.Documents.Open(ref fileName, ref missing, ref readOnly,
           ref missing, ref missing, ref missing, ref missing, ref missing,
           ref missing,
           ref missing, ref missing, ref isVisible);
         Document.Activate();
         wordApp.Visible = showApp;
         result = true;
     }
     catch (Exception ex)
     {
         Quit();
         throw new Exception(string.Format("Cannot open the file:{0}", wordName), ex);
     }
     return result;
 }
开发者ID:EinsteinSu,项目名称:EsuCommon,代码行数:25,代码来源:WordOperationBase.cs

示例13: ConverteerBestand

        /// <summary>
        /// Methode die het word document opslaat als PDF bestand.
        /// </summary>
        /// <param name="excelBestand">Bestand om te zetten</param>
        public void ConverteerBestand(FileInfo wordBestand)
        {
            //Volledig pad ophalen en opslaan als object voor word.Documents.Open methode
            Object filename = (Object)wordBestand.FullName;

            //Optionele argumenten opvullen met leeg object
            doc = word.Documents.Open(ref filename, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing);
            doc.Activate();

            object outputFileName = String.Format("{0}.pdf", wordBestand.FullName.Substring(0, wordBestand.FullName.LastIndexOf('.')));
            object fileFormat = WdSaveFormat.wdFormatPDF;

            //Document opslaanals PDF
            doc.SaveAs(ref outputFileName,
                ref fileFormat, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            //Document sluiten maar word nog niet.
            //Doc moet naar _Document geconverteerd worden zodat de Close methode opgeroepen kan worden.
            if (doc != null)
            {
                object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
                ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
                doc = null;
            }
        }
开发者ID:EusebiusVD,项目名称:Stage,代码行数:35,代码来源:WordNaarPDF.cs


注:本文中的Document.Activate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。