Ejemplo n.º 1
0
        internal Result Save(ITextBuffer textBuffer)
        {
            // In order to save the ITextBuffer we need to get a document cookie for it.  The only way I'm
            // aware of is to use the path moniker which is available for the accompanying ITextDocment
            // value.
            //
            // In many types of files (.cs, .vb, .cpp) there is usually a 1-1 mapping between ITextBuffer
            // and the ITextDocument.  But in any file type where an IProjectionBuffer is common (.js,
            // .aspx, etc ...) this mapping breaks down.  To get it back we must visit all of the
            // source buffers for a projection and individually save them
            var result = Result.Success;

            foreach (var sourceBuffer in TextBufferUtil.GetSourceBuffersRecursive(textBuffer))
            {
                // The inert buffer doesn't need to be saved.  It's used as a fake buffer by web applications
                // in order to render projected content
                if (sourceBuffer.ContentType == _textBufferFactoryService.InertContentType)
                {
                    continue;
                }

                var sourceResult = SaveCore(sourceBuffer);
                if (sourceResult.IsError)
                {
                    result = sourceResult;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Do a save operation using the <see cref="IOleCommandTarget"/> approach if this is a buffer
        /// for the active text view.  Returns null when this operation couldn't be performed and a
        /// non-null value when the operation was actually executed.
        /// </summary>
        private bool?SaveActiveTextView(ITextBuffer textBuffer)
        {
            IWpfTextView activeTextView;

            if (!_vsAdapter.TryGetActiveTextView(out activeTextView) ||
                !TextBufferUtil.GetSourceBuffersRecursive(activeTextView.TextBuffer).Contains(textBuffer))
            {
                return(null);
            }

            return(SafeExecuteCommand(activeTextView, "File.SaveSelectedItems"));
        }
Ejemplo n.º 3
0
        public virtual bool IsDirty(ITextBuffer textBuffer)
        {
            // If this is an IProjectionBuffer then we need to dig into the actual ITextBuffer values
            // which make it up.
            foreach (var sourceTextBuffer in TextBufferUtil.GetSourceBuffersRecursive(textBuffer))
            {
                // The inert buffer doesn't need to be considered.  It's used as a fake buffer by web applications
                // in order to render projected content
                if (sourceTextBuffer.ContentType == _textBufferFactoryService.InertContentType)
                {
                    continue;
                }

                if (_textDocumentFactoryService.TryGetTextDocument(sourceTextBuffer, out ITextDocument document) && document.IsDirty)
                {
                    return(true);
                }
            }

            return(false);
        }