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

Add a command to navigate to a certain page by incremental search #1044

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
8 changes: 6 additions & 2 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,15 @@ public async Task SaveSnippetCmd(IRibbonControl control)


[Command("ribSearchButton_Label", Keys.None, "ribSearchMenu")]
public async Task SearchCmd(IRibbonControl control)
public async Task SearchCmd(IRibbonControl control)
=> await factory.Run<SearchCommand>();

[Command("ribNaviButton_Label", Keys.F7, "ribSearchMenu")]
public async Task NaviPagesCmd(IRibbonControl control)
=> await factory.Run<NaviPagesCommand>();

[Command("ribSearchAndReplaceButton_Label", Keys.Control | Keys.H, "ribSearchMenu")]

[Command("ribSearchAndReplaceButton_Label", Keys.Control | Keys.H, "ribSearchMenu")]
public async Task SearchAndReplaceCmd(IRibbonControl control)
=> await factory.Run<SearchAndReplaceCommand>();

Expand Down
203 changes: 203 additions & 0 deletions OneMore/Commands/Navigator/NaviDialog.Designer.cs
valuex marked this conversation as resolved.
Show resolved Hide resolved

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

149 changes: 149 additions & 0 deletions OneMore/Commands/Navigator/NaviDialog.cs
valuex marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//************************************************************************************************
// Copyright © 2020 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands.Search
{
using River.OneMoreAddIn.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;
using Resx = River.OneMoreAddIn.Properties.Resources;


internal partial class NaviDialog : LocalizableForm
{
private readonly OneNote one;


public NaviDialog()
{
InitializeComponent();

if (NeedsLocalizing())
{
Text = Resx.SearchDialog_Title;

Localize(new string[]
{
"introLabel",
"findLabel",
"moveButton=word_Move",
"copyButton=word_Copy",
"cancelButton=word_Cancel"
});

scopeBox.Items.Clear();
scopeBox.Items.AddRange(Resx.SearchDialog_scopeBox_Items.Split(new char[] { '\n' }));
}

scopeBox.SelectedIndex = 0;
SelectedPages = new List<string>();

one = new OneNote();
}


public bool CopySelections { get; private set; }


public List<string> SelectedPages { get; private set; }


private void ChangeQuery(object sender, EventArgs e)
{
searchButton.Enabled = findBox.Text.Trim().Length > 0;
}


private void SearchOnKeydown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter &&
findBox.Text.Trim().Length > 0)
{
Search(sender, e);
}
}


private void Search(object sender, EventArgs e)
{
resultTree.Nodes.Clear();

string startId = string.Empty;
switch (scopeBox.SelectedIndex)
{
case 1: startId = one.CurrentNotebookId; break;
case 2: startId = one.CurrentSectionId; break;
}

var results = one.Search(startId, findBox.Text);

if (results.HasElements)
{
resultTree.Populate(results, one.GetNamespace(results));
}
}


// async event handlers should be be declared 'async void'
private async void ClickNode(object sender, TreeNodeMouseClickEventArgs e)
{
// thanksfully, Bounds specifies bounds of label
var node = e.Node as HierarchyNode;
if (node.Hyperlinked && e.Node.Bounds.Contains(e.Location))
{
var pageId = node.Root.Attribute("ID").Value;
if (!pageId.Equals(one.CurrentPageId))
{
await one.NavigateTo(pageId);
}
}
}


private void TreeAfterCheck(object sender, TreeViewEventArgs e)
{
var node = e.Node as HierarchyNode;
var id = node.Root.Attribute("ID").Value;

if (node.Checked)
{
if (!SelectedPages.Contains(id))
{
SelectedPages.Add(id);
}
}
else if (SelectedPages.Contains(id))
{
SelectedPages.Remove(id);
}

copyButton.Enabled = moveButton.Enabled = SelectedPages.Count > 0;
}


private void CopyPressed(object sender, EventArgs e)
{
CopySelections = true;
DialogResult = DialogResult.OK;
Close();
}


private void MovePressed(object sender, EventArgs e)
{
CopySelections = false;
DialogResult = DialogResult.OK;
Close();
}

private void Nevermind(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}
Loading