Skip to content

Commit

Permalink
Merge pull request #309 from storybuilder-org/BugBash7.5
Browse files Browse the repository at this point in the history
Fix Search bug and reimpliment dev menu
  • Loading branch information
terrycox authored May 15, 2022
2 parents 7f845f9 + 2d6c8b4 commit 52ab4d2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
11 changes: 8 additions & 3 deletions StoryBuilderLib/Services/Dialogs/Tools/PreferencesDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<StackPanel Width="500">
<Pivot>
<Pivot Name="PivotView">
<PivotItem Header="General">
<StackPanel>
<TextBox Header="Your name:" PlaceholderText="Put the name want to publish under here" HorizontalAlignment="Center" Margin="8" Width="300" Text="{x:Bind PreferencesVm.Name, Mode=TwoWay}"/>
Expand Down Expand Up @@ -43,9 +43,14 @@
</PivotItem>
<PivotItem Opacity="0" IsEnabled="False" Header="" Name="Dev">
<StackPanel>
<Button Content="Show init page on reload"/>
<Button Content="Crash"/>
<Button Content="Set Init to false" Click="SetInitToFalse"/>
<Button Content="Throw exception" Click="ThrowException"/>
<Button Content="Attach Elmah" Click="AttachElmah"/>
<TextBlock Name="cpuarch"/>
<TextBlock Name="osarch"/>
<TextBlock Name="osinfo"/>
<TextBlock Name="apparch"/>
<TextBlock Name="RampiUsage"/>
</StackPanel>
</PivotItem>
</Pivot>
Expand Down
30 changes: 30 additions & 0 deletions StoryBuilderLib/Services/Dialogs/Tools/PreferencesDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using StoryBuilder.Models;
using StoryBuilder.Services.Logging;
using StoryBuilder.ViewModels.Tools;
using WinRT;

Expand All @@ -21,7 +22,22 @@ public PreferencesDialog()
InitializeComponent();
DataContext = PreferencesVm;
Version.Text = "StoryBuilder Version: " + Windows.ApplicationModel.Package.Current.Id.Version.Major + "." + Windows.ApplicationModel.Package.Current.Id.Version.Minor + "." + Windows.ApplicationModel.Package.Current.Id.Version.Build + "." + Windows.ApplicationModel.Package.Current.Id.Version.Revision;

if (Debugger.IsAttached || GlobalData.Preferences.Name == "ShowMeTheDevTab")
{
Dev.IsEnabled = true;
Dev.Opacity = 1;
Dev.Header = "Dev";
cpuarch.Text = "CPU ARCH: " + RuntimeInformation.ProcessArchitecture;
osarch.Text = "OS ARCH: " + RuntimeInformation.OSArchitecture;
osinfo.Text = "OS INFO: Windows Build " + Environment.OSVersion.VersionString.Replace("Microsoft Windows NT 10.0.","").Replace(".0","");
if (IntPtr.Size == 4) { apparch.Text = "Looks like we are running as a 32 bit process."; }
else if (IntPtr.Size == 8) { apparch.Text = "Looks like we are running as a 64 bit process."; }
else { apparch.Text = $"We don't know what architecture we are running on,\nMight want to call for help.\nIntPtr was {IntPtr.Size}, expected 4 or 8."; }
}
else { PivotView.Items.Remove(Dev); }
}

private void OpenPath(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo()
Expand Down Expand Up @@ -99,4 +115,18 @@ public interface IInitializeWithWindow
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto, PreserveSig = true, SetLastError = false)]
public static extern IntPtr GetActiveWindow();

private void ThrowException(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}

private void SetInitToFalse(object sender, RoutedEventArgs e)
{
PreferencesVm.init = false;
}

private void AttachElmah(object sender, RoutedEventArgs e)
{
Ioc.Default.GetRequiredService<LogService>().AddElmahTarget();
}
}
8 changes: 8 additions & 0 deletions StoryBuilderLib/Services/Search/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using StoryBuilder.Models;
using StoryBuilder.ViewModels;
using System;
using Microsoft.Identity.Client;
using LogLevel = StoryBuilder.Services.Logging.LogLevel;

namespace StoryBuilder.Services.Search;

Expand All @@ -18,6 +20,12 @@ public class SearchService
/// <returns>true if StoryyElement contains search argument</returns>
public bool SearchStoryElement(StoryNodeItem node, string searchArg, StoryModel model)
{
if (searchArg == null)
{
Ioc.Default.GetRequiredService<ShellViewModel>().Logger.Log(LogLevel.Warn, "Search argument is null, returning false.");
return false;
} // Fixes blank search

bool result = false;
arg = searchArg.ToLower();
StoryElement element = null;
Expand Down
4 changes: 2 additions & 2 deletions StoryBuilderLib/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,11 +2062,11 @@ public ShellViewModel()
public void SearchNodes()
{
_canExecuteCommands = false; //This prevents other commands from being used till this one is complete.
Logger.Log(LogLevel.Info, "Better search started.");
Logger.Log(LogLevel.Info, $"Search started, Searching for { FilterText }");
SaveModel();
if (DataSource == null || DataSource.Count == 0)
{
Logger.Log(LogLevel.Info, "Datasource is null");
Logger.Log(LogLevel.Info, "Data source is null or Empty.");
Messenger.Send(new StatusChangedMessage(new($"You need to load a story first!", LogLevel.Warn)));

_canExecuteCommands = true;
Expand Down

0 comments on commit 52ab4d2

Please sign in to comment.