Esempio n. 1
0
 public override Task Save(FileSaveInformation fileSaveInformation)
 {
     if (!string.IsNullOrEmpty(fileSaveInformation.FileName))
     {
         AutoSave.RemoveAutoSaveFile(fileSaveInformation.FileName);
     }
     return(textEditorImpl.ViewContent.Save(fileSaveInformation));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public override Task Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.ViewContent.Save());
 }
Esempio n. 4
0
 protected override Task OnSave()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     return(textEditorImpl.Save(new FileSaveInformation(FilePath, Encoding)));
 }
Esempio n. 5
0
 void IViewContent.Save()
 {
     if (!string.IsNullOrEmpty(textEditorImpl.ContentName))
     {
         AutoSave.RemoveAutoSaveFile(textEditorImpl.ContentName);
     }
     textEditorImpl.Save();
 }
Esempio n. 6
0
 void IViewContent.Save(string fileName)
 {
     if (!string.IsNullOrEmpty(fileName))
     {
         AutoSave.RemoveAutoSaveFile(fileName);
     }
     textEditorImpl.Save(new FileSaveInformation(fileName));
 }
Esempio 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();
 }
 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);
     }
 }
Esempio 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);
     }
 }
Esempio 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);
 }
Esempio n. 11
0
        void InformAutoSave()
        {
            if (isDisposed)
            {
                return;
            }
            RemoveAutoSaveTimer();
            autoSaveTimer = GLib.Timeout.Add(500, delegate {
                if (autoSaveTask != null && !autoSaveTask.IsCompleted)
                {
                    return(false);
                }

                autoSaveTask  = AutoSave.InformAutoSaveThread(textEditor.CreateSnapshot(), textEditor.FileName, IsDirty);
                autoSaveTimer = 0;
                return(false);
            });
        }
Esempio n. 12
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);
        }