Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions framework/interactive/internal/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include "muse_framework_config.h"

#include "defer.h"
#ifdef Q_OS_MAC
#include "platform/macos/macosinteractivehelper.h"
#endif

#include "log.h"

using namespace muse;
Expand Down Expand Up @@ -355,15 +359,25 @@ async::Promise<io::path_t> Interactive::selectOpeningFile(const std::string& tit
{
#ifndef Q_OS_LINUX
return async::make_promise<io::path_t>([title, dir, filter](auto resolve, auto reject) {
#ifdef Q_OS_MAC
auto scope = std::make_shared<MacOSInteractiveHelper::NativeDialogScope>();
#endif
QFileDialog* dlg = new QFileDialog(nullptr, QString::fromStdString(title), dir.toQString(), filterToString(filter));

dlg->setFileMode(QFileDialog::ExistingFile);

QObject::connect(dlg, &QFileDialog::finished, [dlg, resolve, reject](int result) {
QObject::connect(dlg, &QFileDialog::finished, [dlg, resolve, reject
#ifdef Q_OS_MAC
, scope
#endif
](int result) mutable {
DEFER {
//! Must be called AFTER resolve/reject, as they may process posted events
dlg->deleteLater();
};
#ifdef Q_OS_MAC
scope.reset();
#endif

QStringList files = dlg->selectedFiles();

Expand Down Expand Up @@ -404,6 +418,9 @@ io::path_t Interactive::selectOpeningFileSync(const std::string& title, const io
const int options)
{
#ifndef Q_OS_LINUX
#ifdef Q_OS_MAC
MacOSInteractiveHelper::NativeDialogScope scope;
#endif
const QFileDialog::Options qoptions = QFileDialog::Options::fromInt(options);
QString result = QFileDialog::getOpenFileName(nullptr, QString::fromStdString(title), dir.toQString(), filterToString(
filter), nullptr, qoptions);
Expand All @@ -424,6 +441,9 @@ io::paths_t Interactive::selectOpeningFilesSync(const std::string& title, const
const int options)
{
#ifndef Q_OS_LINUX
#ifdef Q_OS_MAC
MacOSInteractiveHelper::NativeDialogScope scope;
#endif
const QFileDialog::Options qoptions = QFileDialog::Options::fromInt(options);
const QStringList result = QFileDialog::getOpenFileNames(nullptr, QString::fromStdString(title), dir.toQString(), filterToString(
filter), nullptr, qoptions);
Expand All @@ -445,6 +465,9 @@ io::path_t Interactive::selectSavingFileSync(const std::string& title, const io:
bool confirmOverwrite)
{
#ifndef Q_OS_LINUX
#ifdef Q_OS_MAC
MacOSInteractiveHelper::NativeDialogScope scope;
#endif
QFileDialog::Options options;
options.setFlag(QFileDialog::DontConfirmOverwrite, !confirmOverwrite);
QString result = QFileDialog::getSaveFileName(nullptr, QString::fromStdString(title), dir.toQString(), filterToString(
Expand All @@ -467,10 +490,12 @@ io::path_t Interactive::selectSavingFileSync(const std::string& title, const io:
io::path_t Interactive::selectDirectory(const std::string& title, const io::path_t& dir)
{
#ifndef Q_OS_LINUX
#ifdef Q_OS_MAC
MacOSInteractiveHelper::NativeDialogScope scope;
#endif
QString result = QFileDialog::getExistingDirectory(nullptr, QString::fromStdString(title), dir.toQString());
return result;
#else

UriQuery q("muse://interactive/selectdir");
q.set("title", title);
q.set("folder", QUrl::fromLocalFile(dir.toQString()).toLocalFile().toStdString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#pragma once

#include <map>

#include "io/path.h"
#include "types/ret.h"

Expand All @@ -33,10 +35,34 @@ class UriQuery;
class MacOSInteractiveHelper
{
public:
enum class EditAction {
Undo,
Redo,
Cut,
Copy,
Paste,
SelectAll
};

static void setEditMenuIndex(int menuIndex);
static void setEditMenuStructure(const std::map<EditAction, int>& structure);

static bool revealInFinder(const io::path_t& filePath);

static Ret isAppExists(const std::string& appIdentifier);
static Ret canOpenApp(const UriQuery& uri);
static async::Promise<Ret> openApp(const UriQuery& uri);

class NativeDialogScope
{
public:
NativeDialogScope();
~NativeDialogScope();

NativeDialogScope(const NativeDialogScope&) = delete;
NativeDialogScope& operator=(const NativeDialogScope&) = delete;
NativeDialogScope(NativeDialogScope&&) = delete;
NativeDialogScope& operator=(NativeDialogScope&&) = delete;
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};
}
Loading