Exemple #1
0
        /// <summary>
        /// Get a new unique item file name for the parent context
        /// </summary>
        /// <param name="parentContext">The parent in which ensuring the file name is unique</param>
        /// <param name="baseName">The base file name used for generated a new one</param>
        /// <param name="extension">The file name extension to use</param>
        /// <returns>The unique new item file name</returns>
        public string GetItemNewFileName(ILuaEditDocumentGroup parentContext, string baseName, string extension)
        {
            bool   isNameValid = false;
            string newName     = string.Empty;
            int    counter     = 0;

            while (!isNameValid)
            {
                ++counter;
                isNameValid = true;
                newName     = baseName + counter + extension;

                if (parentContext != null)
                {
                    foreach (ILuaEditDocument doc in parentContext.Documents)
                    {
                        if (Path.GetFileName(doc.FileName).ToLower() == newName.ToLower())
                        {
                            isNameValid = false;
                            break;
                        }
                    }
                }
            }

            return(newName);
        }
Exemple #2
0
        /// <summary>
        /// Show the dialog
        /// </summary>
        /// <param name="title">The title to display for this dialog</param>
        /// <param name="parentContext">The parent contextual to the new object to add</param>
        /// <param name="itemType">The type of new item to suggest in the dialog</param>
        /// <param name="dialogStyle">The layout display style</param>
        /// <returns>The dialog user's choice (will either be OK or Cancel)</returns>
        public DialogResult ShowDialog(string title, ILuaEditDocumentGroup parentContext,
                                       NewItemTypes itemType, NewItemDialogStyle dialogStyle)
        {
            string location = parentContext != null?Path.GetDirectoryName(parentContext.FileName) : string.Empty;

            return(this.ShowDialog(title, parentContext, location, itemType, dialogStyle));
        }
Exemple #3
0
        protected override bool TerminateDocument()
        {
            try
            {
                _terminating = true;

                while (_documentGroups.Count > 0)
                {
                    ILuaEditDocumentGroup childDocGrp = _documentGroups[_documentGroups.Count - 1];
                    RemoveDocument(childDocGrp);
                }

                while (_documents.Count > 0)
                {
                    ILuaEditDocument childDoc = _documents[_documents.Count - 1];
                    RemoveDocument(childDoc);
                }

                return(base.TerminateDocument());
            }
            finally
            {
                _terminating = false;
            }
        }
        public override void RemoveDocument(ILuaEditDocumentGroup docGrp)
        {
            if (docGrp == this.ActiveProject)
            {
                this.ActiveProject = null;
            }

            base.RemoveDocument(docGrp);
        }
        public override void AddDocument(ILuaEditDocumentGroup docGrp)
        {
            base.AddDocument(docGrp);

            if (!_opening && DocumentGroups.Count == 1 && DocumentGroups[0] is ILuaEditDocumentProject)
            {
                this.ActiveProject = DocumentGroups[0] as ILuaEditDocumentProject;
            }
        }
        private void existingItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (solutionExplorerTreeView.SelectedItems.Count == 1)
            {
                ILuaEditDocumentGroup docGrp = solutionExplorerTreeView.SelectedItems[0].Tag as ILuaEditDocumentGroup;

                if (docGrp != null && docGrp.CanAdd())
                {
                    string title = string.Format("Add Existing Item - {0}", docGrp);
                    DocumentsManager.Instance.OpenDocuments(typeof(ILuaEditDocumentEditable), docGrp, title, Path.GetDirectoryName(docGrp.FileName));
                }
            }
        }
        private void newItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (solutionExplorerTreeView.SelectedItems.Count == 1)
            {
                ILuaEditDocumentGroup docGrp = solutionExplorerTreeView.SelectedItems[0].Tag as ILuaEditDocumentGroup;

                if (docGrp != null && docGrp.CanAdd())
                {
                    string title = string.Format("Add New Item - {0}", docGrp);
                    DocumentsManager.Instance.NewDocument(title, docGrp, LuaEdit.HelperDialogs.NewItemTypes.Item);
                }
            }
        }
Exemple #8
0
        internal void FromXml(XmlLuaGroupDocumentBase objectToDeserialize)
        {
            // Deserialize sub-documents
            if (objectToDeserialize.Documents != null)
            {
                foreach (DocumentRef refDoc in objectToDeserialize.Documents)
                {
                    refDoc.FileName = Win32Utils.GetAbsolutePath(refDoc.FileName, _fileName);
                    ILuaEditDocument doc = DocumentsManager.Instance.BaseOpenDocument(refDoc);

                    if (doc != null)
                    {
                        this.AddDocument(doc);
                    }
                }
            }

            // Deserialize sub-folders
            if (objectToDeserialize.DocumentFolders != null)
            {
                foreach (XmlDocumentFolder xmlFolder in objectToDeserialize.DocumentFolders)
                {
                    DocumentFolder folderDoc = new DocumentFolder();
                    folderDoc.ParentDocument = this;
                    folderDoc.FromXml(xmlFolder);

                    if (folderDoc != null)
                    {
                        this.AddDocument(folderDoc as ILuaEditDocumentFolder);
                    }
                }
            }

            // Deserialize sub-group documents
            if (objectToDeserialize.DocumentGroups != null)
            {
                foreach (DocumentRef refDoc in objectToDeserialize.DocumentGroups)
                {
                    refDoc.FileName = Win32Utils.GetAbsolutePath(refDoc.FileName, _fileName);
                    ILuaEditDocumentGroup docGrp = DocumentsManager.Instance.BaseOpenDocument(refDoc) as ILuaEditDocumentGroup;

                    if (docGrp != null)
                    {
                        this.AddDocument(docGrp);
                    }
                }
            }
        }
