Skip to content

Commit

Permalink
highlight hashtags, grep prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored and weissm committed Dec 28, 2023
1 parent b8e4b26 commit 8ec87c5
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 15 deletions.
21 changes: 17 additions & 4 deletions OneMore/Commands/Search/SearchAndReplaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public override async Task Execute(params object[] args)
string withText;
bool matchCase;
bool useRegex;
XElement withElement;

using var one = new OneNote(out var page, out _);
var text = page.GetSelectedText();
Expand All @@ -46,15 +47,27 @@ public override async Task Execute(params object[] args)
withText = dialog.WithText;
matchCase = dialog.MatchCase;
useRegex = dialog.UseRegex;
withElement = dialog.RawXml;
}

// let user insert a newline char
withText = withText.Replace("\\n", "\n");

var editor = new SearchAndReplaceEditor(whatText, withText,
enableRegex: useRegex,
caseSensitive: matchCase
);
SearchAndReplaceEditor editor;
if (withElement == null)
{
editor = new SearchAndReplaceEditor(whatText, withText,
enableRegex: useRegex,
caseSensitive: matchCase
);
}
else
{
editor = new SearchAndReplaceEditor(whatText, withElement,
enableRegex: useRegex,
caseSensitive: matchCase
);
}

var count = editor.SearchAndReplace(page);

Expand Down
22 changes: 19 additions & 3 deletions OneMore/Commands/Search/SearchAndReplaceDialog.Designer.cs

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

43 changes: 43 additions & 0 deletions OneMore/Commands/Search/SearchAndReplaceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public SearchAndReplaceDialog()
"withLabel",
"matchBox",
"regBox",
"rawBox",
"okButton=word_OK",
"cancelButton=word_Cancel"
});
Expand All @@ -46,6 +47,14 @@ public SearchAndReplaceDialog()
private void LoadSettings()
{
var provider = new SettingsProvider();

var experimental = provider.GetCollection("GeneralSheet").Get<bool>("experimental");
if (!experimental)
{
rawBox.Visible = false;
Height -= rawBox.Height;
}

var settings = provider.GetCollection("SearchReplace");
if (settings != null)
{
Expand All @@ -72,6 +81,8 @@ private void LoadSettings()

public bool MatchCase => matchBox.Checked;

public XElement RawXml { get; private set; }

public string WithText => withBox.Text;

public bool UseRegex => regBox.Checked;
Expand All @@ -97,6 +108,12 @@ private void ToggleRegex(object sender, EventArgs e)
}


private void ToggleRawXml(object sender, EventArgs e)
{
CheckXmlFormat(sender, e);
}


private void CheckPattern(object sender, EventArgs e)
{
var text = whatBox.Text.Trim();
Expand Down Expand Up @@ -149,6 +166,32 @@ private void CheckPattern(object sender, EventArgs e)
}


private void CheckXmlFormat(object sender, EventArgs e)
{
if (rawBox.Checked)
{
var xml = withBox.Text.Trim();
try
{
RawXml = XElement.Parse(xml);
}
catch
{
withStatusLabel.Text = "XML format is not correct";
return;
}
}
else
{
RawXml = null;
}

// ensure whatStatus is restored correctly
CheckPattern(sender, e);
}



private void SelectedWhat(object sender, EventArgs e)
{
if (whatBox.SelectedIndex >= 0 && whatBox.SelectedIndex < whats.Elements().Count())
Expand Down
7 changes: 3 additions & 4 deletions OneMore/Commands/Search/SearchAndReplaceEditor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//************************************************************************************************
// Copyright © 2020 Steven M Cohn. All rights reserved.
// Copyright © 2020 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;

Expand Down Expand Up @@ -130,7 +129,7 @@ private int SearchAndReplace(XElement element)
else if (match.Groups.Count > 1)
{
Replace(wrapper, match.Groups[1].Index, match.Groups[1].Length,
replaceElement == null ? ExpandReplacement(match) : null);
replaceElement == null ? ExpandSubstitutions(match) : null);
}
}

