Ejemplo n.º 1
0
        //=====================================================================
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileItem">The project file item to edit</param>
        public TokenEditorWindow(FileItem fileItem)
        {
            InitializeComponent();

            sbStatusBarText.InstanceStatusBar = MainForm.Host.StatusBarTextLabel;

            editor.TextEditorProperties.Font = Settings.Default.TextEditorFont;
            editor.TextEditorProperties.ShowLineNumbers = Settings.Default.ShowLineNumbers;
            editor.SetHighlighting("XML");

            tokens = new TokenCollection(fileItem);
            tokens.Load();
            tokens.ListChanged += new ListChangedEventHandler(tokens_ListChanged);

            this.Text = Path.GetFileName(fileItem.FullPath);
            this.ToolTipText = fileItem.FullPath;
            this.LoadTokens();
        }
Ejemplo n.º 2
0
        internal void Load(XmlNode xnSupply)
        {
            // This needs to be done in reverse order, as AddTo adds cards one at a time on top of the pile instead of the bottom
            foreach (XmlNode xnCard in xnSupply.SelectNodes("cards/card").Cast <XmlNode>().Reverse())
            {
                Type cardType = Type.GetType(xnCard.Attributes["type"].Value);
                this.AddTo(Card.CreateInstance(cardType));
            }

            XmlNode xnSSS = xnSupply.SelectSingleNode("starting_stack_size");

            if (xnSSS != null)
            {
                this.StartingStackSize = int.Parse(xnSSS.InnerText);
            }

            foreach (XmlNode xnType in xnSupply.SelectNodes("types/type"))
            {
                Type type = Type.GetType(xnType.InnerText);
                this._CardTypes.Add(type);
            }

            this.Tokens.AddRange(TokenCollection.Load(xnSupply.SelectSingleNode("tokens")));
        }
        //=====================================================================

        /// <summary>
        /// This loads the tree view with token file entries from the project
        /// </summary>
        private List<EntityReference> LoadTokenInfo()
        {
            EntityReference tokenFileEntity = null;
            TokenCollection tokenColl;

            if(tokens != null)
                return tokens;

            tokens = new List<EntityReference>();

            // Get content from open file editors
            var args = new FileContentNeededEventArgs(FileContentNeededEvent, this);
            base.RaiseEvent(args);

            foreach(var tokenFile in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath))
                try
                {
                    if(File.Exists(tokenFile.FullPath))
                    {
                        tokenFileEntity = new EntityReference
                        {
                            EntityType = EntityType.File,
                            Id = tokenFile.FullPath,
                            Label = Path.GetFileName(tokenFile.FullPath),
                            ToolTip = tokenFile.FullPath
                        };

                        tokens.Add(tokenFileEntity);

                        // If open in an editor, use the edited values
                        if(!args.TokenFiles.TryGetValue(tokenFile.FullPath, out tokenColl))
                        {
                            tokenColl = new TokenCollection(tokenFile.FullPath);
                            tokenColl.Load();
                        }

                        foreach(Token t in tokenColl)
                            tokenFileEntity.SubEntities.Add(new EntityReference
                            {
                                EntityType = EntityType.Token,
                                Id = t.TokenName,
                                Label = t.TokenName,
                                ToolTip = t.TokenName,
                                Tag = t
                            });
                    }

                    tokenFileEntity = null;
                }
                catch(Exception ex)
                {
                    if(tokenFileEntity == null)
                        tokens.Add(new EntityReference
                        {
                            EntityType = EntityType.File,
                            Label = "Unable to load file '" + tokenFile.FullPath +
                                "'.  Reason: " + ex.Message,
                            ToolTip = "Error"
                        });
                    else
                        tokens.Add(new EntityReference
                        {
                            EntityType = EntityType.File,
                            Label = "Unable to load file: " + ex.Message,
                            ToolTip = "Error"
                        });
                }

            if(tokens.Count != 0)
            {
                tokens[0].IsSelected = true;

                if(tokens[0].SubEntities.Count != 0)
                    tokens[0].IsExpanded = true;
            }

            return tokens;
        }
        /// <summary>
        /// This loads the tree view with table of contents file entries from the project
        /// </summary>
        /// <remarks>Token information is also loaded here and passed on to the converter.</remarks>
        private void LoadTableOfContentsInfo()
        {
            List<ITableOfContents> tocFiles;
            TopicCollection contentLayout;
            TokenCollection tokens;

            tvContent.ItemsSource = null;
            tableOfContents = null;
            lblCurrentProject.Text = null;
            browserHistory.Clear();
            historyLocation = -1;

            if(currentProject == null)
            {
                lblCurrentProject.Text = "None - Select a help file builder project in the Solution Explorer";
                return;
            }

            // Make sure the base path is set for imported code blocks
            this.SetImportedCodeBasePath();

            // Get content from open file editors
            var args = new FileContentNeededEventArgs(FileContentNeededEvent, this);
            base.RaiseEvent(args);

            lblCurrentProject.Text = currentProject.Filename;
            browserHistory.Clear();
            historyLocation = -1;
            tableOfContents = new TocEntryCollection();

            try
            {
                converter.MediaFiles.Clear();

                // Get the image files.  This information is used to resolve media link elements in the
                // topic files.
                foreach(var file in currentProject.ImagesReferences)
                    converter.MediaFiles[file.Id] = new KeyValuePair<string, string>(file.FullPath, file.AlternateText);
            }
            catch(Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load media info: " + ex.Message
                });
            }

            try
            {
                converter.Tokens.Clear();

                // Get the token files.  This information is used to resolve token elements in the topic files.
                foreach(var file in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath))
                {
                    // If open in an editor, use the edited values
                    if(!args.TokenFiles.TryGetValue(file.FullPath, out tokens))
                    {
                        tokens = new TokenCollection(file.FullPath);
                        tokens.Load();
                    }

                    // Store the tokens as XElements so that they can be parsed inline with the topic
                    foreach(var t in tokens)
                        converter.Tokens.Add(t.TokenName, XElement.Parse("<token>" + t.TokenValue +
                            "</token>"));
                }
            }
            catch(Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load token info: " + ex.Message
                });
            }

            try
            {
                converter.TopicTitles.Clear();

                // Load the content layout files.  Site maps are ignored as we don't support rendering them.
                tocFiles = new List<ITableOfContents>();

                foreach(var contentFile in currentProject.ContentFiles(BuildAction.ContentLayout))
                {
                    // If open in an editor, use the edited values
                    if(!args.ContentLayoutFiles.TryGetValue(contentFile.FullPath, out contentLayout))
                    {
                        contentLayout = new TopicCollection(contentFile);
                        contentLayout.Load();
                    }

                    tocFiles.Add(contentLayout);
                }

                tocFiles.Sort((x, y) =>
                {
                    ContentFile fx = x.ContentLayoutFile, fy = y.ContentLayoutFile;

                    if(fx.SortOrder < fy.SortOrder)
                        return -1;

                    if(fx.SortOrder > fy.SortOrder)
                        return 1;

                    return String.Compare(fx.Filename, fy.Filename, StringComparison.OrdinalIgnoreCase);
                });

                // Create the merged TOC.  For the purpose of adding links, we'll include everything even topics
                // marked as invisible.
                foreach(ITableOfContents file in tocFiles)
                    file.GenerateTableOfContents(tableOfContents, true);

                // Pass the topic IDs and titles on to the converter for use in hyperlinks
                foreach(var t in tableOfContents.All())
                    if(!String.IsNullOrEmpty(t.Id))
                        converter.TopicTitles[t.Id] = t.LinkText;
            }
            catch(Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load TOC info: " + ex.Message
                });
            }

            if(tableOfContents.Count != 0)
            {
                foreach(var t in tableOfContents.All())
                    t.IsSelected = false;

                tableOfContents[0].IsSelected = true;
            }

            tvContent.ItemsSource = tableOfContents;
        }
        //=====================================================================

        /// <summary>
        /// This loads the tree view with token file entries from the project
        /// </summary>
        private List <EntityReference> LoadTokenInfo()
        {
            EntityReference tokenFileEntity = null;
            TokenCollection tokenColl;

            if (tokens != null)
            {
                return(tokens);
            }

            tokens = new List <EntityReference>();

            // Get content from open file editors
            var args = new FileContentNeededEventArgs(FileContentNeededEvent, this);

            base.RaiseEvent(args);

            foreach (var tokenFile in currentProject.ContentFiles(BuildAction.Tokens).OrderBy(f => f.LinkPath))
            {
                try
                {
                    if (File.Exists(tokenFile.FullPath))
                    {
                        tokenFileEntity = new EntityReference
                        {
                            EntityType = EntityType.File,
                            Id         = tokenFile.FullPath,
                            Label      = Path.GetFileName(tokenFile.FullPath),
                            ToolTip    = tokenFile.FullPath
                        };

                        tokens.Add(tokenFileEntity);

                        // If open in an editor, use the edited values
                        if (!args.TokenFiles.TryGetValue(tokenFile.FullPath, out tokenColl))
                        {
                            tokenColl = new TokenCollection(tokenFile.FullPath);
                            tokenColl.Load();
                        }

                        foreach (Token t in tokenColl)
                        {
                            tokenFileEntity.SubEntities.Add(new EntityReference
                            {
                                EntityType = EntityType.Token,
                                Id         = t.TokenName,
                                Label      = t.TokenName,
                                ToolTip    = t.TokenName,
                                Tag        = t
                            });
                        }
                    }

                    tokenFileEntity = null;
                }
                catch (Exception ex)
                {
                    if (tokenFileEntity == null)
                    {
                        tokens.Add(new EntityReference
                        {
                            EntityType = EntityType.File,
                            Label      = "Unable to load file '" + tokenFile.FullPath +
                                         "'.  Reason: " + ex.Message,
                            ToolTip = "Error"
                        });
                    }
                    else
                    {
                        tokens.Add(new EntityReference
                        {
                            EntityType = EntityType.File,
                            Label      = "Unable to load file: " + ex.Message,
                            ToolTip    = "Error"
                        });
                    }
                }
            }

            if (tokens.Count != 0)
            {
                tokens[0].IsSelected = true;

                if (tokens[0].SubEntities.Count != 0)
                {
                    tokens[0].IsExpanded = true;
                }
            }

            return(tokens);
        }
