Skip to content

Commit

Permalink
In Find split the Text option into Original and Translated
Browse files Browse the repository at this point in the history
  • Loading branch information
Klocman committed Aug 8, 2022
1 parent 79f5c15 commit 1b24807
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 70 deletions.
13 changes: 10 additions & 3 deletions src/Controls/ResourceGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private void ApplyConditionalFormatting(DataGridViewRow r)

ApplyConditionalCellFormatting(r.Cells[Properties.Resources.ColNameKey], SearchParams.TargetType.Key);

ApplyConditionalCellFormatting(r.Cells[Properties.Resources.ColNameNoLang], SearchParams.TargetType.Text);
ApplyConditionalCellFormatting(r.Cells[Properties.Resources.ColNameNoLang], SearchParams.TargetType.OriginalText);

foreach (var lng in CurrentResource.Languages.Values)
{
ApplyConditionalCellFormatting(r.Cells[lng.LanguageId], SearchParams.TargetType.Text);
ApplyConditionalCellFormatting(r.Cells[lng.LanguageId], SearchParams.TargetType.TranslatedText);
}
}

Expand Down Expand Up @@ -387,6 +387,7 @@ public void SelectNextSearchResult()
if (CurrentSearch == null) return;

var keyColumn = dataGridView1.Columns[Properties.Resources.ColNameKey];
var nolangColumn = dataGridView1.Columns[Properties.Resources.ColNameNoLang];

var currentRow = dataGridView1.CurrentCell?.RowIndex ?? dataGridView1.RowCount;
var currentColumn = dataGridView1.CurrentCell?.ColumnIndex ?? -1;
Expand All @@ -399,7 +400,13 @@ public void SelectNextSearchResult()

if (!(cell.Value is string s)) continue;

if (CurrentSearch.Match(cell.OwningColumn == keyColumn ? SearchParams.TargetType.Key : SearchParams.TargetType.Text, s))
var targetType = cell.OwningColumn == keyColumn
? SearchParams.TargetType.Key
: cell.OwningColumn == nolangColumn
? SearchParams.TargetType.OriginalText
: SearchParams.TargetType.TranslatedText;

if (CurrentSearch.Match(targetType, s))
{
dataGridView1.CurrentCell = cell;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/ResourceTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ private static bool MatchNodeToSearch(SearchParams searchParams, TreeNode treeNo
{
if (searchParams.Match(SearchParams.TargetType.Key, row[Properties.Resources.ColNameKey].ToString()))
return true;
if (searchParams.Match(SearchParams.TargetType.Text, row[Properties.Resources.ColNameNoLang].ToString()))
if (searchParams.Match(SearchParams.TargetType.OriginalText, row[Properties.Resources.ColNameNoLang].ToString()))
return true;
if (resource.Languages.Values.Any(
lng => searchParams.Match(SearchParams.TargetType.Text, row[lng.LanguageId].ToString())))
lng => searchParams.Match(SearchParams.TargetType.TranslatedText, row[lng.LanguageId].ToString())))
return true;
}

Expand Down
59 changes: 32 additions & 27 deletions src/ResourceOperations/SearchParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum TargetType
{
Lang,
Key,
Text,
OriginalText,
TranslatedText,
File
}

Expand All @@ -21,20 +22,14 @@ public SearchParams()
{
}

