Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public override Task Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.ViewContent.Save());
 }
Ejemplo n.º 3
0
 protected override Task OnSave()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.Save(new FileSaveInformation(FilePath, Encoding)));
 }
Ejemplo n.º 4
0
 public override Task Save(FileSaveInformation fileSaveInformation)
 {
     if (!string.IsNullOrEmpty(fileSaveInformation.FileName))
     {
         AutoSave.RemoveAutoSaveFile(fileSaveInformation.FileName);
     }
     return(textEditorImpl.ViewContent.Save(fileSaveInformation));
 }
Ejemplo n.º 5
0
 void IViewContent.Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     textEditorImpl.Save();
 }
Ejemplo n.º 6
0
 void IViewContent.Save(string fileName)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         AutoSave.RemoveAutoSaveFile(fileName);
     }
     textEditorImpl.Save(new FileSaveInformation(fileName));
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }