private void SaveDocument(DocumentWindow window)
        {
            NAntDocument document = _documents[window];

            if (document.FileType == FileType.New)
            {
                SaveDocumentAs(window);
            }
            else if (IsDirty(window))
            {
                try
                {
                    document.Save(window.Contents, true);

                    if (window == ActiveWindow)
                    {
                        List <IBuildTarget> targets = _mainForm.SelectedTargets;
                        UpdateTitle();
                        UpdateDisplay();
                        _mainForm.SelectedTargets = targets;
                    }
                }
                catch (Exception ex)
                {
                    Errors.CouldNotSave(document.Name, ex.Message);
                }
            }
        }
        internal void NewBlankDocument()
        {
            NAntDocument   doc    = new NAntDocument(_outputWindow, _options);
            DocumentWindow window = new DocumentWindow(doc.FullName);

            SetupWindow(window, doc);
        }
        internal void LoadDocument(string filename)
        {
            DocumentWindow window = FindDocumentWindow(filename);

            if (window != null)
            {
                window.Select();
                ReloadWindow(window);
            }
            else if (!File.Exists(filename))
            {
                Errors.FileNotFound(filename);
            }
            else
            {
                NAntDocument doc = new NAntDocument(filename, _outputWindow, _options);
                doc.BuildFinished += _mainForm.SetStateStopped;

                Settings.Default.OpenScriptDir = doc.Directory;
                Settings.Default.Save();

                window = new DocumentWindow(doc.FullName);
                SetupWindow(window, doc);

                RecentItems.Add(doc.FullName);

                // Parse the file in the background
                _loader.RunWorkerAsync();
            }
        }
Beispiel #4
0
        private void DocumentClick(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            NAntDocument      doc      = (NAntDocument)menuItem.Tag;

            _controller.SelectWindow(doc.FullName);
        }
        private void SaveDocumentAs(DocumentWindow window)
        {
            string filename = BuildFileBrowser.BrowseForSave();

            if (filename != null)
            {
                NAntDocument document = _documents[window];

                try
                {
                    document.SaveAs(filename, window.Contents);
                    document.BuildFinished += _mainForm.SetStateStopped;

                    Settings.Default.SaveScriptInitialDir = document.Directory;
                    Settings.Default.Save();

                    RecentItems.Add(filename);
                    _mainForm.CreateRecentItemsMenu();
                    UpdateTitle();
                    UpdateDisplay();
                }
                catch (Exception ex)
                {
                    Errors.CouldNotSave(document.Name, ex.Message);
                }
            }
        }
 private void CheckIfFileDeleted(NAntDocument document)
 {
     if (!File.Exists(document.FullName))
     {
         OpenDocumentDeleted(document);
     }
 }
        private void CreateNewProject(object sender, NewProjectEventArgs e)
        {
            NAntDocument   doc    = new NAntDocument(_outputWindow, _options);
            DocumentWindow window = new DocumentWindow(doc.FullName);

            SetupWindow(window, doc);
            window.Contents = Utils.GetNewDocumentContents(e.Info);
            ParseBuildFile(doc);
        }
