Skip to content

Commit

Permalink
Merge pull request #30 from FrozenAssassine/Fix-for-#28
Browse files Browse the repository at this point in the history
Fix for #28
  • Loading branch information
FrozenAssassine authored May 20, 2022
2 parents c4eff9c + e5f032f commit 3073adc
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Fastedit/Controls/Textbox/Searchdialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<Button.Flyout>
<Flyout Placement="Bottom">
<StackPanel CornerRadius="5" Orientation="Vertical">
<ToggleButton x:Uid="MainPage_SearchWindow_ReplaceAllButton" Width="110" Click="FindMatchCaseButton_Click" x:Name="FindMatchCaseButton" CornerRadius="0" Background="Transparent" BorderThickness="0" Content="Match case"/>
<ToggleButton x:Uid="MainPage_SearchWindow_FindMatchCase" Width="110" Click="FindMatchCaseButton_Click" x:Name="FindMatchCaseButton" CornerRadius="0" Background="Transparent" BorderThickness="0" Content="Match case"/>
<ToggleButton x:Uid="MainPage_SearchWindow_FindWholeWordButton" Width="110" Click="FindWholeWordButton_Click" x:Name="FindWholeWordButton" CornerRadius="0" Background="Transparent" BorderThickness="0" Content="Whole word"/>
</StackPanel>
</Flyout>
Expand Down
132 changes: 65 additions & 67 deletions Fastedit/Controls/Textbox/Searchdialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ namespace Fastedit.Controls.Textbox
public sealed partial class Searchdialog : UserControl
{
private AppSettings appsettings = new AppSettings();
public TabViewItem tabpage = null;
private TabActions tabactions = null;
public TextControlBox textbox = null;

public Searchdialog(TabViewItem tabpage, TabActions tabactions)
public Searchdialog(TextControlBox textbox)
{
this.InitializeComponent();
this.tabpage = tabpage;
this.tabactions = tabactions;
textbox = tabactions.GetTextBoxFromTabPage(tabpage);
this.textbox = textbox;
}

public new Brush Background
Expand All @@ -45,77 +41,91 @@ public Searchdialog(TabViewItem tabpage, TabActions tabactions)
}
public bool SearchIsOpen
{
get => SearchWindow.Visibility == Visibility.Visible;
set { SearchWindow.Visibility = Convert.BoolToVisibility(value); }
get => this.Visibility == Visibility.Visible;
set { this.Visibility = Convert.BoolToVisibility(value); }
}
public void ShowReplace(bool Show)
private bool _ReplaceIsOpen = false;
public bool ReplaceIsOpen
{
if (Show == true)
{
ExpandSearch.Begin();
SearchWindow.Height = 125;
ExpandSearchBoxForReplaceButton.Content = "\uF0AD";
appsettings.SaveSettings("SearchExpanded", 0);
TextToReplaceTextBox.Visibility = Visibility.Visible;
ReplaceAllButton.Visibility = Visibility.Visible;
StartReplaceButton.Visibility = Visibility.Visible;
}
else
get => _ReplaceIsOpen;
set
{
if (SearchWindow.Height > 45)
if (value)
{
ExpandSearch.Begin();
SearchWindow.Height = 125;
ExpandSearchBoxForReplaceButton.Content = "\uF0AD";
if(SaveToSettings)
appsettings.SaveSettings("SearchExpanded", 0);
}
else
{
CollapseSearch.Begin();
if (SearchWindow.Height > 45)
CollapseSearch.Begin();
ExpandSearchBoxForReplaceButton.Content = "\uF0AE";
if(SaveToSettings)
appsettings.SaveSettings("SearchExpanded", 1);
}
ExpandSearchBoxForReplaceButton.Content = "\uF0AE";
appsettings.SaveSettings("SearchExpanded", 1);
TextToReplaceTextBox.Visibility = Visibility.Collapsed;
ReplaceAllButton.Visibility = Visibility.Collapsed;
StartReplaceButton.Visibility = Visibility.Collapsed;
_ReplaceIsOpen = value;
TextToReplaceTextBox.Visibility = ReplaceAllButton.Visibility =
StartReplaceButton.Visibility = Convert.BoolToVisibility(value);
}
}
public void Find(bool Up = false)
{
var tb = tabactions.GetTextBoxFromSelectedTabPage();
if (tb != null)
if (textbox != null)
{
var res = tb.FindInText(TextToFindTextbox.Text, Up, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false);

SearchWindow.BorderBrush = res ? DefaultValues.CorrectInput_Color : SearchWindow.BorderBrush = DefaultValues.WrongInput_Color;
var res = textbox.FindInText(TextToFindTextbox.Text, Up, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false);
ColorWindowBorder(res);
}
}
public void ShowSearchWindow(string text = "")
public void Show(string text = "")
{
if (textbox == null)
return;

TextToFindTextbox.Text = text.Length == 0 ? textbox.SelectedText : text;
SearchIsOpen = true;

appsettings.SaveSettings("SearchOpen", true);
FindMatchCaseButton.IsChecked = appsettings.GetSettingsAsBool("FindMatchCase", false);
FindWholeWordButton.IsChecked = appsettings.GetSettingsAsBool("FindWholeWord", false);
if (SaveToSettings)
{
appsettings.SaveSettings("SearchOpen", true);
FindMatchCaseButton.IsChecked = appsettings.GetSettingsAsBool("FindMatchCase", false);
FindWholeWordButton.IsChecked = appsettings.GetSettingsAsBool("FindWholeWord", false);
}

TextToFindTextbox.Focus(FocusState.Keyboard);
TextToFindTextbox.SelectAll();
}
public void CloseSearchWindow()
public void Close()
{
SearchIsOpen = false;
appsettings.SaveSettings("SearchOpen", false);
if(SaveToSettings)
appsettings.SaveSettings("SearchOpen", false);
}
public void ToggleSearchWnd(bool Replace)
public void Toggle(bool Replace)
{
if (!SearchIsOpen)
{
ShowSearchWindow("");
this.ShowReplace(Replace);
Show("");
this.Replace(Replace);
}
else
{
CloseSearchWindow();
Close();
}
}
public void Replace(bool IsOn)
{
ReplaceIsOpen = IsOn;
}
public bool SaveToSettings { get; set; } = true;

