4#include <QtCore/qglobal.h>
12#include <QtCore/qbuffer.h>
13#include <QtCore/qdebug.h>
14#include <QtCore/qstringlist.h>
15#include <QtCore/qvarlengtharray.h>
16#include <QtCore/qabstracteventdispatcher.h>
17#include <QtCore/qsysinfo.h>
18#include <QtCore/qoperatingsystemversion.h>
19#include <QtCore/qdir.h>
20#include <QtCore/qregularexpression.h>
21#include <QtCore/qpointer.h>
22#include <QtCore/private/qcore_mac_p.h>
24#include <QtGui/qguiapplication.h>
25#include <QtGui/private/qguiapplication_p.h>
27#include <qpa/qplatformtheme.h>
28#include <qpa/qplatformnativeinterface.h>
43 if ([
panel isKindOfClass:NSOpenPanel.class])
44 return static_cast<NSOpenPanel*
>(
panel);
66- (instancetype)initWithAcceptMode:(const
QString &)selectFile
74 m_panel = [[NSOpenPanel openPanel] retain];
76 m_panel = [[NSSavePanel savePanel] retain];
78 m_panel.canSelectHiddenExtension = YES;
79 m_panel.level = NSModalPanelWindowLevel;
88 if (sel.isDir() && !sel.isBundle()){
96 [
self createPopUpButton:selectedVisualNameFilter hideDetails:options->testOption(QFileDialogOptions::HideNameFilterDetails)];
97 [
self createTextField];
98 [
self createAccessory];
104 m_panel.delegate =
self;
107 openPanel.accessoryViewDisclosed = YES;
109 [
self updateProperties];
120 [m_panel orderOut:m_panel];
121 m_panel.accessoryView = nil;
122 [m_popupButton release];
123 [m_textField release];
124 [m_accessoryView release];
125 m_panel.delegate = nil;
127 [m_currentDirectory release];
135 NSURL *
url = [NSURL fileURLWithPath:filepath isDirectory:info.isDir()];
137 || [self
panel:m_panel shouldEnableURL:
url];
139 m_panel.directoryURL = [NSURL fileURLWithPath:m_currentDirectory];
140 m_panel.nameFieldStringValue = selectable ?
info.
fileName().toNSString() :
@"";
142 [
self updateProperties];
147 NSView *
view =
reinterpret_cast<NSView*
>(
parent->winId());
148 [m_panel beginSheetModalForWindow:view.window completionHandler:completionHandler];
152 [m_panel beginWithCompletionHandler:completionHandler];
158-(
void)runApplicationModalPanel
177 auto result = [m_panel runModal];
190 [NSApp endSheet:m_panel];
191 else if (NSApp.modalWindow == m_panel)
197- (BOOL)
panel:(
id)sender shouldEnableURL:(NSURL *)url
202 if (!filename.length)
205 QFileInfo fileInfo(QString::fromNSString(filename));
209 if (fileInfo.isDir()) {
215 bool treatBundlesAsFiles = !m_panel.treatsFilePackagesAsDirectories;
216 if (!(treatBundlesAsFiles && [NSWorkspace.sharedWorkspace isFilePackageAtPath:filename]))
220 QString qtFileName = fileInfo.fileName();
239 if (filterPermissions) {
258 [m_popupButton removeAllItems];
263 [m_popupButton.menu addItemWithTitle:filter.toNSString() action:nil keyEquivalent:@""];
265 [m_popupButton selectItemAtIndex:0];
268 m_panel.accessoryView = nil;
271 [
self filterChanged:self];
274- (
void)filterChanged:(
id)sender
282 [m_panel validateVisibleColumns];
283 [
self updateProperties];
294 for (NSURL *
url in openPanel.URLs) {
307 if (fileInfo.suffix().isEmpty() && !defaultSuffix.
isEmpty())
315- (
void)updateProperties
333 openPanel.canChooseFiles = !chooseDirsOnly;
334 openPanel.canChooseDirectories = !chooseFilesOnly;
341 m_panel.allowedFileTypes = [
self computeAllowedFileTypes];
354 if (m_panel.allowedFileTypes.count > 2)
355 m_panel.extensionHidden = NO;
360 [m_panel validateVisibleColumns];
363- (
void)panelSelectionDidChange:(
id)sender
370 if (m_panel.visible) {
379- (
void)
panel:(
id)sender directoryDidChange:(NSString *)path
389 [m_currentDirectory release];
407- (NSArray<NSString*>*)computeAllowedFileTypes
414 if (!
filter.startsWith(
"*."_L1))
417 if (
filter.contains(u
'?'))
420 if (
filter.count(u
'*') != 1)
424 fileTypes += extensions.last();
434 if (
match.hasMatch())
435 return match.captured(1).trimmed();
439- (
void)createTextField
441 NSRect
textRect = { { 0.0, 3.0 }, { 100.0, 25.0 } };
442 m_textField = [[NSTextField alloc] initWithFrame:textRect];
443 m_textField.cell.font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSControlSizeRegular]];
453- (
void)createPopUpButton:(const
QString &)selectedFilter hideDetails:(BOOL)hideDetails
455 NSRect popUpRect = { { 100.0, 5.0 }, { 250.0, 25.0 } };
456 m_popupButton = [[NSPopUpButton alloc] initWithFrame:popUpRect pullsDown:NO];
461 int filterToUse = -1;
464 if (selectedFilter == currentFilter ||
465 (filterToUse == -1 && currentFilter.
startsWith(selectedFilter)))
467 QString filter = hideDetails ? [
self removeExtensions:currentFilter] : currentFilter;
468 [m_popupButton.menu addItemWithTitle:filter.toNSString() action:nil keyEquivalent:@""];
470 if (filterToUse != -1)
471 [m_popupButton selectItemAtIndex:filterToUse];
484- (
void)createAccessory
486 NSRect accessoryRect = { { 0.0, 0.0 }, { 450.0, 33.0 } };
488 [m_accessoryView addSubview:m_textField];
489 [m_accessoryView addSubview:m_popupButton];
512 if (
result == NSModalResponseOK)
521 m_delegate->m_panel.directoryURL = [NSURL fileURLWithPath:directory.toLocalFile().toNSString()];
571 [
m_delegate->m_popupButton selectItemAtIndex:index];
607 createNSOpenSavePanelDelegate();
609 return [
m_delegate showPanel:windowModality withParent:parent];
612void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate()
627 [static_cast<QNSOpenSavePanelDelegate *>(m_delegate) release];
628 m_delegate = delegate;
635 if (m_delegate->m_panel.visible) {
638 m_eventLoop = &eventLoop;
640 m_eventLoop =
nullptr;
virtual void wakeUp()=0
\threadsafe
static void clearCurrentThreadCocoaEventDispatcherInterruptFlag()
QList< QUrl > selectedFiles() const override
bool defaultNameFilterDisables() const override
void setFilter() override
QString selectedNameFilter() const override
QUrl directory() const override
void setDirectory(const QUrl &directory) override
virtual ~QCocoaFileDialogHelper()
bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override
void selectNameFilter(const QString &filter) override
void selectFile(const QUrl &filename) override
void panelClosed(NSInteger result)
static QAbstractEventDispatcher * eventDispatcher()
Returns a pointer to the event dispatcher object for the main thread.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
QList< QUrl > initiallySelectedFiles() const
bool isLabelExplicitlySet(DialogLabel label)
QDir::Filters filter() const
QString initiallySelectedNameFilter() const
QString labelText(DialogLabel label) const
AcceptMode acceptMode() const
QString defaultSuffix() const
void setInitiallySelectedNameFilter(const QString &)
QUrl initialDirectory() const
QStringList nameFilters() const
FileMode fileMode() const
QString windowTitle() const
bool testOption(FileDialogOption option) const
\inmodule QtCore \reentrant
QString fileName() const
Returns the name of the file, excluding the path.
QString filePath() const
Returns the file name, including the path (which may be absolute or relative).
bool isEmpty() const noexcept
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & append(QChar c)
QString trimmed() const &
QString normalized(NormalizationForm mode, QChar::UnicodeVersion version=QChar::Unicode_Unassigned) const
Returns the string in the given Unicode normalization mode, according to the given version of the Uni...
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Combined button and popup list for selecting options.
QString * m_currentSelection
QSharedPointer< QFileDialogOptions > SharedPointerFileDialogOptions
NSString * m_currentDirectory
SharedPointerFileDialogOptions m_options
QStringList * m_nameFilterDropDownList
NSPopUpButton * m_popupButton
static NSString * strippedText(QString s)
QStringList * m_selectedNameFilter
static NSOpenPanel * openpanel_cast(NSSavePanel *panel)
QPointer< QCocoaFileDialogHelper > m_helper
NSTextField * m_textField
NSMutableArray< NSString * > * qt_mac_QStringListToNSMutableArray(const QStringList &list)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
GLenum GLenum GLsizei count
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei const GLchar *const * path
static QString toLocalFile(const QString &url)
static QString absolutePath(const QString &path)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QFileInfo info(fileName)
[8]
QUrl url("example.com")
[constructor-url-reference]
dialog setNameFilters(filters)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QItemSelection * selection
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent