Browse Source

[GTK] Use gtk_file_chooser_set_filename for open dialogs

pull/3816/head
Nikita Tsukanov 6 years ago
parent
commit
2eca7bc08a
  1. 7
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  2. 8
      src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs

7
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
#pragma warning disable 4014
@ -34,7 +37,9 @@ namespace ControlCatalog.Pages
new OpenFileDialog()
{
Title = "Open file",
Filters = GetFilters()
Filters = GetFilters(),
// Almost guaranteed to exist
InitialFileName = Assembly.GetEntryAssembly()?.GetModules().FirstOrDefault()?.FullyQualifiedName
}.ShowAsync(GetWindow());
};
this.FindControl<Button>("SaveFile").Click += delegate

8
src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs

@ -91,7 +91,13 @@ namespace Avalonia.X11.NativeDialogs
gtk_dialog_add_button(dlg, open, GtkResponseType.Cancel);
if (initialFileName != null)
using (var fn = new Utf8Buffer(initialFileName))
gtk_file_chooser_set_current_name(dlg, fn);
{
if (action == GtkFileChooserAction.Save)
gtk_file_chooser_set_current_name(dlg, fn);
else
gtk_file_chooser_set_filename(dlg, fn);
}
gtk_window_present(dlg);
return tcs.Task;
}

Loading…
Cancel
Save