Implements editor interface required by the Emmet engine based on the Visual Studio editor.
Inheritance: IEmmetEditor
Exemple #1
0
        /// <summary>
        /// Executes Emmet command in the specified view.
        /// </summary>
        /// <param name="context">The view context to execute command in.</param>
        /// <param name="cmdId">Identifier of the command to execute.</param>
        internal bool RunCommand(EmmetEditor context, int cmdId)
        {
            DTE2 dte            = GetService(typeof(DTE)) as DTE2;
            bool ownUndoContext = false;

            try
            {
                if (!dte.UndoContext.IsOpen)
                {
                    ownUndoContext = true;
                    dte.UndoContext.Open("Emmet.NET");
                }

                bool succeeded = _engine.RunCommand(cmdId, context);

                if (ownUndoContext)
                {
                    dte.UndoContext.Close();
                }

                return(succeeded);
            }
            catch (Exception <EmmetEngineExceptionArgs> ex)
            {
                if (ownUndoContext)
                {
                    dte.UndoContext.SetAborted();
                }

                string msg = $"Unexpected error occurred inside of the Emmet engine. {ex.Message}";

                VsShellUtilities.ShowMessageBox(
                    this,
                    msg,
                    "Emmet.NET: Unexpected error.",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return(false);
            }
        }
        /// <summary>
        /// Executes Emmet command in the specified view.
        /// </summary>
        /// <param name="context">The view context to execute command in.</param>
        /// <param name="cmdId">Identifier of the command to execute.</param>
        internal bool RunCommand(EmmetEditor context, int cmdId)
        {
            DTE2 dte = GetService(typeof(DTE)) as DTE2;
            bool ownUndoContext = false;
            try
            {
                if (!dte.UndoContext.IsOpen)
                {
                    ownUndoContext = true;
                    dte.UndoContext.Open("Emmet.NET");
                }

                bool succeeded = _engine.RunCommand(cmdId, context);

                if (ownUndoContext)
                    dte.UndoContext.Close();

                return succeeded;
            }
            catch (Exception<EmmetEngineExceptionArgs> ex)
            {
                if (ownUndoContext)
                    dte.UndoContext.SetAborted();

                string msg = $"Unexpected error occurred inside of the Emmet engine. {ex.Message}";

                VsShellUtilities.ShowMessageBox(
                    this,
                    msg,
                    "Emmet.NET: Unexpected error.",
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return false;
            }
        }