private void ColorWindowBorder(bool state)
{
if (SaveToSettings)
SearchWindow.BorderBrush = state ? DefaultValues.CorrectInput_Color : DefaultValues.WrongInput_Color;
}
private void ReplaceTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Enter)
Expand All @@ -142,52 +152,40 @@ private void SearchDownButton_Click(object sender, RoutedEventArgs e)
}
private void FindMatchCaseButton_Click(object sender, RoutedEventArgs e)
{
appsettings.SaveSettings("FindMatchCase", FindMatchCaseButton.IsChecked);
if(SaveToSettings)
appsettings.SaveSettings("FindMatchCase", FindMatchCaseButton.IsChecked);
}
private void FindWholeWordButton_Click(object sender, RoutedEventArgs e)
{
appsettings.SaveSettings("FindWholeWord", FindWholeWordButton.IsChecked);

if(SaveToSettings)
appsettings.SaveSettings("FindWholeWord", FindWholeWordButton.IsChecked);
}
private void ReplaceAllButton_Click(object sender, RoutedEventArgs e)
{
if (textbox != null)
{
if (tabactions.GetTextBoxFromSelectedTabPage().ReplaceAll(
TextToFindTextbox.Text, TextToReplaceTextBox.Text, false, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false))
{
SearchWindow.BorderBrush = DefaultValues.CorrectInput_Color;
}
else
{
SearchWindow.BorderBrush = DefaultValues.WrongInput_Color;
}
var res = textbox.ReplaceAll(TextToFindTextbox.Text, TextToReplaceTextBox.Text,
false, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false);
ColorWindowBorder(res);
}
}
private void ReplaceCurrentButton_Click(object sender, RoutedEventArgs e)
{
if (textbox != null)
{
if (textbox.ReplaceInText(
var res = textbox.ReplaceInText(
TextToFindTextbox.Text, TextToReplaceTextBox.Text,
false, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false))
{
SearchWindow.BorderBrush = DefaultValues.CorrectInput_Color;
}
else
{
SearchWindow.BorderBrush = DefaultValues.WrongInput_Color;
}
false, FindMatchCaseButton.IsChecked ?? false, FindWholeWordButton.IsChecked ?? false);
ColorWindowBorder(res);
}
}
private void SearchWindow_CloseButtonClick(object sender, RoutedEventArgs e)
{
CloseSearchWindow();
Close();
}
private void ExpandSearchBoxForReplaceButton_Click(object sender, RoutedEventArgs e)
{
ShowSearchWindow();
ShowReplace(appsettings.GetSettingsAsInt("SearchExpanded", 0) == 1);
Replace(SaveToSettings ? appsettings.GetSettingsAsInt("SearchExpanded", 0) == 1 : !ReplaceIsOpen);
}
private void TextBoxes_GotFocus(object sender, RoutedEventArgs e)
{
Expand Down
6 changes: 6 additions & 0 deletions Fastedit/Strings/de-DE/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,10 @@
<data name="FileInfo_Lines.Text" xml:space="preserve">
<value>Zeilen:</value>
</data>
<data name="MainPage_SearchWindow_FindMatchCase.Text" xml:space="preserve">
<value>Groß/Kleinschreibung</value>
</data>
<data name="MainPage_SearchWindow_FindWholeWordButton.Text" xml:space="preserve">
<value>Ganzes Wort</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Fastedit/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1096,4 +1096,10 @@
<data name="FileInfo_Lines.Text" xml:space="preserve">
<value>Lines:</value>
</data>
<data name="MainPage_SearchWindow_FindMatchCase.Text" xml:space="preserve">
<value>Match case</value>
</data>
<data name="MainPage_SearchWindow_FindWholeWordButton.Text" xml:space="preserve">
<value>Whole word</value>
</data>
</root>
28 changes: 14 additions & 14 deletions Fastedit/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public MainPage()
secondaryeditinginstance = new SecondaryEditingInstance(this, tabactions, TextTabControl);
if (searchdialog == null)
{
searchdialog = new Searchdialog(CurrentlySelectedTabPage, tabactions);
searchdialog = new Searchdialog(CurrentlySelectedTabPage_Textbox);
searchdialog.Visibility = Visibility.Collapsed;
SearchReplaceWindowDisplay.Children.Add(searchdialog);
}

Expand Down Expand Up @@ -305,12 +306,12 @@ private async void MainPage_KeyDown(object sender, KeyRoutedEventArgs e)

if (searchdialog.SearchIsOpen && !GoToLineWindowIsOpen)
{
searchdialog.CloseSearchWindow();
searchdialog.Close();
}

if (searchdialog.SearchIsOpen && GoToLineWindowIsOpen)
{
searchdialog.CloseSearchWindow();
searchdialog.Close();
CloseGoToLineDialog();
}

Expand All @@ -327,8 +328,8 @@ private async void MainPage_KeyDown(object sender, KeyRoutedEventArgs e)
if (Tab != null)
{
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.G, ShowGoToLineWindow);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.F, searchdialog.ToggleSearchWnd, false);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.R, searchdialog.ToggleSearchWnd, true);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.F, searchdialog.Toggle, false);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.R, searchdialog.Toggle, true);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.W, CloseSelectedTab_SaveDatabase);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.J, ShowFileInfoDialog);
KeyboardCommands.KeyboardCommand(e.Key, VirtualKey.E, ShowEncodingDialog);
Expand Down Expand Up @@ -516,7 +517,6 @@ private async void TextTabControl_SelectionChanged(object sender, SelectionChang
CurrentlySelectedTabPage = tabpage;
CurrentlySelectedTabPage_Textbox = textbox;
searchdialog.textbox = textbox;
searchdialog.tabpage = tabpage;

SettingsWindowSelected = false;

Expand Down Expand Up @@ -910,12 +910,12 @@ private void SetSettingsToSearchDialog()

//Search dialog:
if (appsettings.GetSettingsAsBool("SearchOpen", false))
searchdialog.ShowSearchWindow("");
searchdialog.Show("");
else
searchdialog.CloseSearchWindow();
searchdialog.Close();

//Expand the search for replacing:
searchdialog.ShowReplace(!(appsettings.GetSettingsAsInt("SearchExpanded", 1) == 1));
searchdialog.Replace(!(appsettings.GetSettingsAsInt("SearchExpanded", 1) == 1));
}
private void SetSettingsToTabControl()
{
Expand Down Expand Up @@ -1432,12 +1432,12 @@ private void SearchWindow_Action()
{
if (!searchdialog.SearchIsOpen && CurrentlySelectedTabPage_Textbox != null)
{
searchdialog.ShowSearchWindow(CurrentlySelectedTabPage_Textbox.SelectedText);
searchdialog.ShowReplace(false);
searchdialog.Show(CurrentlySelectedTabPage_Textbox.SelectedText);
searchdialog.Replace(false);
}
else
{
searchdialog.CloseSearchWindow();
searchdialog.Close();
}
}
private void Share_Action()
Expand Down Expand Up @@ -1766,8 +1766,8 @@ private void DuplicateLine_Click(object sender, RoutedEventArgs e)
//Search-Dialog
private void ExpandSearchBoxForReplaceButton_Click(object sender, RoutedEventArgs e)
{
searchdialog.ShowSearchWindow();
searchdialog.ShowReplace(appsettings.GetSettingsAsInt("SearchExpanded", 0) == 1);
searchdialog.Show();
searchdialog.Replace(appsettings.GetSettingsAsInt("SearchExpanded", 0) == 1);
}

//Go to line dialog
Expand Down
3 changes: 3 additions & 0 deletions Fastedit/Views/TextboxViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
</StackPanel>
<Grid Margin="0,30,0,0" HorizontalAlignment="Stretch" Height="2" x:Name="OverTextboxLine"/>
<textbox:TextControlBox LineNumberForeground="purple" Margin="0,32,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="MainTextbox"/>
<StackPanel x:Name="SearchGoToLineViewWindow" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,30,0,0">

</StackPanel>
</Grid>
</Page>
Loading

0 comments on commit 3073adc

Please sign in to comment.