Exemple #9
0
        public virtual void RemoveDocument(ILuaEditDocumentGroup docGrp)
        {
            docGrp.ParentDocument  = null;
            docGrp.ReferenceCount -= this;
            _documentGroups.Remove(docGrp);

            if (!_terminating)
            {
                IsModified = true;

                if (DocumentRemoved != null)
                {
                    DocumentRemoved(this, new DocGroupDocActionEventArgs(docGrp));
                }
            }
        }
Exemple #10
0
        private void GetEditableFilesFromPrjRecursive(ILuaEditDocumentGroup docGrp, List <ILuaEditDocumentEditable> scriptList)
        {
            foreach (ILuaEditDocumentEditable doc in docGrp.Documents)
            {
                scriptList.Add(doc as ILuaEditDocumentEditable);
            }

            foreach (ILuaEditDocumentGroup docGrpChild in docGrp.DocumentGroups)
            {
                GetEditableFilesFromPrjRecursive(docGrpChild, scriptList);
            }

            foreach (ILuaEditDocumentFolder docFolderChild in docGrp.DocumentFolders)
            {
                GetEditableFilesFromPrjRecursive(docFolderChild, scriptList);
            }
        }
        private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (solutionExplorerTreeView.SelectedItems.Count == 1)
            {
                ILuaEditDocumentGroup  grpDoc    = solutionExplorerTreeView.SelectedItems[0].Tag as ILuaEditDocumentGroup;
                ILuaEditDocumentFolder folderDoc = grpDoc.CreateNewFolder();
                TreeListViewItem       tlvi      = null;

                FindTreeListViewItemByDocument(solutionExplorerTreeView.RootItem, folderDoc, ref tlvi);

                if (tlvi != null)
                {
                    solutionExplorerTreeView.SelectedItems.Clear();
                    solutionExplorerTreeView.SelectedItems.Add(tlvi);
                    solutionExplorerTreeView.Refresh();
                    solutionExplorerTreeView.EditTreeListViewItem(tlvi, null);
                }
            }
        }
Exemple #12
0
        public virtual void AddDocument(ILuaEditDocumentGroup docGrp)
        {
            if (_opening || FindDocumentGroup(docGrp.FileName) == null)
            {
                docGrp.ParentDocument  = this;
                docGrp.ReferenceCount += this;
                _documentGroups.Add(docGrp);

                if (!_opening)
                {
                    IsModified = true;

                    if (DocumentAdded != null)
                    {
                        DocumentAdded(this, new DocGroupDocActionEventArgs(docGrp));
                    }
                }
            }
        }
Exemple #13
0
        /// <summary>
        /// Show the dialog
        /// </summary>
        /// <param name="title">The title to display for this dialog</param>
        /// <param name="parentContext">The parent contextual to the new object to add</param>
        /// <param name="location">The location directory to suggest</param>
        /// <param name="itemType">The type of new item to suggest in the dialog</param>
        /// <param name="dialogStyle">The layout display style</param>
        /// <returns>The dialog user's choice (will either be OK or Cancel)</returns>
        public DialogResult ShowDialog(string title, ILuaEditDocumentGroup parentContext, string location,
                                       NewItemTypes itemType, NewItemDialogStyle dialogStyle)
        {
            this.DialogStyle           = dialogStyle;
            this.Text                  = title;
            btnAdd.Text                = parentContext == null ? "OK" : "Add";
            _parentContext             = parentContext;
            _itemType                  = itemType;
            lvwNewItems.SmallImageList = DocumentFactory.Instance.DocumentSmallImages;
            lvwNewItems.LargeImageList = DocumentFactory.Instance.DocumentLargeImages;
            txtLocation.Text           = location;
            FillList();

            if (lvwNewItems.Items.Count > 0)
            {
                lvwNewItems.Items[0].Selected = true;
            }

            return(this.ShowDialog(FrameworkManager.Instance.MainDialog));
        }
        /// <summary>
        /// Occurs when a document gets added to a group document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDocumentAdded(object sender, DocGroupDocActionEventArgs e)
        {
            TreeListViewItem result = null;
            ILuaEditDocument doc    = sender as ILuaEditDocument;

            FindTreeListViewItemByDocument(solutionExplorerTreeView.Items[0], doc, ref result);

            if (result != null)
            {
                e.Document.ToTreeListViewItem(result);
                result.Expand();

                if (e.Document is ILuaEditDocumentGroup)
                {
                    ILuaEditDocumentGroup grpDoc = e.Document as ILuaEditDocumentGroup;
                    grpDoc.DocumentRemoved += OnDocumentRemoved;
                    grpDoc.DocumentAdded   += OnDocumentAdded;
                }
            }

            solutionExplorerTreeView.ShowRootTreeLines = (solutionExplorerTreeView.Items.Count > 0 && solutionExplorerTreeView.Items[0].Items.Count > 0);
            solutionExplorerTreeView.AutoSizeColumnWidths(true);
        }
Exemple #15
0
 public DocumentRef(string fileName, ILuaEditDocumentGroup parentDocument)
     : this(fileName)
 {
     _parentDoc = parentDocument;
 }