Example #1
0
 void ClearDocument( )
 {
     _documentState = DocumentStates.Closed;
     _documentPath  = string.Empty;
     _document      = null;
     PublishToSubscriber();
 }
Example #2
0
        void IPublishable.Publish(DocumentStates DocumentState)
        {
            switch (DocumentState)
            {
            case DocumentStates.Closed:
                tabControlMain.Visible          = false;
                closeToolStripMenuItem.Enabled  = false;
                saveToolStripMenuItem.Enabled   = false;
                saveAsToolStripMenuItem.Enabled = false;
                toolStripButtonSave.Enabled     = false;
                tabControlMain.SelectedIndex    = 0;
                break;

            case DocumentStates.Dirty:
                toolStripButtonSave.Enabled = true;
                break;

            case DocumentStates.Clean:
                tabControlMain.Visible          = true;
                closeToolStripMenuItem.Enabled  = true;
                saveAsToolStripMenuItem.Enabled = true;
                saveToolStripMenuItem.Enabled   = true;
                toolStripButtonSave.Enabled     = false;
                break;

            default:
                MessageBox.Show("Unkown Documentstate recieved");
                break;
            }
        }
Example #3
0
 public void CreateFromTemplate(string templateName)
 {
     if (AskClose())
     {
         try
         {
             string templatePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Templates\\" + templateName);
             _templateName      = templateName;
             _documentExtension = Path.GetExtension(templatePath);
             _document          = XDocument.Load(templatePath);
             _documentState     = DocumentStates.Clean;
             _document.Changed += new EventHandler <XObjectChangeEventArgs>(DocumentChanged);
             if (SaveAs(_documentDirectoryMRU) == false)
             {
                 ClearDocument();
             }
             PublishToSubscriber();
             _subscriber.PublishDocumentChange();
         }
         catch (Exception e)
         {
             MessageBox.Show(e.ToString());
         }
     }
 }
Example #4
0
        public bool Save()
        {
            bool status = false;

            if (_canSave)
            {
                if (new FileInfo(_documentPath).IsReadOnly == true)
                {
                    status = SaveAs(new FileInfo(DocumentPath).DirectoryName);
                }
                else
                {
                    try
                    {
                        _document.Save(_documentPath);
                        _documentState = DocumentStates.Clean;
                        _subscriber.Publish(_documentState);
                        status = true;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("The document could not be saved.");
                    }
                }
            }
            else
            {
                MessageBox.Show("The document is not ready to be saved.");
            }
            return(status);
        }
Example #5
0
        public void Open()
        {
            if (AskClose())
            {
                var openFileDialog = new OpenFileDialog();
                openFileDialog.FileName         = "";
                openFileDialog.InitialDirectory = _documentDirectoryMRU;
                openFileDialog.Filter           = "All files (*.*)|*.*";
                var result = openFileDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    try
                    {
                        XDocument _tmpDocument = XDocument.Load(openFileDialog.FileName);
                        _documentPath      = openFileDialog.FileName;
                        _document          = XDocument.Load(_documentPath);
                        _documentState     = DocumentStates.Clean;
                        _document.Changed += new EventHandler <XObjectChangeEventArgs>(DocumentChanged);
                        PublishToSubscriber();
                        _subscriber.Publish(DefaultNamespace);
                        _subscriber.PublishDocumentChange();
                        UpdateMRU();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
//                        ClearDocument();
                    }
                }
            }
        }
Example #6
0
 public void Save(string filePath)
 {
     _document.Save(filePath);
     _savedDocument = new XDocument(_document);
     _documentPath  = filePath;
     _documentState = DocumentStates.Clean;
     PublishToSubscriber();
 }
 public bool RemoveDocument(Uri documentUri)
 {
     if (DocumentStates.TryRemove(documentUri, out var doc))
     {
         Detach(doc);
         return(true);
     }
     return(false);
 }