Ejemplo n.º 6
0
        //=====================================================================

        /// <summary>
        /// Load a token file for editing
        /// </summary>
        /// <param name="tokenFile">The token file to load</param>
        /// <param name="selectedToken">The token ID to select by default or null if no selection</param>
        public void LoadTokenFile(string tokenFile, string selectedToken)
        {
            if(tokenFile == null)
                throw new ArgumentNullException("tokenFile", "A token filename must be specified");

            tokens = new TokenCollection(tokenFile);
            tokens.Load();

            tokens.ListChanged += new ListChangedEventHandler(tokens_ListChanged);

            if(tokens.Count != 0)
                if(selectedToken == null)
                    tokens[0].IsSelected = true;
                else
                {
                    var match = tokens.Find(t => t.TokenName == selectedToken).FirstOrDefault();

                    if(match != null)
                        match.IsSelected = true;
                    else
                        tokens[0].IsSelected = true;
                }

            lbTokens.ItemsSource = tokens;

            this.tokens_ListChanged(this, new ListChangedEventArgs(ListChangedType.Reset, -1));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This loads the tree view with table of contents file entries from the project
        /// </summary>
        /// <remarks>Token information is also loaded here and passed on to the converter.</remarks>
        private void LoadTableOfContentsInfo()
        {
            FileItemCollection      imageFiles, tokenFiles, contentLayoutFiles;
            List <ITableOfContents> tocFiles;
            TopicCollection         contentLayout;
            TokenCollection         tokens;

            tvContent.ItemsSource  = null;
            tableOfContents        = null;
            lblCurrentProject.Text = null;
            browserHistory.Clear();
            historyLocation = -1;

            if (currentProject == null)
            {
                lblCurrentProject.Text = "None - Select a help file builder project in the Solution Explorer";
                return;
            }

            // Make sure the base path is set for imported code blocks
            this.SetImportedCodeBasePath();

            // Get content from open file editors
            var args = new FileContentNeededEventArgs(FileContentNeededEvent, this);

            base.RaiseEvent(args);

            currentProject.EnsureProjectIsCurrent(false);
            lblCurrentProject.Text = currentProject.Filename;
            browserHistory.Clear();
            historyLocation = -1;
            tableOfContents = new TocEntryCollection();

            try
            {
                converter.MediaFiles.Clear();

                // Get the image files.  This information is used to resolve media link elements in the
                // topic files.
                imageFiles = new FileItemCollection(currentProject, BuildAction.Image);

                foreach (FileItem file in imageFiles)
                {
                    if (!String.IsNullOrEmpty(file.ImageId))
                    {
                        converter.MediaFiles[file.ImageId] = new KeyValuePair <string, string>(file.FullPath,
                                                                                               file.AlternateText);
                    }
                }
            }
            catch (Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load media info: " + ex.Message
                });
            }

            try
            {
                converter.Tokens.Clear();

                // Get the token files.  This information is used to resolve token elements in the
                // topic files.
                tokenFiles = new FileItemCollection(currentProject, BuildAction.Tokens);

                foreach (FileItem file in tokenFiles)
                {
                    // If open in an editor, use the edited values
                    if (!args.TokenFiles.TryGetValue(file.FullPath, out tokens))
                    {
                        tokens = new TokenCollection(file.FullPath);
                        tokens.Load();
                    }

                    // Store the tokens as XElements so that they can be parsed inline with the topic
                    foreach (var t in tokens)
                    {
                        converter.Tokens.Add(t.TokenName, XElement.Parse("<token>" + t.TokenValue +
                                                                         "</token>"));
                    }
                }
            }
            catch (Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load token info: " + ex.Message
                });
            }

            try
            {
                converter.TopicTitles.Clear();

                // Get the content layout files.  Site maps are ignored.  We don't support rendering them.
                contentLayoutFiles = new FileItemCollection(currentProject, BuildAction.ContentLayout);
                tocFiles           = new List <ITableOfContents>();

                // Add the conceptual content layout files
                foreach (FileItem file in contentLayoutFiles)
                {
                    // If open in an editor, use the edited values
                    if (!args.ContentLayoutFiles.TryGetValue(file.FullPath, out contentLayout))
                    {
                        contentLayout = new TopicCollection(file);
                        contentLayout.Load();
                    }

                    tocFiles.Add(contentLayout);
                }

                // Sort the files
                tocFiles.Sort((x, y) =>
                {
                    FileItem fx = x.ContentLayoutFile, fy = y.ContentLayoutFile;

                    if (fx.SortOrder < fy.SortOrder)
                    {
                        return(-1);
                    }

                    if (fx.SortOrder > fy.SortOrder)
                    {
                        return(1);
                    }

                    return(String.Compare(fx.Name, fy.Name, StringComparison.OrdinalIgnoreCase));
                });

                // Create the merged TOC.  For the purpose of adding links, we'll include everything
                // even topics marked as invisible.
                foreach (ITableOfContents file in tocFiles)
                {
                    file.GenerateTableOfContents(tableOfContents, currentProject, true);
                }

                // Pass the topic IDs and titles on to the converter for use in hyperlinks
                foreach (var t in tableOfContents.All())
                {
                    if (!String.IsNullOrEmpty(t.Id))
                    {
                        converter.TopicTitles[t.Id] = t.LinkText;
                    }
                }
            }
            catch (Exception ex)
            {
                tableOfContents.Add(new TocEntry(currentProject)
                {
                    Title = "ERROR: Unable to load TOC info: " + ex.Message
                });
            }

            if (tableOfContents.Count != 0)
            {
                foreach (var t in tableOfContents.All())
                {
                    t.IsSelected = false;
                }

                tableOfContents[0].IsSelected = true;
            }

            tvContent.ItemsSource = tableOfContents;
        }
        //=====================================================================
        /// <summary>
        /// This loads the tree view with token file entries from the project
        /// </summary>
        private void LoadTokenInfo()
        {
            TreeNode rootNode = null, node;
            TokenCollection tokens;

            tvEntities.ImageList = ilImages;
            tvEntities.Nodes.Clear();

            if(tokenFiles == null)
                tokenFiles = new FileItemCollection(currentProject,
                    BuildAction.Tokens);

            foreach(FileItem tokenFile in tokenFiles)
                try
                {
                    if(File.Exists(tokenFile.FullPath))
                    {
                        rootNode = tvEntities.Nodes.Add(Path.GetFileName(
                            tokenFile.FullPath));
                        rootNode.ImageIndex = rootNode.SelectedImageIndex =
                            (int)EntityType.CodeEntities;

                        tokens = new TokenCollection(tokenFile);
                        tokens.Load();

                        foreach(Token t in tokens)
                        {
                            node = rootNode.Nodes.Add(t.TokenName);
                            node.Name = t.TokenName;
                            node.Tag = t;
                            node.ImageIndex = node.SelectedImageIndex =
                                (int)EntityType.Tokens;
                        }
                    }

                    rootNode = null;
                }
                catch(Exception ex)
                {
                    if(rootNode == null)
                        tvEntities.Nodes.Add("Unable to load file '" +
                            tokenFile.FullPath + "'.  Reason: " + ex.Message);
                    else
                        rootNode.Nodes.Add("Unable to load file: " + ex.Message);
                }

            txtFindName.Enabled = true;
            tvEntities.Enabled = true;
            tvEntities.ExpandAll();
        }