blob: 86ba6d33832d84923b9a88d782feac2e698f9b51 (
plain)
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
99
100
101
102
103
104
105
106
107
|
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace macdoc
{
public partial class BookmarkAssistantController : MonoMac.AppKit.NSViewController
{
IList<BookmarkManager.Entry> entries;
BookmarkDataSource source;
public BookmarkAssistantController (IntPtr handle) : base (handle)
{
}
[Export ("initWithCoder:")]
public BookmarkAssistantController (NSCoder coder) : base (coder)
{
}
public BookmarkAssistantController (IList<BookmarkManager.Entry> entries) : base ("BookmarkAssistant", NSBundle.MainBundle)
{
this.entries = entries;
this.source = new BookmarkDataSource (entries, AppDelegate.BookmarkManager);
View.TableView.DataSource = source;
View.BookmarkDeleted += HandleBookmarkDeleted;
}
void HandleBookmarkDeleted (int row)
{
var entry = entries[row];
AppDelegate.BookmarkManager.DeleteBookmark (entry);
Logger.Log ("Removed entry {0}", entry.Name);
View.TableView.ReloadData ();
}
public new BookmarkAssistant View {
get {
return (BookmarkAssistant)base.View;
}
}
public class BookmarkDataSource : NSTableViewDataSource
{
IList<BookmarkManager.Entry> entries;
BookmarkManager manager;
public BookmarkDataSource (IList<BookmarkManager.Entry> entries, BookmarkManager manager)
{
this.entries = entries;
this.manager = manager;
}
public override NSObject GetObjectValue (NSTableView tableView, NSTableColumn tableColumn, int row)
{
if (tableColumn == null)
return null;
int columnIndex = tableView.FindColumn ((NSString)tableColumn.Identifier);
switch (columnIndex) {
case 0:
return new NSString (entries[row].Name);
case 1:
return new NSString (entries[row].Notes);
case 2:
return new NSString (entries[row].Url);
default:
return null;
}
}
public override void SetObjectValue (NSTableView tableView, NSObject theObject, NSTableColumn tableColumn, int row)
{
NSString newNSValue = theObject as NSString;
if (newNSValue == null)
return;
string newValue = newNSValue.ToString ();
int columnIndex = tableView.FindColumn ((NSString)tableColumn.Identifier);
BookmarkManager.Entry entry = entries[row];
switch (columnIndex) {
case 0:
if (!string.IsNullOrWhiteSpace (newValue))
entry.Name = newValue;
break;
case 1:
entry.Notes = newValue;
break;
case 2:
if (!string.IsNullOrWhiteSpace (newValue))
entry.Url = newValue;
break;
default:
break;
}
manager.CommitBookmarkChange (entry);
}
public override int GetRowCount (NSTableView tableView)
{
return entries.Count;
}
}
}
}
|