Added new version that uses storyboards and left the version that uses
`.xib` files since there is a known issue in Xcode 7 that renders
Collection Controllers unusable if added to Storyboards. This is per
GitHub defect #1018.
This commit is contained in:
Kevin Mullins 2015-12-16 12:40:07 -06:00
Родитель f66f41c407
Коммит 26fffc440c
115 изменённых файлов: 3963 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MacDatabinding", "MacDatabinding\MacDatabinding.csproj", "{0317DA38-93D7-4107-9C6C-EACFA2934681}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0317DA38-93D7-4107-9C6C-EACFA2934681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0317DA38-93D7-4107-9C6C-EACFA2934681}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0317DA38-93D7-4107-9C6C-EACFA2934681}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0317DA38-93D7-4107-9C6C-EACFA2934681}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,24 @@
using AppKit;
using Foundation;
namespace MacDatabinding
{
[Register ("AppDelegate")]
public class AppDelegate : NSApplicationDelegate
{
public AppDelegate ()
{
}
public override void DidFinishLaunching (NSNotification notification)
{
// Insert code here to initialize your application
}
public override void WillTerminate (NSNotification notification)
{
// Insert code here to tear down your application
}
}
}

Просмотреть файл

@ -0,0 +1,49 @@
using System;
using AppKit;
using Foundation;
using CoreGraphics;
namespace MacDatabinding
{
[Register("ReplaceViewSeque")]
public class ReplaceViewSeque : NSStoryboardSegue
{
#region Constructors
public ReplaceViewSeque() {
}
public ReplaceViewSeque (string identifier, NSObject sourceController, NSObject destinationController) : base(identifier,sourceController,destinationController) {
}
public ReplaceViewSeque (IntPtr handle) : base(handle) {
}
public ReplaceViewSeque (NSObjectFlag x) : base(x) {
}
#endregion
#region Override Methods
public override void Perform ()
{
// Cast the source and destination controllers
var source = SourceController as MainViewController;
var destination = DestinationController as NSViewController;
// Remove any existing view
if (source.Content.Subviews.Length > 0) {
source.Content.Subviews [0].RemoveFromSuperview ();
}
// Adjust sizing and add new view
destination.View.Frame = new CGRect(0 ,0 ,source.Content.Frame.Width, source.Content.Frame.Height);
destination.View.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
source.Content.AddSubview(destination.View);
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,33 @@
using System;
using AppKit;
using Foundation;
namespace MacDatabinding
{
[Register("StoryboardCollectionView")]
public class StoryboardCollectionView : NSCollectionView
{
#region Computed Properties
public override NSCollectionViewItem ItemPrototype {
get {
var storyboard = NSStoryboard.FromName ("Main", null);
var prototype = storyboard.InstantiateControllerWithIdentifier ("CollectionItem") as CollectionItemController;
return prototype;
}
set {
// Ignore for now
}
}
#endregion
#region Constructors
public StoryboardCollectionView (IntPtr handle) : base (handle)
{
// TODO: Update this once Xcode 7 is fixed to handle Collection Views inside of
// storyboards.
Console.WriteLine ("WARNING! Due to a bug in Xcode 7, Collection Views ARE NOT supported in Storyboards. \n" +
"Please continue to use .xib files if Collection Views are required.");
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,16 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class CollectionItemController : NSCollectionViewItem
{
public CollectionItemController (IntPtr handle) : base (handle)
{
}
}
}

Просмотреть файл

@ -0,0 +1,20 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("CollectionItemController")]
partial class CollectionItemController
{
void ReleaseDesignerOutlets ()
{
}
}
}

Просмотреть файл

@ -0,0 +1,168 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class CollectionViewController : NSViewController
{
#region Private Variables
private NSMutableArray _people = new NSMutableArray();
#endregion
#region Computed Properties
[Export("personModelArray")]
public NSArray People {
get { return _people; }
}
public PersonModel SelectedPerson { get; private set; }
public nint SelectionIndex {
get { return (nint)PeopleArray.SelectionIndex; }
set { PeopleArray.SelectionIndex = (ulong)value; }
}
#endregion
#region Constructors
public CollectionViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Build list of employees
AddPerson (new PersonModel ("Craig Dunn", "Documentation Manager", true));
AddPerson (new PersonModel ("Amy Burns", "Technical Writer"));
AddPerson (new PersonModel ("Joel Martinez", "Web & Infrastructure"));
AddPerson (new PersonModel ("Kevin Mullins", "Technical Writer"));
AddPerson (new PersonModel ("Mark McLemore", "Technical Writer"));
AddPerson (new PersonModel ("Tom Opgenorth", "Technical Writer"));
AddPerson (new PersonModel ("Larry O'Brien", "API Documentation Manager", true));
AddPerson (new PersonModel ("Mike Norman", "API Documentor"));
// Watch for the selection value changing
PeopleArray.AddObserver ("selectionIndexes", NSKeyValueObservingOptions.New, (sender) => {
// Inform caller of selection change
try {
SelectedPerson = _people.GetItem<PersonModel>((nuint)SelectionIndex);
} catch {
SelectedPerson = null;
}
});
}
public override void PrepareForSegue (NSStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
// Take action based on type
switch (segue.Identifier) {
case "EditorSegue":
var editor = segue.DestinationController as PersonEditorViewController;
editor.Presentor = this;
editor.Person = SelectedPerson;
break;
}
}
#endregion
#region Public Methods
public void DeletePerson(NSWindow window) {
if (SelectedPerson == null) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = "Please select the person to remove from the list of people.",
MessageText = "Delete Person",
};
alert.BeginSheet (window);
} else {
// Confirm delete
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = string.Format("Are you sure you want to delete person `{0}` from the table?",SelectedPerson.Name),
MessageText = "Delete Person",
};
alert.AddButton ("Ok");
alert.AddButton ("Cancel");
alert.BeginSheetForResponse (window, (result) => {
// Delete?
if (result == 1000) {
RemovePerson(SelectionIndex);
}
});
}
}
public void EditPerson(NSWindow window) {
if (SelectedPerson == null) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Informational,
InformativeText = "Please select the person to edit from the list of people.",
MessageText = "Edit Person",
};
alert.BeginSheet (window);
} else {
// Display editor
PerformSegue("EditorSegue", this);
}
}
public void FindPerson(string text) {
// Convert to lower case
text = text.ToLower ();
// Scan each person in the list
for (nuint n = 0; n < _people.Count; ++n) {
var person = _people.GetItem<PersonModel> (n);
if (person.Name.ToLower ().Contains (text)) {
SelectionIndex = (nint)n;
return;
}
}
// Not found, select none
SelectionIndex = 0;
}
#endregion
#region Array Controller Methods
[Export("addObject:")]
public void AddPerson(PersonModel person) {
WillChangeValue ("personModelArray");
_people.Add (person);
DidChangeValue ("personModelArray");
}
[Export("insertObject:inPersonModelArrayAtIndex:")]
public void InsertPerson(PersonModel person, nint index) {
WillChangeValue ("personModelArray");
_people.Insert (person, index);
DidChangeValue ("personModelArray");
}
[Export("removeObjectFromPersonModelArrayAtIndex:")]
public void RemovePerson(nint index) {
WillChangeValue ("personModelArray");
_people.RemoveObject (index);
DidChangeValue ("personModelArray");
}
[Export("setPersonModelArray:")]
public void SetPeople(NSMutableArray array) {
WillChangeValue ("personModelArray");
_people = array;
DidChangeValue ("personModelArray");
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,34 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("CollectionViewController")]
partial class CollectionViewController
{
[Outlet]
AppKit.NSArrayController PeopleArray { get; set; }
[Outlet]
AppKit.NSCollectionView PeopleCollection { get; set; }
void ReleaseDesignerOutlets ()
{
if (PeopleCollection != null) {
PeopleCollection.Dispose ();
PeopleCollection = null;
}
if (PeopleArray != null) {
PeopleArray.Dispose ();
PeopleArray = null;
}
}
}
}

Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>MacDatabinding</string>
<key>CFBundleIdentifier</key>
<string>com.xamarin.macdatabinding</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>NSHumanReadableCopyright</key>
<string>kmullins</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>XSAppIconAssets</key>
<string>Resources/Images.xcassets/AppIcons.appiconset</string>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{0317DA38-93D7-4107-9C6C-EACFA2934681}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MacDatabinding</RootNamespace>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<AssemblyName>MacDatabinding</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<Profiling>true</Profiling>
<UseRefCounting>true</UseRefCounting>
<UseSGen>true</UseSGen>
<IncludeMonoRuntime>false</IncludeMonoRuntime>
<CreatePackage>false</CreatePackage>
<CodeSigningKey>Mac Developer</CodeSigningKey>
<EnableCodeSigning>false</EnableCodeSigning>
<EnablePackageSigning>false</EnablePackageSigning>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<LinkMode>SdkOnly</LinkMode>
<Profiling>false</Profiling>
<UseRefCounting>true</UseRefCounting>
<UseSGen>true</UseSGen>
<IncludeMonoRuntime>true</IncludeMonoRuntime>
<CreatePackage>true</CreatePackage>
<CodeSigningKey>Developer ID Application</CodeSigningKey>
<EnableCodeSigning>true</EnableCodeSigning>
<EnablePackageSigning>false</EnablePackageSigning>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\Contents.json" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-128.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-128%402x.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-16.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-16%402x.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-256.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-256%402x.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-32.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-32%402x.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-512.png" />
<ImageAsset Include="Resources\Images.xcassets\AppIcons.appiconset\AppIcon-512%402x.png" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="Classes\ActivatableItem.cs" />
<Compile Include="Datamodel\PersonModel.cs" />
<Compile Include="Enums\SubviewType.cs" />
<Compile Include="SourceList\SourceListDataSource.cs" />
<Compile Include="SourceList\SourceListDelegate.cs" />
<Compile Include="SourceList\SourceListItem.cs" />
<Compile Include="SourceList\SourceListView.cs" />
<Compile Include="Classes\ReplaceViewSegue.cs" />
<Compile Include="MainViewController.cs" />
<Compile Include="MainViewController.designer.cs">
<DependentUpon>MainViewController.cs</DependentUpon>
</Compile>
<Compile Include="MainWindowController.cs" />
<Compile Include="MainWindowController.designer.cs">
<DependentUpon>MainWindowController.cs</DependentUpon>
</Compile>
<Compile Include="SimpleViewController.cs" />
<Compile Include="SimpleViewController.designer.cs">
<DependentUpon>SimpleViewController.cs</DependentUpon>
</Compile>
<Compile Include="TableViewController.cs" />
<Compile Include="TableViewController.designer.cs">
<DependentUpon>TableViewController.cs</DependentUpon>
</Compile>
<Compile Include="OutlineViewController.cs" />
<Compile Include="OutlineViewController.designer.cs">
<DependentUpon>OutlineViewController.cs</DependentUpon>
</Compile>
<Compile Include="CollectionViewController.cs" />
<Compile Include="CollectionViewController.designer.cs">
<DependentUpon>CollectionViewController.cs</DependentUpon>
</Compile>
<Compile Include="PersonEditorViewController.cs" />
<Compile Include="PersonEditorViewController.designer.cs">
<DependentUpon>PersonEditorViewController.cs</DependentUpon>
</Compile>
<Compile Include="Classes\StoryboardCollectionView.cs" />
<Compile Include="CollectionItemController.cs" />
<Compile Include="CollectionItemController.designer.cs">
<DependentUpon>CollectionItemController.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Main.storyboard" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
<ItemGroup>
<BundleResource Include="Resources\circle-plus.png" />
<BundleResource Include="Resources\circle-plus%402x.png" />
<BundleResource Include="Resources\circle-x.png" />
<BundleResource Include="Resources\circle-x%402x.png" />
<BundleResource Include="Resources\group.png" />
<BundleResource Include="Resources\group%402x.png" />
<BundleResource Include="Resources\info.png" />
<BundleResource Include="Resources\info%402x.png" />
<BundleResource Include="Resources\shoebox.png" />
<BundleResource Include="Resources\shoebox%402x.png" />
<BundleResource Include="Resources\user.png" />
<BundleResource Include="Resources\user%402x.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Classes\" />
<Folder Include="Datamodel\" />
<Folder Include="Enums\" />
<Folder Include="SourceList\" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,13 @@
using AppKit;
namespace MacDatabinding
{
static class MainClass
{
static void Main (string[] args)
{
NSApplication.Init ();
NSApplication.Main (args);
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,107 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class MainViewController : NSViewController
{
#region Private Variables
private SubviewType _viewType = SubviewType.None;
#endregion
#region Computed Properties
public MainWindowController WindowController { get; set;}
public NSView Content {
get { return ContentView; }
}
public NSViewController ContentController { get; set; }
public SubviewType ViewType {
get { return _viewType; }
set {
_viewType = value;
WindowController?.UpdateUI ();
}
}
#endregion
#region Constructors
public MainViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Populate Source List
SourceList.Initialize ();
var TableViews = new SourceListItem ("Data Binding Type");
TableViews.AddItem ("Simple Binding", "shoebox.png", () => {
ViewType = SubviewType.SimpleBinding;
PerformSegue("SimpleSegue", this);
});
TableViews.AddItem ("Table Binding", "shoebox.png", () => {
ViewType = SubviewType.TableBinding;
PerformSegue("TableSegue", this);
});
TableViews.AddItem ("Outline Binding", "shoebox.png", () => {
ViewType = SubviewType.OutlineBinging;
PerformSegue("OutlineSegue", this);
});
TableViews.AddItem ("Collection View", "shoebox.png", () => {
ViewType = SubviewType.CollectionView;
PerformSegue("CollectionSegue", this);
});
SourceList.AddItem (TableViews);
// Display Source List
SourceList.ReloadData();
SourceList.ExpandItem (null, true);
}
public override void PrepareForSegue (NSStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
// Take action based on type
switch (segue.Identifier) {
case "AddSegue":
var editor = segue.DestinationController as PersonEditorViewController;
editor.Presentor = this;
editor.Person = new PersonModel();
// Wire-up
editor.PersonModified += (person) => {
// Take action based on type
switch(ViewType) {
case SubviewType.TableBinding:
var controller = ContentController as TableViewController;
controller.AddPerson(person);
break;
case SubviewType.CollectionView:
// var collection = SubviewController as SubviewCollectionViewController;
// collection.EditPerson(this);
break;
}
};
break;
default:
// Save link to child controller
ContentController = segue.DestinationController as NSViewController;
break;
}
}
#endregion
}
}

34
MacDatabinding-Storyboard/MacDatabinding/MainViewController.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,34 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("MainViewController")]
partial class MainViewController
{
[Outlet]
AppKit.NSView ContentView { get; set; }
[Outlet]
AppKit.SourceListView SourceList { get; set; }
void ReleaseDesignerOutlets ()
{
if (ContentView != null) {
ContentView.Dispose ();
ContentView = null;
}
if (SourceList != null) {
SourceList.Dispose ();
SourceList = null;
}
}
}
}