Beispiel #8
0
        internal void AddDocumentMenuItem(NAntDocument document)
        {
            ToolStripMenuItem item = new ToolStripMenuItem(document.Name);

            item.Tag    = document;
            item.Name   = document.FullName;
            item.Click += DocumentClick;
            _documentsMenuItem.DropDownItems.Add(item);
        }
        private void CloseDocument(object sender, FormClosingEventArgs e)
        {
            DocumentWindow window;

            if (sender is DocumentWindow)
            {
                window = sender as DocumentWindow;
            }
            else
            {
                window = ActiveWindow;
            }

            NAntDocument document = _documents[window];

            if (document.FileType == FileType.New)
            {
                DialogResult result = Errors.DocumentNotSaved(document.Name);

                if (result == DialogResult.Yes)
                {
                    SaveDocumentAs(window);
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
            else if (IsDirty(window))
            {
                DialogResult result = Errors.DocumentNotSaved(document.Name);

                if (result == DialogResult.Yes)
                {
                    try
                    {
                        document.Save(window.Contents, false);
                    }
                    catch (Exception ex)
                    {
                        Errors.CouldNotSave(document.Name, ex.Message);
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }

            if (!e.Cancel)
            {
                _mainForm.RemoveDocumentMenuItem(document);
            }
        }
Beispiel #10
0
 internal void CheckActiveDocument(NAntDocument document)
 {
     foreach (ToolStripItem item in _documentsMenuItem.DropDownItems)
     {
         if (item is ToolStripMenuItem)
         {
             ToolStripMenuItem menuItem = item as ToolStripMenuItem;
             menuItem.Checked = (menuItem.Tag == document);
         }
     }
 }
Beispiel #11
0
 private void ParseBuildFile(NAntDocument document)
 {
     try
     {
         document.ParseBuildScript();
     }
     catch (BuildFileLoadException error)
     {
         Errors.CouldNotLoadFile(document.Name, error.InnerException.Message);
         SetCursor(error.LineNumber, error.ColumnNumber);
     }
 }
Beispiel #12
0
        private void CheckForFileChanges()
        {
            NAntDocument[] docs = new NAntDocument[_documents.Values.Count];
            _documents.Values.CopyTo(docs, 0);

            foreach (NAntDocument document in docs)
            {
                if (document.FileType == FileType.Existing && _mainForm.IsActive)
                {
                    CheckIfFileDeleted(document);
                    CheckIfFileModified(document);
                }
            }
        }
Beispiel #13
0
        private void OpenDocumentDeleted(NAntDocument document)
        {
            DocumentWindow window = FindDocumentWindow(document.FullName);
            DialogResult   result = Errors.ShowDocumentDeletedMessage(document.FullName);

            if (result == DialogResult.No)
            {
                window.Close();
            }
            else
            {
                window.TabText    = Utils.AddAsterisk(window.TabText);
                document.FileType = FileType.New;
            }
        }
Beispiel #14
0
 internal void UpdateDocumentMenuItem(NAntDocument document, string name)
 {
     if (_documentsMenuItem.DropDownItems[document.FullName] != null)
     {
         _documentsMenuItem.DropDownItems[document.FullName].Text = name;
     }
     else  // During a SaveAs the FullName changes
     {
         foreach (ToolStripItem item in _documentsMenuItem.DropDownItems)
         {
             if (item.Tag == document)
             {
                 item.Text = name;
             }
         }
     }
 }
Beispiel #15
0
        private void CheckIfFileModified(NAntDocument document)
        {
            DateTime lastWrite = File.GetLastWriteTime(document.FullName);

            if (lastWrite > document.LastModified && lastWrite != document.IgnoreModifiedDate)
            {
                DialogResult result = Errors.ShowDocumentChangedMessage(document.FullName);

                if (result == DialogResult.Yes)
                {
                    LoadDocument(document.FullName);
                }
                else
                {
                    document.IgnoreModifiedDate = lastWrite;
                }
            }
        }
Beispiel #16
0
        private void SetupWindow(DocumentWindow window, NAntDocument doc)
        {
            _documents.Add(window, doc);
            _mainForm.AddDocumentMenuItem(doc);

            window.Contents = doc.Contents;
            window.TabText  = doc.Name;

            window.DocumentChanged        += WindowDocumentChanged;
            window.FormClosing            += CloseDocument;
            window.FormClosed             += WindowFormClosed;
            window.CloseClicked           += delegate { Close(); };
            window.CloseAllClicked        += delegate { CloseAllDocuments(); };
            window.CloseAllButThisClicked += delegate { CloseAllButThisClicked(); };
            window.SaveClicked            += delegate { SaveDocument(); };
            window.Leave += WindowLeave;
            window.Enter += WindowEnter;
            window.Show(_mainForm.DockPanel);
        }
Beispiel #17
0
        internal void ReloadWindow(DocumentWindow window)
        {
            if (!IsDirty(window) || Errors.ReloadUnsaved() == DialogResult.Yes)
            {
                NAntDocument document = _documents[window];

                try
                {
                    TextLocation position = window.CaretPosition;
                    document.Reload();
                    window.Contents = document.Contents;
                    window.MoveCaretTo(position.Line, position.Column);
                    UpdateDisplay();
                }
                catch (Exception ex)
                {
                    Errors.CouldNotLoadFile(document.FullName, ex.Message);
                }
            }
        }
Beispiel #18
0
        internal DocumentWindow GetWindow(string filename)
        {
            DocumentWindow window = null;

            if (File.Exists(filename))
            {
                NAntDocument doc = new NAntDocument(filename, _outputWindow, _options);
                doc.BuildFinished += _mainForm.SetStateStopped;

                window = new DocumentWindow(doc.FullName);
                SetupWindow(window, doc);

                RecentItems.Add(doc.FullName);

                ParseBuildFile(doc);
            }
            else
            {
                Errors.FileNotFound(filename);
            }

            return(window);
        }
 private void CreateNewProject(object sender, NewProjectEventArgs e)
 {
     NAntDocument doc = new NAntDocument(_outputWindow, _options);
     DocumentWindow window = new DocumentWindow(doc.FullName);
     SetupWindow(window, doc);
     window.Contents = Utils.GetNewDocumentContents(e.Info);
     ParseBuildFile(doc);
 }
Beispiel #20
0
 internal void RemoveDocumentMenuItem(NAntDocument document)
 {
     _documentsMenuItem.DropDownItems.RemoveByKey(document.FullName);
 }
Beispiel #21
0
 internal void UpdateDocumentMenuItem(NAntDocument document, string name)
 {
     if (_documentsMenuItem.DropDownItems[document.FullName] != null)
     {
         _documentsMenuItem.DropDownItems[document.FullName].Text = name;
     }
     else  // During a SaveAs the FullName changes
     {
         foreach (ToolStripItem item in _documentsMenuItem.DropDownItems)
             if (item.Tag == document)
                 item.Text = name;
     }
 }
Beispiel #22
0
 internal void RemoveDocumentMenuItem(NAntDocument document)
 {
     _documentsMenuItem.DropDownItems.RemoveByKey(document.FullName);
 }
        internal DocumentWindow GetWindow(string filename)
        {
            DocumentWindow window = null;

            if (File.Exists(filename))
            {
                NAntDocument doc = new NAntDocument(filename, _outputWindow, _options);
                doc.BuildFinished += _mainForm.SetStateStopped;

                window = new DocumentWindow(doc.FullName);
                SetupWindow(window, doc);

                RecentItems.Add(doc.FullName);

                ParseBuildFile(doc);
            }
            else
            {
                Errors.FileNotFound(filename);
            }

            return window;
        }
        internal void LoadDocument(string filename)
        {
            DocumentWindow window = FindDocumentWindow(filename);

            if (window != null)
            {
                window.Select();
                ReloadWindow(window);
            }
            else if (!File.Exists(filename))
            {
                Errors.FileNotFound(filename);
            }
            else
            {
                NAntDocument doc = new NAntDocument(filename, _outputWindow, _options);
                doc.BuildFinished += _mainForm.SetStateStopped;

                Settings.Default.OpenScriptDir = doc.Directory;
                Settings.Default.Save();

                window = new DocumentWindow(doc.FullName);
                SetupWindow(window, doc);

                RecentItems.Add(doc.FullName);

                // Parse the file in the background
                _loader.RunWorkerAsync();
            }
        }
        private void CheckForFileChanges()
        {
            NAntDocument[] docs = new NAntDocument[_documents.Values.Count];
            _documents.Values.CopyTo(docs, 0);

            foreach (NAntDocument document in docs)
            {
                if (document.FileType == FileType.Existing && _mainForm.IsActive)
                {
                    CheckIfFileDeleted(document);
                    CheckIfFileModified(document);
                }
            }
        }
 internal void NewBlankDocument()
 {
     NAntDocument doc = new NAntDocument(_outputWindow, _options);
     DocumentWindow window = new DocumentWindow(doc.FullName);
     SetupWindow(window, doc);
 }
 private void CheckIfFileDeleted(NAntDocument document)
 {
     if (!File.Exists(document.FullName))
     {
         OpenDocumentDeleted(document);
     }
 }
        private void SetupWindow(DocumentWindow window, NAntDocument doc)
        {
            _documents.Add(window, doc);
            _mainForm.AddDocumentMenuItem(doc);

            window.Contents = doc.Contents;
            window.TabText = doc.Name;

            window.DocumentChanged += WindowDocumentChanged;
            window.FormClosing += CloseDocument;
            window.FormClosed += WindowFormClosed;
            window.CloseClicked += delegate { Close(); };
            window.CloseAllClicked += delegate { CloseAllDocuments(); };
            window.CloseAllButThisClicked += delegate { CloseAllButThisClicked(); };
            window.SaveClicked += delegate { SaveDocument(); };
            window.Leave += WindowLeave;
            window.Enter += WindowEnter;
            window.Show(_mainForm.DockPanel);
        }
 private void ParseBuildFile(NAntDocument document)
 {
     try
     {
         document.ParseBuildScript();
     }
     catch (BuildFileLoadException error)
     {
         Errors.CouldNotLoadFile(document.Name, error.InnerException.Message);
         SetCursor(error.LineNumber, error.ColumnNumber);
     }
 }
Beispiel #30
0
 internal void CheckActiveDocument(NAntDocument document)
 {
     foreach (ToolStripItem item in _documentsMenuItem.DropDownItems)
     {
         if (item is ToolStripMenuItem)
         {
             ToolStripMenuItem menuItem = item as ToolStripMenuItem;
             menuItem.Checked = (menuItem.Tag == document);
         }
     }
 }
        private void CheckIfFileModified(NAntDocument document)
        {
            DateTime lastWrite = File.GetLastWriteTime(document.FullName);
            if (lastWrite > document.LastModified && lastWrite != document.IgnoreModifiedDate)
            {
                DialogResult result = Errors.ShowDocumentChangedMessage(document.FullName);

                if (result == DialogResult.Yes)
                {
                    LoadDocument(document.FullName);
                }
                else
                {
                    document.IgnoreModifiedDate = lastWrite;
                }
            }
        }
        private void OpenDocumentDeleted(NAntDocument document)
        {
            DocumentWindow window = FindDocumentWindow(document.FullName);
            DialogResult result = Errors.ShowDocumentDeletedMessage(document.FullName);

            if (result == DialogResult.No)
            {
                window.Close();
            }
            else
            {
                window.TabText = Utils.AddAsterisk(window.TabText);
                document.FileType = FileType.New;
            }
        }
Beispiel #33
0
 internal void AddDocumentMenuItem(NAntDocument document)
 {
     ToolStripMenuItem item = new ToolStripMenuItem(document.Name);
     item.Tag = document;
     item.Name = document.FullName;
     item.Click += DocumentClick;
     _documentsMenuItem.DropDownItems.Add(item);
 }