private void view_entry(object sender, RoutedEventArgs e) { int row_idx = this.entries_list.SelectedIndex, idx = this.state.domain.entries.Count - row_idx - 1; if ((idx < 0) || (idx >= this.state.domain.entries.Count)) { return; } EntryWindow entry_window = new EntryWindow(this.state, idx) { Owner = this }; entry_window.ShowDialog(); if (!entry_window.valid) { return; } if (entry_window.topics is not null) { this.state.domain.topics = entry_window.topics; } if (entry_window.topic_refs is not null) { this.state.topic_refs = entry_window.topic_refs; } if (entry_window.notes is not null) { this.state.domain.notes = entry_window.notes; } decimal timestamp = entry_window.timestamp_box.calendar_value; DateTime created = entry_window.get_created(); string description = entry_window.description_box.Text; int session = (int)(entry_window.session_box.Value); Entry ent = this.state.domain.entries[idx]; bool changed = (timestamp != ent.timestamp) || (created != ent.created) || (description != ent.description) || (session != ent.session); if ((!changed) && (entry_window.actions.Count != ent.actions.Count)) { changed = true; } if (!changed) { for (int i = 0; i < entry_window.actions.Count; i++) { if (entry_window.actions[i] != ent.actions[i]) { changed = true; break; } } } if (!changed) { return; } this.state_dirty = true; this.state.domain.remove_entry(idx, true); this.entry_rows.RemoveAt(row_idx); this.state.remove_references(ent.actions); this.state.add_references(entry_window.actions); ent.timestamp = timestamp; ent.created = created; ent.description = description; ent.session = session; ent.actions = entry_window.actions; idx = this.state.domain.add_entry(ent); int valid_idx = this.state.domain.valid_entries - 1; if (valid_idx < 0) { valid_idx = this.state.domain.entries.Count - 1; } this.session_num_box.Content = (this.state.domain.entries[valid_idx].session ?? 0).ToString(); this.current_timestamp = this.state.domain.entries[valid_idx].timestamp; this.current_timestamp_box.Content = this.state.calendar.format_timestamp(this.current_timestamp, verbose: true); EntryRow row = new EntryRow( this.state.calendar.format_timestamp(ent.timestamp, verbose: true), idx >= this.state.domain.valid_entries, (ent.session ?? 0).ToString(), ent.created.ToString("G"), ent.description ); this.entry_rows.Insert(this.entry_rows.Count - idx, row); for (int i = 0; i < this.entry_rows.Count; i++) { this.entry_rows[i].set_invalid(this.entry_rows.Count - i > this.state.domain.valid_entries); } this.refresh_lists(); }
private void entry_action_callback( List <EntryAction> actions, Guid?entry_guid = null, Dictionary <Guid, Topic> topics = null, Dictionary <Guid, int> topic_refs = null, Dictionary <Guid, ExternalNote> notes = null ) { if (topics is not null) { this.state.domain.topics = topics; } if (topic_refs is not null) { this.state.topic_refs = topic_refs; } if (notes is not null) { this.state.domain.notes = notes; } if (actions is not null) { EntryWindow entry_window = new EntryWindow(this.state, actions: actions) { Owner = this }; entry_window.ShowDialog(); if (!entry_window.valid) { return; } if (entry_window.topics is not null) { this.state.domain.topics = entry_window.topics; } if (entry_window.topic_refs is not null) { this.state.topic_refs = entry_window.topic_refs; } if (entry_window.notes is not null) { this.state.domain.notes = entry_window.notes; } decimal timestamp = entry_window.timestamp_box.calendar_value; DateTime created = entry_window.get_created(); string description = entry_window.description_box.Text; int session = (int)(entry_window.session_box.Value); Entry ent = new Entry(timestamp, created, description, session, new List <EntryAction>(entry_window.actions), entry_guid); this.state_dirty = true; int idx = this.state.domain.add_entry(ent); this.state.add_references(ent.actions); int valid_idx = this.state.domain.valid_entries - 1; if (valid_idx < 0) { valid_idx = this.state.domain.entries.Count - 1; } this.session_num_box.Content = (this.state.domain.entries[valid_idx].session ?? 0).ToString(); this.current_timestamp = this.state.domain.entries[valid_idx].timestamp; this.current_timestamp_box.Content = this.state.calendar.format_timestamp(this.current_timestamp, verbose: true); EntryRow row = new EntryRow( this.state.calendar.format_timestamp(ent.timestamp, verbose: true), idx >= this.state.domain.valid_entries, (ent.session ?? 0).ToString(), ent.created.ToString("G"), ent.description ); this.entry_rows.Insert(this.entry_rows.Count - idx, row); for (int i = 0; i < this.entry_rows.Count; i++) { this.entry_rows[i].set_invalid(this.entry_rows.Count - i > this.state.domain.valid_entries); } } this.refresh_lists(); }