Просмотреть файл

@ -0,0 +1,117 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class MainWindowController : NSWindowController
{
#region Computed Properties
public MainViewController Controller {
get { return ContentViewController as MainViewController; }
}
#endregion
#region Constructors
public MainWindowController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void AwakeFromNib ()
{
base.AwakeFromNib ();
// Wire-up controls
Addbutton.Active = false;
Addbutton.Activated += (sender, e) => {
// Take action based on type
switch(Controller.ViewType) {
case SubviewType.TableBinding:
case SubviewType.CollectionView:
Controller.PerformSegue("AddSegue", Controller);
break;
}
};
EditButton.Active = false;
EditButton.Activated += (sender, e) => {
// Take action based on type
switch(Controller.ViewType) {
case SubviewType.TableBinding:
var controller = Controller.ContentController as TableViewController;
controller.EditPerson(this.Window);
break;
case SubviewType.CollectionView:
// var collection = SubviewController as SubviewCollectionViewController;
// collection.EditPerson(this);
break;
}
};
DeleteButton.Active = false;
DeleteButton.Activated += (sender, e) => {
// Take action based on type
switch(Controller.ViewType) {
case SubviewType.TableBinding:
var controller = Controller.ContentController as TableViewController;
controller.DeletePerson(this.Window);
break;
case SubviewType.CollectionView:
// var collection = SubviewController as SubviewCollectionViewController;
// collection.DeletePerson(this);
break;
}
};
Search.Enabled = false;
Search.EditingEnded += (sender, e) => {
// Take action based on type
switch(Controller.ViewType) {
case SubviewType.TableBinding:
var controller = Controller.ContentController as TableViewController;
controller.FindPerson(Search.StringValue);
break;
case SubviewType.CollectionView:
// var collection = SubviewController as SubviewCollectionViewController;
// collection.FindPerson(Search.StringValue);
break;
}
};
// Attach window to view
Controller.WindowController = this;
}
#endregion
#region Public Methods
public void UpdateUI() {
// Take action on type
switch (Controller.ViewType) {
case SubviewType.TableBinding:
Addbutton.Active = true;
EditButton.Active = true;
DeleteButton.Active = true;
Search.Enabled = true;
break;
case SubviewType.CollectionView:
Addbutton.Active = true;
EditButton.Active = true;
DeleteButton.Active = true;
Search.Enabled = true;
break;
default:
Addbutton.Active = false;
EditButton.Active = false;
DeleteButton.Active = false;
Search.Enabled = false;
break;
}
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,50 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("MainWindowController")]
partial class MainWindowController
{
[Outlet]
AppKit.ActivatableItem Addbutton { get; set; }
[Outlet]
AppKit.ActivatableItem DeleteButton { get; set; }
[Outlet]
AppKit.ActivatableItem EditButton { get; set; }
[Outlet]
AppKit.NSSearchField Search { get; set; }
void ReleaseDesignerOutlets ()
{
if (Addbutton != null) {
Addbutton.Dispose ();
Addbutton = null;
}
if (DeleteButton != null) {
DeleteButton.Dispose ();
DeleteButton = null;
}
if (EditButton != null) {
EditButton.Dispose ();
EditButton = null;
}
if (Search != null) {
Search.Dispose ();
Search = null;
}
}
}
}

