public NoteStreamEditorViewModel(NoteRepository db, string title, Cmd newNoteCol, Func <NoteStreamEditorViewModel, Cmd> getRemoveCommand)
        {
            this.db         = db;
            db.OnNoteSaved += refreshNotes;
            this.title      = title;
            SaveNote        = new Cmd(saveNote, canSaveNote);
            RemoveNoteCol   = getRemoveCommand(this);

            NewNoteCol = newNoteCol;
        }
Beispiel #2
0
        public CogNotesMainWindow()
        {
            timerSaveDrafts          = new DispatcherTimer();
            timerSaveDrafts.Interval = TimeSpan.FromSeconds(30);
            timerSaveDrafts.Tick    += TimerSaveDrafts_Tick;
            timerSaveDrafts.Start();

            db = new NoteRepository($@"Data Source={System.IO.Path.Combine(homeFolder, "cognotes.db")}");
            db.CreateTables();
            InitializeComponent();
            this.DataContext = vm = new CogNotesViewModel(db);
            addNoteCol       = new Cmd(AddNoteCol, () => vm.NoteStreams.Count < 5);
            if (File.Exists(topicsPath()))
            {
                foreach (string topic in File.ReadAllLines(topicsPath()).Take(4))
                {
                    string[] elems = topic.Split('\x1f');
                    if (elems.Length != 2)
                    {
                        // Read the new version
                        vm.AddNoteStream(new NoteStreamEditorViewModel(db, topic, addNoteCol, getRemoveCommand)
                        {
                            SearchTerms = topic
                        });
                    }
                    else
                    {
                        // Migrate up from old version.
                        vm.AddNoteStream(new NoteStreamEditorViewModel(db, elems[0], addNoteCol, getRemoveCommand)
                        {
                            SearchTerms = elems[1]
                        });
                    }
                }
            }
            if (vm.NoteStreams.Count() == 0)
            {
                vm.AddNoteStream(new NoteStreamEditorViewModel(db, "Notes", addNoteCol, getRemoveCommand)
                {
                    SearchTerms = "",
                });
            }
            this.Closing += CogNotesMainWindow_Closing;
        }
 private static ObservableCollection <NoteViewModel> searchNotes(NoteRepository db, string searchTerms)
 {
     return(new ObservableCollection <NoteViewModel>(
                db.ViewNotesForSearch(searchTerms).Take(5)
                ));
 }