Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract PDF bookmark with priority #66

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions PDF/PDFElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,22 @@ public static CreationResult Create(
int pageMargin = PDFConst.DefaultPageMargin,
float zoom = PDFConst.DefaultZoom,
bool shouldDisplay = true,
string subtitle = null)
string subtitle = null,
double priority = -1)
{
PDFElement pdfEl;
string title;
string author;
string creationDate;
string filePath;


if (priority < 0 || priority > 100)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Can you also add a LogTo.Error(...) message since this should never happen ? That way a bug report will be sent if it does happen

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sorted.

{
LogTo.Error("Attempted to call PDFElement.Create with invalid priority value. Resorting to user's config PDF Extract Priority.");
priority = PDFState.Instance.Config.PDFExtractPriority;
}

try
{
filePath = binMem.GetFilePath("pdf");
Expand Down Expand Up @@ -348,7 +356,7 @@ public static CreationResult Create(
elementHtml)
.WithParent(parentElement)
.WithTitle(subtitle ?? title)
.WithPriority(PDFState.Instance.Config.PDFExtractPriority)
.WithPriority(priority)
.WithReference(
r => r.WithTitle(title)
.WithAuthor(author)
Expand Down
2 changes: 2 additions & 0 deletions PDF/PDFWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
<Separator />
<MenuItem Header="PDF Extract (Ctrl+Alt+X)"
Click="TvBookmark_MenuItem_PDFExtract" />
<MenuItem Header="PDF Extract with Priority (Ctrl+Shift+X)"
Click="TvBookmark_MenuItem_PDFExtractWithPriority"/>
</ContextMenu>
</StackPanel.ContextMenu>
</StackPanel>
Expand Down
41 changes: 41 additions & 0 deletions PDF/PDFWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
using Patagames.Pdf.Net;
using SuperMemoAssistant.Extensions;
using SuperMemoAssistant.Plugins.PDF.Models;
using System.Threading.Tasks;
using Forge.Forms;
using SuperMemoAssistant.Services.IO.HotKeys;
using SuperMemoAssistant.Sys.IO.Devices;
using SuperMemoAssistant.Sys.Threading;
Expand Down Expand Up @@ -342,6 +344,37 @@ private void TvBookmark_MenuItem_PDFExtract(object sender,
IPDFViewer.ExtractBookmark(bookmark);
}

private async void TvBookmark_MenuItem_PDFExtractWithPriority(object sender,
RoutedEventArgs e)
{

var result = await Forge.Forms.Show.Window()
.For(new Prompt<double> { Title = "Bookmark Priority?", Value = Config.PDFExtractPriority });

if (!result.Model.Confirmed)
{
return;
}

double priority = result.Model.Value;

if (priority < 0 || priority > 100)
{
await Forge.Forms.Show.Window()
.For(new Alert("Priority value must be between 0 and 100."));
return;
}

PdfBookmark bookmark = (PdfBookmark)tvBookmarks.SelectedItem;
if (bookmark == null)
{
return;
}

IPDFViewer.ExtractBookmark(bookmark, priority);
}


private void TvBookmarks_PreviewKeyDown(object sender,
KeyEventArgs e)
{
Expand All @@ -364,6 +397,14 @@ private void TvBookmarks_PreviewKeyDown(object sender,

e.Handled = true;
}

else if (kbMod == (KeyModifiers.Ctrl | KeyModifiers.Shift)
&& e.Key == Key.X)
{
TvBookmark_MenuItem_PDFExtractWithPriority(sender,
null);
e.Handled = true;
}
}

private void BtnExpandAll_Click(object sender,
Expand Down
6 changes: 4 additions & 2 deletions PDF/Viewer/IPDFViewer.SuperMemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ protected bool CreatePDFExtract()
}

protected bool CreatePDFExtract(SelectInfo selInfo,
string title = null)
string title = null,
double priority = -1)
{
Save(false);

Expand All @@ -282,7 +283,8 @@ protected bool CreatePDFExtract(SelectInfo selInfo,
PDFElement.PageMargin,
PDFElement.Zoom,
false,
title) == PDFElement.CreationResult.Ok;
title,
priority) == PDFElement.CreationResult.Ok;

if (ret)
{
Expand Down
5 changes: 3 additions & 2 deletions PDF/Viewer/IPDFViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,16 @@ public void LoadDocument(PDFElement pdfElement)
OnDocumentLoaded(null);
}

public void ExtractBookmark(PdfBookmark bookmark)
public void ExtractBookmark(PdfBookmark bookmark, double priority = -1)
{
var selInfo = bookmark.GetSelection(Document);

if (selInfo == null)
return;

CreatePDFExtract(selInfo.Value,
bookmark.Title);
bookmark.Title,
priority);
}

public void ProcessBookmark(PdfBookmark bookmark)
Expand Down