public SearchParams(string text
, bool searchLanguage
, bool searchKeys
, bool searchText
, bool searchFileName
, bool useRegex
, bool optCase
, bool optWord)
public SearchParams(string text, bool searchLanguage, bool searchKeys, bool searchOriginalText, bool searchTranslatedText, bool searchFileName, bool useRegex, bool optCase, bool optWord)
{
Text = text;

SearchLanguage = searchLanguage;
SearchKeys = searchKeys;
SearchText = searchText;
SearchOriginalText = searchOriginalText;
SearchTranslatedText = searchTranslatedText;
SearchFileName = searchFileName;
UseRegex = useRegex;
OptCase = optCase;
Expand All @@ -45,63 +40,71 @@ public SearchParams(string text
[DefaultSettingValue("false")]
public bool OptCase
{
get { return (bool) this["optCase"]; }
get { return (bool)this["optCase"]; }
set { this["optCase"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("false")]
public bool OptWord
{
get { return (bool) this["optWord"]; }
get { return (bool)this["optWord"]; }
set { this["optWord"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("false")]
public bool SearchKeys
{
get { return (bool) this["searchKeys"]; }
get { return (bool)this["searchKeys"]; }
set { this["searchKeys"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("false")]
public bool SearchLanguage
{
get { return (bool) this["searchLanguage"]; }
get { return (bool)this["searchLanguage"]; }
set { this["searchLanguage"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("true")]
public bool SearchText
public bool SearchOriginalText
{
get { return (bool) this["searchText"]; }
set { this["searchText"] = value; }
get { return (bool)this["searchOriginalText"]; }
set { this["searchOriginalText"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("true")]
public bool SearchTranslatedText
{
get { return (bool)this["searchTranslatedText"]; }
set { this["searchTranslatedText"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("false")]
public bool SearchFileName
{
get { return (bool) this["searchFileName"]; }
get { return (bool)this["searchFileName"]; }
set { this["searchFileName"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("")]
public string Text
{
get { return (string) this["text"]; }
get { return (string)this["text"]; }
set { this["text"] = value; }
}

[UserScopedSetting]
[DefaultSettingValue("false")]
public bool UseRegex
{
get { return (bool) this["useRegex"]; }
get { return (bool)this["useRegex"]; }
set { this["useRegex"] = value; }
}

Expand Down Expand Up @@ -132,13 +135,15 @@ public bool Match(TargetType targType, string matchText)
if (_re == null)
_re = GetComparator();

if (targType == TargetType.Key && SearchKeys && _re.IsMatch(matchText))
return true;
if (targType == TargetType.Lang && SearchLanguage && _re.IsMatch(matchText))
return true;
if (targType == TargetType.Text && SearchText && _re.IsMatch(matchText))
return true;
return targType == TargetType.File && SearchFileName && _re.IsMatch(matchText);
switch (targType)
{
case TargetType.Key: return SearchKeys && _re.IsMatch(matchText);
case TargetType.Lang: return SearchLanguage && _re.IsMatch(matchText);
case TargetType.OriginalText: return SearchOriginalText && _re.IsMatch(matchText);
case TargetType.TranslatedText: return SearchTranslatedText && _re.IsMatch(matchText);
case TargetType.File: return SearchFileName && _re.IsMatch(matchText);
default: return false;
}
}
}
}
34 changes: 23 additions & 11 deletions src/Windows/FindWindow.Designer.cs

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

6 changes: 4 additions & 2 deletions src/Windows/FindWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ private void buttonFind_Click(object sender, EventArgs e)
textBoxSearch.Text
, checkBoxLang.Checked
, checkBoxKey.Checked
, checkBoxText.Checked
, checkBoxOrigText.Checked
, checkBoxTranslText.Checked
, checkBoxFile.Checked
, radioButtonRegexp.Checked
, checkBoxCS.Checked
Expand All @@ -48,7 +49,8 @@ private void FindDialog_Load(object sender, EventArgs e)
textBoxSearch.Text = sp.Text;
checkBoxLang.Checked = sp.SearchLanguage;
checkBoxKey.Checked = sp.SearchKeys;
checkBoxText.Checked = sp.SearchText;
checkBoxOrigText.Checked = sp.SearchOriginalText;
checkBoxTranslText.Checked = sp.SearchTranslatedText;
checkBoxFile.Checked = sp.SearchFileName;
radioButtonRegexp.Checked = sp.UseRegex;
checkBoxCS.Checked = sp.OptCase;
Expand Down
Loading

0 comments on commit 1b24807

Please sign in to comment.