Natural Docs Version 1.2 |
NaturalDocs:: MenuA package handling the menu’s contents and state. Usage and Dependencies
Summary
Constantsmenu
The parsed menu file. Is stored as a <MENU_GROUP> NaturalDocs::Menu::Entry object, with the top-level entries being stored as the group’s content. This is done because it makes a number of functions simpler to implement, plus it allows group flags to be set on the top-level. However, it is exposed externally via Content() as an arrayref. This structure will only contain objects for <MENU_FILE>, <MENU_GROUP>, <MENU_TEXT>, <MENU_LINK>, and <MENU_INDEX> entries. Other types, such as <MENU_TITLE>, are stored in variables such as title. defaultTitlesChanged
An existence hash of default titles that have changed, since OnDefaultTitleChange() will be called before LoadAndUpdate(). Collects them to be applied later. The keys are the file names. Menu.txtThe file used to generate the menu. FormatThe file is plain text. Blank lines can appear anywhere and are ignored. Tags and their content must be completely contained on one line with the exception of Group’s braces. # [comment] The file supports single-line comments via #. They can appear alone on a line or after content. Format: [version] Title: [title] SubTitle: [subtitle] Footer: [footer] The file format version, menu title, subtitle, and footer are specified as above. Each can only be specified once, with subsequent ones being ignored. Subtitle is ignored if Title is not present. Format must be the first entry in the file. If it’s not present, it’s assumed the menu is from version 0.95 or earlier, since it was added with 1.0. File: [title] ([file name]) File: [title] (auto-title, [file name]) File: [title] (no auto-title, [file name]) Files are specified as above. If “no auto-title” is specified, the title on the line is used. If not, the title is ignored and the default file title is used instead. Auto-title defaults to on, so specifying “auto-title” is for compatibility only. Group: [title]
Group: [title] { ... }Groups are specified as above. If no braces are specified, the group’s content is everything that follows until the end of the file, the next group (braced or unbraced), or the closing brace of a parent group. Group braces are the only things in this file that can span multiple lines. There is no limitations on where the braces can appear. The opening brace can appear after the group tag, on its own line, or preceding another tag on a line. Similarly, the closing brace can appear after another tag or on its own line. Being bitchy here would just get in the way of quick and dirty editing; the package will clean it up automatically when it writes it back to disk. Text: [text] Arbitrary text is specified as above. As with other tags, everything must be contained on the same line. Link: [URL] Link: [title] ([URL]) External links can be specified as above. If the titled form is not used, the URL is used as the title. Index: [name] [modifier] Index: [name] Indexes are specified with the types above. Valid modifiers are topic keywords, either singular or plural. If the modifier is “General” or not specified, the line specifies a general index. Don't Index: [type] Don't Index: [type], [type], ... The option above prevents indexes that exist but are not on the menu from being automatically added. “General” is used to specify the general index. Commas aren’t required. Data: 1([obscured: [directory name]///[input directory]]) Used to store non-user editable data. The leading 1 specifies it as storage for the input directories used in the last run and their names. This allows menu files to be shared across machines, since the names will be consistent and the directories can be used to convert filenames to the local machine’s paths. We don’t want this user-editable because they may think changing it changes the input directories, when it doesn’t. Also, changing it without changing all the paths screws up resolving. Revisions1.16
1.14
1.1
This is also the point where indexes were automatically added and removed, so all index entries from prior revisions were manually added and are not guaranteed to contain anything. 1.0
This is also the point where auto-organization and better auto-titles were introduced. All groups in prior revisions were manually added, with the exception of a top-level Other group where new files were automatically added if there were groups defined. 0.9
PreviousMenuState.ndThe file used to store the previous state of the menu so as to detect changes. [BINARY_FORMAT] The file is binary, so the first byte is the <BINARY_FORMAT> token. [app version] Immediately after is the application version it was generated with. Manage with the binary functions in NaturalDocs::Version. [UInt8: 0 (end group)] [UInt8: MENU_FILE] [UInt8: noAutoTitle] [AString16: title] [AString16: target] [UInt8: MENU_GROUP] [AString16: title] [UInt8: MENU_INDEX] [AString16: title] [UInt8: type (0 for general)] [UInt8: MENU_LINK] [AString16: title] [AString16: url] [UInt8: MENU_TEXT] [AString16: text] The first UInt8 of each following line is either zero or one of the <Menu Entry Types>. What follows is contextual. AString16s are big-endian UInt16’s followed by that many ASCII characters. There are no entries for title, subtitle, or footer. Only the entries present in menu. Dependencies
Revisions1.16
1.14
1.0
0.95
0.9
Content
Returns the parsed menu as an arrayref of NaturalDocs::Menu::Entry objects. Do not change the arrayref. The arrayref will only contain <MENU_FILE>, <MENU_GROUP>, <MENU_INDEX>, <MENU_TEXT>, and <MENU_LINK> entries. Entries such as <MENU_TITLE> are parsed out and are only accessible via functions such as Title(). FilesInMenu
Returns a hashref of all the files present in the menu. The keys are the file names, and the values are references to their NaturalDocs::Menu::Entry objects. Event HandlersThese functions are called by NaturalDocs::Project only. You don’t need to worry about calling them. For example, when changing the default menu title of a file, you only need to call NaturalDocs::Project->SetDefaultMenuTitle(). That function will handle calling OnDefaultTitleChange(). OnFileChange
Called by NaturalDocs::Project if it detects that the menu file has changed. OnDefaultTitleChange
Called by NaturalDocs::Project if the default menu title of a source file has changed. Parameters
LoadMenuFile
Loads and parses the menu file Menu.txt. This will fill menu, title, subTitle, footer, indexes, and bannedIndexes. If there are any errors in the file, they will be recorded with NaturalDocs::ConfigFile->AddError(). ReturnsThe array ( inputDirectories, oldLockedTitles, relativeFiles ).
SaveMenuFile
Saves the current menu to Menu.txt. WriteMenuEntries
A recursive function to write the contents of an arrayref of NaturalDocs::Menu::Entry objects to disk. Parameters
LoadPreviousMenuStateFile
Loads and parses the previous menu state file. Note that this is not affected by NaturalDocs::Settings->RebuildData(). Since this is used to detect user changes, the information here can’t be ditched on a whim. ReturnsThe array ( previousMenu, previousIndexes, previousFiles ).
If there is no data available on a topic, it will be undef. For example, if the file didn’t exist, all three will be undef. If the file was from 0.95 or earlier, previousIndexes will be set but the other two would be undef. SavePreviousMenuStateFile
Saves changes to PreviousMenuState.nd. WritePreviousMenuStateEntries
A recursive function to write the contents of an arrayref of NaturalDocs::Menu::Entry objects to disk. Parameters
CheckForTrashedMenu
Checks the menu to see if a significant number of file entries didn’t resolve to actual files, and if so, saves a backup of the menu and issues a warning. Parameters
ResolveInputDirectories
Detects if the input directories in the menu file match those in the command line, and if not, tries to resolve them. This allows menu files to work across machines, since the absolute paths won’t be the same but the relative ones should be. Parameters
ResolveFile
Tests a relative path against a list of directories. Adds one to the score of each base where there is a match. Parameters
LockUserTitleChanges
Detects if the user manually changed any file titles, and if so, automatically locks them with <MENU_FILE_NOAUTOTITLE>. Parameters
AutoPlaceNewFiles
Adds files to the menu that aren’t already on it, attempting to guess where they belong. New files are placed after a dummy <MENU_ENDOFORIGINAL> entry so that they don’t affect the detected order. Also, the groups they’re placed in get <MENU_GROUP_UPDATETITLES>, <MENU_GROUP_UPDATESTRUCTURE>, and <MENU_GROUP_UPDATEORDER> flags. Parameters
MatchDirectoriesAndGroups
Determines which groups files in certain directories should be placed in. ReturnsA hashref. The keys are the directory names, and the values are references to the group objects they should be placed in. This only repreesents directories that currently have files on the menu, so it shouldn’t be assumed that every possible directory will exist. To match, you should first try to match the directory, and then strip the deepest directories one by one until there’s a match or there’s none left. If there’s none left, use the root group menu. AddAndRemoveIndexes
Automatically adds and removes index entries on the menu as necessary. DetectIndexGroups() should be called beforehand. RemoveIfDeadChecks a group and all its sub-groups for life and remove any that are dead. Empty groups are removed, and groups with one entry and the <MENU_GROUP_UPDATESTRUCTURE> flag have their entry moved to the parent group. Parameters
ReturnsWhether the group was removed or not. DetectOrderDetects the order of the entries in all groups that have the <MENU_GROUP_UPDATEORDER> flag set. Will set one of the <MENU_GROUP_FILESSORTED>, <MENU_GROUP_FILESANDGROUPSSORTED>, <MENU_GROUP_EVERYTHINGSORTED>, or <MENU_GROUP_UNSORTED> flags. It will always go for the most comprehensive sort possible, so if a group only has one entry, it will be flagged as <MENU_GROUP_EVERYTHINGSORTED>. DetectIndexGroups() should be called beforehand, as the <MENU_GROUP_ISINDEXGROUP> flag affects how the order is detected. The sort detection stops if it reaches a <MENU_ENDOFORIGINAL> entry, so new entries can be added to the end while still allowing the original sort to be detected. Parameters
GenerateAutoFileTitlesCreates titles for the unlocked file entries in all groups that have the <MENU_GROUP_UPDATETITLES> flag set. It clears the flag afterwards so it can be used efficiently for multiple sweeps. Parameters
ResortGroupsResorts all groups that have <MENU_GROUP_UPDATEORDER> set. Assumes DetectOrder() and GenerateAutoFileTitles() have already been called. Will clear the flag and any <MENU_ENDOFORIGINAL> entries on reordered groups. Parameters
CompareEntriesA comparison function for use in sorting. Compares the two entries by their titles with StringCompare(), but in the case of a tie, puts <MENU_FILE> entries above <MENU_GROUP> entries. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
my %menuSynonyms |
my $hasChanged |
my $fileChanged |
my $menu |
my %defaultTitlesChanged |
sub OnDefaultTitleChange #(file) |
sub LoadAndUpdate |
my $title |
my $subTitle |
my $footer |
my %indexes |
my %previousIndexes |
my %bannedIndexes |
sub Save |
sub HasChanged |
sub Content |
sub Title |
sub SubTitle |
sub Footer |
sub Indexes |
sub PreviousIndexes |
sub FilesInMenu |
sub OnFileChange |
sub LoadMenuFile |
sub SaveMenuFile |
| |||||||||||||||
sub LoadPreviousMenuStateFile |
sub SavePreviousMenuStateFile |
| ||||||||||
| ||||||||||
sub ResolveInputDirectories #(inputDirectoryNames) |
sub ResolveRelativeInputDirectories |
| |||||||||||||||
sub LockUserTitleChanges #(previousMenuFiles) |
sub FlagAutoTitleChanges |
sub AutoPlaceNewFiles #(fileInMenu) |
sub MatchDirectoriesAndGroups |
sub RemoveDeadFiles |
sub BanAndUnbanIndexes |
sub AddAndRemoveIndexes |
sub ParseForInformation #(file) |
sub GenerateDirectoryNames #(hints) |
| ||||||||||
| ||||||||||
sub RebuildData |
| ||||||||||