namespace zavai {
namespace widgets {
+private string month_path(int year, int month)
+{
+ return "%s/cal/%04d/%02d".printf(zavai.config.homedir, year, month);
+}
+
+private string day_path(int year, int month, int day)
+{
+ return "%s/%02d.txt".printf(month_path(year, month), day);
+}
+
+
public class FileNotes : Gtk.ScrolledWindow
{
protected Gtk.TextBuffer text_buffer;
{
protected Gtk.ListStore model;
protected Gtk.TreeView list;
+ public signal void selected(int year, int month, int day);
public Next30()
{
list.insert_column_with_attributes (-1, "Day", new Gtk.CellRendererText(), "text", 0);
list.insert_column_with_attributes (-1, "Notes", new Gtk.CellRendererText(), "text", 1);
add(list);
+
+ list.cursor_changed += on_row_selected;
}
- public void clear()
+ //private void on_row_selected(Gtk.TreeView tv, Gtk.TreePath path, Gtk.TreeViewColumn column)
+ private void on_row_selected(Gtk.TreeView tv)
{
- model.clear();
+ Gtk.TreePath path;
+ list.get_cursor(out path, null);
+
+ Gtk.TreeIter iter;
+
+ if (!model.get_iter(out iter, path)) return;
+ Value year, month, day;
+ model.get_value(iter, 2, out year);
+ model.get_value(iter, 3, out month);
+ model.get_value(iter, 4, out day);
+ selected((int)year, (int)month, (int)day);
}
- public void add_day(Date date, string notes)
+ protected void add_day(Date date, string notes)
{
var buffer = new char[64];
date.strftime(buffer, "%d %a");
model.append (out iter);
model.set(iter, 0, (string)buffer);
model.set(iter, 1, notes);
- model.set(iter, 2, date.get_day());
+ model.set(iter, 2, date.get_year());
model.set(iter, 3, date.get_month());
- model.set(iter, 4, date.get_year());
+ model.set(iter, 4, date.get_day());
+ }
+
+ public void update(Date start)
+ {
+ Date date = start;
+ model.clear();
+ for (uint i = 0; i < 30; ++i)
+ {
+ string path = day_path(date.get_year(), date.get_month(), date.get_day());
+ string text;
+ if (!FileUtils.test (path, FileTest.IS_REGULAR))
+ text = "";
+ else
+ {
+ try {
+ FileUtils.get_contents(path, out text);
+ } catch (FileError e) {
+ text = "";
+ }
+ }
+ if (i == 0 || text != "")
+ {
+ add_day(date, text);
+ }
+ date.add_days(1);
+ }
}
}
{
protected Gtk.Calendar calendar;
protected Gtk.Notebook notebook;
+ protected Gtk.Notebook day_notebook;
protected FileNotes month_notes;
protected FileNotes day_notes;
protected FileNotes general_notes;
notebook = new Gtk.Notebook();
+ day_notebook = new Gtk.Notebook();
next_30 = new Next30();
- notebook.append_page(next_30, new Gtk.Label("Next 30"));
+ next_30.selected += on_next30_selected;
+ day_notebook.append_page(next_30, new Gtk.Label("Next 30"));
day_notes = new FileNotes();
- notebook.append_page(day_notes, new Gtk.Label("Day"));
+ day_notebook.append_page(day_notes, new Gtk.Label("Day"));
+ notebook.append_page(day_notebook, new Gtk.Label("Day"));
+ day_notebook.show_tabs = false;
+
month_notes = new FileNotes();
notebook.append_page(month_notes, new Gtk.Label("Month"));
general_notes = new FileNotes();
re_dayfile = new Regex("[0-9][0-9]\\.txt");
on_month_changed();
+ on_day_selected();
}
- private string month_path(int year, int month)
+ private void on_next30_selected(int year, int month, int day)
{
- return "%s/cal/%04d/%02d".printf(zavai.config.homedir, year, month);
- }
+ // Select this day in the calendar
+ calendar.year = year;
+ calendar.month = month-1;
+ calendar.day = day;
- private string day_path(int year, int month, int day)
- {
- return "%s/%02d.txt".printf(month_path(year, month), day);
+ // View the day notes
+ day_notebook.set_current_page(1);
+
+ // TODO: when clicking on calendar, show next30 again
}
private void on_month_changed()
string mpath = month_path(cur_year, cur_month);
month_notes.load(mpath + "/00.txt");
- next_30.clear();
Date date = Date();
date.set_dmy((DateDay)cur_day, cur_month, (DateYear)cur_year);
- for (uint i = 0; i < 30; ++i)
- {
- path = day_path(date.get_year(), date.get_month(), date.get_day());
- string text;
- if (!FileUtils.test (path, FileTest.IS_REGULAR))
- text = "";
- else
- {
- try {
- FileUtils.get_contents(path, out text);
- } catch (FileError e) {
- text = "";
- }
- }
- if (text != "")
- {
- next_30.add_day(date, text);
- }
- date.add_days(1);
- }
+ next_30.update(date);
+ day_notebook.set_current_page(0);
}
public void flush()