Skip to content

Commit

Permalink
Merge pull request #5 from mikeMoreno/feature/bookmarks
Browse files Browse the repository at this point in the history
Feature/bookmarks
  • Loading branch information
mikeMoreno authored Feb 13, 2022
2 parents 7b70cb9 + ea6f99b commit d3409f4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 58 deletions.
3 changes: 2 additions & 1 deletion Waffle/Bookmarks/Bookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Waffle.Lib;

namespace Waffle.Bookmarks
{
internal class Bookmark : BookmarkEntity
{
public override string BookmarkEntityType => "Bookmark";

public string Url { get; set; }
public SelectorLine SelectorLine { get; set; }
}
}
12 changes: 5 additions & 7 deletions Waffle/Bookmarks/BookmarkAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Waffle.Bookmarks
{
public partial class BookmarkAdder : Form
{
private string AbsoluteUrl { get; }
private SelectorLine SelectorLine { get; }

private List<BookmarkEntity> BookmarkEntities { get; }

public BookmarkAdder(LinkLine linkLine)
public BookmarkAdder(SelectorLine selectorLine)
{
InitializeComponent();

AbsoluteUrl = linkLine.Raw.Trim();
SelectorLine = selectorLine;

txtName.Text = linkLine.GetUserFriendlyName();
txtName.Text = selectorLine.GetUserFriendlyName();

BookmarkEntities = LoadBookmarks();

Expand Down Expand Up @@ -84,8 +84,6 @@ private void PopulateBookmarkTree(BookmarkEntity bookmarkEntity, TreeNode parent

private void btnSave_Click(object sender, EventArgs e)
{
// TODO: persist entire selectorLine

var name = txtName.Text.Trim();

if (string.IsNullOrWhiteSpace(name))
Expand All @@ -98,7 +96,7 @@ private void btnSave_Click(object sender, EventArgs e)
var bookmark = new Bookmark()
{
Name = name,
Url = AbsoluteUrl,
SelectorLine = SelectorLine
};

var selectedNode = bookmarkTree.SelectedNode;
Expand Down
8 changes: 5 additions & 3 deletions Waffle/Bookmarks/BookmarkClickedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Waffle.Lib;

namespace Waffle.Bookmarks
{

class BookmarkClickedEventArgs : EventArgs
{
public Bookmark Bookmark { get; private set; }
public SelectorLine SelectorLine { get; }

public BookmarkClickedEventArgs(Bookmark bookmark)

public BookmarkClickedEventArgs(SelectorLine selectorLine)
{
Bookmark = bookmark;
SelectorLine = selectorLine;
}
}
}
2 changes: 1 addition & 1 deletion Waffle/Bookmarks/BookmarkEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public BookmarkEditor(BookmarkEntity bookmarkEntity)

if (bookmarkEntity is Bookmark bookmark)
{
txtUrl.Text = bookmark.Url;
txtUrl.Text = bookmark.SelectorLine.GetLink();
}
else
{
Expand Down
36 changes: 28 additions & 8 deletions Waffle/Bookmarks/BookmarkPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using Waffle.Bookmarks;
using Waffle.Lib;

namespace Waffle.Bookmarks
{
partial class BookmarkPanel : UserControl
{
private WaffleLib WaffleLib { get; }

private List<BookmarkEntity> BookmarkEntities { get; }

public delegate void BookmarkClickedEventHandler(object sender, BookmarkClickedEventArgs e);
Expand All @@ -24,7 +27,7 @@ partial class BookmarkPanel : UserControl

public event OpenInNewTabEventHandler OpenInNewTabClicked;

public BookmarkPanel()
public BookmarkPanel(WaffleLib waffleLib)
{
InitializeComponent();

Expand All @@ -33,6 +36,8 @@ public BookmarkPanel()
return;
}

WaffleLib = waffleLib;

BookmarkEntities = LoadBookmarks();

PopulateBookmarkTree(BookmarkEntities);
Expand Down Expand Up @@ -180,7 +185,7 @@ private void btnEdit_Click(object sender, EventArgs e)

if (bookmarkEntity is Bookmark bookmark)
{
bookmark.Url = bookmarkEditor.BookmarkUrl;
bookmark.SelectorLine.Raw = bookmarkEditor.BookmarkUrl;
}
}
}
Expand All @@ -202,16 +207,17 @@ private void bookmarkTree_MouseDown(object sender, MouseEventArgs e)
{
if (bookmarkTree.SelectedNode.Tag is Bookmark bookmark)
{
LinkClicked?.Invoke(this, new BookmarkClickedEventArgs(bookmark));
LinkClicked?.Invoke(this, new BookmarkClickedEventArgs(bookmark.SelectorLine));
}
}
}

private void btnAddBookmark_Click(object sender, EventArgs e)
{
// TODO: persist entire selectorLine

var newBookmark = new Bookmark();
var newBookmark = new Bookmark()
{
SelectorLine = new SelectorLine()
};

using (var bookmarkEditor = new BookmarkEditor(newBookmark))
{
Expand All @@ -225,7 +231,9 @@ private void btnAddBookmark_Click(object sender, EventArgs e)
}

newBookmark.Name = bookmarkEditor.BookmarkName;
newBookmark.Url = bookmarkEditor.BookmarkUrl;
newBookmark.SelectorLine.Raw = bookmarkEditor.BookmarkUrl;

newBookmark.SelectorLine.ItemType = DetermineItemType(newBookmark.SelectorLine.Raw);

var selectedNode = bookmarkTree.SelectedNode;

Expand Down Expand Up @@ -261,6 +269,18 @@ private void btnAddBookmark_Click(object sender, EventArgs e)
SaveBookmarks(BookmarkEntities);
}

private ItemType DetermineItemType(string absoluteUrl)
{
var linkLine = new LinkLine(absoluteUrl);

if (linkLine.ItemType == ItemType.Unknown)
{
linkLine.ItemType = ItemType.Menu;
}

return linkLine.ItemType;
}

private void btnAddFolder_Click(object sender, EventArgs e)
{
var newFolder = new BookmarkFolder();
Expand Down Expand Up @@ -325,7 +345,7 @@ private void btnOpenInNewTab_Click(object sender, EventArgs e)
{
if (bookmarkTree.SelectedNode.Tag is Bookmark bookmark)
{
OpenInNewTabClicked?.Invoke(this, new BookmarkClickedEventArgs(bookmark));
OpenInNewTabClicked?.Invoke(this, new BookmarkClickedEventArgs(bookmark.SelectorLine));
}
}
}
Expand Down
62 changes: 31 additions & 31 deletions Waffle/Navigation/Navigator.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions Waffle/Navigation/Navigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,21 +434,28 @@ private void btnAbout_Click(object sender, EventArgs e)
aboutForm.Show();
}

private void btnFavorite_Click(object sender, EventArgs e)
private void btnAddBookmark_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtUrl.Text))
if (tabSitePages.SelectedTab is not RequestTab selectedTab)
{
return;
}

using var favAdder = new BookmarkAdder(new LinkLine(txtUrl.Text));
var pageRenderer = selectedTab.Controls.OfType<PageRenderer>().Single();

if(pageRenderer == null || pageRenderer.CurrentSelectorLine == null)
{
return;
}

using var favAdder = new BookmarkAdder(pageRenderer.CurrentSelectorLine);

var ans = favAdder.ShowDialog();
}

private void btnBookmarks_Click(object sender, EventArgs e)
private void btnOpenBookmarkPanel_Click(object sender, EventArgs e)
{
var bookmarkPanel = new BookmarkPanel()
var bookmarkPanel = new BookmarkPanel(WaffleLib)
{
Dock = DockStyle.Right,
Size = new Size()
Expand All @@ -466,12 +473,12 @@ private void btnBookmarks_Click(object sender, EventArgs e)

private async void BookmarkPanel_LinkClicked(object sender, BookmarkClickedEventArgs e)
{
await VisitSiteAsync(e.Bookmark.Url);
await VisitSiteAsync(e.SelectorLine);
}

private async void BookmarkPanel_OpenInNewTabClicked(object sender, BookmarkClickedEventArgs e)
{
await VisitSiteAsync(e.Bookmark.Url, newTab: true);
await VisitSiteAsync(e.SelectorLine, newTab: true);
}

private async void HistoryForm_LinkClicked(object sender, NavigationLinkClickedEventArgs e)
Expand Down

0 comments on commit d3409f4

Please sign in to comment.