private void LoadFiles() { LvwFiles.Items.Clear(); Files = new List <NoteFile>(); DirectoryInfo dir = new DirectoryInfo(GetFullPath()); foreach (FileInfo file in dir.EnumerateFiles()) { if (IsNoteFile(file)) { NoteFile noteFile = new NoteFile(System, this); noteFile.BareFileName = file.Name; noteFile.LabelText = file.Name; noteFile.CreatedAt = file.CreationTime; noteFile.ModifiedAt = file.LastWriteTime; noteFile.Load(); List <string> columnValues = new List <string>(); columnValues.Add(noteFile.LabelText); foreach (ExtraColumnDef extraDef in ExtraColumns) { switch (extraDef.NormalizedName) { case "createdon": columnValues.Add(noteFile.CreatedAt.ToString("MM/dd/yy hh:mmtt")); break; case "updatedon": columnValues.Add(noteFile.ModifiedAt.ToString("MM/dd/yy hh:mmtt")); break; default: string dataValue; if (noteFile.DataFields.TryGetValue(extraDef.NormalizedName, out dataValue)) { columnValues.Add(dataValue); } else { columnValues.Add(""); } break; } } ListViewItem item = new ListViewItem(columnValues.ToArray()); item.Tag = noteFile; LvwFiles.Items.Add(item); } } NeedsRefresh = false; }
private void lvwFileList_DoubleClick(object sender, EventArgs e) { Monitor.Enter(_System.LockObject); try { NoteFile file = GetSelectedFile(); if (file == null) { return; } EditFile(file.GetFullPath()); } catch (Exception ex) { ShowException(ex); } finally { Monitor.Exit(_System.LockObject); } }
private void menuArchive_Click(object sender, EventArgs e) { NoteFile file = GetSelectedFile(); if (file == null) { return; } DialogResult result = MessageBox.Show( "Are you sure you want to archive the selected note " + "(this will move it to the archive subfolder)?", "Confirm Archive", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.OK) { return; } Monitor.Enter(_System.LockObject); try { string archiveDirPath = _System.CurrentFolder.GetArchiveDirPath(); string baseName = Path.GetFileNameWithoutExtension(file.BareFileName); string archiveFileName = baseName + "." + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; string archiveFilePath = Path.Combine(archiveDirPath, archiveFileName); File.Move(file.GetFullPath(), archiveFilePath); _System.RefreshCurrentFolder(); } catch (Exception ex) { ShowException(ex); } finally { Monitor.Exit(_System.LockObject); } }