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-folderSpecifies the folder into which the code view or file should be placed.
data-cb-packageSpecifies 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>&lt;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"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;io.github.jirkasa&lt;/groupId&gt;
    &lt;artifactId&gt;example-app&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;name&gt;example-app&lt;/name&gt;
&lt;/project&gt;</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
  • 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:

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 : stringNew name.

add folder

Creates new folder(s) (if not created yet).

Properties

folderPath : stringFolder 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 : stringPath to folder that should be removed.

rename folder

Renames folder. This can also change (rename) folder for packages and rename packages.

Properties

folderPath : stringPath to folder that should be renamed.
newName : stringNew name for folder.

open folder

Opens folder.

Properties

folderPath : stringPath to folder that should be opened.
openParentFolders ?: booleanDetermines whether parent folders should also be opened (default = false).

close folder

Closes folder.

Properties

folderPath : stringPath to folder that should be closed.
closeChildFolders ?: booleanDetermines whether subfolders should be closed too (default = false).

add package

Creates new package (if it does not exist yet).

Properties

name : stringName of package.

remove package

Removes package.

Properties

name : stringPackage name.
removePackageFoldersAndContents ?: booleanDetermines whether package folder and its contents should be removed (default = true).
removeAllCodeViewsAndFiles ?: booleanDetermines 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 : stringCurrent package name.
newName : stringNew package name.

open package

Opens package.

Properties

name ?: string | nullPackage name (null or undefined for default package).

close package

Closes package.

Properties

name ?: string | nullPackage name (null or undefined for default package).

remove code view

Removes code view from code box.

Properties

identifier : stringIdentifier of code view to be removed.

rename code view

Changes file name of code view.

Properties

identifier : stringIdentifier of code view to be renamed.
newName : stringNew 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 : stringIdentifier of code view.
folderPath : stringPath to folder.

change code view package

Changes package of code view.

Properties

identifier : stringIdentifier of code view.
packageName ?: string | nullPackage name (null and undefined for default package). If package does not exist, it is created.
keepFolderPath : booleanDetermines 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 : stringIdentifier 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 : stringIdentifier of code view.
start : numberStart line of highlight.
end ?: numberEnd 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 : stringIdentifier of code view.
start ?: number | nullStart line (passing null or leaving it empty defaults to the first line).
end ?: numberEnd 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 : stringIdentifier 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 : stringIdentifier of file to be removed.

rename file

Changes name of file.

Properties

identifier : stringIdentifier of file to be renamed.
newName : stringNew file name.

move file to folder

Moves file to folder (if folder does not exist, it is created; package is not changed).

Properties

identifier : stringIdentifier of file.
folderPath : stringPath to folder.

change file package

Changes package of file.

Properties

identifier : stringIdentifier of file.
packageName ?: string | nullPackage name (null and undefined for default package). If package does not exist, it is created.
keepFolderPath : booleanDetermines 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 : stringIdentifier 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
svgSpritePathSpecifies path to the SVG sprite that contains icons.
svgSpriteIconsSpecifies names of the icons in the SVG sprite.
folderStructureHeadingSpecifies folder structure heading.
packagesHeadingSpecifies packages heading.
projectNameSpecifies name of project.
packagesFolderPathSpecifies path to folder for packages.
defaultPackageNameSpecifies name under which the default package should be displayed.
createFoldersForPackagesSpecifies whether folders should be created for packages.
foldersDelimiterForPackagesSpecifies delimiter to be used when creating folders for packages.
folderAnimationSpeedSpecifies speed of folder open/close animation.
folderAnimationEasingFunctionSpecifies CSS easing function for folder open/close animation.
openActiveCodeViewFolderOnInitSpecifies whether folder and its parent folders containing the active code view should be opened on initialization.
openActiveCodeViewPackageOnInitSpecifies whether package containing the active code view should be opened on initialization.
preventActiveCodeViewFolderOpenOnInitIfPackageSpecifies 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.
openRootFolderOnInitSpecifies whether the project (root) folder should be opened on initialization.
openPanelOnInitSpecifies whether the side panel should be opened on initialization.
closePanelOnCodeViewSelectSpecifies whether the side panel should be closed when code view is selected by clicking on its button.
openPanelButtonAriaLabelSpecifies value of the panel open/close button aria-label attribute when panel is closed.
closePanelButtonAriaLabelSpecifies 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.

