Browse Source

Merge branch 'master' into refactor/combobox

pull/2393/head
Jumar Macato 7 years ago
committed by GitHub
parent
commit
c39c40dfc4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      samples/ControlCatalog/Pages/DialogsPage.xaml
  2. 26
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  3. 4
      src/Avalonia.Controls/ControlExtensions.cs
  4. 3
      src/Avalonia.Native/AvaloniaNativePlatform.cs
  5. 12
      src/Avalonia.X11/NativeDialogs/Gtk.cs
  6. 25
      src/Avalonia.X11/NativeDialogs/GtkNativeFileDialogs.cs
  7. 5
      src/Avalonia.X11/X11Platform.cs
  8. 12
      src/Avalonia.X11/X11Window.cs

1
samples/ControlCatalog/Pages/DialogsPage.xaml

@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ControlCatalog.Pages.DialogsPage"> x:Class="ControlCatalog.Pages.DialogsPage">
<StackPanel Orientation="Vertical" Spacing="4" Margin="4"> <StackPanel Orientation="Vertical" Spacing="4" Margin="4">
<CheckBox Name="UseFilters">Use filters</CheckBox>
<Button Name="OpenFile">Open File</Button> <Button Name="OpenFile">Open File</Button>
<Button Name="SaveFile">Save File</Button> <Button Name="SaveFile">Save File</Button>
<Button Name="SelectFolder">Select Folder</Button> <Button Name="SelectFolder">Select Folder</Button>

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

