Skip to content

Commit

Permalink
Merge pull request #484 from BlueDotBrigade/Features/251-ResizeFont
Browse files Browse the repository at this point in the history
Merge `Features/251` branch to main: for user can resize application font
  • Loading branch information
Pressacco authored Feb 8, 2025
2 parents aa86ad0 + 529d815 commit f75a240
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Src/BlueDotBrigade.Weevil.Gui/Filter/FilterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
IsChecked="{Binding AreFilterOptionsVisible, Mode=TwoWay}"
IsEnabled="{Binding IsFilterToolboxEnabled}" />
<Button Grid.Column="4"
Command="{Binding FilterOrCancelCommand}"
Command="{Binding FilterOrCancelCommand}"
Style="{StaticResource MaterialDesignRaisedButton}"
Margin="{StaticResource ButtonMargin}"
IsEnabled="{Binding IsFilterToolboxEnabled}" >
Expand Down Expand Up @@ -277,7 +277,7 @@
<MenuItem Header="Between Selected Records" Command="{Binding ClearBetweenSelectedRecordsCommand}" />
<MenuItem Header="After Selected Record" Command="{Binding ClearAfterSelectedRecordCommand}" />
<Separator/>
<MenuItem Header="Clear Outside Regions" Command="{Binding ClearOutsideRegionsCommand}" />
<MenuItem Header="Clear Outside Regions" Command="{Binding ClearBeyondRegionsCommand}" />
<Separator/>
<MenuItem Header="Selected Comments" Command="{Binding RemoveSelectedCommentsCommand}" InputGestureText="Back" />
<MenuItem Header="All Comments" Command="{Binding RemoveAllCommentsCommand}" InputGestureText="Ctrl+Shift+Back"/>
Expand Down Expand Up @@ -462,7 +462,8 @@
</ListView>
<StackPanel Grid.Row="1"
Visibility="{Binding IsProcessingLongOperation, Converter={StaticResource BooleanToVisibilityConverter}}"
VerticalAlignment="Center" HorizontalAlignment="Center" >
VerticalAlignment="Center" HorizontalAlignment="Center"
IsVisibleChanged="OnProgressBarVisibilityChanged">
<TextBlock Text="Boring log file for tasty bytes..." />
<ProgressBar Width="200" Height="15" Foreground="LightSkyBlue" BorderBrush="Blue"
Value="0"
Expand Down
61 changes: 54 additions & 7 deletions Src/BlueDotBrigade.Weevil.Gui/Filter/FilterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@
/// </summary>
public partial class FilterView : UserControl
{
private bool _isLogFileOpening;

public FilterView()
{
DataContextChanged += (sender, args) =>
{
if (args.OldValue != null)
{
((FilterViewModel)args.OldValue).ResultsChanged -= OnResultsChanged;
var viewModel = args.OldValue as FilterViewModel;

viewModel.FileOpened -= OnFileOpened;
viewModel.ResultsChanged -= OnResultsChanged;
viewModel.RegionsChanged -= OnRegionsChanged;
}
if (args.NewValue != null)
{
((FilterViewModel)args.NewValue).ResultsChanged += OnResultsChanged;
var viewModel = args.NewValue as FilterViewModel;

viewModel.FileOpened += OnFileOpened;
viewModel.ResultsChanged += OnResultsChanged;
viewModel.RegionsChanged += OnRegionsChanged;
}
};

Expand All @@ -35,6 +45,8 @@ public FilterView()
Loaded += OnControlLoaded;
}

private FilterViewModel ViewModel => (FilterViewModel)this.DataContext;

private void OnControlLoaded(object sender, System.Windows.RoutedEventArgs e)
{
var window = Window.GetWindow(this);
Expand All @@ -55,7 +67,16 @@ private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArg
}
}

private FilterViewModel ViewModel => (FilterViewModel)this.DataContext;
private void OnFileOpened(object sender, EventArgs e)
{
_isLogFileOpening = true;
}

private void OnRegionsChanged(object sender, EventArgs e)
{
// Force bindings (and converters) for only the visible items to be refreshed.
this.ListView.Items.Refresh();
}

private void OnResultsChanged(object sender, EventArgs e)
{
Expand All @@ -67,9 +88,6 @@ private void OnResultsChanged(object sender, EventArgs e)
{
this.ListView.SelectedItems.Add(record);
}

// Force bindings (and converters) for only the visible items to be refreshed.
this.ListView.Items.Refresh();
}
catch (Exception exception)
{
Expand Down Expand Up @@ -138,6 +156,19 @@ private void OnGotFocus(object sender, RoutedEventArgs e)
}
}

