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 2 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
11 changes: 9 additions & 2 deletions PDF/PDFElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,21 @@ 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.

{
priority = PDFState.Instance.Config.PDFExtractPriority;
}

try
{
filePath = binMem.GetFilePath("pdf");
Expand Down Expand Up @@ -348,7 +355,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
32 changes: 32 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,28 @@ 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 = -1 });

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

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

IPDFViewer.ExtractBookmark(bookmark, result.Model.Value);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a check for the Priority value provided by the user, like in your other Extract with priority PR ?

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. I added a check and included an Alert window if the priority value is invalid.

}


private void TvBookmarks_PreviewKeyDown(object sender,
KeyEventArgs e)
{
Expand All @@ -364,6 +388,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
8 changes: 5 additions & 3 deletions PDF/Viewer/IPDFViewer.SuperMemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ protected ContentBase CreateImageContent(Image image, string title)

// PDF Extracts

protected bool CreatePDFExtract()
protected bool CreatePDFExtract(double priority = -1)
Copy link
Member

Choose a reason for hiding this comment

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

Why is priority never used ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I think I added that by mistake. I removed it in the latest commit.

{
bool ret = false;

Expand Down 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