Ejemplo n.º 1
0
        public override void CloseIfAllViewsClosed()
        {
            if (registeredViews.Count == 0)
            {
                bool wasDirty = this.IsDirty;
                FileService.OpenedFileClosed(this);

                FileClosed.RaiseEvent(this, EventArgs.Empty);

                if (fileChangeWatcher != null)
                {
                    fileChangeWatcher.Dispose();
                    fileChangeWatcher = null;
                }

                if (wasDirty)
                {
                    // We discarded some information when closing the file,
                    // so we need to re-parse it.
                    if (System.IO.File.Exists(this.FileName))
                    {
                        ParserService.BeginParse(this.FileName);
                    }
                    else
                    {
                        ParserService.ClearParseInformation(this.FileName);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnFileNameChanged(OpenedFile file)
        {
            base.OnFileNameChanged(file);
            if (file == PrimaryFile)
            {
                FileName oldFileName = codeEditor.FileName;
                FileName newFileName = FileName.Create(file.FileName);

                if (!string.IsNullOrEmpty(oldFileName))
                {
                    ParserService.ClearParseInformation(oldFileName);
                }


                BookmarksNotifyNameChange(oldFileName, newFileName);
                // changing the filename on the codeEditor raises several events; ensure
                // we got our state updated first (bookmarks, persistent anchors) before other code
                // processes the file name change

                codeEditor.FileName = newFileName;
                UpdateSyntaxHighlighting(newFileName);

                ParserService.BeginParse(file.FileName, codeEditor.DocumentAdapter);
            }
        }
Ejemplo n.º 3
0
        public override void Save(string fileName)
        {
            OnSaving(EventArgs.Empty);
            watcher.Disable();

            if (!textAreaControl.CanSaveWithCurrentEncoding())
            {
                if (MessageService.AskQuestion("The file cannot be saved with the current encoding " +
                                               textAreaControl.Encoding.EncodingName + " without losing data." +
                                               "\nDo you want to save it using UTF-8 instead?"))
                {
                    textAreaControl.Encoding = System.Text.Encoding.UTF8;
                }
            }

            textAreaControl.SaveFile(fileName);
            if (fileName != this.FileName)
            {
                ParserService.ClearParseInformation(this.FileName ?? this.UntitledName);
                FileName = fileName;
                ParserService.ParseViewContent(this);
            }
            TitleName = Path.GetFileName(fileName);
            IsDirty   = false;

            watcher.SetWatcher(this.FileName);
            OnSaved(new SaveEventArgs(true));
        }
 public override void Dispose()
 {
     if (this.PrimaryFile.IsUntitled)
     {
         ParserService.ClearParseInformation(this.PrimaryFile.FileName);
     }
     textEditorControl.Dispose();
     base.Dispose();
 }
Ejemplo n.º 5
0
 public override void Dispose()
 {
     if (this.IsUntitled)
     {
         ParserService.ClearParseInformation(this.UntitledName);
     }
     watcher.Dispose();
     textAreaControl.Dispose();
     base.Dispose();
 }
Ejemplo n.º 6
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (PrimaryFile != null && this.PrimaryFile.IsUntitled)
                {
                    ParserService.ClearParseInformation(this.PrimaryFile.FileName);
                }
                textEditorControl.Dispose();

                workbenchWindow = null;
                UnregisterOnActiveViewContentChanged();
                if (AutomaticallyRegisterViewOnFiles)
                {
                    this.Files.Clear();
                }
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 7
0
        protected void OnFileNameChanged(OpenedFile file)
        {
            Debug.Assert(file == this.Files[0]);

            string oldFileName = textEditorControl.FileName;
            string newFileName = file.FileName;

            if (Path.GetExtension(oldFileName) != Path.GetExtension(newFileName))
            {
                if (textEditorControl.Document.HighlightingStrategy != null)
                {
                    textEditorControl.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategyForFile(newFileName);
                    textEditorControl.Refresh();
                }
            }

            SetIcon();

            ParserService.ClearParseInformation(oldFileName);
            textEditorControl.FileName = newFileName;
            ParserService.ParseViewContent(this);
        }
Ejemplo n.º 8
0
        public bool CloseWindow(bool force)
        {
            bool fileDiscarded = false;

            if (!force && this.IsDirty)
            {
                DialogResult dr = MessageBox.Show(ResourceService.GetString("MainWindow.SaveChangesMessage"),
                                                  ResourceService.GetString("MainWindow.SaveChangesMessageHeader") + " " + Title + " ?",
                                                  MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
                                                  MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign);
                //RightToLeftConverter.IsRightToLeft ? MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
                switch (dr)
                {
                case DialogResult.Yes:
                    foreach (IViewContent vc in this.ViewContents)
                    {
                        while (vc.IsDirty)
                        {
                            ICSharpCode.SharpDevelop.Commands.SaveFile.Save(vc);
                            if (vc.IsDirty)
                            {
                                if (MessageService.AskQuestion("${res:MainWindow.DiscardChangesMessage}"))
                                {
                                    fileDiscarded = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;

                case DialogResult.No:
                    fileDiscarded = true;
                    break;

                case DialogResult.Cancel:
                    return(false);
                }
            }

            // Create list of files to reparse after the window is closed.
            // This is necessary because when changes were discarded,
            // the ParserService still has the information with the changes
            // that are now invalid.
            string[] filesToReparse;
            if (fileDiscarded)
            {
                filesToReparse = this.ViewContents
                                 .SelectMany(vc => vc.Files)
                                 .Select(f => f.FileName)
                                 .Distinct(StringComparer.OrdinalIgnoreCase)
                                 .ToArray();
            }
            else
            {
                filesToReparse = null;
            }

            OnCloseEvent(null);
            Dispose();

            if (filesToReparse != null)
            {
                // This must happen after Dispose so that the ViewContents
                // are closed and their content is no longer found by
                // the ParserService.
                LoggingService.Debug("SdiWorkspaceWindow closed with discarding changes, enqueueing files for parsing: " + String.Join(", ", filesToReparse));
                foreach (string file in filesToReparse)
                {
                    if (File.Exists(file))
                    {
                        ParserService.EnqueueForParsing(file);
                    }
                    else
                    {
                        ParserService.ClearParseInformation(file);
                    }
                }
            }

            return(true);
        }