Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez Gual <lluis@xamarin.com>2016-05-31 13:45:56 +0300
committerLluis Sanchez Gual <lluis@xamarin.com>2016-05-31 13:45:56 +0300
commit9923445b3361f306441c17e69c0ba34f5ea047b0 (patch)
tree0c26c8379c01ff47902e478177bef49283880721
parentc8b36a92ac67f9ebc32df25ae497733eb969401d (diff)
Implemented folder selectorgtkmac-native-dialog
-rw-r--r--TestApps/Samples/MainWindow.cs1
-rw-r--r--TestApps/Samples/Samples.csproj1
-rw-r--r--TestApps/Samples/Samples/FolderSelectorSample.cs44
-rw-r--r--Xwt.Gtk.Mac/GtkMacSelectFolderBackend.cs109
-rw-r--r--Xwt.Gtk.Mac/MacPlatformBackend.cs1
-rw-r--r--Xwt.Gtk.Mac/Xwt.Gtk.Mac.csproj1
-rw-r--r--Xwt/Xwt.Backends/IFolderSelectorBackend.cs66
-rw-r--r--Xwt/Xwt.csproj2
-rw-r--r--Xwt/Xwt/FolderSelector.cs242
9 files changed, 467 insertions, 0 deletions
diff --git a/TestApps/Samples/MainWindow.cs b/TestApps/Samples/MainWindow.cs
index 560762b5..5c3b495e 100644
--- a/TestApps/Samples/MainWindow.cs
+++ b/TestApps/Samples/MainWindow.cs
@@ -74,6 +74,7 @@ namespace Samples
AddSample (w, "Clipboard", typeof(ClipboardSample));
AddSample (w, "ColorSelector", typeof(ColorSelectorSample));
AddSample (w, "FileSelector", typeof (FileSelectorSample));
+ AddSample (w, "FolderSelector", typeof (FolderSelectorSample));
AddSample (w, "FontSelector", typeof(FontSelectorSample));
AddSample (w, "ComboBox", typeof(ComboBoxes));
AddSample (w, "DatePicker", typeof(DatePickerSample));
diff --git a/TestApps/Samples/Samples.csproj b/TestApps/Samples/Samples.csproj
index ce4d8e89..071da1ae 100644
--- a/TestApps/Samples/Samples.csproj
+++ b/TestApps/Samples/Samples.csproj
@@ -115,6 +115,7 @@
<Compile Include="Samples\FontSelectorSample.cs" />
<Compile Include="Samples\ListViewEntries.cs" />
<Compile Include="Samples\FileSelectorSample.cs" />
+ <Compile Include="Samples\FolderSelectorSample.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
diff --git a/TestApps/Samples/Samples/FolderSelectorSample.cs b/TestApps/Samples/Samples/FolderSelectorSample.cs
new file mode 100644
index 00000000..60fd3d25
--- /dev/null
+++ b/TestApps/Samples/Samples/FolderSelectorSample.cs
@@ -0,0 +1,44 @@
+//
+// FolderSelectorSample.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Xwt;
+
+namespace Samples
+{
+ public class FolderSelectorSample: VBox
+ {
+ public FolderSelectorSample ()
+ {
+ FolderSelector fsel;
+ Label label;
+ PackStart (new Label ("An open file selector:"));
+ PackStart (fsel = new FolderSelector ());
+ PackStart (label = new Label ());
+ fsel.FolderChanged += (sender, e) => { label.Text = "Folder changed: " + fsel.Folder; };
+ }
+ }
+}
+
diff --git a/Xwt.Gtk.Mac/GtkMacSelectFolderBackend.cs b/Xwt.Gtk.Mac/GtkMacSelectFolderBackend.cs
new file mode 100644
index 00000000..2eec7b0e
--- /dev/null
+++ b/Xwt.Gtk.Mac/GtkMacSelectFolderBackend.cs
@@ -0,0 +1,109 @@
+//
+// GtkMacSelectFolderBackend.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Xwt.Backends;
+using AppKit;
+using Foundation;
+using System.Linq;
+
+namespace Xwt.Gtk.Mac
+{
+ public class GtkMacSelectFolderBackend: NSOpenPanel, ISelectFolderDialogBackend
+ {
+ #region ISelectFolderDialogBackend implementation
+ public void Initialize (bool multiselect)
+ {
+ this.AllowsMultipleSelection = multiselect;
+ this.CanChooseFiles = false;
+ this.CanChooseDirectories = true;
+
+ this.Prompt = "Select Folder" + (multiselect ? "s" : "");
+ }
+
+ public bool Run (IWindowFrameBackend parent)
+ {
+ var returnValue = this.RunModal ();
+ return returnValue == 1;
+ }
+
+ public void Cleanup ()
+ {
+
+ }
+
+ public string Folder {
+ get {
+ return this.Url == null ? string.Empty : Url.Path;
+ }
+ }
+
+ public string [] Folders {
+ get {
+ return this.Urls.Length == 0 ? new string [0] : this.Urls.Select (x => x.Path).ToArray ();
+ }
+ }
+
+ public string CurrentFolder {
+ get {
+ return DirectoryUrl.AbsoluteString;
+ }
+ set {
+ this.DirectoryUrl = new NSUrl (value, true);
+ }
+ }
+
+ public bool CanCreateFolders {
+ get {
+ return false;
+ }
+ set {
+
+ }
+ }
+
+ #endregion
+
+ #region IBackend implementation
+
+ public void InitializeBackend (object frontend, ApplicationContext context)
+ {
+
+ }
+
+ public void EnableEvent (object eventId)
+ {
+
+ }
+
+ public void DisableEvent (object eventId)
+ {
+
+ }
+
+ #endregion
+ }
+}
+
diff --git a/Xwt.Gtk.Mac/MacPlatformBackend.cs b/Xwt.Gtk.Mac/MacPlatformBackend.cs
index b2606e38..ea5bbdf9 100644
--- a/Xwt.Gtk.Mac/MacPlatformBackend.cs
+++ b/Xwt.Gtk.Mac/MacPlatformBackend.cs
@@ -46,6 +46,7 @@ namespace Xwt.Gtk.Mac
toolit.RegisterBackend <IPopoverBackend,GtkMacPopoverBackend> ();
toolit.RegisterBackend <IOpenFileDialogBackend, GtkMacOpenFileDialogBackend> ();
toolit.RegisterBackend <ISaveFileDialogBackend, GtkMacSaveFileDialogBackend> ();
+ toolit.RegisterBackend <ISelectFolderDialogBackend, GtkMacSelectFolderBackend> ();
}
}
}
diff --git a/Xwt.Gtk.Mac/Xwt.Gtk.Mac.csproj b/Xwt.Gtk.Mac/Xwt.Gtk.Mac.csproj
index df711951..31e6bfce 100644
--- a/Xwt.Gtk.Mac/Xwt.Gtk.Mac.csproj
+++ b/Xwt.Gtk.Mac/Xwt.Gtk.Mac.csproj
@@ -49,6 +49,7 @@
<Compile Include="GtkMacPopoverBackend.cs" />
<Compile Include="GtkMacOpenFileDialogBackend.cs" />
<Compile Include="GtkMacSaveFileDialogBackend.cs" />
+ <Compile Include="GtkMacSelectFolderBackend.cs" />
</ItemGroup>
<Import Project="..\BuildHelpers.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
diff --git a/Xwt/Xwt.Backends/IFolderSelectorBackend.cs b/Xwt/Xwt.Backends/IFolderSelectorBackend.cs
new file mode 100644
index 00000000..430aff39
--- /dev/null
+++ b/Xwt/Xwt.Backends/IFolderSelectorBackend.cs
@@ -0,0 +1,66 @@
+//
+// IFolderSelectorBackend.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+namespace Xwt.Backends
+{
+ public interface IFolderSelectorBackend: IWidgetBackend
+ {
+ /// <summary>
+ /// Gets or sets the current folder.
+ /// </summary>
+ /// <value>The current folder.</value>
+ string CurrentFolder { get; set; }
+
+ /// <summary>
+ /// Gets or sets the path to the folder
+ /// </summary>
+ /// <value>The name of the folder.</value>
+ string Folder { get; set; }
+
+ /// <summary>
+ /// Gets or sets the title of the folder selection dialog
+ /// </summary>
+ /// <value>The title.</value>
+ string Title { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the user can create folders when using the folder selection dialog
+ /// </summary>
+ bool CanCreateFolders { get; set; }
+
+ }
+
+ public interface IFolderSelectorEventSink : IWidgetEventSink
+ {
+ void OnFolderChanged ();
+ }
+
+ public enum FolderSelectorEvent
+ {
+ FolderChanged
+ }
+}
+
diff --git a/Xwt/Xwt.csproj b/Xwt/Xwt.csproj
index 2cf4e04b..59f900c5 100644
--- a/Xwt/Xwt.csproj
+++ b/Xwt/Xwt.csproj
@@ -339,6 +339,8 @@
<Compile Include="Xwt.Drawing\StyleSet.cs" />
<Compile Include="Xwt\FileSelector.cs" />
<Compile Include="Xwt.Backends\IFileSelectorBackend.cs" />
+ <Compile Include="Xwt\FolderSelector.cs" />
+ <Compile Include="Xwt.Backends\IFolderSelectorBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />
diff --git a/Xwt/Xwt/FolderSelector.cs b/Xwt/Xwt/FolderSelector.cs
new file mode 100644
index 00000000..f544de2b
--- /dev/null
+++ b/Xwt/Xwt/FolderSelector.cs
@@ -0,0 +1,242 @@
+//
+// FolderSelector.cs
+//
+// Author:
+// Lluis Sanchez Gual <lluis@xamarin.com>
+//
+// Copyright (c) 2016 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using Xwt.Backends;
+
+namespace Xwt
+{
+ [BackendType (typeof (IFolderSelectorBackend))]
+ public class FolderSelector: Widget
+ {
+ protected new class WidgetBackendHost : Widget.WidgetBackendHost, IFolderSelectorEventSink
+ {
+ protected override IBackend OnCreateBackend ()
+ {
+ var b = base.OnCreateBackend ();
+ if (b == null)
+ b = new DefaultFolderSelectorBackend ();
+ return b;
+ }
+
+ public void OnFolderChanged ()
+ {
+ ((FolderSelector)Parent).OnFolderChanged (EventArgs.Empty);
+ }
+ }
+
+ static FolderSelector ()
+ {
+ MapEvent (FolderSelectorEvent.FolderChanged, typeof (FolderSelector), "OnFolderChanged");
+ }
+
+ public FolderSelector ()
+ {
+ }
+
+
+ protected override BackendHost CreateBackendHost ()
+ {
+ return new WidgetBackendHost ();
+ }
+
+ IFolderSelectorBackend Backend {
+ get { return (IFolderSelectorBackend)BackendHost.Backend; }
+ }
+
+ public string Title {
+ get { return Backend.Title; }
+ set { Backend.Title = value; }
+ }
+
+ /// <summary>
+ /// Gets the name of the folder that the user has selected
+ /// </summary>
+ /// <value>
+ /// The name of the folder, or null if no selection was made
+ /// </value>
+ public string Folder {
+ get { return Backend.Folder; }
+ set { Backend.Folder = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets the folder to show when opening the folder selector dialog
+ /// </summary>
+ /// <value>
+ /// The current folder.
+ /// </value>
+ public string CurrentFolder {
+ get { return Backend.CurrentFolder; }
+ set { Backend.CurrentFolder = value; }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the user can create folders when using the folder selection dialog
+ /// </summary>
+ /// <value><c>true</c> if this instance can create folders; otherwise, <c>false</c>.</value>
+ public bool CanCreateFolders {
+ get { return Backend.CanCreateFolders; }
+ set { Backend.CanCreateFolders = value; }
+ }
+
+ protected virtual void OnFolderChanged (EventArgs args)
+ {
+ if (folderChanged != null)
+ folderChanged (this, args);
+ }
+
+ EventHandler folderChanged;
+
+ /// <summary>
+ /// Occurs when the font changed.
+ /// </summary>
+ public event EventHandler FolderChanged {
+ add {
+ BackendHost.OnBeforeEventAdd (FolderSelectorEvent.FolderChanged, folderChanged);
+ folderChanged += value;
+ }
+ remove {
+ folderChanged -= value;
+ BackendHost.OnAfterEventRemove (FolderSelectorEvent.FolderChanged, folderChanged);
+ }
+ }
+ }
+
+
+ class DefaultFolderSelectorBackend : XwtWidgetBackend, IFolderSelectorBackend
+ {
+ TextEntry entry;
+ SelectFolderDialog dialog;
+ string currentFolder;
+ string folderName;
+ bool enableFolderChangedEvent;
+ string title;
+ bool canCreateFolders;
+
+ public DefaultFolderSelectorBackend ()
+ {
+ var box = new HBox ();
+ entry = new TextEntry ();
+ entry.ReadOnly = true;
+ box.PackStart (entry, true);
+
+ var btn = new Button ("...");
+ box.PackStart (btn);
+ btn.Clicked += BtnClicked;
+ Content = box;
+ }
+
+ public string CurrentFolder {
+ get {
+ return dialog != null ? dialog.CurrentFolder : currentFolder;
+ }
+ set {
+ if (dialog != null)
+ dialog.CurrentFolder = value;
+ else
+ currentFolder = value;
+ }
+ }
+
+ public string Folder {
+ get { return dialog != null ? dialog.Folder : folderName; }
+
+ set {
+ folderName = value;
+ entry.Text = value;
+ if (enableFolderChangedEvent)
+ EventSink.OnFolderChanged ();
+ }
+ }
+
+ protected new IFolderSelectorEventSink EventSink {
+ get { return (IFolderSelectorEventSink)base.EventSink; }
+ }
+
+ public string Title {
+ get {
+ return title;
+ }
+
+ set {
+ title = value;
+ if (dialog != null)
+ dialog.Title = value;
+ }
+ }
+
+ public bool CanCreateFolders {
+ get {
+ return canCreateFolders;
+ }
+
+ set {
+ canCreateFolders = value;
+ if (dialog != null)
+ dialog.CanCreateFolders = value;
+ }
+ }
+
+ public override void EnableEvent (object eventId)
+ {
+ base.EnableEvent (eventId);
+ if (eventId is FolderSelectorEvent) {
+ switch ((FolderSelectorEvent)eventId) {
+ case FolderSelectorEvent.FolderChanged: enableFolderChangedEvent = true; break;
+ }
+ }
+ }
+
+ public override void DisableEvent (object eventId)
+ {
+ base.DisableEvent (eventId);
+ if (eventId is FolderSelectorEvent) {
+ switch ((FolderSelectorEvent)eventId) {
+ case FolderSelectorEvent.FolderChanged: enableFolderChangedEvent = false; break;
+ }
+ }
+ }
+
+ void BtnClicked (object sender, EventArgs e)
+ {
+ dialog = new SelectFolderDialog ();
+
+ try {
+ if (!string.IsNullOrEmpty (currentFolder))
+ dialog.CurrentFolder = currentFolder;
+ if (!string.IsNullOrEmpty (title))
+ dialog.Title = title;
+ if (dialog.Run (ParentWindow))
+ Folder = dialog.Folder;
+ } finally {
+ currentFolder = dialog.CurrentFolder;
+ dialog.Dispose ();
+ dialog = null;
+ }
+ }
+ }
+}
+