<commit_before>package pman.core.engine;

import tannus.io.*;
import tannus.ds.*;
import tannus.sys.Path;
import tannus.sys.FileSystem as Fs;
import tannus.async.*;
import tannus.async.promises.*;

import electron.ext.FileFilter;
import electron.ext.Dialog.FileDialogProperty;
import electron.ext.Dialog.FileOpenOptions;
import electron.ext.Dialog.FileDialogOptions;
import electron.ext.Dialog as D;

import js.html.Notification;
import js.html.NotificationPermission;
//import js.html.NotificationOptions;

import pman.Globals.*;

using StringTools;
using tannus.ds.StringUtils;
using Slambda;
using tannus.ds.ArrayTools;
using tannus.async.Asyncs;
using pman.bg.URITools;

class Dialogs {
    /* Constructor Function */
    public function new(e : Engine):Void {
        engine = e;
    }

/* === Instance Methods === */

    /**
      * prompt the user to select files to open
      */
    public function open(?opts:FSDialogOptions, ?done:Cb<Array<Path>>):ArrayPromise<Path> {
        var options:FileOpenOptions = _convertOpen(_completeOpen(opts != null ? opts : {}));
        return Promise.create({
            D.showOpenDialog(options, function( stringPaths ) {
                if (stringPaths == null)
                    stringPaths = [];
                var paths:Array<Path> = stringPaths.compact().map.fn(Path.fromString(_));
                if (!paths.empty()) {
                    var first:Path = paths[0].directory;
                    if (first.toString().hasContent()) {
                        engine.db.configInfo.lastDirectory = first;
                    }
                }
                return paths;
            });
        }).toAsync( done ).array();
    }

    /**
	  * create and display a FileSystem 'save' dialog
	  */
	public function save(?opts:FSDialogOptions, ?done:Cb<Path>):Promise<Null<Path>> {
	    if (opts == null) opts = {};
	    var options:FileOpenOptions = _convertOpen(_completeOpen( opts ));
	    return new Promise<Path>(function(accept, reject) {
            D.showSaveDialog(options, function(name : Null<String>) {
                var path:Null<Path> = (name != null ? new Path( name ) : null);
                return accept( path );
            });
        });<commit_msg>pman.core.engine.Dialogs.open now ensures that the Path in question points to a Directory when saving 'lastDirectory' variable<commit_after>package pman.core.engine;

import tannus.io.*;
import tannus.ds.*;
import tannus.sys.Path;
import tannus.sys.FileSystem as Fs;
import tannus.async.*;
import tannus.async.promises.*;

import electron.ext.FileFilter;
import electron.ext.Dialog.FileDialogProperty;
import electron.ext.Dialog.FileOpenOptions;
import electron.ext.Dialog.FileDialogOptions;
import electron.ext.Dialog as D;

import js.html.Notification;
import js.html.NotificationPermission;
//import js.html.NotificationOptions;

import pman.Globals.*;

using StringTools;
using tannus.ds.StringUtils;
using Slambda;
using tannus.ds.ArrayTools;
using tannus.async.Asyncs;
using pman.bg.URITools;

class Dialogs {
    /* Constructor Function */
    public function new(e : Engine):Void {
        engine = e;
    }

/* === Instance Methods === */

    /**
      * prompt the user to select files to open
      */
    public function open(?opts:FSDialogOptions, ?done:Cb<Array<Path>>):ArrayPromise<Path> {
        var options:FileOpenOptions = _convertOpen(_completeOpen(opts != null ? opts : {}));
        return Promise.create({
            D.showOpenDialog(options, function( stringPaths ) {
                if (stringPaths == null)
                    stringPaths = [];
                var paths:Array<Path> = stringPaths.compact().map.fn(Path.fromString(_));
                if (!paths.empty()) {
                    var first:Path = paths[0];
                    while (!Fs.isDirectory( first ))
                        first = first.directory;

                    if (first.toString().hasContent()) {
                        engine.db.configInfo.lastDirectory = first;
                    }
                }
                return paths;
            });
        }).toAsync( done ).array();
    }

    /**
	  * create and display a FileSystem 'save' dialog
	  */
	public function save(?opts:FSDialogOptions, ?done:Cb<Path>):Promise<Null<Path>> {
	    if (opts == null) opts = {};
	    var options:FileOpenOptions = _convertOpen(_completeOpen( opts ));
	    return new Promise<Path>(function(accept, reject) {
            D.showSaveDialog(options, function(name : Null<String>) {
                var path:Null<Path> = (name != null ? new Path( name ) : null);
                return accept( path );
            });
        });
{'fraction_non_alphanumeric': 0.12489270386266095, 'fraction_numerical': 0.00042918454935622315, 'mean_word_length': 2.4551519644180875, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '498772', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1301, 'n_words': 300}