Exemple #1
0
        /// <summary>
        /// Raises events for when a file load/save occurs.
        /// </summary>
        private void RaiseFileActionChangedEvent(DateTime actionTime, FileActionTypes actionType, string filePath)
        {
            _raisingFileActionChangedEvent = true;

            try
            {
                if ((actionType & FileActionTypes.ContentLoadedFromDisk) == FileActionTypes.ContentLoadedFromDisk ||
                    (actionType & FileActionTypes.ContentSavedToDisk) == FileActionTypes.ContentSavedToDisk)
                {
                    // We did a reload or a save so we probably want to clear the dirty flag unless someone modified
                    // the buffer -- changing the reiterated version number -- between the reload and when this call was made
                    // (for example, modifying the buffer in the text buffer changed event).
                    if (_cleanReiteratedVersion == _textBuffer.CurrentSnapshot.Version.ReiteratedVersionNumber)
                    {
                        RaiseDirtyStateChangedEvent(false);
                    }
                }

                _textDocumentFactoryService.GuardedOperations.RaiseEvent(this, FileActionOccurred, new TextDocumentFileActionEventArgs(filePath, actionTime, actionType));
            }
            finally
            {
                _raisingFileActionChangedEvent = false;
            }
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="TextDocumentFileActionEventArgs"/> for a file action event.
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <param name="time">The <see cref="DateTime"/> when the file action occurred.</param>
        /// <param name="fileActionType">The <see cref="FileActionTypes"/> that occurred.</param>
        /// <exception cref="ArgumentNullException"><paramref name="filePath"/> is null.</exception>
        public TextDocumentFileActionEventArgs(string filePath, DateTime time, FileActionTypes fileActionType)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            _filePath       = filePath;
            _time           = time;
            _fileActionType = fileActionType;
        }
Exemple #3
0
        private void UpdateSaveStatus(string filePath, bool renamed)
        {
            FileInfo fileInfo = new FileInfo(filePath);

            _lastSavedTimeUtc       = fileInfo.LastWriteTimeUtc;
            _cleanReiteratedVersion = _textBuffer.CurrentSnapshot.Version.ReiteratedVersionNumber;

            FileActionTypes actionType = FileActionTypes.ContentSavedToDisk;

            if (renamed)
            {
                actionType |= FileActionTypes.DocumentRenamed;
            }
            RaiseFileActionChangedEvent(_lastSavedTimeUtc, actionType, filePath);
        }
Exemple #4
0
        public void TextDocument_FileActionOccurred_NonRenameEvent_Noops(FileActionTypes fileActionType)
        {
            // Arrange
            var lspDocumentManager = new Mock <TrackingLSPDocumentManager>(MockBehavior.Strict);

            lspDocumentManager.Setup(manager => manager.TrackDocument(It.IsAny <ITextBuffer>()))
            .Throws <XunitException>();
            lspDocumentManager.Setup(manager => manager.UntrackDocument(It.IsAny <ITextBuffer>()))
            .Throws <XunitException>();
            var listener = CreateListener(lspDocumentManager.Object);
            var args     = new TextDocumentFileActionEventArgs("C:/path/to/file.razor", DateTime.UtcNow, fileActionType);

            // Act & Assert
            listener.TextDocument_FileActionOccurred(RazorTextDocument, args);
        }
        public async Task NonFileSavedToDisk_DoesNotSaveProjectFile(FileActionTypes action)
        {
            var tempFile              = @"C:\Temp\ConsoleApp1.csproj";
            var docData               = IVsPersistDocDataFactory.ImplementAsIVsTextBuffer();
            var shellUtilities        = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(tempFile, docData);
            var textBuffer            = ITextBufferFactory.Create();
            var editorAdaptersService = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDoc               = ITextDocumentFactory.Create();
            var textDocFactoryService = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDoc, true);
            var editorModel           = IProjectFileEditorPresenterFactory.Create();

            var watcher = new TempFileBufferStateListener(editorModel, editorAdaptersService, textDocFactoryService, new IProjectThreadingServiceMock(), shellUtilities,
                                                          IServiceProviderFactory.Create());

            await watcher.InitializeListenerAsync(tempFile);

            Mock.Get(shellUtilities).Verify(u => u.GetRDTDocumentInfoAsync(It.IsAny <IServiceProvider>(), tempFile), Times.Once);
            Mock.Get(editorAdaptersService).Verify(e => e.GetDocumentBuffer((IVsTextBuffer)docData), Times.Once);
            Mock.Get(textDocFactoryService).Verify(t => t.TryGetTextDocument(textBuffer, out textDoc), Times.Once);

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null, new[] { null, new TextDocumentFileActionEventArgs(tempFile, DateTime.Now, action) });
            Mock.Get(editorModel).Verify(e => e.SaveProjectFileAsync(), Times.Never);
        }
Exemple #6
0
        public async Task AbstractEditProjectFileCommand_NonSaveAction_DoesNotOverwriteProjectFile(FileActionTypes actionType)
        {
            var projectPath     = $"C:\\Project1\\Project1.{EditProjectFileCommand.Extension}";
            var tempFile        = "C:\\Temp\\asdf.xyz";
            var tempProjFile    = $"{tempFile}.{EditProjectFileCommand.Extension}";
            var expectedCaption = $"Project1.{EditProjectFileCommand.Extension}";
            var projectXml      = @"<Project></Project>";

            var fileSystem = new IFileSystemMock();
            var textDoc    = ITextDocumentFactory.Create();
            var frame      = IVsWindowFrameFactory.ImplementShowAndSetProperty(VSConstants.S_OK, (prop, obj) => VSConstants.S_OK);

            var command = SetupScenario(projectXml, tempFile, tempProjFile, projectPath, expectedCaption, fileSystem, textDoc, frame);
            var tree    = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot})
");
            var nodes   = ImmutableHashSet.Create(tree);

            // Verify the frame was setup correctly
            Assert.True(await command.TryHandleCommandAsync(nodes, CommandId, true, 0, IntPtr.Zero, IntPtr.Zero));

            var args = new TextDocumentFileActionEventArgs(tempProjFile, DateTime.Now, actionType);

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null, args);
            Assert.False(fileSystem.FileExists(projectPath));
        }