<commit_before>#include <QQuickWindow>
#include <QDebug>

#include "myfilesavedialog.h"

MyFileSaveDialog::MyFileSaveDialog(QQuickItem *parent) :
    QQuickItem(parent)
  , m_modality(Qt::WindowModal)
  , m_options(QSharedPointer<QFileDialogOptions>(new QFileDialogOptions()))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
    qDebug() << "Working with Qt 5.2";
#else
    qDebug() << "Working with Qt 5.1";
#endif

    m_dlgHelper = init_helper();

    connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept()));
    connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject()));
}

MyFileSaveDialog::~MyFileSaveDialog()
{
    if (m_dlgHelper)
        m_dlgHelper->hide();
    delete m_dlgHelper;
}

QUrl MyFileSaveDialog::fileUrl() const
{
    return fileUrl_;
}

void MyFileSaveDialog::setFileUrl(QUrl fileUrl)
{
    if (fileUrl_ != fileUrl)
    {
        fileUrl_ = fileUrl;
        emit fileUrlChanged();
    }
}

QString MyFileSaveDialog::filename() const
{
    return filename_;
}

void MyFileSaveDialog::setFilename(QString filename)
{
    if (filename_ != filename)
    {
        filename_ = filename;
        emit filenameChanged();
    }
}

QString MyFileSaveDialog::title() const
{
    return title_;
}

void MyFileSaveDialog::setTitle(QString title)
{
    if (title_ != title)
    {
        title_ = title;
        emit titleChanged();
    }
}

QPlatformFileDialogHelper* MyFileSaveDialog::init_helper()
{
    m_dlgHelper = static_cast<QPlatformFileDialogHelper*>(QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(QPlatformTheme::FileDialog));
    if (!m_dlgHelper)
        return NULL;

    return m_dlgHelper;
}

void MyFileSaveDialog::open()
{
    QQuickItem *me = this;
    Q_ASSERT(me);

    QQuickItem *parent = me->parentItem();
    Q_ASSERT(parent);

    QQuickWindow *window = parent->window();
    Q_ASSERT(window);

    m_parentWindow = window;

    m_options->setFileMode(QFileDialogOptions::AnyFile);
    m_options->setAcceptMode(QFileDialogOptions::AcceptSave);
    m_options->setWindowTitle(title());

    m_dlgHelper->setOptions(m_options);<commit_msg>Set initial file via setInitiallySelectedFiles on OSX<commit_after>#include <QQuickWindow>
#include <QDebug>

#include "myfilesavedialog.h"

MyFileSaveDialog::MyFileSaveDialog(QQuickItem *parent) :
    QQuickItem(parent)
  , m_modality(Qt::WindowModal)
  , m_options(QSharedPointer<QFileDialogOptions>(new QFileDialogOptions()))
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
    qDebug() << "Working with Qt 5.2";
#else
    qDebug() << "Working with Qt 5.1";
#endif

    m_dlgHelper = init_helper();

    connect(m_dlgHelper, SIGNAL(accept()), this, SLOT(accept()));
    connect(m_dlgHelper, SIGNAL(reject()), this, SLOT(reject()));
}

MyFileSaveDialog::~MyFileSaveDialog()
{
    if (m_dlgHelper)
        m_dlgHelper->hide();
    delete m_dlgHelper;
}

QUrl MyFileSaveDialog::fileUrl() const
{
    return fileUrl_;
}

void MyFileSaveDialog::setFileUrl(QUrl fileUrl)
{
    if (fileUrl_ != fileUrl)
    {
        fileUrl_ = fileUrl;
        emit fileUrlChanged();
    }
}

QString MyFileSaveDialog::filename() const
{
    return filename_;
}

void MyFileSaveDialog::setFilename(QString filename)
{
    if (filename_ != filename)
    {
        filename_ = filename;
        emit filenameChanged();
    }
}

QString MyFileSaveDialog::title() const
{
    return title_;
}

void MyFileSaveDialog::setTitle(QString title)
{
    if (title_ != title)
    {
        title_ = title;
        emit titleChanged();
    }
}

QPlatformFileDialogHelper* MyFileSaveDialog::init_helper()
{
    m_dlgHelper = static_cast<QPlatformFileDialogHelper*>(QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(QPlatformTheme::FileDialog));
    if (!m_dlgHelper)
        return NULL;

    return m_dlgHelper;
}

void MyFileSaveDialog::open()
{
    QQuickItem *me = this;
    Q_ASSERT(me);

    QQuickItem *parent = me->parentItem();
    Q_ASSERT(parent);

    QQuickWindow *window = parent->window();
    Q_ASSERT(window);

    m_parentWindow = window;

    m_options->setFileMode(QFileDialogOptions::AnyFile);
    m_options->setAcceptMode(QFileDialogOptions::AcceptSave);
    m_options->setWindowTitle(title());

#ifdef Q_OS_OSX
    // Mac: Set filename incl. directory via setInitiallySelectedFiles()
    QString initialSelection = QFileInfo(QDir::homePath(), filename()).absoluteFilePath();
    qDebug() << "Initial file: " << initialSelection;
    // TODO: make Qt 5.1 compatible
    m_options->setInitiallySelectedFiles(QList<QUrl>() << QUrl::fromLocalFile(initialSelection));
#endif

    m_dlgHelper->setOptions(m_options);
{'fraction_non_alphanumeric': 0.12841056734517106, 'fraction_numerical': 0.0034647033347769596, 'mean_word_length': 4.370930232558139, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 31, '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': '470851', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1508, 'n_words': 270}