1+ /*
2+ * Copyright © 2019 Alain M. (https://github.com/alainm23/planner)
3+ *
4+ * This program is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 3 of the License, or (at your option) any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public
15+ * License along with this program; if not, write to the
16+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+ * Boston, MA 02110-1301 USA
18+ *
19+ * Authored by: Alain M. <[email protected] > 20+ */
21+
22+ public class Dialogs.QuickFind : Gtk .Dialog {
23+ public QuickFind () {
24+ Object (
25+ transient_for: Planner . instance. main_window,
26+ deletable: false ,
27+ destroy_with_parent: true ,
28+ window_position: Gtk . WindowPosition . CENTER_ON_PARENT ,
29+ modal: false
30+ );
31+ }
32+
33+ construct {
34+ get_style_context (). add_class (" planner-dialog" );
35+ width_request = 600 ;
36+
37+ int window_x, window_y;
38+ int window_width, width_height;
39+
40+ Planner . settings. get (" window-position" , " (ii)" , out window_x, out window_y);
41+ Planner . settings. get (" window-size" , " (ii)" , out window_width, out width_height);
42+
43+ move (window_x + ((window_width - width_request) / 2 ), window_y + 64 );
44+
45+ var search_label = new Gtk .Label (_(" Search:" ));
46+ search_label. get_style_context (). add_class (" h3" );
47+
48+ var search_entry = new Gtk .SearchEntry ();
49+ search_entry. hexpand = true ;
50+
51+ var top_grid = new Gtk .Grid ();
52+ top_grid. column_spacing = 12 ;
53+ top_grid. margin_start = 34 ;
54+ top_grid. margin_end = 16 ;
55+ top_grid. add (search_label);
56+ top_grid. add (search_entry);
57+
58+ var listbox = new Gtk .ListBox ();
59+ listbox. get_style_context (). add_class (" background" );
60+ listbox. hexpand = true ;
61+
62+ var listbox_scrolled = new Gtk .ScrolledWindow (null , null );
63+ listbox_scrolled. height_request = 250 ;
64+ listbox_scrolled. hscrollbar_policy = Gtk . PolicyType . NEVER ;
65+ listbox_scrolled. expand = true ;
66+ listbox_scrolled. add (listbox);
67+
68+ var separator = new Gtk .Separator (Gtk . Orientation . HORIZONTAL );
69+ separator. margin_top = 16 ;
70+
71+ var main_box = new Gtk .Box (Gtk . Orientation . VERTICAL , 0 );
72+ main_box. pack_start (top_grid, false , false , 0 );
73+ main_box. pack_start (separator, false , false , 0 );
74+ main_box. pack_start (listbox_scrolled, true , true , 0 );
75+
76+ get_content_area (). add (main_box);
77+
78+ search_entry. search_changed. connect (() = > {
79+ listbox. foreach ((widget) = > {
80+ widget. destroy ();
81+ });
82+
83+ if (search_entry. text != " " ) {
84+ foreach (var item in Planner . database. get_items_by_search (search_entry. text)) {
85+ var row = new SearchItem (
86+ " item" ,
87+ item. content,
88+ search_entry. text
89+ );
90+
91+ listbox. add (row);
92+ listbox. show_all ();
93+ }
94+
95+ foreach (var project in Planner . database. get_all_projects_by_search (search_entry. text)) {
96+ var row = new SearchItem (
97+ " project" ,
98+ project. name,
99+ search_entry. text
100+ );
101+
102+ listbox. add (row);
103+ listbox. show_all ();
104+ }
105+ } else {
106+
107+ }
108+ });
109+ }
110+ }
111+
112+ public class SearchItem : Gtk .ListBoxRow {
113+ public string result_type { get ; construct; }
114+ public string content { get ; construct; }
115+ public string search_text { get ; construct; }
116+
117+ public SearchItem (string result_type , string content , string search_text ) {
118+ Object (
119+ result_type: result_type,
120+ content: content,
121+ search_text: search_text
122+ );
123+ }
124+
125+ construct {
126+ get_style_context (). add_class (" searchitem-row" );
127+ if (result_type == " item" ) {
128+ var header_label = new Gtk .Label (_(" Tasks" ));
129+ header_label. get_style_context (). add_class (" h3" );
130+ header_label. width_request = 84 ;
131+ header_label. xalign = 1 ;
132+ header_label. margin_end = 12 ;
133+
134+ var checked_button = new Gtk .CheckButton ();
135+ checked_button. valign = Gtk . Align . CENTER ;
136+ // checked_button.margin_top = 1;
137+ checked_button. get_style_context (). add_class (" checklist-button" );
138+
139+ var content_label = new Gtk .Label (content. replace (search_text, " <b>%s </b>" . printf (search_text)));
140+ content_label. wrap = true ;
141+ content_label. xalign = 0 ;
142+ content_label. use_markup = true ;
143+ content_label. get_style_context (). add_class (" label" );
144+
145+ var grid = new Gtk .Grid ();
146+ grid. margin = 6 ;
147+ grid. column_spacing = 6 ;
148+ grid. add (checked_button);
149+ grid. add (content_label);
150+
151+ var main_grid = new Gtk .Grid ();
152+ main_grid. attach (header_label, 0 , 0 , 1 , 1 );
153+ main_grid. attach (new Gtk .Separator (Gtk . Orientation . VERTICAL ), 1 , 0 , 1 , 1 );
154+ main_grid. attach (grid, 2 , 0 , 1 , 1 );
155+
156+ add (main_grid);
157+ } else if (result_type == " project" ) {
158+ var header_label = new Gtk .Label (_(" Projects" ));
159+ header_label. get_style_context (). add_class (" h3" );
160+ header_label. width_request = 84 ;
161+ header_label. xalign = 1 ;
162+ header_label. margin_end = 12 ;
163+
164+ var project_progress = new Widgets .ProjectProgress ();
165+ project_progress. line_cap = Cairo . LineCap . ROUND ;
166+ project_progress. radius_filled = true ;
167+ project_progress. line_width = 2 ;
168+ project_progress. valign = Gtk . Align . CENTER ;
169+ project_progress. halign = Gtk . Align . CENTER ;
170+ project_progress. percentage = 0.5 ;
171+ // project_progress.progress_fill_color = Planner.utils.get_color (project.color);
172+
173+ var content_label = new Gtk .Label (content. replace (search_text, " <b>%s </b>" . printf (search_text)));
174+ content_label. wrap = true ;
175+ content_label. xalign = 0 ;
176+ content_label. use_markup = true ;
177+ content_label. get_style_context (). add_class (" label" );
178+
179+ var grid = new Gtk .Grid ();
180+ grid. margin = 6 ;
181+ grid. margin_start = 4 ;
182+ grid. column_spacing = 3 ;
183+ grid. add (project_progress);
184+ grid. add (content_label);
185+
186+ var main_grid = new Gtk .Grid ();
187+ main_grid. attach (header_label, 0 , 0 , 1 , 1 );
188+ main_grid. attach (new Gtk .Separator (Gtk . Orientation . VERTICAL ), 1 , 0 , 1 , 1 );
189+ main_grid. attach (grid, 2 , 0 , 1 , 1 );
190+
191+ add (main_grid);
192+ }
193+ }
194+ // public string title { get; construct; }
195+ // public int64 id { get; construct; }
196+ // public int64 project_id { get; construct; }
197+ // public string icon { get; construct; }
198+ // public string element { get; construct; }
199+
200+ // public SearchItem (string title, string icon, string element, int64 id, int64 project_id=0) {
201+ // Object (
202+ // title: title,
203+ // icon: icon,
204+ // element: element,
205+ // id: id,
206+ // project_id: project_id
207+ // );
208+ // }
209+
210+ // construct {
211+ // margin_start = margin_end = 6;
212+ // get_style_context ().add_class ("pane-row");
213+
214+ // var image = new Gtk.Image ();
215+ // image.gicon = new ThemedIcon (icon);
216+ // image.pixel_size = 16;
217+
218+ // var title_label = new Gtk.Label (title);
219+ // //title_label.get_style_context ().add_class ("h3");
220+ // title_label.ellipsize = Pango.EllipsizeMode.END;
221+ // //title_label.use_markup = true;
222+
223+ // var box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
224+ // box.hexpand = true;
225+ // box.margin = 6;
226+ // box.pack_start (image, false, false, 0);
227+ // box.pack_start (title_label, false, false, 0);
228+
229+ // add (box);
230+ // }
231+ }
0 commit comments