/// <summary>
/// Adjusts the position and size of user controls, thus ensuring that they have been
/// arranged correctly based on the available space and layout rules.
/// </summary>
/// <remarks>
/// Layout is influenced by a number of factors:
/// <list type="bullet">
/// <item>font size</item>
/// <item>column width</item>
/// <item>only applies to visible controls</item>
/// <item>etc.</item>
/// </list>
/// </remarks>
private void UpdateLayout()
{
base.UpdateLayout();
Expand Down Expand Up @@ -199,7 +230,23 @@ private void RowFontSizeSlider_ValueChanged(object sender, RoutedPropertyChanged

Application.Current.Resources["RowFontSize"] = e.NewValue;
Settings.Default.RowFontSize = e.NewValue;
Settings.Default.Save();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
UpdateLayout();
}

private void OnProgressBarVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if(_isLogFileOpening)
{
_isLogFileOpening = false;

// The following ensures that the filter results are displayed properly.
// NOTE: The ListView layout can only be adjusted when the control is visible (i.e. progress bar hidden).
UpdateLayout();
}
}
}
}
61 changes: 51 additions & 10 deletions Src/BlueDotBrigade.Weevil.Gui/Filter/FilterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ internal partial class FilterViewModel : IDropTarget, INotifyPropertyChanged

private readonly DragAndDropViewModel _dragAndDrop;

public event PropertyChangedEventHandler PropertyChanged;

private string _inclusiveFilter;
private string _exclusiveFilter;

Expand Down Expand Up @@ -308,7 +306,23 @@ public string SourceFileRemarks

public ObservableCollection<MenuItemViewModel> CustomAnalyzerCommands { get; }

public event PropertyChangedEventHandler PropertyChanged;

/// <summary>
/// Indicates that the records have changed due to either:
/// <list type="bullet">
/// <item>opening a new file</item>
/// <item>applying a filter</item>
/// </list>
/// </summary>
public event EventHandler ResultsChanged;

/// <summary>
/// Indicates that a region of interest has been added, removed, or modified.
/// </summary>
public event EventHandler RegionsChanged;

public event EventHandler FileOpened;
#endregion

#region Event Handlers
Expand Down Expand Up @@ -431,7 +445,7 @@ public async Task OpenAsync(string sourceFilePath)
this.IsFilterToolboxEnabled = false;

var openAsResult = new OpenAsResult();
var wasFileOpened = false;
var wasOpenRequested = false;

try
{
Expand All @@ -444,12 +458,12 @@ public async Task OpenAsync(string sourceFilePath)
(path) => Engine.UsingPath(path),
sourceFilePath);

wasFileOpened = result.Item1;
wasOpenRequested = result.Item1;
openAsResult = result.Item2;
}
else
{
wasFileOpened = true;
wasOpenRequested = true;
}
}
catch (NotSupportedException e)
Expand All @@ -462,7 +476,7 @@ public async Task OpenAsync(string sourceFilePath)
MessageBox.Show(message, "Open Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
}

if (wasFileOpened)
if (wasOpenRequested)
{
await Task.Run(() =>
{
Expand All @@ -481,6 +495,8 @@ await Task.Run(() =>
.UsingRange(openAsResult.Range)
.Open();

this.FileOpened?.Invoke(this, EventArgs.Empty);

_bulletinMediator.Post(new SourceFileOpenedBulletin
{
SourceFilePath = _engine.SourceFilePath,
Expand All @@ -489,7 +505,6 @@ await Task.Run(() =>
TotalRecordCount = _engine.Count
});


_uiDispatcher.Invoke(() =>
{
this.SourceFileRemarks = _engine.SourceFileRemarks;
Expand Down Expand Up @@ -518,7 +533,6 @@ await Task.Run(() =>

RefreshFilterResults();


var analyzers = _engine
.Analyzer
.GetAnalyzers(ComponentType.Extension)
Expand Down Expand Up @@ -1213,6 +1227,29 @@ public void RemoveComments(bool clearAll)
}

#endregion
protected virtual void RaiseRegionsChanged()
{
EventHandler threadSafeHandler = this.RegionsChanged;

if (threadSafeHandler != null)
{
try
{
Log.Default.Write(
LogSeverityType.Debug,
$"Raising the {nameof(RegionsChanged)} event.");

_uiDispatcher.Invoke(() => threadSafeHandler(this, EventArgs.Empty));
}
catch (Exception exception)
{
Log.Default.Write(
LogSeverityType.Error,
exception,
$"An unexpected error occurred while raising the {nameof(RegionsChanged)} event.");
}
}
}

protected virtual void RaiseResultsChanged()
{
Expand All @@ -1222,6 +1259,10 @@ protected virtual void RaiseResultsChanged()
{
try
{
Log.Default.Write(
LogSeverityType.Debug,
$"Raising the {nameof(ResultsChanged)} event.");

_uiDispatcher.Invoke(() => threadSafeHandler(this, EventArgs.Empty));
}
catch (Exception exception)
Expand Down Expand Up @@ -1466,7 +1507,7 @@ private void AddRegion()
{
var selectedLineNumbers = _engine.Selector.Selected.Keys.ToArray();
_engine.Regions.CreateFromSelection(selectedLineNumbers);
RaiseResultsChanged();
RaiseRegionsChanged();
}
}
catch (Exception e)
Expand All @@ -1478,7 +1519,7 @@ private void AddRegion()
private void RemoveAllRegions()
{
_engine.Regions.Clear();
RaiseResultsChanged();
RaiseRegionsChanged();
}

public bool RegionStartsWith(IRecord record, out string regionName)
Expand Down

0 comments on commit f75a240

Please sign in to comment.