Пример #1
0
        /// <summary>
        /// Loads the content from an auto save file and removes the auto save file.
        /// </summary>
        public static ITextSource LoadAndRemoveAutoSave(string fileName)
        {
            string autoSaveFileName = GetAutoSaveFileName(fileName);
            var    result           = StringTextSource.ReadFrom(autoSaveFileName);

            AutoSave.RemoveAutoSaveFile(fileName);
            return(result);
        }
Пример #2
0
 public override Task Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.ViewContent.Save());
 }
Пример #3
0
 protected override Task OnSave()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.Save(new FileSaveInformation(FilePath, Encoding)));
 }
Пример #4
0
 public override Task Save(FileSaveInformation fileSaveInformation)
 {
     if (!string.IsNullOrEmpty(fileSaveInformation.FileName))
     {
         AutoSave.RemoveAutoSaveFile(fileSaveInformation.FileName);
     }
     return(textEditorImpl.ViewContent.Save(fileSaveInformation));
 }
Пример #5
0
 void IViewContent.Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     textEditorImpl.Save();
 }
Пример #6
0
 void IViewContent.Save(string fileName)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         AutoSave.RemoveAutoSaveFile(fileName);
     }
     textEditorImpl.Save(new FileSaveInformation(fileName));
 }
Пример #7
0
 public override void DiscardChanges()
 {
     if (autoSaveTask != null)
     {
         autoSaveTask.Wait(TimeSpan.FromSeconds(5));
     }
     RemoveAutoSaveTimer();
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     textEditorImpl.ViewContent.DiscardChanges();
 }
 protected override void OnContentNameChanged()
 {
     base.OnContentNameChanged();
     if (ContentName != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     textEditorImpl.ContentName = this.ContentName;
     if (this.WorkbenchWindow?.Document != null)
     {
         textEditor.InitializeExtensionChain(this.WorkbenchWindow.Document);
     }
 }
Пример #9
0
 protected override void OnFileNameChanged()
 {
     base.OnFileNameChanged();
     if (textEditor != null)
     {
         if (FilePath != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
         {
             AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
         }
         textEditor.FileName = FilePath;                 // TOTEST: VSTS #770920
         if (documentContext != null)
         {
             textEditor.InitializeExtensionChain(documentContext);
         }
         UpdateTextEditorOptions(null, null);
     }
 }
Пример #10
0
 protected override void OnContentNameChanged()
 {
     base.OnContentNameChanged();
     if (ContentName != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     if (ContentName != null)             // Happens when a file is converted to an untitled file, but even in that case the text editor should be associated with the old location, otherwise typing can be messed up due to change of .editconfig settings etc.
     {
         textEditor.FileName = ContentName;
     }
     if (this.WorkbenchWindow?.Document != null)
     {
         textEditor.InitializeExtensionChain(this.WorkbenchWindow.Document);
     }
     UpdateTextEditorOptions(null, null);
 }
Пример #11
0
        protected override void OnDispose()
        {
            if (isDisposed)
            {
                return;
            }

            isDisposed = true;

            HasUnsavedChangesChanged -= TextEditorViewContent_HasUnsavedChangesChanged;

            if (textEditorImpl != null)
            {
                if (autoSaveTask != null)
                {
                    autoSaveTask.Wait(TimeSpan.FromSeconds(5));
                }
                RemoveAutoSaveTimer();
                if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
                {
                    AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
                }

                EditorConfigService.RemoveEditConfigContext(textEditor.FileName).Ignore();
                textEditorImpl.DirtyChanged -= HandleDirtyChanged;
                textEditor.MimeTypeChanged  -= UpdateTextEditorOptions;
                textEditor.TextChanged      -= HandleTextChanged;
                textEditorImpl.DirtyChanged -= ViewContent_DirtyChanged;;

                DefaultSourceEditorOptions.Instance.Changed -= UpdateTextEditorOptions;
                textEditor.Dispose();
            }
            RemovePolicyChangeHandler();

            editorOptionsUpdateCancellationSource?.Cancel();

            base.OnDispose();
        }
        protected override async void OnContentNameChanged()
        {
            base.OnContentNameChanged();
            if (ContentName != textEditorImpl.ContentName && !string.IsNullOrEmpty(textEditorImpl.ContentName))
            {
                AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
            }
            if (textEditorImpl.ContentName != null && textEditorImpl.ContentName != this.ContentName)
            {
                EditorConfigService.RemoveEditConfigContext(textEditorImpl.ContentName).Ignore();
                var context = await EditorConfigService.GetEditorConfigContext(textEditor.FileName, default(CancellationToken));

                if (context != null)
                {
                    ((DefaultSourceEditorOptions)textEditor.Options).SetContext(context);
                }
            }
            textEditorImpl.ContentName = this.ContentName;
            if (this.WorkbenchWindow?.Document != null)
            {
                textEditor.InitializeExtensionChain(this.WorkbenchWindow.Document);
            }
            UpdateTextEditorOptions(null, null);
        }