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

[PTRun][OneNote] Improve the OneNote plugin #36813

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix incorrect query text
  • Loading branch information
Odotocodot committed Jan 18, 2025
commit 88d9e3238e9c57279658eff3387af627012e0218
Original file line number Diff line number Diff line change
@@ -72,7 +72,12 @@ private string GetTitle(IOneNoteItem item, List<int>? highlightData)
return title;
}

private string GetQueryTextDisplay(IOneNoteItem item) => $"{Keywords.NotebookExplorer}{GetNicePath(item, Keywords.NotebookExplorerSeparator)}{Keywords.NotebookExplorerSeparator}";
private string GetQueryTextDisplay(IOneNoteItem? parent)
{
return parent is null
? $"{Keywords.NotebookExplorer}"
: $"{Keywords.NotebookExplorer}{GetNicePath(parent, Keywords.NotebookExplorerSeparator)}{Keywords.NotebookExplorerSeparator}";
}

internal List<Result> EmptyQuery(Query query)
{
@@ -174,7 +179,7 @@ internal Result CreateOneNoteItemResult(IOneNoteItem item, bool actionIsAutoComp

break;
case OneNotePage page:
queryTextDisplay = !actionIsAutoComplete ? string.Empty : queryTextDisplay[..^1];
queryTextDisplay = !actionIsAutoComplete ? page.Name : queryTextDisplay[..^1];

actionIsAutoComplete = false;

@@ -233,7 +238,7 @@ internal Result CreateNewPageResult(string newPageName, OneNoteSection section)
{
Title = string.Format(CultureInfo.CurrentCulture, CreatePage, newPageName),
SubTitle = string.Format(CultureInfo.CurrentCulture, Path, GetNicePath(section) + PathSeparator + newPageName),
QueryTextDisplay = $"{GetQueryTextDisplay}{newPageName}",
QueryTextDisplay = $"{GetQueryTextDisplay(section)}{newPageName}",
IcoPath = _iconProvider.NewPage,
Action = ResultAction(() =>
{
@@ -254,7 +259,7 @@ internal Result CreateNewSectionResult(string newSectionName, IOneNoteItem paren
SubTitle = validTitle
? string.Format(CultureInfo.CurrentCulture, Path, GetNicePath(parent) + PathSeparator + newSectionName)
: string.Format(CultureInfo.CurrentCulture, SectionNamesCannotContain, string.Join(' ', OneNoteApplication.InvalidSectionChars)),
QueryTextDisplay = $"{GetQueryTextDisplay}{newSectionName}",
QueryTextDisplay = $"{GetQueryTextDisplay(parent)}{newSectionName}",
IcoPath = _iconProvider.NewSection,
Action = ResultAction(() =>
{
@@ -292,7 +297,7 @@ internal Result CreateNewSectionGroupResult(string newSectionGroupName, IOneNote
SubTitle = validTitle
? string.Format(CultureInfo.CurrentCulture, Path, GetNicePath(parent) + PathSeparator + newSectionGroupName)
: string.Format(CultureInfo.CurrentCulture, SectionGroupNamesCannotContain, string.Join(' ', OneNoteApplication.InvalidSectionGroupChars)),
QueryTextDisplay = $"{GetQueryTextDisplay}{newSectionGroupName}",
QueryTextDisplay = $"{GetQueryTextDisplay(parent)}{newSectionGroupName}",
IcoPath = _iconProvider.NewSectionGroup,
Action = ResultAction(() =>
{
@@ -330,7 +335,7 @@ internal Result CreateNewNotebookResult(string newNotebookName)
SubTitle = validTitle
? string.Format(CultureInfo.CurrentCulture, Location, OneNoteApplication.GetDefaultNotebookLocation())
: string.Format(CultureInfo.CurrentCulture, NotebookNamesCannotContain, string.Join(' ', OneNoteApplication.InvalidNotebookChars)),
QueryTextDisplay = $"{GetQueryTextDisplay}{newNotebookName}",
QueryTextDisplay = $"{GetQueryTextDisplay(null)}{newNotebookName}",
IcoPath = _iconProvider.NewNotebook,
Action = ResultAction(() =>
{
@@ -426,25 +431,22 @@ internal List<Result> NoItemsInCollection(IOneNoteItem? parent, List<Result> res
results.Add(NoItemsInCollectionResult(Resources.CreateSection, _iconProvider.NewSection));
results.Add(NoItemsInCollectionResult(Resources.CreateSectionGroup, _iconProvider.NewSectionGroup));
break;
case OneNoteSection section:
case OneNoteSection section when !section.IsDeletedPages && !section.Locked:
// Can create page
if (!section.Locked)
{
results.Add(NoItemsInCollectionResult(Resources.CreatePage, _iconProvider.NewPage));
}

results.Add(NoItemsInCollectionResult(Resources.CreatePage, _iconProvider.NewPage));
break;
default:
break;
}

return results;

static Result NoItemsInCollectionResult(string title, string iconPath)
Result NoItemsInCollectionResult(string title, string iconPath)
{
return new Result
{
Title = title,
Title = string.Format(CultureInfo.CurrentCulture, title, string.Empty),
QueryTextDisplay = $"{GetQueryTextDisplay(parent)}",
SubTitle = Resources.NoItemsFoundTypeValidName,
IcoPath = iconPath,
};
Original file line number Diff line number Diff line change
@@ -167,12 +167,8 @@ private void AddCreateNewOneNoteItemResults(string newItemName, IOneNoteItem? pa
results.Add(_resultCreator.CreateNewSectionResult(newItemName, parent));
results.Add(_resultCreator.CreateNewSectionGroupResult(newItemName, parent));
break;
case OneNoteSection section:
if (!section.Locked)
{
results.Add(_resultCreator.CreateNewPageResult(newItemName, section));
}

case OneNoteSection section when !section.Locked:
results.Add(_resultCreator.CreateNewPageResult(newItemName, section));
break;
default:
break;