コード例 #1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            using (var copyWithLocationOptions = new CopyWithLocationOptions())
            {
                copyWithLocationOptions.LoadDefaultSettingsIfNecessary();

                ExtendedCopier.CopySelectionWithLocation(_dte, copyWithLocationOptions);
            }
        }
コード例 #2
0
        public static void CopySelectionWithLocation(DTE dte, CopyWithLocationOptions options)
        {
            var activeDocument = dte.ActiveDocument;

            if (activeDocument == null)
            {
                return;
            }

            var textSelection = activeDocument.Selection as TextSelection;

            if (textSelection == null)
            {
                return;
            }

            var methodName    = textSelection.GetMethodName();
            var className     = textSelection.GetClassName();
            var selectedLines = textSelection.GetSelectedLines();

            var format =
                string.IsNullOrEmpty(className)
                    ? options.CodeBlockCopyFormat
                    : string.IsNullOrEmpty(methodName)
                          ? options.ClassCopyFormat
                          : options.MethodCopyFormat;

            if (string.IsNullOrEmpty(className))
            {
                className  = activeDocument.Path;
                methodName = activeDocument.Name;
            }

            var selectionWithLocation = string.Format(format, className, methodName, selectedLines, textSelection.Text);

            Clipboard.SetText(selectionWithLocation);
        }