Fixed memory leaks

This commit is contained in:
Ben 2015-06-27 22:24:35 +01:00
parent dce21d84b3
commit 4e77075182
9 changed files with 44 additions and 17 deletions

View File

@ -8,6 +8,7 @@ namespace Filtration.Translators
internal interface IBlockGroupHierarchyBuilder internal interface IBlockGroupHierarchyBuilder
{ {
void Initialise(ItemFilterBlockGroup rootBlockGroup); void Initialise(ItemFilterBlockGroup rootBlockGroup);
void Cleanup();
ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings); ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings);
} }
@ -20,6 +21,11 @@ namespace Filtration.Translators
_rootBlockGroup = rootBlockGroup; _rootBlockGroup = rootBlockGroup;
} }
public void Cleanup()
{
_rootBlockGroup = null;
}
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings) public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings)
{ {
if (_rootBlockGroup == null) if (_rootBlockGroup == null)

View File

@ -70,7 +70,8 @@ namespace Filtration.Translators
} }
script.ThemeComponents = _themeComponentListBuilder.GetComponents(); script.ThemeComponents = _themeComponentListBuilder.GetComponents();
_blockGroupHierarchyBuilder.Cleanup();
_themeComponentListBuilder.Cleanup();
return script; return script;
} }

View File

@ -12,6 +12,7 @@ namespace Filtration.Translators
void Initialise(); void Initialise();
ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor); ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor);
List<ThemeComponent> GetComponents(); List<ThemeComponent> GetComponents();
void Cleanup();
} }
internal class ThemeComponentListBuilder : IThemeComponentListBuilder internal class ThemeComponentListBuilder : IThemeComponentListBuilder
@ -28,6 +29,11 @@ namespace Filtration.Translators
_themeComponents = new List<ThemeComponent>(); _themeComponents = new List<ThemeComponent>();
} }
public void Cleanup()
{
_themeComponents = null;
}
public ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor) public ThemeComponent AddComponent(ThemeComponentType componentType, string componentName, Color componentColor)
{ {
if (ComponentExists(componentType, componentName)) if (ComponentExists(componentType, componentName))

View File

@ -1,4 +1,5 @@
using System.Windows; using System;
using System.Windows;
using System.Windows.Media; using System.Windows.Media;
namespace Filtration.UserControls namespace Filtration.UserControls
@ -10,6 +11,7 @@ namespace Filtration.UserControls
InitializeComponent(); InitializeComponent();
// ReSharper disable once PossibleNullReferenceException // ReSharper disable once PossibleNullReferenceException
(Content as FrameworkElement).DataContext = this; (Content as FrameworkElement).DataContext = this;
} }
public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register( public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register(
@ -35,9 +37,9 @@ namespace Filtration.UserControls
public static readonly DependencyProperty BlockFontSizeProperty = DependencyProperty.Register( public static readonly DependencyProperty BlockFontSizeProperty = DependencyProperty.Register(
"BlockFontSize", "BlockFontSize",
typeof(int), typeof(double),
typeof(ItemPreviewControl), typeof(ItemPreviewControl),
new FrameworkPropertyMetadata() new FrameworkPropertyMetadata((double)19)
); );
public Color TextColor public Color TextColor
@ -58,9 +60,12 @@ namespace Filtration.UserControls
set { SetValue(BorderColorProperty, value); } set { SetValue(BorderColorProperty, value); }
} }
public int BlockFontSize public double BlockFontSize
{ {
get { return (int)GetValue(BlockFontSizeProperty); } get
{
return (double)GetValue(BlockFontSizeProperty);
}
set { SetValue(BlockFontSizeProperty, value); } set { SetValue(BlockFontSizeProperty, value); }
} }
} }

View File

@ -145,6 +145,10 @@ namespace Filtration.ViewModels
} }
_openDocuments.Remove(document); _openDocuments.Remove(document);
if (_activeDocument == document)
{
_activeDocument = null;
}
} }
public void SwitchActiveDocument(IDocument document) public void SwitchActiveDocument(IDocument document)

View File

@ -275,10 +275,16 @@ namespace Filtration.ViewModels
get { return Block.HasBlockItemOfType<FontSizeBlockItem>(); } get { return Block.HasBlockItemOfType<FontSizeBlockItem>(); }
} }
public int DisplayFontSize public double DisplayFontSize
{ {
// Dividing by 1.8 roughly scales in-game font sizes down to WPF sizes // Dividing by 1.8 roughly scales in-game font sizes down to WPF sizes
get { return HasFontSize ? (int)(BlockItems.OfType<FontSizeBlockItem>().First().Value / 1.8) : 19; } get
{
var fontSize = HasFontSize ? (BlockItems.OfType<FontSizeBlockItem>().First().Value / 1.8) : 19;
return fontSize;
}
} }
public bool HasSound public bool HasSound

View File

@ -98,8 +98,6 @@ namespace Filtration.ViewModels
{ {
case "ActiveDocumentChanged": case "ActiveDocumentChanged":
{ {
_activeDocument = _avalonDockWorkspaceViewModel.ActiveDocument;
CopyScriptCommand.RaiseCanExecuteChanged(); CopyScriptCommand.RaiseCanExecuteChanged();
SaveCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged();
SaveAsCommand.RaiseCanExecuteChanged(); SaveAsCommand.RaiseCanExecuteChanged();
@ -178,7 +176,7 @@ namespace Filtration.ViewModels
get get
{ {
{ {
var isScript = _activeDocument is ItemFilterScriptViewModel; var isScript = AvalonDockWorkspaceViewModel.ActiveDocument is ItemFilterScriptViewModel;
return isScript; return isScript;
} }
} }
@ -191,12 +189,12 @@ namespace Filtration.ViewModels
public bool ActiveDocumentIsTheme public bool ActiveDocumentIsTheme
{ {
get { { return _activeDocument is ThemeViewModel; } } get { { return AvalonDockWorkspaceViewModel.ActiveDocument is ThemeViewModel; } }
} }
private bool ActiveDocumentIsEditable() private bool ActiveDocumentIsEditable()
{ {
return _activeDocument is IEditableDocument; return AvalonDockWorkspaceViewModel.ActiveDocument is IEditableDocument;
} }
public bool ShowAdvancedStatus public bool ShowAdvancedStatus

View File

@ -31,6 +31,7 @@ namespace Filtration.ViewModels
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
private static void OnOpenScriptCommand() private static void OnOpenScriptCommand()
{ {
Messenger.Default.Send(new NotificationMessage("OpenScript")); Messenger.Default.Send(new NotificationMessage("OpenScript"));

View File

@ -24,9 +24,9 @@
AllowMixedOrientation="True" AllowMixedOrientation="True"
DocumentsSource="{Binding OpenDocuments}" DocumentsSource="{Binding OpenDocuments}"
ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}" > ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}" >
<xcad:DockingManager.Theme> <!--<xcad:DockingManager.Theme>
<xcad:Vs2013LightTheme /> <xcad:Vs2013LightTheme />
</xcad:DockingManager.Theme> </xcad:DockingManager.Theme>-->
<xcad:DockingManager.LayoutItemTemplateSelector> <xcad:DockingManager.LayoutItemTemplateSelector>
<viewsAvalonDock:PanesTemplateSelector> <viewsAvalonDock:PanesTemplateSelector>
<viewsAvalonDock:PanesTemplateSelector.ItemFilterScriptTemplate> <viewsAvalonDock:PanesTemplateSelector.ItemFilterScriptTemplate>