Skip to content

Commit

Permalink
Merge pull request #1130 from substance/dar-templates
Browse files Browse the repository at this point in the history
DAR Templates: ability to create a new ‘Figure Package’
  • Loading branch information
oliver7654 authored Feb 3, 2019
2 parents 2b53954 + c8f3450 commit 6cce387
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
BrowserWindow, Menu, ipcMain
} = electron
const DEBUG = process.env.DEBUG
const BLANK_DOCUMENT = path.join(__dirname, 'templates', 'blank.dar')

const tmpDir = app.getPath('temp')
const darStorageFolder = path.join(tmpDir, app.getName(), 'dar-storage')
Expand All @@ -18,6 +17,13 @@ fsExtra.ensureDirSync(darStorageFolder)
const windowStates = new Map()
const isDAR = path => Boolean(/.dar$/i.exec(path))

const BLANK_DOCUMENT = path.join(__dirname, 'templates', 'blank.dar')
const BLANK_FIGURE_PACKAGE = path.join(__dirname, 'templates', 'blank-figure-package.dar')
const templates = {
'article': BLANK_DOCUMENT,
'figure-package': BLANK_FIGURE_PACKAGE
}

app.on('ready', () => {
protocol.registerFileProtocol('dar', (request, handler) => {
const resourcePath = path.normalize(request.url.substr(6))
Expand Down Expand Up @@ -180,8 +186,10 @@ function promptOpen () {
})
}

function openNew () {
createEditorWindow(BLANK_DOCUMENT, true)
function openNew (templateId) {
templateId = templateId || 'article'
const template = templates[templateId]
createEditorWindow(template, true)
}

// used to dispatch save requests from the menu to the window
Expand Down Expand Up @@ -209,10 +217,21 @@ function createMenu () {
submenu: [
{
label: 'New',
accelerator: 'CommandOrControl+N',
click () {
openNew()
}
submenu: [
{
label: 'Article',
accelerator: 'CommandOrControl+N',
click () {
openNew('article')
}
},
{
label: 'Figure Pacakge',
click () {
openNew('figure-package')
}
}
]
},
{
label: 'Open',
Expand Down
Binary file added app/templates/blank-figure-package.dar
Binary file not shown.

0 comments on commit 6cce387

Please sign in to comment.