Просмотреть файл

@ -0,0 +1,95 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class OutlineViewController : NSViewController
{
#region Private Variables
private NSMutableArray _people = new NSMutableArray();
#endregion
#region Computed Properties
[Export("personModelArray")]
public NSArray People {
get { return _people; }
}
public PersonModel SelectedPerson { get; private set; }
#endregion
#region Constructors
public OutlineViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Build list of employees
var Craig = new PersonModel ("Craig Dunn", "Documentation Manager");
Craig.AddPerson (new PersonModel ("Amy Burns", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Joel Martinez", "Web & Infrastructure"));
Craig.AddPerson (new PersonModel ("Kevin Mullins", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Mark McLemore", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Tom Opgenorth", "Technical Writer"));
AddPerson (Craig);
var Larry = new PersonModel ("Larry O'Brien", "API Documentation Manager");
Larry.AddPerson (new PersonModel ("Mike Norman", "API Documentor"));
AddPerson (Larry);
}
public override void PrepareForSegue (NSStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
// Take action based on type
switch (segue.Identifier) {
case "EditorSegue":
var editor = segue.DestinationController as PersonEditorViewController;
editor.Presentor = this;
editor.Person = SelectedPerson;
break;
}
}
#endregion
#region Array Controller Methods
[Export("addObject:")]
public void AddPerson(PersonModel person) {
WillChangeValue ("personModelArray");
_people.Add (person);
DidChangeValue ("personModelArray");
}
[Export("insertObject:inPersonModelArrayAtIndex:")]
public void InsertPerson(PersonModel person, nint index) {
WillChangeValue ("personModelArray");
_people.Insert (person, index);
DidChangeValue ("personModelArray");
}
[Export("removeObjectFromPersonModelArrayAtIndex:")]
public void RemovePerson(nint index) {
WillChangeValue ("personModelArray");
_people.RemoveObject (index);
DidChangeValue ("personModelArray");
}
[Export("setPersonModelArray:")]
public void SetPeople(NSMutableArray array) {
WillChangeValue ("personModelArray");
_people = array;
DidChangeValue ("personModelArray");
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,20 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("OutlineViewController")]
partial class OutlineViewController
{
void ReleaseDesignerOutlets ()
{
}
}
}

Просмотреть файл

@ -0,0 +1,63 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class PersonEditorViewController : NSViewController
{
#region Private Variables
private PersonModel _person;
#endregion
#region Computed Properties
[Export("Person")]
public PersonModel Person {
get { return _person; }
set {
WillChangeValue ("Person");
_person = value;
DidChangeValue ("Person");
}
}
public bool isNew { get; set; } = false;
public NSViewController Presentor { get; set; }
#endregion
#region Constructor
public PersonEditorViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Private Methods
private void CloseSheet() {
Presentor.DismissViewController (this);
}
#endregion
#region Actions
partial void CancelClicked (Foundation.NSObject sender) {
CloseSheet();
}
partial void OKClicked (Foundation.NSObject sender) {
RaisePersonModified(Person);
CloseSheet();
}
#endregion
#region Events
public delegate void PersonModifiedDelegate(PersonModel person);
public event PersonModifiedDelegate PersonModified;
internal void RaisePersonModified(PersonModel person) {
if (this.PersonModified!=null) this.PersonModified(person);
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,25 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("PersonEditorViewController")]
partial class PersonEditorViewController
{
[Action ("CancelClicked:")]
partial void CancelClicked (Foundation.NSObject sender);
[Action ("OKClicked:")]
partial void OKClicked (Foundation.NSObject sender);
void ReleaseDesignerOutlets ()
{
}
}
}

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.9 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 711 B

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 58 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.3 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 58 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 174 KiB

Просмотреть файл

@ -0,0 +1,222 @@
{
"images": [
{
"size": "29x29",
"scale": "1x",
"idiom": "iphone"
},
{
"size": "29x29",
"scale": "2x",
"idiom": "iphone"
},
{
"size": "29x29",
"scale": "3x",
"idiom": "iphone"
},
{
"size": "40x40",
"scale": "2x",
"idiom": "iphone"
},
{
"size": "40x40",
"scale": "3x",
"idiom": "iphone"
},
{
"size": "57x57",
"scale": "1x",
"idiom": "iphone"
},
{
"size": "57x57",
"scale": "2x",
"idiom": "iphone"
},
{
"size": "60x60",
"scale": "2x",
"idiom": "iphone"
},
{
"size": "60x60",
"scale": "3x",
"idiom": "iphone"
},
{
"size": "29x29",
"scale": "1x",
"idiom": "ipad"
},
{
"size": "29x29",
"scale": "2x",
"idiom": "ipad"
},
{
"size": "40x40",
"scale": "1x",
"idiom": "ipad"
},
{
"size": "40x40",
"scale": "2x",
"idiom": "ipad"
},
{
"size": "50x50",
"scale": "1x",
"idiom": "ipad"
},
{
"size": "50x50",
"scale": "2x",
"idiom": "ipad"
},
{
"size": "72x72",
"scale": "1x",
"idiom": "ipad"
},
{
"size": "72x72",
"scale": "2x",
"idiom": "ipad"
},
{
"size": "76x76",
"scale": "1x",
"idiom": "ipad"
},
{
"size": "76x76",
"scale": "2x",
"idiom": "ipad"
},
{
"size": "120x120",
"scale": "1x",
"idiom": "car"
},
{
"role": "notificationCenter",
"size": "24x24",
"subtype": "38mm",
"scale": "2x",
"idiom": "watch"
},
{
"role": "notificationCenter",
"size": "27.5x27.5",
"subtype": "42mm",
"scale": "2x",
"idiom": "watch"
},
{
"role": "companionSettings",
"size": "29x29",
"scale": "2x",
"idiom": "watch"
},
{
"role": "companionSettings",
"size": "29x29",
"scale": "3x",
"idiom": "watch"
},
{
"role": "appLauncher",
"size": "40x40",
"subtype": "38mm",
"scale": "2x",
"idiom": "watch"
},
{
"role": "longLook",
"size": "44x44",
"subtype": "42mm",
"scale": "2x",
"idiom": "watch"
},
{
"role": "quickLook",
"size": "86x86",
"subtype": "38mm",
"scale": "2x",
"idiom": "watch"
},
{
"role": "quickLook",
"size": "98x98",
"subtype": "42mm",
"scale": "2x",
"idiom": "watch"
},
{
"filename": "AppIcon-16.png",
"size": "16x16",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-16@2x.png",
"size": "16x16",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-32.png",
"size": "32x32",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-32@2x.png",
"size": "32x32",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-128.png",
"size": "128x128",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-128@2x.png",
"size": "128x128",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-256.png",
"size": "256x256",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-256@2x.png",
"size": "256x256",
"scale": "2x",
"idiom": "mac"
},
{
"filename": "AppIcon-512.png",
"size": "512x512",
"scale": "1x",
"idiom": "mac"
},
{
"filename": "AppIcon-512@2x.png",
"size": "512x512",
"scale": "2x",
"idiom": "mac"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.3 KiB

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.7 KiB

После

Ширина:  |  Высота:  |  Размер: 1.7 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.4 KiB

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.9 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.3 KiB

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.9 KiB

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.4 KiB

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 2.1 KiB

После

Ширина:  |  Высота:  |  Размер: 2.1 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.2 KiB

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.6 KiB

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.1 KiB

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.4 KiB

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Просмотреть файл

@ -0,0 +1,50 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class SimpleViewController : NSViewController
{
#region Private Variables
private PersonModel _person = new PersonModel();
#endregion
#region Computed Properties
[Export("Person")]
public PersonModel Person {
get {return _person; }
set {
WillChangeValue ("Person");
_person = value;
DidChangeValue ("Person");
}
}
#endregion
#region Constructors
public SimpleViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Set a default person
var Craig = new PersonModel ("Craig Dunn", "Documentation Manager");
Craig.AddPerson (new PersonModel ("Amy Burns", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Joel Martinez", "Web & Infrastructure"));
Craig.AddPerson (new PersonModel ("Kevin Mullins", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Mark McLemore", "Technical Writer"));
Craig.AddPerson (new PersonModel ("Tom Opgenorth", "Technical Writer"));
Person = Craig;
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,20 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("SimpleViewController")]
partial class SimpleViewController
{
void ReleaseDesignerOutlets ()
{
}
}
}

Просмотреть файл

@ -0,0 +1,158 @@
// This file has been autogenerated from a class added in the UI designer.
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
public partial class TableViewController : NSViewController
{
#region Private Variables
private NSMutableArray _people = new NSMutableArray();
#endregion
#region Computed Properties
[Export("personModelArray")]
public NSArray People {
get { return _people; }
}
public PersonModel SelectedPerson { get; private set; }
#endregion
#region Constructors
public TableViewController (IntPtr handle) : base (handle)
{
}
#endregion
#region Override Methods
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Build list of employees
AddPerson (new PersonModel ("Craig Dunn", "Documentation Manager", true));
AddPerson (new PersonModel ("Amy Burns", "Technical Writer"));
AddPerson (new PersonModel ("Joel Martinez", "Web & Infrastructure"));
AddPerson (new PersonModel ("Kevin Mullins", "Technical Writer"));
AddPerson (new PersonModel ("Mark McLemore", "Technical Writer"));
AddPerson (new PersonModel ("Tom Opgenorth", "Technical Writer"));
AddPerson (new PersonModel ("Larry O'Brien", "API Documentation Manager", true));
AddPerson (new PersonModel ("Mike Norman", "API Documentor"));
}
public override void PrepareForSegue (NSStoryboardSegue segue, NSObject sender)
{
base.PrepareForSegue (segue, sender);
// Take action based on type
switch (segue.Identifier) {
case "EditorSegue":
var editor = segue.DestinationController as PersonEditorViewController;
editor.Presentor = this;
editor.Person = SelectedPerson;
break;
}
}
#endregion
#region Public Methods
public void DeletePerson(NSWindow window) {
if (Table.SelectedRow == -1) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = "Please select the person to remove from the list of people.",
MessageText = "Delete Person",
};
alert.BeginSheet (window);
} else {
// Grab person
SelectedPerson = _people.GetItem<PersonModel> ((nuint)Table.SelectedRow);
// Confirm delete
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Critical,
InformativeText = string.Format("Are you sure you want to delete person `{0}` from the table?",SelectedPerson.Name),
MessageText = "Delete Person",
};
alert.AddButton ("Ok");
alert.AddButton ("Cancel");
alert.BeginSheetForResponse (window, (result) => {
// Delete?
if (result == 1000) {
RemovePerson(Table.SelectedRow);
}
});
}
}
public void EditPerson(NSWindow window) {
if (Table.SelectedRow == -1) {
var alert = new NSAlert () {
AlertStyle = NSAlertStyle.Informational,
InformativeText = "Please select the person to edit from the list of people.",
MessageText = "Edit Person",
};
alert.BeginSheet (window);
} else {
// Grab person
SelectedPerson = _people.GetItem<PersonModel> ((nuint)Table.SelectedRow);
// Display editor
PerformSegue("EditorSegue", this);
}
}
public void FindPerson(string text) {
// Convert to lower case
text = text.ToLower ();
// Scan each person in the list
for (nuint n = 0; n < _people.Count; ++n) {
var person = _people.GetItem<PersonModel> (n);
if (person.Name.ToLower ().Contains (text)) {
Table.SelectRow ((nint)n, false);
return;
}
}
// Not found, select none
Table.DeselectAll (this);
}
#endregion
#region Array Controller Methods
[Export("addObject:")]
public void AddPerson(PersonModel person) {
WillChangeValue ("personModelArray");
_people.Add (person);
DidChangeValue ("personModelArray");
}
[Export("insertObject:inPersonModelArrayAtIndex:")]
public void InsertPerson(PersonModel person, nint index) {
WillChangeValue ("personModelArray");
_people.Insert (person, index);
DidChangeValue ("personModelArray");
}
[Export("removeObjectFromPersonModelArrayAtIndex:")]
public void RemovePerson(nint index) {
WillChangeValue ("personModelArray");
_people.RemoveObject (index);
DidChangeValue ("personModelArray");
}
[Export("setPersonModelArray:")]
public void SetPeople(NSMutableArray array) {
WillChangeValue ("personModelArray");
_people = array;
DidChangeValue ("personModelArray");
}
#endregion
}
}

26
MacDatabinding-Storyboard/MacDatabinding/TableViewController.designer.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,26 @@
// WARNING
//
// This file has been generated automatically by Xamarin Studio to store outlets and
// actions made in the UI designer. If it is removed, they will be lost.
// Manual changes to this file may not be handled correctly.
//
using Foundation;
using System.CodeDom.Compiler;
namespace MacDatabinding
{
[Register ("TableViewController")]
partial class TableViewController
{
[Outlet]
AppKit.NSTableView Table { get; set; }
void ReleaseDesignerOutlets ()
{
if (Table != null) {
Table.Dispose ();
Table = null;
}
}
}
}

Просмотреть файл

@ -5,5 +5,5 @@
<Level>Beginning</Level>
<Tags>Getting Started, User Interface</Tags>
<Gallery>true</Gallery>
<Brief>Demonstrates how to use Data Binding in a Xamarin.Mac application.</Brief>
<Brief>Demonstrates how to use Data Binding in a Xamarin.Mac application using .storyboard files.</Brief>
</SampleMetadata>

Просмотреть файл

@ -0,0 +1,8 @@
MacDatabinding Storyboard
==============
Source code for the [Data Binding and Key-Value Coding](/guides/mac/application_fundamentals/databinding/) documentation on [Xamarin Developer Center](http://docs.xamarin.com)
Uses [Xamarin.Mac](http://xamarin.com).
This project covers working with Data Binding and Key-Value Coding in a Xamarin.Mac application (using a `.storyboard` files) from simple control binding to Table View & Outlines and finally covers Collection Views (`NSCollectionView`).

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 93 KiB

После

Ширина:  |  Высота:  |  Размер: 93 KiB

Просмотреть файл

Просмотреть файл

@ -0,0 +1,36 @@
using System;
using Foundation;
using AppKit;
namespace AppKit
{
[Register("ActivatableItem")]
public class ActivatableItem : NSToolbarItem
{
public bool Active { get; set;} = true;
public ActivatableItem ()
{
}
public ActivatableItem (IntPtr handle) : base (handle)
{
}
public ActivatableItem (NSObjectFlag t) : base (t)
{
}
public ActivatableItem (string title) : base (title)
{
}
public override void Validate ()
{
base.Validate ();
Enabled = Active;
}
}
}

Просмотреть файл

@ -0,0 +1,130 @@
using System;
using Foundation;
using AppKit;
namespace MacDatabinding
{
[Register("PersonModel")]
public class PersonModel : NSObject
{
#region Private Variables
private string _name = "";
private string _occupation = "";
private bool _isManager = false;
private NSMutableArray _people = new NSMutableArray();
#endregion
#region Computed Properties
[Export("Name")]
public string Name {
get { return _name; }
set {
WillChangeValue ("Name");
_name = value;
DidChangeValue ("Name");
}
}
[Export("Occupation")]
public string Occupation {
get { return _occupation; }
set {
WillChangeValue ("Occupation");
_occupation = value;
DidChangeValue ("Occupation");
}
}
[Export("isManager")]
public bool isManager {
get { return _isManager; }
set {
WillChangeValue ("isManager");
WillChangeValue ("Icon");
_isManager = value;
DidChangeValue ("isManager");
DidChangeValue ("Icon");
}
}
[Export("isEmployee")]
public bool isEmployee {
get { return (NumberOfEmployees == 0); }
}
[Export("Icon")]
public NSImage Icon {
get {
if (isManager) {
return NSImage.ImageNamed ("group.png");
} else {
return NSImage.ImageNamed ("user.png");
}
}
}
[Export("personModelArray")]
public NSArray People {
get { return _people; }
}
[Export("NumberOfEmployees")]
public nint NumberOfEmployees {
get { return (nint)_people.Count; }
}
#endregion
#region Constructors
public PersonModel ()
{
}
public PersonModel (string name, string occupation)
{
// Initialize
this.Name = name;
this.Occupation = occupation;
}
public PersonModel (string name, string occupation, bool manager)
{
// Initialize
this.Name = name;
this.Occupation = occupation;
this.isManager = manager;
}
#endregion
#region Array Controller Methods
[Export("addObject:")]
public void AddPerson(PersonModel person) {
WillChangeValue ("personModelArray");
isManager = true;
_people.Add (person);
DidChangeValue ("personModelArray");
}
[Export("insertObject:inPersonModelArrayAtIndex:")]
public void InsertPerson(PersonModel person, nint index) {
WillChangeValue ("personModelArray");
_people.Insert (person, index);
DidChangeValue ("personModelArray");
}
[Export("removeObjectFromPersonModelArrayAtIndex:")]
public void RemovePerson(nint index) {
WillChangeValue ("personModelArray");
_people.RemoveObject (index);
DidChangeValue ("personModelArray");
}
[Export("setPersonModelArray:")]
public void SetPeople(NSMutableArray array) {
WillChangeValue ("personModelArray");
_people = array;
DidChangeValue ("personModelArray");
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,14 @@
using System;
namespace MacDatabinding
{
public enum SubviewType
{
None,
SimpleBinding,
TableBinding,
OutlineBinging,
CollectionView
}
}

Просмотреть файл

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/circle-plus.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/circle-plus@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.7 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/circle-x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/circle-x@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/group.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/group@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.9 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/info.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/info@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.1 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/shoebox.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/shoebox@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/user.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Двоичные данные
MacDatabinding-XIBs/MacDatabinding/Resources/user@2x.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Просмотреть файл

@ -0,0 +1,116 @@
using System;
using System.Collections;
using System.Collections.Generic;
using AppKit;
using Foundation;
namespace AppKit
{
public class SourceListDataSource : NSOutlineViewDataSource
{
#region Private Variables
private SourceListView _controller;
#endregion
#region Public Variables
/// <summary>
/// The collection of <see cref="Rotation.SourceListGroup"/> that are being displayed.
/// </summary>
public List<SourceListItem> Items = new List<SourceListItem>();
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineDataSource"/> class.
/// </summary>
/// <param name="controller">Controller.</param>
public SourceListDataSource (SourceListView controller)
{
// Initialize
this._controller = controller;
}
#endregion
#region Override Properties
/// <summary>
/// Gets the children count.
/// </summary>
/// <returns>The children count.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="item">Item.</param>
public override nint GetChildrenCount (NSOutlineView outlineView, Foundation.NSObject item)
{
if (item == null) {
return Items.Count;
} else {
return ((SourceListItem)item).Count;
}
}
/// <summary>
/// Items the expandable.
/// </summary>
/// <returns><c>true</c>, if expandable was itemed, <c>false</c> otherwise.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="item">Item.</param>
public override bool ItemExpandable (NSOutlineView outlineView, Foundation.NSObject item)
{
return ((SourceListItem)item).HasChildren;
}
/// <summary>
/// Gets the child.
/// </summary>
/// <returns>The child.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="childIndex">Child index.</param>
/// <param name="item">Item.</param>
public override NSObject GetChild (NSOutlineView outlineView, nint childIndex, Foundation.NSObject item)
{
if (item == null) {
return Items [(int)childIndex];
} else {
return ((SourceListItem)item) [(int)childIndex];
}
}
/// <summary>
/// Gets the object value.
/// </summary>
/// <returns>The object value.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="tableColumn">Table column.</param>
/// <param name="item">Item.</param>
public override NSObject GetObjectValue (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
{
return new NSString (((SourceListItem)item).Title);
}
#endregion
#region Internal Methods
/// <summary>
/// Items for row.
/// </summary>
/// <returns>The for row.</returns>
/// <param name="row">Row.</param>
internal SourceListItem ItemForRow(int row) {
int index = 0;
// Look at each group
foreach (SourceListItem item in Items) {
// Is the row inside this group?
if (row >= index && row <= (index + item.Count)) {
return item [row - index - 1];
}
// Move index
index += item.Count + 1;
}
// Not found
return null;
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,127 @@
using System;
using AppKit;
using Foundation;
namespace AppKit
{
public class SourceListDelegate : NSOutlineViewDelegate
{
#region Private variables
private SourceListView _controller;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineViewDelegate"/> class.
/// </summary>
/// <param name="controller">Controller.</param>
public SourceListDelegate (SourceListView controller)
{
// Initialize
this._controller = controller;
}
#endregion
#region Override Methods
/// <summary>
/// Shoulds the edit table column.
/// </summary>
/// <returns><c>true</c>, if edit table column was shoulded, <c>false</c> otherwise.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="tableColumn">Table column.</param>
/// <param name="item">Item.</param>
public override bool ShouldEditTableColumn (NSOutlineView outlineView, NSTableColumn tableColumn, Foundation.NSObject item)
{
return false;
}
/// <summary>
/// Gets the cell.
/// </summary>
/// <returns>The cell.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="tableColumn">Table column.</param>
/// <param name="item">Item.</param>
public override NSCell GetCell (NSOutlineView outlineView, NSTableColumn tableColumn, Foundation.NSObject item)
{
nint row = outlineView.RowForItem (item);
return tableColumn.DataCellForRow (row);
}
/// <summary>
/// Determines whether this instance is group item the specified outlineView item.
/// </summary>
/// <returns><c>true</c> if this instance is group item the specified outlineView item; otherwise, <c>false</c>.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="item">Item.</param>
public override bool IsGroupItem (NSOutlineView outlineView, Foundation.NSObject item)
{
return ((SourceListItem)item).HasChildren;
}
/// <summary>
/// Views for table column.
/// </summary>
/// <returns>The for table column.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="tableColumn">Table column.</param>
/// <param name="item">Item.</param>
public override NSView GetView (NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
{
NSTableCellView view = null;
// Is this a group item?
if (((SourceListItem)item).HasChildren) {
view = (NSTableCellView)outlineView.MakeView ("HeaderCell", this);
} else {
view = (NSTableCellView)outlineView.MakeView ("DataCell", this);
view.ImageView.Image = ((SourceListItem)item).Icon;
}
// Initialize view
view.TextField.StringValue = ((SourceListItem)item).Title;
// Return new view
return view;
}
/// <summary>
/// Shoulds the select item.
/// </summary>
/// <returns><c>true</c>, if select item was shoulded, <c>false</c> otherwise.</returns>
/// <param name="outlineView">Outline view.</param>
/// <param name="item">Item.</param>
public override bool ShouldSelectItem (NSOutlineView outlineView, Foundation.NSObject item)
{
return (outlineView.GetParent (item) != null);
}
/// <summary>
/// Selections the did change.
/// </summary>
/// <param name="notification">Notification.</param>
public override void SelectionDidChange (NSNotification notification)
{
NSIndexSet selectedIndexes = _controller.SelectedRows;
// More than one item selected?
if (selectedIndexes.Count > 1) {
// Not handling this case
} else {
// Grab the item
var item = _controller.Data.ItemForRow ((int)selectedIndexes.FirstIndex);
// Was an item found?
if (item != null) {
// Fire the clicked event for the item
item.RaiseClickedEvent ();
// Inform caller of selection
_controller.RaiseItemSelected (item);
}
}
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,366 @@
using System;
using System.Collections;
using System.Collections.Generic;
using AppKit;
using Foundation;
namespace AppKit
{
public class SourceListItem: NSObject, IEnumerator, IEnumerable
{
#region Private Properties
private string _title;
private NSImage _icon;
private string _tag;
private List<SourceListItem> _items = new List<SourceListItem> ();
#endregion
#region Computed Properties
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public string Title {
get { return _title; }
set { _title = value; }
}
/// <summary>
/// Gets or sets the icon.
/// </summary>
/// <value>The icon.</value>
public NSImage Icon {
get { return _icon; }
set { _icon = value; }
}
/// <summary>
/// Gets or sets the tag.
/// </summary>
/// <value>The tag.</value>
public string Tag {
get { return _tag; }
set { _tag=value; }
}
#endregion
#region Indexer
/// <summary>
/// Gets or sets the <see cref="Rotation.SourceListGroup"/> at the specified index.
/// </summary>
/// <param name="index">Index.</param>
public SourceListItem this[int index]
{
get
{
return _items[index];
}
set
{
_items[index] = value;
}
}
/// <summary>
/// Gets the count.
/// </summary>
/// <value>The count.</value>
public int Count {
get { return _items.Count; }
}
/// <summary>
/// Gets a value indicating whether this instance has children.
/// </summary>
/// <value><c>true</c> if this instance has children; otherwise, <c>false</c>.</value>
public bool HasChildren {
get { return (Count > 0); }
}
#endregion
#region Enumerable Routines
private int _position = -1;
/// <summary>
/// Gets the enumerator.
/// </summary>
/// <returns>The enumerator.</returns>
public IEnumerator GetEnumerator()
{
_position = -1;
return (IEnumerator)this;
}
/// <summary>
/// Moves the next.
/// </summary>
/// <returns><c>true</c>, if next was moved, <c>false</c> otherwise.</returns>
public bool MoveNext()
{
_position++;
return (_position < _items.Count);
}
/// <Docs>The collection was modified after the enumerator was instantiated.</Docs>
/// <attribution license="cc4" from="Microsoft" modified="false"></attribution>
/// <see cref="M:System.Collections.IEnumerator.MoveNext"></see>
/// <see cref="M:System.Collections.IEnumerator.Reset"></see>
/// <see cref="T:System.InvalidOperationException"></see>
/// <summary>
/// Reset this instance.
/// </summary>
public void Reset()
{_position = -1;}
/// <summary>
/// Gets the current.
/// </summary>
/// <value>The current.</value>
public object Current
{
get
{
try
{
return _items[_position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
public SourceListItem ()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
public SourceListItem (string title)
{
// Initialize
this._title = title;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
public SourceListItem (string title, string icon)
{
// Initialize
this._title = title;
this._icon = NSImage.ImageNamed (icon);
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="clicked">Clicked.</param>
public SourceListItem (string title, string icon, ClickedDelegate clicked)
{
// Initialize
this._title = title;
this._icon = NSImage.ImageNamed (icon);
this.Clicked = clicked;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
public SourceListItem (string title, NSImage icon)
{
// Initialize
this._title = title;
this._icon = icon;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="clicked">Clicked.</param>
public SourceListItem (string title, NSImage icon, ClickedDelegate clicked)
{
// Initialize
this._title = title;
this._icon = icon;
this.Clicked = clicked;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
public SourceListItem (string title, NSImage icon, string tag)
{
// Initialize
this._title = title;
this._icon = icon;
this._tag = tag;
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="tag">Tag.</param>
/// <param name="clicked">Clicked.</param>
public SourceListItem (string title, NSImage icon, string tag, ClickedDelegate clicked)
{
// Initialize
this._title = title;
this._icon = icon;
this._tag = tag;
this.Clicked = clicked;
}
#endregion
#region Public Methods
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="item">Item.</param>
public void AddItem(SourceListItem item) {
_items.Add (item);
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
public void AddItem(string title) {
_items.Add (new SourceListItem (title));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
public void AddItem(string title, string icon) {
_items.Add (new SourceListItem (title, icon));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="clicked">Clicked.</param>
public void AddItem(string title, string icon, ClickedDelegate clicked) {
_items.Add (new SourceListItem (title, icon, clicked));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
public void AddItem(string title, NSImage icon) {
_items.Add (new SourceListItem (title, icon));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="clicked">Clicked.</param>
public void AddItem(string title, NSImage icon, ClickedDelegate clicked) {
_items.Add (new SourceListItem (title, icon, clicked));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="tag">Tag.</param>
public void AddItem(string title, NSImage icon, string tag) {
_items.Add (new SourceListItem (title, icon, tag));
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="title">Title.</param>
/// <param name="icon">Icon.</param>
/// <param name="tag">Tag.</param>
/// <param name="clicked">Clicked.</param>
public void AddItem(string title, NSImage icon, string tag, ClickedDelegate clicked) {
_items.Add (new SourceListItem (title, icon, tag, clicked));
}
/// <summary>
/// Insert the specified n and item.
/// </summary>
/// <param name="n">N.</param>
/// <param name="item">Item.</param>
public void Insert(int n, SourceListItem item) {
_items.Insert (n, item);
}
/// <summary>
/// Removes the item.
/// </summary>
/// <param name="item">Item.</param>
public void RemoveItem(SourceListItem item) {
_items.Remove (item);
}
/// <summary>
/// Removes the item.
/// </summary>
/// <param name="n">N.</param>
public void RemoveItem(int n) {
_items.RemoveAt (n);
}
/// <summary>
/// Clear this instance.
/// </summary>
public void Clear() {
_items.Clear ();
}
#endregion
#region Events
/// <summary>
/// Clicked delegate.
/// </summary>
public delegate void ClickedDelegate();
/// <summary>
/// Occurs when clicked.
/// </summary>
public event ClickedDelegate Clicked;
/// <summary>
/// Raises the clicked event.
/// </summary>
internal void RaiseClickedEvent() {
// Inform caller
if (this.Clicked != null)
this.Clicked ();
}
#endregion
}
}

Просмотреть файл

@ -0,0 +1,112 @@
using System;
using AppKit;
using Foundation;
namespace AppKit
{
[Register("SourceListView")]
public class SourceListView : NSOutlineView
{
#region Computed Properties
/// <summary>
/// Gets the data.
/// </summary>
/// <value>The data.</value>
public SourceListDataSource Data {
get {return (SourceListDataSource)this.DataSource; }
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineViewController"/> class.
/// </summary>
public SourceListView ()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineViewController"/> class.
/// </summary>
/// <param name="handle">Handle.</param>
public SourceListView (IntPtr handle) : base(handle)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineViewController"/> class.
/// </summary>
/// <param name="coder">Coder.</param>
public SourceListView (NSCoder coder) : base(coder)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Rotation.OutlineViewController"/> class.
/// </summary>
/// <param name="t">T.</param>
public SourceListView (NSObjectFlag t) : base(t)
{
}
#endregion
#region Override Methods
public override void AwakeFromNib ()
{
base.AwakeFromNib ();
}
#endregion
#region Public Methods
/// <summary>
/// Initialize this instance.
/// </summary>
public void Initialize() {
// Initialize this instance
this.DataSource = new SourceListDataSource (this);
this.Delegate = new SourceListDelegate (this);
}
/// <summary>
/// Adds the item.
/// </summary>
/// <param name="item">Item.</param>
public void AddItem(SourceListItem item) {
if (Data != null) {
Data.Items.Add (item);
}
}
#endregion
#region Events
/// <summary>
/// Item selected delegate.
/// </summary>
public delegate void ItemSelectedDelegate(SourceListItem item);
/// <summary>
/// Occurs when item selected.
/// </summary>
public event ItemSelectedDelegate ItemSelected;
/// <summary>
/// Raises the item selected.
/// </summary>
/// <param name="item">Item.</param>
internal void RaiseItemSelected(SourceListItem item) {
// Inform caller
if (this.ItemSelected != null) {
this.ItemSelected (item);
}
}
#endregion
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше