forked from xamarin/mac-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindowController.cs
99 lines (85 loc) · 3.17 KB
/
MainWindowController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using AppKit;
using ImageKit;
namespace ImageKitDemo
{
public partial class MainWindowController : AppKit.NSWindowController
{
#region Constructors
// Called when created from unmanaged code
public MainWindowController(IntPtr handle) : base(handle)
{
Initialize();
}
// Called when created directly from a XIB file
[Export("initWithCoder:")]
public MainWindowController(NSCoder coder) : base(coder)
{
Initialize();
}
// Call to load from the XIB/NIB file
public MainWindowController() : base("MainWindow")
{
Initialize();
}
// Shared initialization code
void Initialize()
{
}
#endregion
//strongly typed window accessor
public new MainWindow Window
{
get { return (MainWindow)base.Window; }
}
public override void AwakeFromNib()
{
browseData.AddImages(NSUrl.FromString("https://raw.githubusercontent.com/xamarin/mac-samples/master/ImageKitDemoStep1/grain.jpg"));
browseData.AddImages(NSUrl.FromFilename("/Library/Desktop Pictures/Nature/"));
browseData.AddImages(NSUrl.FromFilename("/Library/Desktop Pictures/"));
browserView.DataSource = browseData;
browserView.ReloadData();
//setup delegate for drag and drop
browserView.DraggingDestinationDelegate = new DragDelegate(browserView);
// set up event handlers just for testing
browserView.BackgroundWasRightClicked += delegate { Console.WriteLine("BackgroundWasRightClicked"); };
browserView.SelectionDidChange += delegate { Console.WriteLine("SelectionDidChange"); };
browserView.CellWasDoubleClicked += delegate { Console.WriteLine("CellWasDoubleClicked"); };
browserView.CellWasRightClicked += delegate { Console.WriteLine("CellWasRightClicked"); };
}
private BrowseData browseData = new BrowseData();
#region interface actions
partial void SliderChanged(NSSlider sender)
{
browserView.ZoomValue = sender.FloatValue;
}
partial void SearchTextChanged(NSSearchField sender)
{
browseData.SetFilter(sender.StringValue);
browserView.ReloadData();
}
partial void AddButtonClicked(NSButton sender)
{
var panel = NSOpenPanel.OpenPanel;
panel.FloatingPanel = true;
panel.CanChooseDirectories = true;
panel.CanChooseFiles = true;
panel.AllowedFileTypes = new string[] { "tiff", "jpeg", "jpg", "gif", "png" };
//FIXME - create enum for open/save panel return code
int i = (int)panel.RunModal();
if (i == 1 && panel.Urls != null)
{
foreach (NSUrl url in panel.Urls)
{
browseData.AddImages(url);
}
browserView.ReloadData();
}
}
#endregion
}
}