Example #8
0
 private void CompareDocuments()
 {
     if (_document.ToString() == _savedDocument.ToString())
     {
         _documentState = DocumentStates.Clean;
     }
     else
     {
         _documentState = DocumentStates.Dirty;
     }
     PublishToSubscriber();
 }
        void IPublishable.Publish(DocumentStates DocumentState)
        {
            switch (DocumentState)
            {
            case DocumentStates.Closed:
                //tabControlMain.Visible = false;
                EnableClose = false;
                EnableSave  = false;
                //tabControlMain.SelectedIndex = 0;
                EnableDifferencesView = false;
                GridVisibility        = Visibility.Hidden;
                break;

            case DocumentStates.Dirty:
                //tabControlMain.Visible = true;
                EnableClose      = true;
                EnableSave       = true;
                EnableSaveButton = true;
                GridVisibility   = Visibility.Visible;
                if (_documentManager.Subscribers.ContainsKey("differences"))
                {
                    EnableDifferencesView = false;
                }
                else
                {
                    EnableDifferencesView = true;
                }
                break;

            case DocumentStates.Clean:
                //tabControlMain.Visible = true;
                EnableClose      = true;
                EnableSave       = true;
                EnableSaveButton = false;
                GridVisibility   = Visibility.Visible;
                if (_documentManager.Subscribers.ContainsKey("differences"))
                {
                    EnableDifferencesView = false;
                }
                else
                {
                    EnableDifferencesView = true;
                }
                break;

            default:
                MessageBox.Show("Unkown Documentstate recieved");
                break;
            }
        }
Example #10
0
 public void OpenFilePath(string filePath)
 {
     try
     {
         XDocument _tmpDocument = XDocument.Load(filePath);
         _documentPath      = filePath;
         _document          = _tmpDocument;
         _documentState     = DocumentStates.Clean;
         _document.Changed += new EventHandler <XObjectChangeEventArgs>(DocumentChanged);
         PublishToSubscriber();
     }
     catch (Exception e)
     {
         MessageBox.Show($"An error occurred loading '{filePath}'. Please make sure it's a valid XML file.");
         ClearDocument();
     }
 }
Example #11
0
 public void Load(string filePath)
 {
     try
     {
         _document      = XDocument.Load(filePath);
         _savedDocument = new XDocument(_document);
         _documentPath  = filePath;
         _documentState = DocumentStates.Clean;
         RefreshNamespaces();
         EnableChangeWatcher();
         PublishToSubscriber();
     }
     catch (Exception ex)
     {
         throw new Exception("Load Failed");
     }
 }
Example #12
0
 public void OpenFilePath(string filePath)
 {
     try
     {
         XDocument _tmpDocument = XDocument.Load(filePath);
         _documentPath      = filePath;
         _document          = _tmpDocument;
         _documentState     = DocumentStates.Clean;
         _document.Changed += new EventHandler <XObjectChangeEventArgs>(DocumentChanged);
         PublishToSubscriber();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
         ClearDocument();
     }
 }
Example #13
0
        public bool SaveAs(string initialDirectory)
        {
            bool saved = false;

            if (_canSave)
            {
                var saveDialog = new SaveFileDialog();

                saveDialog.InitialDirectory = initialDirectory;
                saveDialog.FileName         = _documentPath;
                saveDialog.Filter           = Path.GetFileNameWithoutExtension(_templateName) + " files (*" + _documentExtension + ")|*" + _documentExtension + "|All files (*.*)|*.*";

                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        _document.Save(saveDialog.FileName);
                        _documentPath  = saveDialog.FileName;
                        _documentState = DocumentStates.Clean;
                        saved          = true;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("The document could not be saved.");
                    }

                    if (saved)
                    {
                        PublishToSubscriber();
                        _subscriber.PublishDocumentChange();
                        UpdateMRU();
                    }
                }
            }
            else
            {
                MessageBox.Show("The document is not ready to be saved.");
            }

            return(saved);
        }
Example #14
0
 void DocumentChanged(object sender, XObjectChangeEventArgs e)
 {
     _documentState = DocumentStates.Dirty;
     PublishToSubscriber();
 }
 public void Publish(DocumentStates DocumentState)
 {
 }
Example #16
0
 public DocumentState(DocumentStates currentState, TDocument document)
 {
     CurrentState = currentState;
     Document     = document ?? throw new ArgumentException("The document cannot be null when creating a document state.", nameof(document));
 }