Show total number of results for google driver too. Helps to know if my query resulte...
[beagle.git] / search / Tiles / DetailsPane.cs
blob74de4366d62ec35d528c79e4b333994eb27cc717
1 using System;
3 namespace Search.Tiles {
5 public class DetailsPane : Gtk.Table {
7 public DetailsPane () : base (1, 2, false)
9 RowSpacing = ColumnSpacing = 6;
10 BorderWidth = 6;
12 icon = new Gtk.Image ();
13 icon.Show ();
14 Attach (icon, 0, 1, 0, 1, fill, fill, 0, 0);
16 SizeRequested += DetailsSizeRequested;
19 private Gtk.Image icon;
20 public Gtk.Image Icon {
21 get { return icon; }
24 private Gtk.Label snippet;
25 public Gtk.Label Snippet {
26 get { return snippet; }
29 bool maximized = false;
31 // FIXME: overriding OnSizeRequested directly results in a 0x0 req
32 [GLib.ConnectBefore]
33 private void DetailsSizeRequested (object obj, Gtk.SizeRequestedArgs args)
35 if (maximized)
36 return;
38 Gtk.Table.TableChild[,] children = new Gtk.Table.TableChild[NColumns, NRows];
40 foreach (Gtk.Widget child in Children) {
41 Gtk.Table.TableChild tc = this[child] as Gtk.Table.TableChild;
42 children[tc.LeftAttach, tc.TopAttach] = tc;
45 // Expand the icon down to the bottom or the first label
46 if (children[0, 0] != null && children[0, 0].Child == icon) {
47 uint max_icon_row;
48 for (max_icon_row = 1; max_icon_row < NRows; max_icon_row++) {
49 if (children[0, max_icon_row] != null)
50 break;
53 children[0, 0].BottomAttach = max_icon_row;
56 // Expand all labels (except in column 0) rightward
57 for (uint row = 0; row < NRows; row++) {
58 for (uint col = 1; col < NColumns; col++) {
59 if (children[col, row] == null ||
60 !(children[col, row].Child is Gtk.Label))
61 continue;
62 uint end = col + 1;
63 while (end < NColumns &&
64 children[end, row] == null)
65 end++;
66 if (end > col + 1)
67 children[col, row].RightAttach = end;
71 // Vertically expand only the bottom row
72 for (uint row = 0; row < NRows; row++) {
73 for (uint col = 1; col < NColumns; col++) {
74 if (children[col, row] == null)
75 continue;
76 children[col, row].YOptions = (row == NRows - 1) ? expand : fill;
80 maximized = true;
83 private const Gtk.AttachOptions expand = Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill;
84 private const Gtk.AttachOptions fill = Gtk.AttachOptions.Fill;
86 private uint current_row = 0;
88 private Gtk.Label AddGrayLabel (string text, uint row, uint column)
90 Gtk.Label label = WidgetFu.NewGrayLabel (text);
91 label.Show ();
92 Attach (label, column, column + 1, row, row + 1, fill, fill, 0, 0);
93 maximized = false;
94 return label;
97 private Gtk.Label AddLabel (string text, uint row, uint column)
99 Gtk.Label label = WidgetFu.NewLabel (text);
100 label.Selectable = true;
101 WidgetFu.EllipsizeLabel (label);
102 label.Show ();
103 Attach (label, column, column + 1, row, row + 1, expand, fill, 0, 0);
104 maximized = false;
105 return label;
108 private Gtk.Label AddBoldLabel (string text, uint row, uint column)
110 Gtk.Label label = WidgetFu.NewBoldLabel (text);
111 WidgetFu.EllipsizeLabel (label);
112 label.Show ();
113 Attach (label, column, column + 1, row, row + 1, expand, fill, 0, 0);
114 maximized = false;
115 return label;
118 public Gtk.Label AddTitleLabel (string text)
120 Gtk.Label label = AddBoldLabel (text, current_row++, 1);
121 label.Selectable = true;
122 return label;
125 public Gtk.Label AddTextLabel (string text)
127 Gtk.Label label = AddLabel (text, current_row++, 1);
128 return label;
131 public void AddLabelPair (string label, string text)
133 AddGrayLabel (label, current_row, 1);
134 AddLabel (text, current_row++, 2);
137 public Gtk.Label AddSnippet ()
139 snippet = WidgetFu.NewLabel ();
140 snippet.Selectable = true;
141 WidgetFu.EllipsizeLabel (snippet);
142 snippet.Show ();
143 Attach (snippet, 1, 2, current_row, ++current_row, expand, fill, 48, 0);
144 maximized = false;
146 return snippet;
149 public Gtk.Label AddNewLine ()
151 Gtk.Label label = WidgetFu.NewLabel ("");
152 label.Show ();
153 Attach (label, 1, 2, current_row, ++current_row, fill, fill, 0, 0);
154 return label;
157 public Gtk.Label AddFinalLine ()
159 Gtk.Label label = WidgetFu.NewLabel ("");
160 label.Show ();
161 Attach (label, 1, 2, current_row, ++current_row, expand, expand, 0, 0);
162 return label;
165 public void GotSnippet (string text)
167 snippet.Markup = text;