Skip to content

Common TypeScript Use Cases

Casper Thule edited this page Jun 11, 2018 · 1 revision

The paths used below are relative to the file your are working in.

Obtaining the IntoCpsApp in a render process

Type imports:

import {IntoCpsApp} from  "../IntoCpsApp"

Example:

/// <reference path="../../typings/browser/ambient/github-electron/index.d.ts"/>
/// <reference path="../../typings/browser/ambient/node/index.d.ts"/>

let app : IntoCpsApp = IntoCpsApp.getInstance()

Obtaining the active project in a render process

Type imports:

import {IntoCpsApp} from  "../IntoCpsApp"
import {IProject} from "../proj/IProject";

Example:

let app : IntoCpsApp = ...

let project = app.getActiveProject();

Global Settings

Type imports:

import {IntoCpsApp} from  "../IntoCpsApp"
import * as Main from  "../settings/Settings"
import {SettingKeys} from "../settings/SettingKeys";

Example:

let app : IntoCpsApp = ...

let settings = app.getSettings();

settings.setValue(SettingKeys.MY_SETTINGS_KEY,myValue);
let value = settings.getValue(SettingKeys.MY_SETTINGS_KEY);

We recommend that global settings keys are defined in SettingKeys to avoid duplication.

Project Settings

Type imports:

import * as IntoCpsApp from  "../IntoCpsApp"
import {IProject} from "../proj/IProject";

Example:

let project : IProject = ...

let settings = project.getSettings();

settings.setValue("my-settings-json-key",myValue);
let value = settings.getValue("my-settings-json-key");

project.save();