@ -1,3 +1,4 @@
using System.Collections.Generic;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
#pragma warning disable 4014 #pragma warning disable 4014
@ -9,18 +10,39 @@ namespace ControlCatalog.Pages
public DialogsPage() public DialogsPage()
{ {
this.InitializeComponent(); this.InitializeComponent();
List<FileDialogFilter> GetFilters()
{
if (this.FindControl<CheckBox>("UseFilters").IsChecked != true)
return null;
return new List<FileDialogFilter>
{
new FileDialogFilter
{
Name = "Text files (.txt)", Extensions = new List<string> {"txt"}
},
new FileDialogFilter
{
Name = "All files",
Extensions = new List<string> {"*"}
}
};
}
this.FindControl<Button>("OpenFile").Click += delegate this.FindControl<Button>("OpenFile").Click += delegate
{ {
new OpenFileDialog() new OpenFileDialog()
{ {
Title = "Open file" Title = "Open file",
Filters = GetFilters()
}.ShowAsync(GetWindow()); }.ShowAsync(GetWindow());
}; };
this.FindControl<Button>("SaveFile").Click += delegate this.FindControl<Button>("SaveFile").Click += delegate
{ {
new SaveFileDialog() new SaveFileDialog()
{ {
Title = "Save file" Title = "Save file",
Filters = GetFilters()
}.ShowAsync(GetWindow()); }.ShowAsync(GetWindow());
}; };
this.FindControl<Button>("SelectFolder").Click += delegate this.FindControl<Button>("SelectFolder").Click += delegate

4
src/Avalonia.Controls/ControlExtensions.cs

@ -15,7 +15,7 @@ namespace Avalonia.Controls
public static class ControlExtensions public static class ControlExtensions
{ {
/// <summary> /// <summary>
/// Tries to being the control into view. /// Tries to bring the control into view.
/// </summary> /// </summary>
/// <param name="control">The control.</param> /// <param name="control">The control.</param>
public static void BringIntoView(this IControl control) public static void BringIntoView(this IControl control)
@ -26,7 +26,7 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Tries to being the control into view. /// Tries to bring the control into view.
/// </summary> /// </summary>
/// <param name="control">The control.</param> /// <param name="control">The control.</param>
/// <param name="rect">The area of the control to being into view.</param> /// <param name="rect">The area of the control to being into view.</param>

3
src/Avalonia.Native/AvaloniaNativePlatform.cs

@ -67,8 +67,7 @@ namespace Avalonia.Native
if (_factory.MacOptions != null) if (_factory.MacOptions != null)
{ {
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>(); var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
if (macOpts != null) _factory.MacOptions.ShowInDock = macOpts?.ShowInDock != false ? 1 : 0;
_factory.MacOptions.ShowInDock = macOpts.ShowInDock ? 1 : 0;
} }
AvaloniaLocator.CurrentMutable AvaloniaLocator.CurrentMutable

12
src/Avalonia.X11/NativeDialogs/Gtk.cs

@ -190,6 +190,18 @@ namespace Avalonia.X11.NativeDialogs
[DllImport(GtkName)] [DllImport(GtkName)]
public static extern void gtk_file_chooser_set_filename(IntPtr chooser, Utf8Buffer file); public static extern void gtk_file_chooser_set_filename(IntPtr chooser, Utf8Buffer file);
[DllImport(GtkName)]
public static extern IntPtr gtk_file_filter_new();
[DllImport(GtkName)]
public static extern IntPtr gtk_file_filter_set_name(IntPtr filter, Utf8Buffer name);
[DllImport(GtkName)]
public static extern IntPtr gtk_file_filter_add_pattern(IntPtr filter, Utf8Buffer pattern);
[DllImport(GtkName)]
public static extern IntPtr gtk_file_chooser_add_filter(IntPtr chooser, IntPtr filter);
[DllImport(GtkName)] [DllImport(GtkName)]
public static extern void gtk_widget_realize(IntPtr gtkWidget); public static extern void gtk_widget_realize(IntPtr gtkWidget);

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

@ -16,7 +16,7 @@ namespace Avalonia.X11.NativeDialogs
{ {
private Task<bool> _initialized; private Task<bool> _initialized;
private unsafe Task<string[]> ShowDialog(string title, IWindowImpl parent, GtkFileChooserAction action, private unsafe Task<string[]> ShowDialog(string title, IWindowImpl parent, GtkFileChooserAction action,
bool multiSelect, string initialFileName) bool multiSelect, string initialFileName, IEnumerable<FileDialogFilter> filters)
{ {
IntPtr dlg; IntPtr dlg;
using (var name = new Utf8Buffer(title)) using (var name = new Utf8Buffer(title))
@ -35,6 +35,20 @@ namespace Avalonia.X11.NativeDialogs
foreach (var d in disposables) d.Dispose(); foreach (var d in disposables) d.Dispose();
disposables.Clear(); disposables.Clear();
} }
if(filters != null)
foreach (var f in filters)
{
var filter = gtk_file_filter_new();
using (var b = new Utf8Buffer(f.Name))
gtk_file_filter_set_name(filter, b);
foreach (var e in f.Extensions)
using (var b = new Utf8Buffer("*." + e))
gtk_file_filter_add_pattern(filter, b);
gtk_file_chooser_add_filter(dlg, filter);
}
disposables = new List<IDisposable> disposables = new List<IDisposable>
{ {
@ -68,7 +82,10 @@ namespace Avalonia.X11.NativeDialogs
return false; return false;
}) })
}; };
using (var open = new Utf8Buffer("Open")) using (var open = new Utf8Buffer(
action == GtkFileChooserAction.Save ? "Save"
: action == GtkFileChooserAction.SelectFolder ? "Select"
: "Open"))
gtk_dialog_add_button(dlg, open, GtkResponseType.Accept); gtk_dialog_add_button(dlg, open, GtkResponseType.Accept);
using (var open = new Utf8Buffer("Cancel")) using (var open = new Utf8Buffer("Cancel"))
gtk_dialog_add_button(dlg, open, GtkResponseType.Cancel); gtk_dialog_add_button(dlg, open, GtkResponseType.Cancel);
@ -87,7 +104,7 @@ namespace Avalonia.X11.NativeDialogs
dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save, dialog is OpenFileDialog ? GtkFileChooserAction.Open : GtkFileChooserAction.Save,
(dialog as OpenFileDialog)?.AllowMultiple ?? false, (dialog as OpenFileDialog)?.AllowMultiple ?? false,
Path.Combine(string.IsNullOrEmpty(dialog.InitialDirectory) ? "" : dialog.InitialDirectory, Path.Combine(string.IsNullOrEmpty(dialog.InitialDirectory) ? "" : dialog.InitialDirectory,
string.IsNullOrEmpty(dialog.InitialFileName) ? "" : dialog.InitialFileName))); string.IsNullOrEmpty(dialog.InitialFileName) ? "" : dialog.InitialFileName), dialog.Filters));
} }
public async Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent) public async Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
@ -96,7 +113,7 @@ namespace Avalonia.X11.NativeDialogs
return await await RunOnGlibThread(async () => return await await RunOnGlibThread(async () =>
{ {
var res = await ShowDialog(dialog.Title, parent, var res = await ShowDialog(dialog.Title, parent,
GtkFileChooserAction.SelectFolder, false, dialog.InitialDirectory); GtkFileChooserAction.SelectFolder, false, dialog.InitialDirectory, null);
return res?.FirstOrDefault(); return res?.FirstOrDefault();
}); });
} }