appendToAppends code box to element.
detachDetaches code box from its parent element.
initInitializes code box if it hasn't been initialized yet.
isInitializedChecks whether the code box is initialized.
addOnInitListenerRegisteres function to be called when code box is initialized.
addCodeViewAdds new code view to code box.
getCodeViewsReturns all code views of code box.
getCodeViewsByFolderPathReturns code views in folder.
getCodeViewsByPackageReturns code views in package.
getCodeViewReturns code view based on identifier.
getCodeViewByFolderPathReturns code view based on folder path and name.
getCodeViewByPackageReturns code view based on package and name.
removeCodeViewRemoves code view from code box.
removeAllCodeViewsRemoves all code views from code box.
changeCodeViewIdentifierChanges identifier of code view in code box.
changeCodeViewPackageChanges package of code view.
removeCodeViewPackageRemoves code view from package.
getCodeViewPackageReturns package of code view.
setActiveCodeViewSets code view as active (displays it in code box).
setNoActiveCodeViewDisplays no code view in code box.
getActiveCodeViewReturns currently active code view.
addFileAdds new file to code box.
getFilesReturns all files of code box.
getFilesByFolderPathReturns files in folder.
getFilesByPackageReturns files in package.
getFileReturns file based on identifier.
getFileByFolderPathReturns files based on folder path and name.
getFileByPackageReturns file based on package and name.
removeFileRemoves file from code box.
removeAllFilesRemoves all files from code box.
changeFileIdentifierChanges identifier of file in code box.
changeFilePackageChanges package of file.
removeFilePackageRemoves file from package.
getFilePackageReturns package of file.
changeFileDownloadLinkChanges download link of file.
addFolderCreates new folder(s).
removeFolderRemoves folder and all its contents.
renameFolderRenames folder.
openFolderOpens folder.
closeFolderCloses folder.
folderExistsChecks whether folder exists.
isFolderOpenedChecks whether folder is opened.
getSubfolderNamesReturns names of folder subfolders.
addPackageCreates new package.
removePackageRemoves package.
renamePackageRenames package.
openPackageOpens package.
closePackageCloses package.
packageExistsChecks whether package exists.
isPackageOpenedChecks whether package is opened.
getPackagesReturns all packages.
getPackagesFolderPathReturns path to folder that is currently used for packages.
changePackagesFolderPathAndRemoveAllSets new folder path for packages and removes all code views, files, folders and packages.
getProjectNameReturns project name.
setProjectNameSets new project name.
openPanelOpens panel.
closePanelCloses panel.
isPanelOpenedChecks whether panel is opened.
resetResets code box to its post-initialization state.
createMementoCreates memento.
applyMementoApplies memento.

appendTo

appendTo(element: HTMLElement): void

Appends code box to element.

Params

element : HTMLElementElement 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

booleanIndicates whether the code box is initialized.

addOnInitListener

addOnInitListener(callback: () => void): void

Registeres function to be called when code box is initialized.

Params

callback : () => voidFunction 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 : stringIdentifier under which the code view should be added to code box.
codeView : CodeViewCode view.

Returns

booleanIndicates whether code view has been successfully added.

getCodeViews

getCodeViews(): ProjectCodeBoxCodeView[]

Returns all code views of code box.

Returns

getCodeViewsByFolderPath

getCodeViewsByFolderPath(folderPath: string, includeSubfolders: boolean = false): ProjectCodeBoxCodeView[]

Returns code views in folder.

Params

folderPath : stringFolder path.
includeSubfolders ?: booleanDetermines whether code views in subfolders should also be included.

Returns

getCodeViewsByPackage

getCodeViewsByPackage(packageName : string | null): ProjectCodeBoxCodeView[]

Returns code views in package.

Params

packageName : string | nullPackage name or null for default package.

Returns

getCodeView

getCodeView(identifier: string): ProjectCodeBoxCodeView | null

Returns code view based on identifier.

Params

identifier : stringIdentifier of code view.

Returns

ProjectCodeBoxCodeView | nullCode 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 : stringFolder path.
fileName : stringName of code view.

Returns

ProjectCodeBoxCodeView | nullCode 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 | nullPackage name or null for default package.
fileName : stringName of code view.

Returns

ProjectCodeBoxCodeView | nullCode view or null if code view wasn't found.

removeCodeView

removeCodeView(identifier: string): boolean

Removes code view from code box.

Params

identifier : stringIdentifier of code view to be removed.

Returns

booleanIndicates 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 : stringIdentifier of code view whose identifier should be changed.
newIdentifier : stringNew identifier.

Returns

booleanIndicates 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 : stringIdentifier of code view whose package should be changed.
packageName : string | nullPackage name or null for default package. If package does not exist, it is created.
keepFolderPath : booleanDetermines whether code view should stay in the same folder (if false, code view can be moved to different folder based on package).

Returns

booleanIndicates whether change has been successfully completed.

removeCodeViewPackage

removeCodeViewPackage(identifier: string): boolean

Removes code view from package.

Params

identifier : stringIdentifier of code view that should be removed from package.

Returns

booleanIndicates whether code view has been successfully removed from package.

getCodeViewPackage

getCodeViewPackage(identifier: string): string | null | undefined

Returns package of code view.

Params

identifier : stringIdentifier of code view.

Returns

string | null | undefinedPackage 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 : stringIdentifier of code view which should be set as active.

Returns

booleanIndicates 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 | nullActive 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 : stringIdentifier under which the file should be added to code box.
downloadLink : string | nullDownload link or null if file should not be downloadable.

Returns

booleanIndicates whether file has been successfully added.

getFiles

getFiles(): ProjectCodeBoxFile[]

Returns all files of code box.

Returns

getFilesByFolderPath

getFilesByFolderPath(folderPath: string, includeSubfolders: boolean = false): ProjectCodeBoxFile[]

