private void LoadFileList(List <string> allFiles, SelectedDatesCollection filter = null) { using (new WaitCursor()) { // Put file names in list. fileListBox.Items.Clear(); allFiles.Sort(); allFiles.Reverse(); _calendarReload = false; DateTime?filterDate = null; if (filter?.Any() == true) { // Nulling the selected date will null out our filter, so save a copy. // Fortunately we know there can only be one, so... filterDate = filter[0]; } entriesCalendar.SelectedDate = null; foreach (string fileName in allFiles) { EntryFile entryFile = new EntryFile() { FileName = fileName }; if (entryFile.FileDateTime != DateTime.MinValue && (filterDate == null || filterDate.Value == entryFile.FileDate)) { fileListBox.Items.Add(entryFile); entriesCalendar.SelectedDates.Add(entryFile.FileDateTime); } } } _calendarReload = true; }
private async void New_Click(object sender, RoutedEventArgs e) { SaveFileDialog sfd = new SaveFileDialog() { DefaultExt = ".zip", Filter = "Zip files (*.zip)|*.zip" }; if (sfd.ShowDialog() == true) { _selectedFile = null; await AddNewEntry(sfd.FileName); await OpenJournalFile(sfd.FileName); } }
private async void fileListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { SaveSelectedEntry(false); if (fileListBox.SelectedValue != null) { _selectedFile = fileListBox.SelectedValue as EntryFile; if (await LoadFileFromZipAsync(_journalFilePath, _selectedFile.FileName, _pw)) { TitleLabel.Content = _selectedFile.FileDateTime.ToString("dddd, MMMM d yyyy, hh:mm:ss tt"); } } }
private async void Open_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog() { DefaultExt = ".zip", Filter = "Zip files (*.zip)|*.zip" }; if (ofd.ShowDialog() == true) { _selectedFile = null; if (await OpenJournalFile(ofd.FileName)) { Properties.Settings.Default["DefaultFile"] = _journalFilePath; Properties.Settings.Default.Save(); } } }
private void DeleteSelectedEntry(bool dontPrompt) { if (_selectedFile != null && !string.IsNullOrWhiteSpace(_journalFilePath)) { if (dontPrompt || MessageBox.Show("Are you sure you want to delete the selected entry? This cannot be undone!", "Save?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { // We have changes and the user wants to save them. using (ZipFile file = ZipFile.Read(_journalFilePath)) { DeleteFileFromZip(file, _selectedFile.FileName, _pw); file.Save(); _selectedFileBytes = null; _selectedFile = null; LoadFileList(GetFileNames(file)); } fileListBox.SelectedIndex = 0; FocusManager.SetFocusedElement(entryGrid, entryTextBox); } } }