Esempio n. 1
0
        /// <summary>
        /// Indicates that no amount of undoing/redoing will get the undo queue into a saved state
        /// (This could occur, for example, if a file were modified outside the application.
        /// </summary>
        public void NeverSaved()
        {
            bool modified = Modified;

            m_undoSaved = UndoAction.NeverSaved;
            if (!modified)
            {
                ModifiedChanged.Execute();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The associated file has been saved and so any existing items are effectively modifications from the saved state of the file if you undo them
        /// </summary>
        public void Saved()
        {
            bool modified = Modified;

            m_undoSaved = m_undoActions.Count != 0 ? m_undoActions.Peek() : null;
            if (modified)
            {
                ModifiedChanged.Execute();
            }
        }
Esempio n. 3
0
        public void Queue(UndoAction action)
        {
            bool modified = Modified;

            m_redoActions.Clear();
            m_undoActions.Push(action);
            Changed.Execute();
            Logger.Log(m_name + "changes.txt", "Action: " + action.LogDescription);
            if (!modified)
            {
                ModifiedChanged.Execute();
            }
        }
Esempio n. 4
0
        public void RequestNewDocument(EditorDocument template, String text)
        {
            if (template.FullName != null && template.FullName.Length > 0)
            {
                template.HasLocation = true;
                template.FileName    = System.IO.Path.GetFileName(template.FullName);
            }
            else
            {
                template.HasLocation = false;
                if (template.FileName == null || template.FileName.Length <= 0)
                {
                    template.FileName = "Untitled" + untitledNumer;
                    untitledNumer++;
                }
            }
            template.EditorControl = new TextBox()
            {
                AcceptsReturn = true,
                AcceptsTab    = true,
                FontFamily    = new FontFamily("Courier New"),
                FontSize      = 12.0,
                HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                Text = text,
                SnapsToDevicePixels = true,
                //BorderThickness = new Thickness(0,2,0,0),
                Margin  = new Thickness(0),
                Padding = new Thickness(0)
            };
            template.EditorControl.TextChanged +=
                delegate(object source, TextChangedEventArgs e)
            {
                if (template.IsModified == false)
                {
                    template.IsModified = true;
                    ModifiedChanged.Invoke(this, new EditorEventArgs()
                    {
                        Document = template
                    });
                }
            };

            documents.Add(template);

            InsertedEditor.Invoke(this, new EditorEventArgs()
            {
                Document = template
            });
        }
Esempio n. 5
0
 public void Redo()
 {
     if (m_redoActions.Any())
     {
         bool modified = Modified;
         var  a        = m_redoActions.Pop();
         a.Redo();
         m_undoActions.Push(a);
         if (modified != Modified)
         {
             ModifiedChanged.Execute();
         }
         Changed.Execute();
         Logger.Log(m_name + "changes.txt", "Redo: " + a.LogDescription);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Вызвать событие ModifiedChanged
 /// </summary>
 private void OnModifiedChanged()
 {
     ModifiedChanged?.Invoke(this, EventArgs.Empty);
 }
Esempio n. 7
0
        private bool saveHelper(EditorDocument document, bool isSaveAs)
        {
            if (document.IsModified || isSaveAs)
            {
                // Choose location if first save.  Also sets IsModified to true.
                bool   cancelled;
                string newLocation;
                if (isSaveAs || !document.HasLocation)
                {
                    #region Prompt for location
                    ActivatedEditor.Invoke(this, new EditorEventArgs()
                    {
                        Document = document
                    });

                    var dlg = new SaveFileDialog()
                    {
                        DefaultExt = ".py",
                        Filter     = fileFilter
                    };
                    if (document.HasLocation && document.FullName != null)
                    {
                        dlg.FileName = document.FullName;
                    }
                    if (dlg.ShowDialog(this.owner) == true)
                    {
                        newLocation = dlg.FileName;
                        cancelled   = false;
                    }
                    else
                    {
                        newLocation = null;
                        cancelled   = true;
                    }
                    #endregion
                }
                else
                {
                    cancelled   = false;
                    newLocation = null;
                }

                // If selecting a path was not cancelled, and document is modified
                // (IsModified was set to true if the file did not have a path).
                if (cancelled == true)
                {
                    return(false);
                }
                else
                {
                    try
                    {
                        #region Write file and store new location
                        using (var stream =
                                   (newLocation != null ?
                                    File.CreateText(newLocation) :
                                    File.CreateText(document.FullName)))
                        {
                            stream.Write(document.EditorControl.Text);
                            document.IsModified = false;
                            // If there is a new location, either due to save as
                            // or first save, update properties and invoke the
                            // name change event.
                            if (newLocation != null)
                            {
                                document.FullName    = newLocation;
                                document.FileName    = System.IO.Path.GetFileName(newLocation);
                                document.HasLocation = true;
                                NameChanged.Invoke(this, new EditorEventArgs()
                                {
                                    Document = document
                                });
                            }
                            ModifiedChanged.Invoke(this, new EditorEventArgs()
                            {
                                Document = document
                            });
                        }
                        #endregion
                        return(true);
                    }
                    catch (Exception e)
                    {
                        if (e.Message != null && e.Message.Length > 0)
                        {
                            MessageBox.Show(this.owner, e.Message, "Error saving file",
                                            MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                        }
                        throw e;
                    }
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Raises the ModifiedChanged event.
 /// </summary>
 /// <param name="e">An EventArgs that contains the event data.</param>
 protected virtual void OnModifiedChanged(EventArgs e)
 {
     ModifiedChanged?.Invoke(this, e);
 }
Esempio n. 9
0
 /// <summary>
 /// Notifies when the modified state of the document changes
 /// </summary>
 protected virtual void OnModifiedChanged()
 {
     ModifiedChanged?.Invoke();
 }
Esempio n. 10
0
 protected virtual void OnModifiedChanged()
 {
     ModifiedChanged?.Invoke(this, EventArgs.Empty);
 }