Skip to content

Commit

Permalink
File Open... action was disconnected from the menuItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
tecimovic committed Jun 30, 2020
1 parent 3a84432 commit 9129315
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
1 change: 1 addition & 0 deletions src-electron/importexport/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function createStateFromDatabase(db, sessionId) {
}
var promises = []

env.logInfo(`Exporting data for session: ${sessionId}`)
// Deal with the key/value table
var getKeyValues = mapping
.exportSessionKeyValues(db, sessionId)
Expand Down
56 changes: 30 additions & 26 deletions src-electron/main-process/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
*/

const { dialog, Menu } = require('electron')
const { appDirectory, logInfo, mainDatabase } = require('../util/env.js')
const env = require('../util/env.js')
const queryConfig = require('../db/query-config.js')
const queryGeneric = require('../db/query-generic.js')
const { getSessionInfoFromWindowId } = require('../db/query-session.js')
const querySession = require('../db/query-session.js')
const staticGenerator = require('../generator/static-generator.js')
const { exportDataIntoFile } = require('../importexport/export.js')
const {
readDataFromFile,
writeStateToDatabase,
} = require('../importexport/import.js')
const exportJs = require('../importexport/export.js')
const importJs = require('../importexport/import.js')
const { showErrorMessage } = require('./ui.js')
const { windowCreate } = require('./window.js')
const preference = require('./preference.js')

var httpPort
var generationDirectory = appDirectory() + '/generation-output'
var generationDirectory = env.appDirectory() + '/generation-output'
var handlebarTemplateDirectory = __dirname + '/../../test/gen-template'
var generationOptionsFile =
handlebarTemplateDirectory + '/generation-options.json'
Expand All @@ -55,7 +52,7 @@ const template = [
{
label: 'Open File...',
accelerator: 'CmdOrCtrl+O',
click(meimportnuItem, browserWindow, event) {
click(menuItem, browserWindow, event) {
doOpen(menuItem, browserWindow, event)
},
},
Expand All @@ -72,7 +69,8 @@ const template = [
label: 'Session Information...',
click(menuItem, browserWindow, event) {
let winId = browserWindow.id
getSessionInfoFromWindowId(mainDatabase(), winId)
querySession
.getSessionInfoFromWindowId(env.mainDatabase(), winId)
.then((row) => {
dialog.showMessageBox(browserWindow, {
title: 'Information',
Expand Down Expand Up @@ -141,7 +139,7 @@ const template = [
*/
function doOpen(menuItem, browserWindow, event) {
queryGeneric
.selectFileLocation(mainDatabase(), 'save')
.selectFileLocation(env.mainDatabase(), 'save')
.then((filePath) => {
var opts = {
properties: ['openFile', 'multiSelections'],
Expand All @@ -153,7 +151,7 @@ function doOpen(menuItem, browserWindow, event) {
})
.then((result) => {
if (!result.canceled) {
fileOpen(mainDatabase(), browserWindow.id, result.filePaths)
fileOpen(env.mainDatabase(), browserWindow.id, result.filePaths)
}
})
.catch((err) => showErrorMessage('Open file', err))
Expand All @@ -167,15 +165,20 @@ function doOpen(menuItem, browserWindow, event) {
* @param {*} event
*/
function doSave(menuItem, browserWindow, event) {
getSessionInfoFromWindowId(mainDatabase(), browserWindow.id)
querySession
.getSessionInfoFromWindowId(env.mainDatabase(), browserWindow.id)
.then((row) =>
queryConfig.getSessionKeyValue(mainDatabase(), row.sessionId, 'filePath')
queryConfig.getSessionKeyValue(
env.mainDatabase(),
row.sessionId,
'filePath'
)
)
.then((filePath) => {
if (filePath == null) {
doSaveAs(menuItem, browserWindow, event)
} else {
return fileSave(mainDatabase(), browserWindow.id, filePath)
return fileSave(env.mainDatabase(), browserWindow.id, filePath)
}
})
}
Expand All @@ -189,7 +192,7 @@ function doSave(menuItem, browserWindow, event) {
*/
function doSaveAs(menuItem, browserWindow, event) {
queryGeneric
.selectFileLocation(mainDatabase(), 'save')
.selectFileLocation(env.mainDatabase(), 'save')
.then((filePath) => {
var opts = {}
if (filePath != null) {
Expand All @@ -199,14 +202,14 @@ function doSaveAs(menuItem, browserWindow, event) {
})
.then((result) => {
if (!result.canceled) {
return fileSave(mainDatabase(), browserWindow.id, result.filePath)
return fileSave(env.mainDatabase(), browserWindow.id, result.filePath)
} else {
return null
}
})
.then((filePath) => {
if (filePath != null) {
queryGeneric.insertFileLocation(mainDatabase(), filePath, 'save')
queryGeneric.insertFileLocation(env.mainDatabase(), filePath, 'save')
browserWindow.setTitle(filePath)
dialog.showMessageBox(browserWindow, {
title: 'Save',
Expand Down Expand Up @@ -245,7 +248,7 @@ function generateInDir(browserWindow) {
.getGenerationProperties(generationOptionsFile)
.then((generationOptions) =>
staticGenerator.generateCode(
mainDatabase(),
env.mainDatabase(),
generationOptions,
generationDirectory,
handlebarTemplateDirectory
Expand Down Expand Up @@ -273,7 +276,7 @@ function generateCodeViaCli(generationDir) {
.getGenerationProperties(generationOptionsFile)
.then((generationOptions) =>
staticGenerator.generateCode(
mainDatabase(),
env.mainDatabase(),
generationOptions,
generationDirectory,
handlebarTemplateDirectory
Expand Down Expand Up @@ -317,7 +320,7 @@ function setHandlebarTemplateDirectory(browserWindow) {
handlebarTemplateDirectory = filePath
dialog.showMessageBox(browserWindow, {
title: 'Handlebar Templates',
message: `Handlebar Template Directory: ${filePath}`,
message: `Handlebar Template Directory: meimportnuItem${filePath}`,
buttons: ['Ok'],
})
}
Expand All @@ -334,13 +337,14 @@ function setHandlebarTemplateDirectory(browserWindow) {
* @returns Promise of saving.
*/
function fileSave(db, winId, filePath) {
return getSessionInfoFromWindowId(db, winId)
return querySession
.getSessionInfoFromWindowId(db, winId)
.then((row) => {
return queryConfig
.updateKeyValue(db, row.sessionId, 'filePath', filePath)
.then(() => row)
})
.then((row) => exportDataIntoFile(db, row.sessionId, filePath))
.then((row) => exportJs.exportDataIntoFile(db, row.sessionId, filePath))
.catch((err) => showErrorMessage('File save', err))
}

Expand All @@ -365,9 +369,9 @@ function fileOpen(db, winId, filePaths) {
* @param {*} filePath
*/
function readAndProcessFile(db, filePath) {
logInfo(`Read and process: ${filePath}`)
readDataFromFile(filePath)
.then((state) => writeStateToDatabase(mainDatabase(), state))
env.logInfo(`Read and process: ${filePath}`)
importJs
.importDataFromFile(env.mainDatabase(), filePath)
.then((sessionId) => {
windowCreate(httpPort, filePath, sessionId)
return true
Expand Down

0 comments on commit 9129315

Please sign in to comment.