private static Bookmark loadOne(string filename) { if(!File.Exists(filename)) { return null; } var lines = File.ReadAllLines(filename); if(lines.Length < 12) { return null; } var pathElements = filename.Split(Path.DirectorySeparatorChar); var bm = new Bookmark(); bm.filename = pathElements.Last().Trim().Replace(".txt", string.Empty); bm.Category = pathElements.Skip(pathElements.Length - 2).First().Trim(); bm.Name = lines[0].Trim(); bm.Keywords = lines[1].Trim(); bm.Description = lines[2].Trim(); bm.Program = lines[3].Trim(); bm.Arguments = lines[4].Trim(); bm.Visits = uint.Parse(lines[5].Trim()); bm.LastCheck = long.Parse(lines[6].Trim()).convertUnixTimestamp2DateTime(); bm.IsAvailable = lines[7].Trim().ToLower() == "true"; bm.Rating = byte.Parse(lines[8].Trim()); bm.CurrentContentHash = lines[9].Trim(); bm.LastChange = long.Parse(lines[10].Trim()).convertUnixTimestamp2DateTime(); bm.WasChanged = lines[11].Trim().ToLower() == "true"; return bm; }
/// <summary> /// Create and returns a new bookmark. The bookmark is then added to any cache and saved to a file. /// </summary> /// <param name="category">The category i.e. directory for this new instance</param> /// <returns>An empty bookmark</returns> internal static Bookmark getNewBookmark(string baseFolder, string category) { var newBookmark = new Bookmark(); newBookmark.Category = category; newBookmark.save(baseFolder); Bookmark.AllBookmarks.Add(newBookmark); return newBookmark; }
private Bookmark transferChangedProperties2Instance(Bookmark destination) { destination.Name = this.textBoxName.Text.Trim(); destination.Keywords = this.textBoxKeywords.Text.Trim(); destination.Description = this.textBoxDescription.Text.Trim().Replace("\n", " ").Replace("\r", string.Empty); destination.Program = this.textBoxProgram.Text.Trim(); destination.Arguments = this.textBoxURL.Text.Trim(); destination.Rating = (byte)this.trackBarRating.Value; return destination; }
private void loadBookmarksProperties(Bookmark nextBookmark) { if(nextBookmark == null) { return; } if(this.propertiesDirty) { if(MessageBox.Show("Your last changes are not saved! Proceed and reject any changes?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } } this.currentBookmark = nextBookmark; this.textBoxName.Text = this.currentBookmark.Name; this.labelCategory.Text = this.currentBookmark.Category; this.textBoxKeywords.Text = this.currentBookmark.Keywords; this.textBoxDescription.Text = this.currentBookmark.Description; this.textBoxProgram.Text = this.currentBookmark.Program; this.textBoxURL.Text = this.currentBookmark.Arguments; this.labelVisits.Text = string.Format("{0}", this.currentBookmark.Visits); this.labelLastCheckDays.Text = this.currentBookmark.getLastCheckDay(); this.labelStatus.Text = this.currentBookmark.IsAvailable ? "AVAILABLE" : "NOT AVAILABLE"; this.labelStatus.ForeColor = this.currentBookmark.IsAvailable ? Color.DarkGreen : Color.DarkRed; this.trackBarRating.Value = this.currentBookmark.Rating; this.propertiesDirty = false; }
private void ButtonSaveThisInstanceClick(object sender, EventArgs e) { if(this.currentBookmark == null) { MessageBox.Show("Please select a bookmark!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.currentBookmark = this.transferChangedProperties2Instance(this.currentBookmark); this.currentBookmark.save(this.baseFolder); this.propertiesDirty = false; Bookmark.loadAllBookmarks(this.baseFolder); this.selectLastUsedTab(); }
private void ButtonDeleteBookmarkClick(object sender, EventArgs e) { if(this.currentBookmark == null) { MessageBox.Show("Please select a bookmark!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if(MessageBox.Show("Are you sure to delete this bookmark?", "Sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { this.currentBookmark.delete(this.baseFolder); this.currentBookmark = null; } }