Project Code Box
ProjectCodeBox is designed to simulate a complete project by displaying the entire source code.
Elements of Project Code Box
In addition to code view and file elements (described here), a project code box can also include folder structure configuration elements and commands. The following code sample shows what an element for a project code box might look like.
<!-- project code box -->
<div id="MyProjectCodeBox">
<!-- folder structure -->
<ul data-cb-folders>
<li>
src
<ul>
<li>main</li>
</ul>
</li>
<li data-cb-opened>test</li>
</ul>
<!-- code view -->
<pre data-cb-name="MyApp.java" data-cb-package="io.github.jirkasa" data-cb-active><code>package io.github.jirkasa;
public class MyApp {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}</code></pre>
<!-- code view -->
<pre data-cb-name="README.txt"><code>This is example app.</code></pre>
<!-- file -->
<div data-cb-name="Image.png" data-cb-file="../../static/Image.png" data-cb-folder="assets/img"></div>
<!-- commands -->
<script data-cb-commands type="application/json">
[
{
"command": "rename project",
"name": "code-box-example"
},
{
"command": "add code view highlight",
"identifier": "README.txt",
"start": 1
}
]
</script>
</div>
Additional data attributes for code views and files
In addition to the attributes data-cb-name, data-cb-active, and data-cb-file, code views and files in a project code box can also contain the following data attributes.
data-cb-folder | Specifies the folder into which the code view or file should be placed. |
---|---|
data-cb-package | Specifies the package into which the code view or file is placed. If no value is provided, it is placed into the default package. |
In a project code box, it is acceptable to have multiple code views or files with the same data-cb-name attribute because the identifier is composed of both the folder and the name.
Folder structure configuration
If the data-cb-folder attribute is used for a code view or file and the folder does not exist, it will be created. However, if you need to create folders that do not contain any content, you can use a folder structure configuration element. This element allows you to define a specific folder structure, as shown in the following example. The folder structure configuration element is marked with the data-cb-folders attribute. To have a folder opened on initialization, you can mark it with the data-cb-opened attribute.
<ul data-cb-folders>
<li>
src
<ul>
<li>
main
<ul>
<li>java</li>
</ul>
</li>
</ul>
</li>
<li data-cb-opened>test</li>
</ul>
Commands
A project code box can include a script element with commands to be executed, such as renaming a folder, removing a file, and so on. The script must have its type attribute set to application/json to prevent it from being executed. Commands are written as objects within an array in JSON format, as demonstrated in the following example. Each object should have a command property that specifies the type of command, along with other properties depending on the command type.
<script data-cb-commands type="application/json">
[
{
"command": "rename project",
"name": "code-box-example"
},
{
"command": "remove folder",
"folderPath": "src/main"
},
{
"command": "open folder",
"folderPath": "js/common",
"openParentFolders": true
}
]
</script>
Usage Example
The following example demonstrates how to create a ProjectCodeBox. Simply instantiate the ProjectCodeBox class by passing a reference to the root element of code box. You can also provide additional options as a second parameter.
<div id="MyProjectCodeBox">
<ul data-cb-folders>
<li>
src
<ul>
<li>
main
<ul>
<li>java</li>
<li>resources</li>
<li>webapp</li>
</ul>
</li>
<li>
test
<ul>
<li>java</li>
<li>resources</li>
</ul>
</li>
</ul>
</li>
<li>target</li>
</ul>
<pre data-cb-name="MyApp.java" data-cb-package="io.github.jirkasa" data-cb-active><code>package io.github.jirkasa;
public class MyApp {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}</code></pre>
<pre data-cb-name="pom.xml"><code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jirkasa</groupId>
<artifactId>example-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>example-app</name>
</project></code></pre>
</div>
import { ProjectCodeBox } from "@jirkasa/code-box";
new ProjectCodeBox(document.getElementById("MyProjectCodeBox"), {
minCodeViewLinesCount: 20,
projectName: "example-app",
packagesFolderPath: "src/main/java",
foldersDelimiterForPackages: ".",
svgSpritePath: "./img/icon-sprite.svg",
svgSpriteIcons: {
codeFile: "file",
file: "file-2",
download: "download",
panelOpenButton: "double-arrow-right",
folderArrow: "arrow-right",
folder: "folder",
project: "inventory",
package: "package"
}
});
- src
- main
- java
- resources
- webapp
- test
- java
- resources
- main
- target
package io.github.jirkasa;
public class MyApp {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.jirkasa</groupId>
<artifactId>example-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>example-app</name>
</project>
If you want to create multiple project code boxes, you can use the ProjectCodeBoxCreator. For more information, refer to the chapter on creators.
Inheritance
Project code boxes have the ability to inherit from other project code boxes. When creating an instance of a ProjectCodeBox, you can pass a parent project code box as the third parameter. The newly created project code box will inherit all code views, files, folders, and packages from its parent code box. Additionally, the new code box can add its own code views or files, delete some, or make other modifications as needed. The following example shows how to create a project code box that inherits from a parent code box.
<div id="CodeBox1">
<pre data-cb-active data-cb-name="style.css" data-cb-folder="css" data-cb-active><code>h1 {
font-size: 16px;
color: red;
}</code></pre>
</div>
<br>
<div id="CodeBox2">
<pre data-cb-name="main.js" data-cb-folder="js" data-cb-active><code>let x = 1;
let y = 2;
console.log("result: " + (x + y));</code></pre>
</div>
import { ProjectCodeBox } from "@jirkasa/code-box";
const codeBox1 = new ProjectCodeBox(document.getElementById("CodeBox1"), {
minCodeViewLinesCount: 10,
svgSpritePath: "./img/icon-sprite.svg",
projectName: "example-app",
svgSpriteIcons: {
codeFile: "file",
file: "file-2",
download: "download",
panelOpenButton: "double-arrow-right",
folderArrow: "arrow-right",
folder: "folder",
project: "inventory",
package: "package"
}
});
new ProjectCodeBox(document.getElementById("CodeBox2"), {
minCodeViewLinesCount: 10,
svgSpritePath: "./img/icon-sprite.svg",
svgSpriteIcons: {
codeFile: "file",
file: "file-2",
download: "download",
panelOpenButton: "double-arrow-right",
folderArrow: "arrow-right",
folder: "folder",
project: "inventory",
package: "package"
}
}, codeBox1);
h1 {
font-size: 16px;
color: red;
}
let x = 1;
let y = 2;
console.log("result: " + (x + y));
Most of the time, you will likely use ProjectCodeBoxCreator to avoid manually creating each code box and redundantly specifying options.
What is inherited
The following things are inherited:
- code views
- files
- folders
- packages
- folder path for packages
- project name
- createFoldersForPackages option
- foldersDelimiterForPackages option
What is not inherited
The following things are not inherited:
- open/close state of panel
- open/close state of folders
- open/close state of packages
- highlights of code views
Note on packages
The packages of overwritten code views and files are not changed unless a new package is explicitly assigned.
Commands
As mentioned previously, a project code box can include a script element with commands to be executed. The following commands are available:
rename project
Renames project.
Properties
name : string | New name. |
---|
add folder
Creates new folder(s) (if not created yet).
Properties
folderPath : string | Folder path. |
---|
remove folder
Removes folder and all its contents. This might also remove packages if their folders are removed (if generation of folders for packages is enabled via createFoldersForPackages option).
Properties
folderPath : string | Path to folder that should be removed. |
---|
rename folder
Renames folder. This can also change (rename) folder for packages and rename packages.
Properties
folderPath : string | Path to folder that should be renamed. |
---|---|
newName : string | New name for folder. |
open folder
Opens folder.
Properties
folderPath : string | Path to folder that should be opened. |
---|---|
openParentFolders ?: boolean | Determines whether parent folders should also be opened (default = false). |
close folder
Closes folder.
Properties
folderPath : string | Path to folder that should be closed. |
---|---|
closeChildFolders ?: boolean | Determines whether subfolders should be closed too (default = false). |
add package
Creates new package (if it does not exist yet).
Properties
name : string | Name of package. |
---|
remove package
Removes package.
Properties
name : string | Package name. |
---|---|
removePackageFoldersAndContents ?: boolean | Determines whether package folder and its contents should be removed (default = true). |
removeAllCodeViewsAndFiles ?: boolean | Determines whether all code views and files in package should be removed (default = false). |
rename package
Renames package. This can also rename folders for package if generation of folders is enabled via createFoldersForPackages option.
Properties
name : string | Current package name. |
---|---|
newName : string | New package name. |
open package
Opens package.
Properties
name ?: string | null | Package name (null or undefined for default package). |
---|
close package
Closes package.
Properties
name ?: string | null | Package name (null or undefined for default package). |
---|
remove code view
Removes code view from code box.
Properties
identifier : string | Identifier of code view to be removed. |
---|
rename code view
Changes file name of code view.
Properties
identifier : string | Identifier of code view to be renamed. |
---|---|
newName : string | New file name. |
move code view to folder
Moves code view to folder (if folder does not exist, it is created; package is not changed).
Properties
identifier : string | Identifier of code view. |
---|---|
folderPath : string | Path to folder. |
change code view package
Changes package of code view.
Properties
identifier : string | Identifier of code view. |
---|---|
packageName ?: string | null | Package name (null and undefined for default package). If package does not exist, it is created. |
keepFolderPath : boolean | Determines whether code view should stay in the same folder (if false, code view can be moved to different folder based on package). |
remove code view package
Removes code view from package.
Properties
identifier : string | Identifier of code view. |
---|
remove all code views
Removes all code views from code box.
add code view highlight
Adds new highlight to code view.
Properties
identifier : string | Identifier of code view. |
---|---|
start : number | Start line of highlight. |
end ?: number | End line of highlight (default is the same as start line). |
remove code view highlight
Removes highlights from code view based on specified range (all intersecting highlights are removed).
Properties
identifier : string | Identifier of code view. |
---|---|
start ?: number | null | Start line (passing null or leaving it empty defaults to the first line). |
end ?: number | End line (default is the same as start line; passing null defaults to the last line). |
set active code view
Sets code view as active (displays it in code box).
Properties
identifier : string | Identifier of code view to be set as active. |
---|
set no active code view
Displays no code view in code box.
remove file
Removes file from code box.
Properties
identifier : string | Identifier of file to be removed. |
---|
rename file
Changes name of file.
Properties
identifier : string | Identifier of file to be renamed. |
---|---|
newName : string | New file name. |
move file to folder
Moves file to folder (if folder does not exist, it is created; package is not changed).
Properties
identifier : string | Identifier of file. |
---|---|
folderPath : string | Path to folder. |
change file package
Changes package of file.
Properties
identifier : string | Identifier of file. |
---|---|
packageName ?: string | null | Package name (null and undefined for default package). If package does not exist, it is created. |
keepFolderPath : boolean | Determines whether file should stay in the same folder (if false, file can be moved to different folder based on package). |
remove file package
Removes file from package.
Properties
identifier : string | Identifier of file. |
---|
remove all files
Removes all files from code box.
Options
ProjectCodeBox accepts the following options and all options from the base CodeBox class.
...all options from CodeBox class | |
---|---|
svgSpritePath | Specifies path to the SVG sprite that contains icons. |
svgSpriteIcons | Specifies names of the icons in the SVG sprite. |
folderStructureHeading | Specifies folder structure heading. |
packagesHeading | Specifies packages heading. |
projectName | Specifies name of project. |
packagesFolderPath | Specifies path to folder for packages. |
defaultPackageName | Specifies name under which the default package should be displayed. |
createFoldersForPackages | Specifies whether folders should be created for packages. |
foldersDelimiterForPackages | Specifies delimiter to be used when creating folders for packages. |
folderAnimationSpeed | Specifies speed of folder open/close animation. |
folderAnimationEasingFunction | Specifies CSS easing function for folder open/close animation. |
openActiveCodeViewFolderOnInit | Specifies whether folder and its parent folders containing the active code view should be opened on initialization. |
openActiveCodeViewPackageOnInit | Specifies whether package containing the active code view should be opened on initialization. |
preventActiveCodeViewFolderOpenOnInitIfPackage | Specifies whether the folder and its parent folders containing the active code view should not be opened on initialization when the code view is within a package. |
openRootFolderOnInit | Specifies whether the project (root) folder should be opened on initialization. |
openPanelOnInit | Specifies whether the side panel should be opened on initialization. |
closePanelOnCodeViewSelect | Specifies whether the side panel should be closed when code view is selected by clicking on its button. |
openPanelButtonAriaLabel | Specifies value of the panel open/close button aria-label attribute when panel is closed. |
closePanelButtonAriaLabel | Specifies value of the panel open/close button aria-label attribute when panel is opened. |
svgSpritePath : string
Default value: undefined
Specifies path to the SVG sprite that contains icons.
svgSpriteIcons : object
Default value: {}
Specifies names of the icons in the SVG sprite in a form of object with the following properties:
- codeFile - name of icon for code view button
- file - name of icon for file button
- download - name of icon that is displayed for button of downloadable file
- panelOpenButton - name of icon for panel open/close button
- folderArrow - name of icon for folder arrow
- folder - name of icon for folder
- project - name of icon for project (root) folder
- package - name of icon for package
// ...
svgSpriteIcons: {
codeFile: "file",
file: "file-2",
download: "download",
panelOpenButton: "double-arrow-right",
folderArrow: "arrow-right",
folder: "folder",
project: "inventory",
package: "package"
}
// ...
folderStructureHeading : string
Default value: "Folder structure"
Data attribute alternative: data-cb-folder-structure-heading
Specifies folder structure heading.
packagesHeading : string
Default value: "Packages"
Data attribute alternative: data-cb-packages-heading
Specifies packages heading.
projectName : string
Default value: "unnamed"
Data attribute alternative: data-cb-project-name
Specifies the name of project (root) folder. This option is not used if the code box has parent code box.
packagesFolderPath : string
Default value: "/"
Data attribute alternative: data-cb-packages-folder-path
Specifies path to folder for packages. This option is not used if the code box has parent code box.
defaultPackageName : string
Default value: "default"
Data attribute alternative: data-cb-default-package-name
Specifies name under which the default package should be displayed.
createFoldersForPackages : boolean
Default value: true
Data attribute alternative: data-cb-create-folders-for-packages
Specifies whether folders should be created for packages. This option is not used if the code box has parent code box.
foldersDelimiterForPackages : string
Default value: undefined
Data attribute alternative: data-cb-folders-delimiter-for-packages
Specifies delimiter to be used when creating folders for packages. For example, if the delimiter is "." and the package name is "io.github.jirkasa", folders "io/github/jirkasa" are created. This option is not used if the code box has a parent code box.
folderAnimationSpeed : number
Default value: 200
Data attribute alternative: data-cb-folder-animation-speed
Specifies speed of folder open/close animation (in milliseconds).
folderAnimationEasingFunction : string
Default value: "ease-in-out"
Data attribute alternative: data-cb-folder-animation-easing-function
Specifies CSS easing function for folder open/close animation.
openActiveCodeViewFolderOnInit : boolean
Default value: true
Data attribute alternative: data-cb-open-active-code-view-folder-on-init
Specifies whether folder and its parent folders containing the active code view should be opened on initialization.
openActiveCodeViewPackageOnInit : boolean
Default value: true
Data attribute alternative: data-cb-open-active-code-view-package-on-init
Specifies whether package containing the active code view should be opened on initialization.
preventActiveCodeViewFolderOpenOnInitIfPackage : boolean
Default value: false
Data attribute alternative: data-cb-prevent-active-code-view-folder-open-on-init-if-package
Specifies whether the folder and its parent folders containing the active code view should not be opened on initialization when the code view is within a package. This option overrides openActiveCodeViewFolderOnInit when set to true and the active code view is within a package.
openRootFolderOnInit : boolean
Default value: true
Data attribute alternative: data-cb-open-root-folder-on-init
Specifies whether the project (root) folder should be opened on initialization. This option has effect only in certain situations (openActiveCodeViewFolderOnInit option takes precedence).
openPanelOnInit : boolean
Default value: false
Data attribute alternative: data-cb-open-panel-on-init
Specifies whether the side panel should be opened on initialization.
closePanelOnCodeViewSelect : boolean
Default value: true
Data attribute alternative: data-cb-close-panel-on-code-view-select
Specifies whether the side panel should be closed when code view is selected by clicking on its button.
openPanelButtonAriaLabel : string
Default value: "Open panel"
Data attribute alternative: data-cb-open-panel-button-aria-label
Specifies value of the panel open/close button aria-label attribute when panel is closed.
closePanelButtonAriaLabel : string
Default value: "Close panel"
Data attribute alternative: data-cb-close-panel-button-aria-label
Specifies value of the panel open/close button aria-label attribute when panel is opened.
Methods
ProjectCodeBox has the following methods. Many of these methods are also described in the chapter about the base CodeBox class. However, some of them have a return type that is a subclass of CodeBoxCodeView or CodeBoxFile - specifically, ProjectCodeBoxCodeView or ProjectCodeBoxFile. For clarity, these methods are also listed in this chapter.
appendTo | Appends code box to element. |
---|---|
detach | Detaches code box from its parent element. |
init | Initializes code box if it hasn't been initialized yet. |
isInitialized | Checks whether the code box is initialized. |
addOnInitListener | Registeres function to be called when code box is initialized. |
addCodeView | Adds new code view to code box. |
getCodeViews | Returns all code views of code box. |
getCodeViewsByFolderPath | Returns code views in folder. |
getCodeViewsByPackage | Returns code views in package. |
getCodeView | Returns code view based on identifier. |
getCodeViewByFolderPath | Returns code view based on folder path and name. |
getCodeViewByPackage | Returns code view based on package and name. |
removeCodeView | Removes code view from code box. |
removeAllCodeViews | Removes all code views from code box. |
changeCodeViewIdentifier | Changes identifier of code view in code box. |
changeCodeViewPackage | Changes package of code view. |
removeCodeViewPackage | Removes code view from package. |
getCodeViewPackage | Returns package of code view. |
setActiveCodeView | Sets code view as active (displays it in code box). |
setNoActiveCodeView | Displays no code view in code box. |
getActiveCodeView | Returns currently active code view. |
addFile | Adds new file to code box. |
getFiles | Returns all files of code box. |
getFilesByFolderPath | Returns files in folder. |
getFilesByPackage | Returns files in package. |
getFile | Returns file based on identifier. |
getFileByFolderPath | Returns files based on folder path and name. |
getFileByPackage | Returns file based on package and name. |
removeFile | Removes file from code box. |
removeAllFiles | Removes all files from code box. |
changeFileIdentifier | Changes identifier of file in code box. |
changeFilePackage | Changes package of file. |
removeFilePackage | Removes file from package. |
getFilePackage | Returns package of file. |
changeFileDownloadLink | Changes download link of file. |
addFolder | Creates new folder(s). |
removeFolder | Removes folder and all its contents. |
renameFolder | Renames folder. |
openFolder | Opens folder. |
closeFolder | Closes folder. |
folderExists | Checks whether folder exists. |
isFolderOpened | Checks whether folder is opened. |
getSubfolderNames | Returns names of folder subfolders. |
addPackage | Creates new package. |
removePackage | Removes package. |
renamePackage | Renames package. |
openPackage | Opens package. |
closePackage | Closes package. |
packageExists | Checks whether package exists. |
isPackageOpened | Checks whether package is opened. |
getPackages | Returns all packages. |
getPackagesFolderPath | Returns path to folder that is currently used for packages. |
changePackagesFolderPathAndRemoveAll | Sets new folder path for packages and removes all code views, files, folders and packages. |
getProjectName | Returns project name. |
setProjectName | Sets new project name. |
openPanel | Opens panel. |
closePanel | Closes panel. |
isPanelOpened | Checks whether panel is opened. |
reset | Resets code box to its post-initialization state. |
createMemento | Creates memento. |
applyMemento | Applies memento. |
appendTo
appendTo(element: HTMLElement): void
Appends code box to element.
Params
element : HTMLElement | Element to append code box to. |
---|
detach
detach(): void
Detaches code box from its parent element.
init
init(): void
Initializes code box if it hasn't been initialized yet. When lazy initialization is disabled, the code box is initialized immediately after it is created.
isInitialized
isInitialized(): boolean
Checks whether the code box is initialized.
Returns
boolean | Indicates whether the code box is initialized. |
---|
addOnInitListener
addOnInitListener(callback: () => void): void
Registeres function to be called when code box is initialized.
Params
callback : () => void | Function to be called after initialization of code box. |
---|
addCodeView
addCodeView(identifier: string, codeView: CodeView): boolean
Adds new code view to code box (copy of passed code view is made).
Params
identifier : string | Identifier under which the code view should be added to code box. |
---|---|
codeView : CodeView | Code view. |
Returns
boolean | Indicates whether code view has been successfully added. |
---|
getCodeViews
getCodeViews(): ProjectCodeBoxCodeView[]
Returns all code views of code box.
Returns
ProjectCodeBoxCodeView[] | Code views. |
---|
getCodeViewsByFolderPath
getCodeViewsByFolderPath(folderPath: string, includeSubfolders: boolean = false): ProjectCodeBoxCodeView[]
Returns code views in folder.
Params
folderPath : string | Folder path. |
---|---|
includeSubfolders ?: boolean | Determines whether code views in subfolders should also be included. |
Returns
ProjectCodeBoxCodeView[] | Code views. |
---|
getCodeViewsByPackage
getCodeViewsByPackage(packageName : string | null): ProjectCodeBoxCodeView[]
Returns code views in package.
Params
packageName : string | null | Package name or null for default package. |
---|
Returns
ProjectCodeBoxCodeView[] | Code views. |
---|
getCodeView
getCodeView(identifier: string): ProjectCodeBoxCodeView | null
Returns code view based on identifier.
Params
identifier : string | Identifier of code view. |
---|
Returns
ProjectCodeBoxCodeView | null | Code view or null if code view wasn't found. |
---|
getCodeViewByFolderPath
getCodeViewByFolderPath(folderPath: string, fileName: string): ProjectCodeBoxCodeView | null
Returns code view based on folder path and name.
Params
folderPath : string | Folder path. |
---|---|
fileName : string | Name of code view. |
Returns
ProjectCodeBoxCodeView | null | Code view or null if code view wasn't found. |
---|
getCodeViewByPackage
getCodeViewByPackage(packageName: string | null, fileName: string): ProjectCodeBoxCodeView | null
Returns code view based on package and name.
Params
packageName : string | null | Package name or null for default package. |
---|---|
fileName : string | Name of code view. |
Returns
ProjectCodeBoxCodeView | null | Code view or null if code view wasn't found. |
---|
removeCodeView
removeCodeView(identifier: string): boolean
Removes code view from code box.
Params
identifier : string | Identifier of code view to be removed. |
---|
Returns
boolean | Indicates whether code view has been removed. |
---|
removeAllCodeViews
removeAllCodeViews(): void
Removes all code views from code box.
changeCodeViewIdentifier
changeCodeViewIdentifier(identifier: string, newIdentifier: string): boolean
Changes identifier of code view in code box. It can change folder path and name of code view but it never changes package of code view.
Params
identifier : string | Identifier of code view whose identifier should be changed. |
---|---|
newIdentifier : string | New identifier. |
Returns
boolean | Indicates whether change has been successfully completed (if passed new identifier already belongs to some other code view in code box, it returns false). |
---|
changeCodeViewPackage
changeCodeViewPackage(identifier: string, packageName: string | null, keepFolderPath: boolean): boolean
Changes package of code view.
Params
identifier : string | Identifier of code view whose package should be changed. |
---|---|
packageName : string | null | Package name or null for default package. If package does not exist, it is created. |
keepFolderPath : boolean | Determines whether code view should stay in the same folder (if false, code view can be moved to different folder based on package). |
Returns
boolean | Indicates whether change has been successfully completed. |
---|
removeCodeViewPackage
removeCodeViewPackage(identifier: string): boolean
Removes code view from package.
Params
identifier : string | Identifier of code view that should be removed from package. |
---|---|
Returns
boolean | Indicates whether code view has been successfully removed from package. |
---|
getCodeViewPackage
getCodeViewPackage(identifier: string): string | null | undefined
Returns package of code view.
Params
identifier : string | Identifier of code view. |
---|---|
Returns
string | null | undefined | Package of code view. If null is returned, code view belongs to default package. If undefined is returned, code view doesn't belong to any package or does not event exist. |
---|
setActiveCodeView
setActiveCodeView(identifier: string): boolean
Sets code view as active (displays it in code box).
Params
identifier : string | Identifier of code view which should be set as active. |
---|
Returns
boolean | Indicates whether code view was found and has been successfully set as active. |
---|
setNoActiveCodeView
setNoActiveCodeView(): void
Displays no code view in code box.
getActiveCodeView
getActiveCodeView(): ProjectCodeBoxCodeView | null
Returns currently active code view.
Returns
ProjectCodeBoxCodeView | null | Active code view or null if no code view is set as active. |
---|
addFile
addFile(identifier: string, downloadLink: string | null): boolean
Adds new file to code box.
Params
identifier : string | Identifier under which the file should be added to code box. |
---|---|
downloadLink : string | null | Download link or null if file should not be downloadable. |
Returns
boolean | Indicates whether file has been successfully added. |
---|
getFiles
getFiles(): ProjectCodeBoxFile[]
Returns all files of code box.
Returns
ProjectCodeBoxFile[] | Files. |
---|
getFilesByFolderPath
getFilesByFolderPath(folderPath: string, includeSubfolders: boolean = false): ProjectCodeBoxFile[]
Returns files in folder.
Params
folderPath : string | Folder path. |
---|---|
includeSubfolders ?: boolean | Determines whether files in subfolders should also be included. |
Returns
ProjectCodeBoxFile[] | Files. |
---|
getFilesByPackage
getFilesByPackage(packageName : string | null): ProjectCodeBoxFile[]
Returns files in package.
Params
packageName : string | null | Package name or null for default package. |
---|
Returns
ProjectCodeBoxFile[] | Files. |
---|
getFile
getFile(identifier: string): ProjectCodeBoxFile | null
Returns file based on identifier.
Params
identifier : string | Identifier of file. |
---|
Returns
ProjectCodeBoxFile | null | File or null if file wasn't found. |
---|
getFileByFolderPath
getFileByFolderPath(folderPath: string, fileName: string): ProjectCodeBoxFile | null
Returns file based on folder path and name.
Params
folderPath : string | Folder path. |
---|---|
fileName : string | Name of file. |
Returns
ProjectCodeBoxFile | null | File or null if file wasn't found. |
---|
getFileByPackage
getFileByPackage(packageName: string | null, fileName: string): ProjectCodeBoxFile | null
Returns file based on package and name.
Params
packageName : string | null | Package name or null for default package. |
---|---|
fileName : string | Name of file. |
Returns
ProjectCodeBoxFile | null | File or null if file wasn't found. |
---|
removeFile
removeFile(identifier: string): boolean
Removes file from code box.
Params
identifier : string | Identifier of file to be removed. |
---|
Returns
boolean | Indicates whether file has been removed. |
---|
removeAllFiles
removeAllFiles(): void
Removes all files from code box.
changeFileIdentifier
changeFileIdentifier(identifier: string, newIdentifier: string): boolean
Changes identifier of file in code box. It can change folder path and name of file but it never changes package of file.
Params
identifier : string | Indentifier of file whose identifier should be changed. |
---|---|
newIdentifier : string | New identifier. |
Returns
boolean | Indicates whether change has been successfully completed (if passed new identifier already belongs to some other file in code box, it returns false). |
---|
changeFilePackage
changeFilePackage(identifier: string, packageName: string | null, keepFolderPath: boolean): boolean
Changes package of file.
Params
identifier : string | Identifier of file whose package should be changed. |
---|---|
packageName : string | null | Package name or null for default package. If package does not exist, it is created. |
keepFolderPath : boolean | Determines whether file should stay in the same folder (if false, file can be moved to different folder based on package). |
Returns
boolean | Indicates whether change has been successfully completed. |
---|
removeFilePackage
removeFilePackage(identifier: string): boolean
Removes file from package.
Params
identifier : string | Identifier of file that should be removed from package. |
---|---|
Returns
boolean | Indicates whether file has been successfully removed from package. |
---|
getFilePackage
getFilePackage(identifier: string): string | null | undefined
Returns package of file.
Params
identifier : string | Identifier of file. |
---|---|
Returns
string | null | undefined | Package of file. If null is returned, file belongs to default package. If undefined is returned, file doesn't belong to any package or does not event exist. |
---|
changeFileDownloadLink
changeFileDownloadLink(identifier: string, newDownloadLink: string | null): boolean
Changes download link of file.
Params
identifier : string | Identifier of file whose download link should be changed. |
---|---|
newDownloadLink : string | null | Download link (or null if file should not be downloadable). |
Returns
boolean | Indicates whether file was found and its download link has been successfully changed. |
---|
addFolder
addFolder(folderPath: string): void
Creates new folder(s) (if not created yet).
Params
folderPath : string | Folder path. |
---|
removeFolder
removeFolder(folderPath: string): boolean
Removes folder and all its contents. This might also remove packages if their folders are removed (if generation of folders for packages is enabled via createFoldersForPackages option).
Params
folderPath : string | Path to folder that should be removed. |
---|
Returns
boolean | Indicates whether folder has been successfully removed. |
---|
renameFolder
renameFolder(folderPath: string, newName: string): boolean
Renames folder. This can also change (rename) folder for packages and rename packages.
Params
folderPath : string | Path to folder that should be renamed. |
---|---|
newName : string | New name for folder. |
Returns
boolean | Indicates whether folder has been successfully renamed. |
---|
openFolder
openFolder(folderPath: string, openParentFolders: boolean = false, animate: boolean = true): void
Opens folder.
Params
folderPath : string | Path to folder that should be opened. |
---|---|
openParentFolders ?: boolean | Determines whether parent folders should also be opened. |
animate ?: boolean | Determines whether animation should be used. |
closeFolder
closeFolder(folderPath: string, closeChildFolders: boolean = false, animate: boolean = true): void
Closes folder.
Params
folderPath : string | Path to folder that should be closed. |
---|---|
closeChildFolders ?: boolean | Determines whether subfolders should be closed too. |
animate ?: boolean | Determines whether animation should be used. |
folderExists
folderExists(folderPath: string): boolean
Checks whether folder exists.
Params
folderPath : string | Path to folder. |
---|
Returns
boolean | Indicates whether folder exists. |
---|
isFolderOpened
isFolderOpened(folderPath: string): boolean
Checks whether folder is opened.
Params
folderPath : string | Path to folder. |
---|
Returns
boolean | Indicates whether folder is opened (false might also be returned if folder does not exist). |
---|
getSubfolderNames
getSubfolderNames(folderPath: string): string[] | null
Returns names of folder subfolders (only direct subfolders).
Params
folderPath : string | Path to folder. |
---|
Returns
string[] | null | Names of subfolders or null if folder does not exist. |
---|
addPackage
addPackage(name: string): void
Creates new package (if it does not exist yet).
Params
name : string | Name of package. |
---|
removePackage
removePackage(name: string, removePackageFoldersAndContents: boolean = true, removeAllCodeViewsAndFiles: boolean = false): boolean
Removes package.
Params
name : string | Package name. |
---|---|
removePackageFoldersAndContents ?: boolean | Determines whether package folder and its contents can be removed (if the folder contains some other code views, files or subfolders, it is not removed). |
removeAllCodeViewsAndFiles ?: boolean | Determines whether all code views and files in package should be removed. |
Returns
boolean | Indicates whether package has been successfully removed. |
---|
renamePackage
renamePackage(name: string, newName: string): boolean
Renames package. This can also rename folders for package if generation of folders is enabled via createFoldersForPackages option.
Params
name : string | Current package name. |
---|---|
newName : string | New package name. |
Returns
boolean | Indicates whether package has been successfully renamed. |
---|
openPackage
openPackage(packageName: string | null, animate: boolean = true): void
Opens package.
Params
packageName : string | null | Package name or null for default package. |
---|---|
animate ?: boolean | Determines whether animation should be used. |
closePackage
closePackage(packageName: string | null, animate: boolean = true): void
Closes package.
Params
packageName : string | null | Package name or null for default package. |
---|---|
animate ?: boolean | Determines whether animation should be used. |
packageExists
packageExists(packageName: string): boolean
Checks whether package exists.
Params
packageName : string | Package name. |
---|
Returns
boolean | Indicates whether package exists. |
---|
isPackageOpened
isPackageOpened(packageName: string | null): boolean
Checks whether package is opened.
Params
packageName : string | null | Package name or null for default package. |
---|
Returns
boolean | Indicates whether package is opened (false might also be returned if package does not exist). |
---|
getPackages
getPackages(): string[]
Returns all packages.
Returns
string[] | Packages (package names). |
---|
getPackagesFolderPath
getPackagesFolderPath(): string
Returns path to folder that is currently used for packages.
Returns
string | Path to folder that is currently used for packages. |
---|
changePackagesFolderPathAndRemoveAll
changePackagesFolderPathAndRemoveAll(newPackagesFolderPath: string): void
Sets new folder path for packages and removes all code views, files, folders and packages (everything needs to be removed, when folder path for packages is changed).
Params
newPackagesFolderPath : string | New folder path for packages. |
---|
getProjectName
getProjectName(): string
Returns project name.
Returns
string | Project name. |
---|
setProjectName
setProjectName(newName: string): void
Sets new project name.
Params
newName : string | New project name. |
---|
openPanel
openPanel(): void
Opens panel.
closePanel
closePanel(): void
Closes panel.
isPanelOpened
isPanelOpened(): boolean
Checks whether panel is opened.
Returns
boolean | Indicates whether panel is opened. |
---|
reset
reset(): void
Resets code box to its post-initialization state.
createMemento
createMemento(): CodeBoxMemento
Creates memento (saved state of code box).
Returns
CodeBoxMemento | Memento (saved state of code box). |
---|
applyMemento
applyMemento(memento: CodeBoxMemento): void
Applies memento (sets code box to the state defined by the provided memento).
Params
memento : CodeBoxMemento | Memento (saved state of code box). |
---|