Expand All @@ -144,7 +143,7 @@ private int SearchAndReplace(XElement element)


// Substitute $1..$n parameters in replacementString with capture groups
private string ExpandReplacement(Match match)
private string ExpandSubstitutions(Match match)
{
if (string.IsNullOrWhiteSpace(replacementString))
{
Expand Down
17 changes: 15 additions & 2 deletions OneMore/Commands/Settings/GeneralSheet.Designer.cs

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

11 changes: 9 additions & 2 deletions OneMore/Commands/Settings/GeneralSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ public GeneralSheet(SettingsProvider provider) : base(provider)
"checkUpdatesBox",
"langLabel",
"advancedGroup=phrase_AdvancedOptions",
"verboseBox"
"verboseBox",
"experimentalBox"
});
}

var settings = provider.GetCollection(Name);

checkUpdatesBox.Checked = settings.Get("checkUpdates", false);
verboseBox.Checked = settings.Get("verbose", false);
experimentalBox.Checked = settings.Get("experimental", false);

var lang = settings.Get("language", "en-US");
foreach (CultureInfo info in langBox.Items)
Expand Down Expand Up @@ -111,11 +113,16 @@ public override bool CollectSettings()

var lang = ((CultureInfo)(langBox.SelectedItem)).Name;
var updated = settings.Add("language", lang);


// requires a restart
updated = verboseBox.Checked
? settings.Add("verbose", true) || updated
: settings.Remove("verbose") || updated;

updated = experimentalBox.Checked
? settings.Add("experimental", true) || updated
: settings.Remove("experimental") || updated;

// deprecated
updated = settings.Remove("imageViewer") || updated;

Expand Down
18 changes: 18 additions & 0 deletions OneMore/Properties/Resources.Designer.cs

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

8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.ar-SA.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,10 @@
<value>تحقق من وجود إصدارات جديدة من OneMore عند بدء OneNote</value>
<comment>checkbox</comment>
</data>
<data name="GeneralSheet_experimentalBox.Text" xml:space="preserve">
<value>تمكين الميزات التجريبية</value>
<comment>checkbox</comment>
</data>
<data name="GeneralSheet_introBox.Text" xml:space="preserve">
<value>تخصيص السلوك العام لـ OneMore</value>
<comment>textbox</comment>
Expand Down Expand Up @@ -3921,6 +3925,10 @@ ISO-code then comma then language name</comment>
<value>حالة مباراة</value>
<comment>checkbox</comment>
</data>
<data name="SearchAndReplaceDialog_rawBox.Text" xml:space="preserve">
<value>استبدله بـ XML الخام</value>
<comment>checkbox</comment>
</data>
<data name="SearchAndReplaceDialog_regBox.Text" xml:space="preserve">
<value>استخدم التعبيرات العادية</value>
<comment>checkbox</comment>
Expand Down
8 changes: 8 additions & 0 deletions OneMore/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,10 @@ Symbole: PI, E</value>
<value>Beim Start von OneNote nach neuen Versionen von OneMore suchen</value>
<comment>checkbox</comment>
</data>
<data name="GeneralSheet_experimentalBox.Text" xml:space="preserve">
<value>Aktivieren Sie experimentelle Funktionen</value>
<comment>checkbox</comment>
</data>
<data name="GeneralSheet_introBox.Text" xml:space="preserve">
<value>Passe das Gesamtverhalten von OneMore an</value>
<comment>textbox</comment>
Expand Down Expand Up @@ -3911,6 +3915,10 @@ Polaroid</value>
<value>Match Case</value>
<comment>checkbox</comment>
</data>
<data name="SearchAndReplaceDialog_rawBox.Text" xml:space="preserve">
<value>Durch rohes XML ersetzen</value>
<comment>checkbox</comment>
</data>
<data name="SearchAndReplaceDialog_regBox.Text" xml:space="preserve">
<value>Verwende reguläre Ausdrücke</value>
<comment>checkbox</comment>
Expand Down
Loading

0 comments on commit 8ec87c5

Please sign in to comment.