Returns files in folder.

Params

folderPath : stringFolder path.
includeSubfolders ?: booleanDetermines whether files in subfolders should also be included.

Returns

getFilesByPackage

getFilesByPackage(packageName : string | null): ProjectCodeBoxFile[]

Returns files in package.

Params

packageName : string | nullPackage name or null for default package.

Returns

getFile

getFile(identifier: string): ProjectCodeBoxFile | null

Returns file based on identifier.

Params

identifier : stringIdentifier of file.

Returns

ProjectCodeBoxFile | nullFile 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 : stringFolder path.
fileName : stringName of file.

Returns

ProjectCodeBoxFile | nullFile 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 | nullPackage name or null for default package.
fileName : stringName of file.

Returns

ProjectCodeBoxFile | nullFile or null if file wasn't found.

removeFile

removeFile(identifier: string): boolean

Removes file from code box.

Params

identifier : stringIdentifier of file to be removed.

Returns

booleanIndicates 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 : stringIndentifier of file whose identifier should be changed.
newIdentifier : stringNew identifier.

Returns

booleanIndicates 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 : stringIdentifier of file whose package should be changed.
packageName : string | nullPackage name or null for default package. If package does not exist, it is created.
keepFolderPath : booleanDetermines whether file should stay in the same folder (if false, file can be moved to different folder based on package).

Returns

booleanIndicates whether change has been successfully completed.

removeFilePackage

removeFilePackage(identifier: string): boolean

Removes file from package.

Params

identifier : stringIdentifier of file that should be removed from package.

Returns

booleanIndicates whether file has been successfully removed from package.

getFilePackage

getFilePackage(identifier: string): string | null | undefined

Returns package of file.

Params

identifier : stringIdentifier of file.

Returns

string | null | undefinedPackage 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(identifier: string, newDownloadLink: string | null): boolean

Changes download link of file.

Params

identifier : stringIdentifier of file whose download link should be changed.
newDownloadLink : string | nullDownload link (or null if file should not be downloadable).

Returns

booleanIndicates 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 : stringFolder 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 : stringPath to folder that should be removed.

Returns

booleanIndicates 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 : stringPath to folder that should be renamed.
newName : stringNew name for folder.

Returns

booleanIndicates whether folder has been successfully renamed.

openFolder

openFolder(folderPath: string, openParentFolders: boolean = false, animate: boolean = true): void

Opens folder.

Params

folderPath : stringPath to folder that should be opened.
openParentFolders ?: booleanDetermines whether parent folders should also be opened.
animate ?: booleanDetermines whether animation should be used.

closeFolder

closeFolder(folderPath: string, closeChildFolders: boolean = false, animate: boolean = true): void

Closes folder.

Params

folderPath : stringPath to folder that should be closed.
closeChildFolders ?: booleanDetermines whether subfolders should be closed too.
animate ?: booleanDetermines whether animation should be used.

folderExists

folderExists(folderPath: string): boolean

Checks whether folder exists.

Params

folderPath : stringPath to folder.

Returns

booleanIndicates whether folder exists.

isFolderOpened

isFolderOpened(folderPath: string): boolean

Checks whether folder is opened.

Params

folderPath : stringPath to folder.

Returns

booleanIndicates 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 : stringPath to folder.

Returns

string[] | nullNames 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 : stringName of package.

removePackage

removePackage(name: string, removePackageFoldersAndContents: boolean = true, removeAllCodeViewsAndFiles: boolean = false): boolean

Removes package.

Params

name : stringPackage name.
removePackageFoldersAndContents ?: booleanDetermines 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 ?: booleanDetermines whether all code views and files in package should be removed.

Returns

booleanIndicates 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 : stringCurrent package name.
newName : stringNew package name.

Returns

booleanIndicates whether package has been successfully renamed.

openPackage

openPackage(packageName: string | null, animate: boolean = true): void

Opens package.

Params

packageName : string | nullPackage name or null for default package.
animate ?: booleanDetermines whether animation should be used.

closePackage

closePackage(packageName: string | null, animate: boolean = true): void

Closes package.

Params

packageName : string | nullPackage name or null for default package.
animate ?: booleanDetermines whether animation should be used.

packageExists

packageExists(packageName: string): boolean

Checks whether package exists.

Params

packageName : stringPackage name.

Returns

booleanIndicates whether package exists.

isPackageOpened

isPackageOpened(packageName: string | null): boolean

Checks whether package is opened.

Params

packageName : string | nullPackage name or null for default package.

Returns

booleanIndicates 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

stringPath 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 : stringNew folder path for packages.

getProjectName

getProjectName(): string

Returns project name.

Returns

stringProject name.

setProjectName

setProjectName(newName: string): void

Sets new project name.

Params

newName : stringNew project name.

openPanel

openPanel(): void

Opens panel.

closePanel

closePanel(): void

Closes panel.

isPanelOpened

isPanelOpened(): boolean

Checks whether panel is opened.

Returns

booleanIndicates 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

CodeBoxMementoMemento (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 : CodeBoxMementoMemento (saved state of code box).