mac setup: prettify tableview rows with markup

This commit is contained in:
Hylke Bons 2012-03-23 03:04:29 +00:00
parent 50dbcac22a
commit bde2931853

View file

@ -329,8 +329,8 @@ namespace SparkleShare {
TableView = new NSTableView () { TableView = new NSTableView () {
Frame = new RectangleF (0, 0, 0, 0), Frame = new RectangleF (0, 0, 0, 0),
RowHeight = 30, RowHeight = 34,
IntercellSpacing = new SizeF (0, 12), IntercellSpacing = new SizeF (8, 12),
HeaderView = null, HeaderView = null,
Delegate = new SparkleTableViewDelegate () Delegate = new SparkleTableViewDelegate ()
}; };
@ -343,9 +343,11 @@ namespace SparkleShare {
}; };
IconColumn = new NSTableColumn (new NSImage ()) { IconColumn = new NSTableColumn (new NSImage ()) {
Width = 42, Width = 36,
HeaderToolTip = "Icon", HeaderToolTip = "Icon",
DataCell = new NSImageCell () DataCell = new NSImageCell () {
ImageAlignment = NSImageAlignment.Right
}
}; };
DescriptionColumn = new NSTableColumn () { DescriptionColumn = new NSTableColumn () {
@ -361,10 +363,7 @@ namespace SparkleShare {
TableView.AddColumn (IconColumn); TableView.AddColumn (IconColumn);
TableView.AddColumn (DescriptionColumn); TableView.AddColumn (DescriptionColumn);
DataSource = new SparkleDataSource (); DataSource = new SparkleDataSource (Controller.Plugins);
foreach (SparklePlugin plugin in Controller.Plugins)
DataSource.Items.Add (plugin);
TableView.DataSource = DataSource; TableView.DataSource = DataSource;
TableView.ReloadData (); TableView.ReloadData ();
@ -802,11 +801,34 @@ namespace SparkleShare {
public class SparkleDataSource : NSTableViewDataSource { public class SparkleDataSource : NSTableViewDataSource {
public List<object> Items ; public List<object> Items ;
public NSAttributedString [] Cells;
public SparkleDataSource () public SparkleDataSource (List<SparklePlugin> plugins)
{ {
Items = new List<object> (); Items = new List <object> ();
Cells = new NSAttributedString [plugins.Count];
int i = 0;
foreach (SparklePlugin plugin in plugins) {
Items.Add (plugin);
NSTextFieldCell cell = new NSTextFieldCell ();
NSData data = NSData.FromString (
"<font face='Lucida Grande'><b>" + plugin.Name + "</b></font>");
NSDictionary dictionary = new NSDictionary();
NSAttributedString attributes = new NSAttributedString (
data, new NSUrl ("file://"), out dictionary);
NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (attributes);
mutable_attributes.Append (new NSAttributedString ("\n" + plugin.Description));
cell.SetAttributedStringValue (mutable_attributes);
Cells [i] = (NSAttributedString) cell.ObjectValue;
i++;
}
} }
@ -824,12 +846,8 @@ namespace SparkleShare {
public NSObject objectValueForTableColumn (NSTableView table_view, public NSObject objectValueForTableColumn (NSTableView table_view,
NSTableColumn table_column, int row_index) NSTableColumn table_column, int row_index)
{ {
// TODO: Style text nicely: "<b>Name</b>\n<grey>Description</grey>"
if (table_column.HeaderToolTip.Equals ("Description")) { if (table_column.HeaderToolTip.Equals ("Description")) {
return new NSString ( return Cells [row_index];
(Items [row_index] as SparklePlugin).Name + "\n" +
(Items [row_index] as SparklePlugin).Description
);
} else { } else {
return new NSImage ((Items [row_index] as SparklePlugin).ImagePath) { return new NSImage ((Items [row_index] as SparklePlugin).ImagePath) {