Skip to content

Commit

Permalink
Fix: Allow Directory Creation In showOpenDialog And showSaveDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
KobaltBlu committed Jan 20, 2021
1 parent acd3848 commit 93ec583
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
},
onError: () => {
console.log('Failed to verify the path for', GameKey);
dialog.showOpenDialog({title: 'Locate Game Directory', properties: ['openDirectory',]}).then(result => {
dialog.showOpenDialog({title: 'Locate Game Directory', properties: ['openDirectory', 'createDirectory']}).then(result => {
console.log(result.canceled);
console.log(result.filePaths);
if(result.filePaths.length && !result.canceled){
Expand Down
5 changes: 3 additions & 2 deletions apps/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ if (typeof global.TopMenu == 'undefined') {
{name: 'File', items: [
{name: 'Open Project', onClick: async () => {
let payload = await dialog.showOpenDialog({
properties: ['openFile'],
properties: ['openFile', 'createDirectory'],
filters: [
{name: 'KForge Project', extensions: ['json']}
]});
Expand Down Expand Up @@ -567,7 +567,8 @@ if (typeof global.TopMenu == 'undefined') {
{name: 'VIS File', extensions: ['vis']},
{name: 'Layout File', extensions: ['lyt']},
{name: 'All Formats', extensions: ['*']},
]
],
properties: ['createDirectory'],
}
).then(result => {
if(!result.canceled){
Expand Down
2 changes: 1 addition & 1 deletion apps/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
console.log('Failed to verify the path for', GameKey);
//loader.Dismiss();

dialog.showOpenDialog({title: 'Locate Game Directory', properties: ['openDirectory',]}).then(result => {
dialog.showOpenDialog({title: 'Locate Game Directory', properties: ['openDirectory', 'createDirectory']}).then(result => {
console.log(result.canceled);
console.log(result.filePaths);
if(result.filePaths.length && !result.canceled){
Expand Down
4 changes: 2 additions & 2 deletions js/editor/GameFinderWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class GameFinderWizard extends Wizard {

this.$kotor_directory_browse.on('click', async (e) => {
e.preventDefault();
let payload = await dialog.showOpenDialog({properties: ['openDirectory']});
let payload = await dialog.showOpenDialog({properties: ['openDirectory', 'createDirectory']});

if(!payload.canceled && payload.filePaths.length){
console.log(payload.filePaths[0]);
Expand All @@ -47,7 +47,7 @@ class GameFinderWizard extends Wizard {

this.$tsl_directory_browse.on('click', async (e) => {
e.preventDefault();
let payload = await dialog.showOpenDialog({properties: ['openDirectory']});
let payload = await dialog.showOpenDialog({properties: ['openDirectory', 'createDirectory']});

if(!payload.canceled && payload.filePaths.length){
console.log(payload.filePaths[0]);
Expand Down
1 change: 1 addition & 0 deletions js/editor/InlineAudioPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class InlineAudioPlayer {
let payload = await dialog.showSaveDialog({
title: 'Export Audio File',
defaultPath: this.audioFile.filename,
properties: ['createDirectory'],
filters: [
{name: 'Wave File', extensions: ['wav']},
{name: 'MP3 File', extensions: ['mp3']}
Expand Down
2 changes: 1 addition & 1 deletion js/editor/NewProjectWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class NewProjectWizard extends Wizard {

this.$project_directory_browse.on('click', async (e) => {
e.preventDefault();
let payload = await dialog.showOpenDialog({properties: ['openDirectory']});
let payload = await dialog.showOpenDialog({properties: ['openDirectory', 'createDirectory']});
if(!payload.canceled && payload.filePaths.length){
console.log(payload.filePaths[0]);
this.parent_directory = payload.filePaths[0];
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/ImageViewerTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class ImageViewerTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Export Image',
defaultPath: this.filename,
properties: ['createDirectory'],
filters: [
{name: 'TGA', extensions: ['tga']}
]
Expand Down
8 changes: 6 additions & 2 deletions js/editor/tabs/LIPEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ class LIPEditorTab extends EditorTab {
title: 'Open Audio File',
filters: [
{name: 'Audio File', extensions: ['wav', 'mp3']}
]},
],
properties: ['createDirectory'],
},
(paths) => {
if(paths.length){
let filename = paths[0].split(path.sep).pop();
Expand Down Expand Up @@ -570,7 +572,9 @@ class LIPEditorTab extends EditorTab {
title: 'Open PHN File',
filters: [
{name: 'PHN File', extensions: ['phn']}
]},
],
properties: ['createDirectory'],
},
(paths) => {
if(paths.length){
let filename = paths[0].split(path.sep).pop();
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/MODEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class MODEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Export File',
defaultPath: resref+'.'+ext,
properties: ['createDirectory'],
filters: [
{name: ext.toUpperCase()+' file', extensions: [ext]}
]
Expand Down
3 changes: 2 additions & 1 deletion js/editor/tabs/ModelViewerTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class ModelViewerTab extends EditorTab {
filters: [
{name: 'TPC Image', extensions: ['tpc']},
{name: 'TGA Image', extensions: ['tga']}
]
],
properties: ['createDirectory'],
});

if(!payload.canceled && payload.filePaths.length){
Expand Down
4 changes: 3 additions & 1 deletion js/editor/tabs/QuickStartTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class QuickStartTab extends EditorTab {
properties: ['openFile'],
filters: [
{name: 'KMS Project', extensions: ['json']}
]});
],
properties: ['createDirectory'],
});
if(!payload.canceled && payload.filePaths.length){
Global.Project = new Project(path.dirname(payload.filePaths[0]));
Global.Project.Open(() => {
Expand Down
4 changes: 3 additions & 1 deletion js/editor/tabs/ScriptEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ScriptEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Export File',
defaultPath: this.file,
properties: ['createDirectory'],
filters: [
{name: 'NSS File', extensions: ['nss']},
{name: 'NCS File', extensions: ['ncs']}
Expand Down Expand Up @@ -128,7 +129,8 @@ class ScriptEditorTab extends EditorTab {
filters: [
{name: 'NSS File', extensions: ['nss']},
{name: 'NCS File', extensions: ['ncs']}
]
],
properties: ['createDirectory'],
});

if(!payload.canceled && payload.filePaths.length){
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/TextEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TextEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Save File As',
defaultPath: this.file.getLocalPath() ? this.file.getLocalPath() : this.file.getFilename(),
properties: ['createDirectory'],
filters: [
{name: this.file.ext.toUpperCase(), extensions: [this.file.ext]}
]
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/UTCEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ class UTCEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Save File As',
defaultPath: this.file.getLocalPath() ? this.file.getLocalPath() : this.file.getFilename(),
properties: ['createDirectory'],
filters: [
{name: this.file.ext.toUpperCase(), extensions: [this.file.ext]}
]
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/UTDEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class UTDEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Save File As',
defaultPath: this.file.getLocalPath() ? this.file.getLocalPath() : this.file.getFilename(),
properties: ['createDirectory'],
filters: [
{name: this.file.ext.toUpperCase(), extensions: [this.file.ext]}
]
Expand Down
1 change: 1 addition & 0 deletions js/editor/tabs/UTPEditorTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ class UTPEditorTab extends EditorTab {
let payload = await dialog.showSaveDialog({
title: 'Save File As',
defaultPath: this.file.getLocalPath() ? this.file.getLocalPath() : this.file.getFilename(),
properties: ['createDirectory'],
filters: [
{name: this.file.ext.toUpperCase(), extensions: [this.file.ext]}
]
Expand Down
1 change: 1 addition & 0 deletions js/resource/LIPObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class LIPObject {
let payload = await dialog.showSaveDialog({
title: 'Export LIP',
defaultPath: this.file,
properties: ['createDirectory'],
filters: [
{name: 'LIP', extensions: ['lip']}
]
Expand Down
2 changes: 1 addition & 1 deletion launcher/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ function buildProfileElement(profile = {}){
e.preventDefault();
let $btn = $(this);
if($btn.hasClass('locate') && !profile.directory){
dialog.showOpenDialog({title: 'KotOR Game Install Folder', properties: ['openDirectory',]}).then(result => {
dialog.showOpenDialog({title: 'KotOR Game Install Folder', properties: ['openDirectory', 'createDirectory']}).then(result => {
if(result.filePaths.length && !result.canceled){
if(result.filePaths[0]){
Config.set('Profiles.'+profile.key+'.directory', result.filePaths[0]);
Expand Down

0 comments on commit 93ec583

Please sign in to comment.