Clean up the bahaviout of Save as and Save menu items. Save cfg file by default.

This commit is contained in:
2026-04-22 17:05:51 +02:00
parent ae86f45a3d
commit 23e2e76414
2 changed files with 22 additions and 4 deletions
+8 -2
View File
@@ -99,6 +99,7 @@ function setWorkFolder(foldername) {
if (typeof updateStatusBar === 'function') {
updateStatusBar({ workPath: folder });
}
ipcRenderer.send('updateWorkPath', folder);
try {
// Change process directory
process.chdir(folder);
@@ -155,8 +156,13 @@ function firstLoad() {
});
// Catch calls for save as
ipcRenderer.on('saveFile', function(event, filename) {
// If filename is empty use default value
if (filename == '') {filename='TrimSP.cfg';}
const workPath = document.getElementById("workPath").value || process.cwd();
if (filename === undefined || filename === null) { return; }
// If filename is empty use default value in the selected work folder
if (filename == '') {filename = path.join(workPath, 'TrimSP.cfg');}
if (path.extname(filename) === '') {
filename += '.cfg';
}
// Get values from all fields and prepare config file
let trimSPcfg=prep_cfg(0);
// Save file to filename
+14 -2
View File
@@ -1,5 +1,8 @@
const path = require('path');
const { app, BrowserWindow, Menu, dialog, ipcMain, fs } = require('electron');
let currentWorkPath = process.cwd();
function showAboutDialog(parentWindow) {
const detail = [
'TRIM.SP simulation GUI for low-energy ion implantation studies.',
@@ -39,7 +42,7 @@ if (process.platform === 'linux') {
}
function getDefaultDialogPath() {
return process.cwd();
return currentWorkPath || process.cwd();
}
function createWindow () {
@@ -122,13 +125,16 @@ function createWindow () {
click () {
dialog.showSaveDialog(win,
{ title : "Save configuration file",
defaultPath : getDefaultDialogPath(),
defaultPath : path.join(getDefaultDialogPath(), 'TrimSP.cfg'),
filters :[
{name: 'Config file type', extensions: ['cfg']},
{name: 'All Files', extensions: ['*']}
],
properties: ['showOverwriteConfirmation']}
).then(result => {
if (result.canceled || !result.filePath) {
return;
}
setImmediate(function() {
var focusedWindow = BrowserWindow.getFocusedWindow();
focusedWindow.webContents.send('saveFile',result.filePath);
@@ -296,6 +302,12 @@ ipcMain.on('browseFolder', (event, args) => {
})
});
ipcMain.on('updateWorkPath', (event, folder) => {
if (folder) {
currentWorkPath = folder;
}
});
//ipcMain.on('browseFolder-send', (event, args) => {
// dialog.showOpenDialog(null, args).then(filePaths => {
// event.sender.dend('browseFolder', filePaths);