5
src/Avalonia.X11/X11Platform.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
using Avalonia.Input; using Avalonia.Input;
@ -24,6 +25,7 @@ namespace Avalonia.X11
public X11Info Info { get; private set; } public X11Info Info { get; private set; }
public IX11Screens X11Screens { get; private set; } public IX11Screens X11Screens { get; private set; }
public IScreenImpl Screens { get; private set; } public IScreenImpl Screens { get; private set; }
public X11PlatformOptions Options { get; private set; }
public void Initialize(X11PlatformOptions options) public void Initialize(X11PlatformOptions options)
{ {
XInitThreads(); XInitThreads();
@ -63,6 +65,8 @@ namespace Avalonia.X11
else else
GlxGlPlatformFeature.TryInitialize(Info); GlxGlPlatformFeature.TryInitialize(Info);
} }
Options = options;
} }
public IntPtr DeferredDisplay { get; set; } public IntPtr DeferredDisplay { get; set; }
@ -91,6 +95,7 @@ namespace Avalonia
{ {
public bool UseEGL { get; set; } public bool UseEGL { get; set; }
public bool UseGpu { get; set; } = true; public bool UseGpu { get; set; } = true;
public string WmClass { get; set; } = Assembly.GetEntryAssembly()?.GetName()?.Name ?? "AvaloniaApplication";
} }
public static class AvaloniaX11PlatformExtensions public static class AvaloniaX11PlatformExtensions
{ {

12
src/Avalonia.X11/X11Window.cs

@ -128,6 +128,8 @@ namespace Avalonia.X11
XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM, XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
32, PropertyMode.Replace, new[] {_x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL}, 1); 32, PropertyMode.Replace, new[] {_x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL}, 1);
if (platform.Options.WmClass != null)
SetWmClass(platform.Options.WmClass);
var surfaces = new List<object> var surfaces = new List<object>
{ {
@ -873,6 +875,16 @@ namespace Avalonia.X11
} }
} }
public void SetWmClass(string wmClass)
{
var data = Encoding.ASCII.GetBytes(wmClass);
fixed (void* pdata = data)
{
XChangeProperty(_x11.Display, _handle, _x11.Atoms.XA_WM_CLASS, _x11.Atoms.XA_STRING, 8,
PropertyMode.Replace, pdata, data.Length);
}
}
public void SetMinMaxSize(Size minSize, Size maxSize) public void SetMinMaxSize(Size minSize, Size maxSize)
{ {
_scaledMinMaxSize = (minSize, maxSize); _scaledMinMaxSize = (minSize, maxSize);

Loading…
Cancel
Save