2017-06-30 20:34:05 +00:00
|
|
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
|
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* gtkfilechoosernativequartz.c: Quartz Native File selector dialog
|
|
|
|
* Copyright (C) 2017, Tom Schoonjans
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkfilechoosernativeprivate.h"
|
|
|
|
#include "gtknativedialogprivate.h"
|
|
|
|
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2017-06-30 20:34:05 +00:00
|
|
|
#include "gtkprivate.h"
|
2022-10-29 15:31:35 +00:00
|
|
|
#include "deprecated/gtkfilechooserdialog.h"
|
2017-06-30 20:34:05 +00:00
|
|
|
#include "gtkfilechooserprivate.h"
|
|
|
|
#include "gtkfilechooserwidgetprivate.h"
|
|
|
|
#include "gtkfilechooserutils.h"
|
|
|
|
#include "gtksizerequest.h"
|
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtksettings.h"
|
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtkheaderbar.h"
|
|
|
|
#include "gtklabel.h"
|
2020-10-10 03:08:23 +00:00
|
|
|
#include "gtknative.h"
|
2017-06-30 20:34:05 +00:00
|
|
|
#include "gtkfilefilterprivate.h"
|
|
|
|
|
2020-10-10 03:08:23 +00:00
|
|
|
#include "macos/gdkmacos.h"
|
2022-03-12 02:19:44 +00:00
|
|
|
#include "macos/gdkmacosdisplay-private.h"
|
2020-10-10 03:08:23 +00:00
|
|
|
#include "macos/gdkmacossurface-private.h"
|
2017-06-30 20:34:05 +00:00
|
|
|
|
2022-10-29 15:31:35 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkFileChooserNative *self;
|
|
|
|
|
|
|
|
NSSavePanel *panel;
|
|
|
|
NSWindow *parent;
|
2017-07-31 20:28:42 +00:00
|
|
|
NSWindow *key_window;
|
2017-06-30 20:34:05 +00:00
|
|
|
gboolean skip_response;
|
|
|
|
gboolean save;
|
|
|
|
gboolean folder;
|
|
|
|
gboolean create_folders;
|
|
|
|
gboolean modal;
|
|
|
|
gboolean select_multiple;
|
|
|
|
gboolean running;
|
|
|
|
|
|
|
|
char *accept_label;
|
|
|
|
char *cancel_label;
|
|
|
|
char *title;
|
2017-07-04 07:07:09 +00:00
|
|
|
char *message;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
GFile *current_folder;
|
|
|
|
GFile *current_file;
|
|
|
|
char *current_name;
|
|
|
|
|
2017-07-23 08:37:26 +00:00
|
|
|
NSMutableArray *filters;
|
|
|
|
NSMutableArray *filter_names;
|
2017-07-09 16:06:12 +00:00
|
|
|
NSComboBox *filter_combo_box;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
GSList *files;
|
|
|
|
int response;
|
|
|
|
} FileChooserQuartzData;
|
|
|
|
|
2017-07-09 16:06:12 +00:00
|
|
|
@interface FilterComboBox : NSObject<NSComboBoxDelegate>
|
|
|
|
{
|
|
|
|
FileChooserQuartzData *data;
|
|
|
|
}
|
|
|
|
- (id) initWithData:(FileChooserQuartzData *) quartz_data;
|
|
|
|
- (void)comboBoxSelectionDidChange:(NSNotification *)notification;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FilterComboBox
|
|
|
|
|
|
|
|
- (id) initWithData:(FileChooserQuartzData *) quartz_data
|
|
|
|
{
|
|
|
|
[super init];
|
|
|
|
data = quartz_data;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
- (void)comboBoxSelectionDidChange:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSInteger selected_index = [data->filter_combo_box indexOfSelectedItem];
|
2017-07-23 08:37:26 +00:00
|
|
|
NSArray *filter = [data->filters objectAtIndex:selected_index];
|
2017-07-09 16:06:12 +00:00
|
|
|
// check for empty strings in filter -> indicates all filetypes should be allowed!
|
|
|
|
if ([filter containsObject:@""])
|
|
|
|
[data->panel setAllowedFileTypes:nil];
|
|
|
|
else
|
|
|
|
[data->panel setAllowedFileTypes:filter];
|
2017-07-13 19:01:38 +00:00
|
|
|
|
2020-07-04 16:15:47 +00:00
|
|
|
GListModel *filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self));
|
|
|
|
data->self->current_filter = g_list_model_get_item (filters, selected_index);
|
|
|
|
g_object_unref (data->self->current_filter);
|
|
|
|
g_object_unref (filters);
|
2017-07-13 19:01:38 +00:00
|
|
|
g_object_notify (G_OBJECT (data->self), "filter");
|
2017-07-09 16:06:12 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
static GFile *
|
|
|
|
ns_url_to_g_file (NSURL *url)
|
|
|
|
{
|
|
|
|
if (url == nil)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_file_new_for_uri ([[url absoluteString] UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
chooser_get_files (FileChooserQuartzData *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
GSList *ret = NULL;
|
|
|
|
|
|
|
|
if (!data->save)
|
|
|
|
{
|
|
|
|
NSArray *urls;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
urls = [(NSOpenPanel *)data->panel URLs];
|
|
|
|
|
|
|
|
for (i = 0; i < [urls count]; i++)
|
|
|
|
{
|
|
|
|
NSURL *url;
|
|
|
|
|
|
|
|
url = (NSURL *)[urls objectAtIndex:i];
|
|
|
|
ret = g_slist_prepend (ret, ns_url_to_g_file (url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
file = ns_url_to_g_file ([data->panel URL]);
|
|
|
|
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
ret = g_slist_prepend (ret, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_slist_reverse (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chooser_set_current_folder (FileChooserQuartzData *data,
|
|
|
|
GFile *folder)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (folder != NULL)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *uri;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
uri = g_file_get_uri (folder);
|
|
|
|
[data->panel setDirectoryURL:[NSURL URLWithString:[NSString stringWithUTF8String:uri]]];
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
chooser_set_current_name (FileChooserQuartzData *data,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name)
|
2017-06-30 20:34:05 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
[data->panel setNameFieldStringValue:[NSString stringWithUTF8String:name]];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
filechooser_quartz_data_free (FileChooserQuartzData *data)
|
|
|
|
{
|
2020-10-10 03:08:23 +00:00
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
if (data->filters)
|
|
|
|
{
|
2017-07-09 16:06:12 +00:00
|
|
|
[data->filters release];
|
2017-06-30 20:34:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 16:06:12 +00:00
|
|
|
if (data->filter_names)
|
|
|
|
{
|
|
|
|
[data->filter_names release];
|
|
|
|
}
|
2020-10-10 03:08:23 +00:00
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
g_clear_object (&data->current_folder);
|
|
|
|
g_clear_object (&data->current_file);
|
|
|
|
g_free (data->current_name);
|
|
|
|
|
|
|
|
g_slist_free_full (data->files, g_object_unref);
|
|
|
|
if (data->self)
|
|
|
|
g_object_unref (data->self);
|
|
|
|
g_free (data->accept_label);
|
|
|
|
g_free (data->cancel_label);
|
|
|
|
g_free (data->title);
|
2017-07-04 07:07:09 +00:00
|
|
|
g_free (data->message);
|
2017-06-30 20:34:05 +00:00
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2017-07-31 20:26:47 +00:00
|
|
|
@protocol CanSetAccessoryViewDisclosed
|
|
|
|
- (void)setAccessoryViewDisclosed:(BOOL)val;
|
|
|
|
@end
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
static gboolean
|
|
|
|
filechooser_quartz_launch (FileChooserQuartzData *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (data->save)
|
|
|
|
{
|
|
|
|
|
2017-07-03 11:54:39 +00:00
|
|
|
if (data->folder)
|
|
|
|
{
|
|
|
|
NSOpenPanel *panel = [[NSOpenPanel openPanel] retain];
|
|
|
|
[panel setCanChooseDirectories:YES];
|
|
|
|
[panel setCanChooseFiles:NO];
|
|
|
|
[panel setCanCreateDirectories:YES];
|
|
|
|
data->panel = panel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSSavePanel *panel = [[NSSavePanel savePanel] retain];
|
|
|
|
if (data->create_folders)
|
|
|
|
{
|
|
|
|
[panel setCanCreateDirectories:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[panel setCanCreateDirectories:NO];
|
|
|
|
}
|
|
|
|
data->panel = panel;
|
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
}
|
2017-07-03 11:54:39 +00:00
|
|
|
else
|
2017-06-30 20:34:05 +00:00
|
|
|
{
|
2017-07-03 11:54:39 +00:00
|
|
|
NSOpenPanel *panel = [[NSOpenPanel openPanel] retain];
|
2017-06-30 20:34:05 +00:00
|
|
|
|
2017-07-03 11:54:39 +00:00
|
|
|
if (data->select_multiple)
|
|
|
|
{
|
|
|
|
[panel setAllowsMultipleSelection:YES];
|
|
|
|
}
|
|
|
|
if (data->folder)
|
|
|
|
{
|
|
|
|
[panel setCanChooseDirectories:YES];
|
|
|
|
[panel setCanChooseFiles:NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[panel setCanChooseDirectories:NO];
|
|
|
|
[panel setCanChooseFiles:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
data->panel = panel;
|
2017-06-30 20:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[data->panel setReleasedWhenClosed:YES];
|
|
|
|
|
|
|
|
if (data->accept_label)
|
|
|
|
[data->panel setPrompt:[NSString stringWithUTF8String:data->accept_label]];
|
|
|
|
|
|
|
|
if (data->title)
|
|
|
|
[data->panel setTitle:[NSString stringWithUTF8String:data->title]];
|
|
|
|
|
2017-07-04 07:07:09 +00:00
|
|
|
if (data->message)
|
|
|
|
[data->panel setMessage:[NSString stringWithUTF8String:data->message]];
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
if (data->current_file)
|
|
|
|
{
|
|
|
|
GFile *folder;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
folder = g_file_get_parent (data->current_file);
|
|
|
|
name = g_file_get_basename (data->current_file);
|
|
|
|
|
|
|
|
chooser_set_current_folder (data, folder);
|
|
|
|
chooser_set_current_name (data, name);
|
|
|
|
|
|
|
|
g_object_unref (folder);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->current_folder)
|
|
|
|
{
|
|
|
|
chooser_set_current_folder (data, data->current_folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->current_name)
|
|
|
|
{
|
|
|
|
chooser_set_current_name (data, data->current_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->filters)
|
|
|
|
{
|
2017-07-09 16:06:12 +00:00
|
|
|
// when filters have been provided, a combobox needs to be added
|
2022-02-17 20:39:21 +00:00
|
|
|
data->filter_combo_box = [[NSComboBox alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
|
2017-07-09 16:06:12 +00:00
|
|
|
[data->filter_combo_box addItemsWithObjectValues:data->filter_names];
|
|
|
|
[data->filter_combo_box setEditable:NO];
|
|
|
|
[data->filter_combo_box setDelegate:[[FilterComboBox alloc] initWithData:data]];
|
2017-07-13 19:01:38 +00:00
|
|
|
|
|
|
|
if (data->self->current_filter)
|
|
|
|
{
|
2020-07-04 16:15:47 +00:00
|
|
|
GListModel *filters;
|
|
|
|
guint i, n;
|
|
|
|
guint current_filter_index = GTK_INVALID_LIST_POSITION;
|
2017-07-13 19:01:38 +00:00
|
|
|
|
2020-07-04 16:15:47 +00:00
|
|
|
filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self));
|
|
|
|
n = g_list_model_get_n_items (filters);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
gpointer item = g_list_model_get_item (filters, i);
|
|
|
|
if (item == data->self->current_filter)
|
|
|
|
{
|
|
|
|
g_object_unref (item);
|
|
|
|
current_filter_index = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
g_object_unref (filters);
|
|
|
|
|
|
|
|
if (current_filter_index != GTK_INVALID_LIST_POSITION)
|
2017-07-13 19:01:38 +00:00
|
|
|
[data->filter_combo_box selectItemAtIndex:current_filter_index];
|
2020-07-04 16:15:47 +00:00
|
|
|
else
|
2017-07-13 19:01:38 +00:00
|
|
|
[data->filter_combo_box selectItemAtIndex:0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[data->filter_combo_box selectItemAtIndex:0];
|
|
|
|
}
|
2017-07-09 16:06:12 +00:00
|
|
|
[data->filter_combo_box setToolTip:[NSString stringWithUTF8String:_("Select which types of files are shown")]];
|
|
|
|
[data->panel setAccessoryView:data->filter_combo_box];
|
2017-07-31 20:26:47 +00:00
|
|
|
if ([data->panel isKindOfClass:[NSOpenPanel class]] && [data->panel respondsToSelector:@selector(setAccessoryViewDisclosed:)])
|
2017-07-09 16:06:12 +00:00
|
|
|
{
|
2017-07-31 20:26:47 +00:00
|
|
|
[(id<CanSetAccessoryViewDisclosed>) data->panel setAccessoryViewDisclosed:YES];
|
2017-07-09 16:06:12 +00:00
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
}
|
|
|
|
data->response = GTK_RESPONSE_CANCEL;
|
|
|
|
|
2020-10-10 03:08:23 +00:00
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
void (^handler)(NSInteger ret) = ^(NSInteger result) {
|
|
|
|
|
2020-11-19 03:56:51 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2017-06-30 20:34:05 +00:00
|
|
|
{
|
|
|
|
// get selected files and update data->files
|
|
|
|
data->response = GTK_RESPONSE_ACCEPT;
|
|
|
|
data->files = chooser_get_files (data);
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkFileChooserNative *self = data->self;
|
|
|
|
|
|
|
|
self->mode_data = NULL;
|
|
|
|
|
2017-07-31 20:28:42 +00:00
|
|
|
if (data->parent)
|
|
|
|
{
|
|
|
|
[data->panel orderOut:nil];
|
|
|
|
[data->parent makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[data->key_window makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
2022-03-12 02:19:44 +00:00
|
|
|
/* Need to clear our cached copy of ordered windows */
|
|
|
|
_gdk_macos_display_clear_sorting (GDK_MACOS_DISPLAY (gdk_display_get_default ()));
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
if (!data->skip_response)
|
|
|
|
{
|
|
|
|
g_slist_free_full (self->custom_files, g_object_unref);
|
|
|
|
self->custom_files = data->files;
|
|
|
|
data->files = NULL;
|
|
|
|
|
|
|
|
_gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (data->self),
|
|
|
|
data->response);
|
|
|
|
}
|
|
|
|
// free data!
|
|
|
|
filechooser_quartz_data_free (data);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (data->parent != NULL && data->modal)
|
|
|
|
{
|
|
|
|
[data->panel beginSheetModalForWindow:data->parent completionHandler:handler];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[data->panel beginWithCompletionHandler:handler];
|
2017-07-03 11:54:39 +00:00
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
|
|
|
strip_mnemonic (const char *s)
|
2017-06-30 20:34:05 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *escaped;
|
|
|
|
char *ret = NULL;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
escaped = g_markup_escape_text (s, -1);
|
|
|
|
pango_parse_markup (escaped, -1, '_', NULL, &ret, NULL, NULL);
|
|
|
|
|
|
|
|
if (ret != NULL)
|
2017-07-04 07:07:09 +00:00
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
else
|
2017-07-04 07:07:09 +00:00
|
|
|
{
|
|
|
|
return g_strdup (s);
|
|
|
|
}
|
2020-10-10 03:08:23 +00:00
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
|
2017-07-09 16:06:12 +00:00
|
|
|
static gboolean
|
|
|
|
file_filter_to_quartz (GtkFileFilter *file_filter,
|
2017-07-23 08:37:26 +00:00
|
|
|
NSMutableArray *filters,
|
|
|
|
NSMutableArray *filter_names)
|
2017-07-09 16:06:12 +00:00
|
|
|
{
|
|
|
|
const char *name;
|
2017-07-23 08:37:26 +00:00
|
|
|
NSArray *pattern_nsstrings;
|
2017-07-09 16:06:12 +00:00
|
|
|
|
|
|
|
pattern_nsstrings = _gtk_file_filter_get_as_pattern_nsstrings (file_filter);
|
|
|
|
if (pattern_nsstrings == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
name = gtk_file_filter_get_name (file_filter);
|
|
|
|
NSString *name_nsstring;
|
|
|
|
if (name == NULL)
|
|
|
|
{
|
|
|
|
name_nsstring = [pattern_nsstrings componentsJoinedByString:@","];;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
name_nsstring = [NSString stringWithUTF8String:name];
|
|
|
|
[name_nsstring retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
[filter_names addObject:name_nsstring];
|
|
|
|
[filters addObject:pattern_nsstrings];
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
gboolean
|
|
|
|
gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self)
|
|
|
|
{
|
|
|
|
FileChooserQuartzData *data;
|
|
|
|
GtkWindow *transient_for;
|
|
|
|
GtkFileChooserAction action;
|
|
|
|
|
2020-07-04 16:15:47 +00:00
|
|
|
GListModel *filters;
|
|
|
|
guint n_filters, i;
|
2017-07-04 07:07:09 +00:00
|
|
|
char *message = NULL;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
data = g_new0 (FileChooserQuartzData, 1);
|
|
|
|
|
2017-07-09 16:06:12 +00:00
|
|
|
// examine filters!
|
2020-07-04 16:15:47 +00:00
|
|
|
filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (self));
|
|
|
|
n_filters = g_list_model_get_n_items (filters);
|
2017-07-09 16:06:12 +00:00
|
|
|
if (n_filters > 0)
|
|
|
|
{
|
2017-07-23 08:37:26 +00:00
|
|
|
data->filters = [NSMutableArray arrayWithCapacity:n_filters];
|
2017-07-09 16:06:12 +00:00
|
|
|
[data->filters retain];
|
2017-07-23 08:37:26 +00:00
|
|
|
data->filter_names = [NSMutableArray arrayWithCapacity:n_filters];
|
2017-07-09 16:06:12 +00:00
|
|
|
[data->filter_names retain];
|
|
|
|
|
2020-10-10 03:08:23 +00:00
|
|
|
for (i = 0; i < n_filters; i++)
|
2017-07-09 16:06:12 +00:00
|
|
|
{
|
2020-07-04 16:15:47 +00:00
|
|
|
GtkFileFilter *filter = g_list_model_get_item (filters, i);
|
|
|
|
if (!file_filter_to_quartz (filter, data->filters, data->filter_names))
|
2017-07-09 16:06:12 +00:00
|
|
|
{
|
|
|
|
filechooser_quartz_data_free (data);
|
2020-07-04 16:15:47 +00:00
|
|
|
g_object_unref (filter);
|
|
|
|
g_object_unref (filters);
|
2017-07-09 16:06:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2020-07-04 16:15:47 +00:00
|
|
|
g_object_unref (filter);
|
2017-07-09 16:06:12 +00:00
|
|
|
}
|
2017-07-13 19:01:38 +00:00
|
|
|
self->current_filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->current_filter = NULL;
|
2017-07-09 16:06:12 +00:00
|
|
|
}
|
2020-07-04 16:15:47 +00:00
|
|
|
g_object_unref (filters);
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
self->mode_data = data;
|
|
|
|
data->self = g_object_ref (self);
|
|
|
|
|
2017-07-09 16:06:12 +00:00
|
|
|
data->create_folders = gtk_file_chooser_get_create_folders (GTK_FILE_CHOOSER (self));
|
2017-06-30 20:34:05 +00:00
|
|
|
|
2020-10-10 03:08:23 +00:00
|
|
|
// shortcut_folder_uris support seems difficult if not impossible
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
// mnemonics are not supported on macOS, so remove the underscores
|
|
|
|
data->accept_label = strip_mnemonic (self->accept_label);
|
|
|
|
// cancel button is not present in macOS filechooser dialogs!
|
|
|
|
// data->cancel_label = strip_mnemonic (self->cancel_label);
|
|
|
|
|
|
|
|
action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self->dialog));
|
|
|
|
|
2020-02-22 14:54:48 +00:00
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2017-06-30 20:34:05 +00:00
|
|
|
data->save = TRUE;
|
|
|
|
|
2020-02-22 14:54:48 +00:00
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
|
2017-06-30 20:34:05 +00:00
|
|
|
data->folder = TRUE;
|
|
|
|
|
|
|
|
if ((action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
|
|
|
|
action == GTK_FILE_CHOOSER_ACTION_OPEN) &&
|
|
|
|
gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self->dialog)))
|
|
|
|
data->select_multiple = TRUE;
|
|
|
|
|
|
|
|
transient_for = gtk_native_dialog_get_transient_for (GTK_NATIVE_DIALOG (self));
|
|
|
|
if (transient_for)
|
|
|
|
{
|
2020-10-13 03:11:35 +00:00
|
|
|
GtkNative *native = GTK_NATIVE (transient_for);
|
|
|
|
GdkSurface *surface = gtk_native_get_surface (native);
|
|
|
|
NSWindow *window = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
gtk_widget_realize (GTK_WIDGET (transient_for));
|
2020-10-13 03:11:35 +00:00
|
|
|
data->parent = window;
|
2017-06-30 20:34:05 +00:00
|
|
|
|
|
|
|
if (gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self)))
|
|
|
|
data->modal = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->title =
|
|
|
|
g_strdup (gtk_native_dialog_get_title (GTK_NATIVE_DIALOG (self)));
|
|
|
|
|
2017-07-04 07:07:09 +00:00
|
|
|
data->message = message;
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
if (self->current_file)
|
|
|
|
data->current_file = g_object_ref (self->current_file);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (self->current_folder)
|
|
|
|
data->current_folder = g_object_ref (self->current_folder);
|
|
|
|
|
2020-02-22 14:54:48 +00:00
|
|
|
if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
|
2017-06-30 20:34:05 +00:00
|
|
|
data->current_name = g_strdup (self->current_name);
|
|
|
|
}
|
|
|
|
|
2017-07-31 20:28:42 +00:00
|
|
|
data->key_window = [NSApp keyWindow];
|
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
return filechooser_quartz_launch(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_file_chooser_native_quartz_hide (GtkFileChooserNative *self)
|
|
|
|
{
|
|
|
|
FileChooserQuartzData *data = self->mode_data;
|
|
|
|
|
|
|
|
/* This is always set while dialog visible */
|
|
|
|
g_assert (data != NULL);
|
|
|
|
|
|
|
|
data->skip_response = TRUE;
|
|
|
|
if (data->panel == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[data->panel orderBack:nil];
|
|
|
|
[data->panel close];
|
2017-07-31 20:28:42 +00:00
|
|
|
|
2017-06-30 20:34:05 +00:00
|
|
|
if (data->parent)
|
2017-07-31 20:28:42 +00:00
|
|
|
{
|
|
|
|
[data->parent makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[data->key_window makeKeyAndOrderFront:nil];
|
|
|
|
}
|
2017-06-30 20:34:05 +00:00
|
|
|
data->panel = NULL;
|
|
|
|
}
|
|
|
|
|