Fixed crash when clicking Close menu option with no script/theme open
Fixed memory leak when documents are closed.
This commit is contained in:
parent
b5788504cb
commit
9d928a374a
|
@ -171,6 +171,19 @@ namespace Filtration.ViewModels
|
||||||
{
|
{
|
||||||
_activeDocument = null;
|
_activeDocument = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Replace _activeScriptViewModel and _activeThemeViewModel with a better solution.
|
||||||
|
|
||||||
|
if (document.IsScript && _activeScriptViewModel == (IItemFilterScriptViewModel) document)
|
||||||
|
{
|
||||||
|
_activeScriptViewModel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.IsTheme && _activeThemeViewModel == (IThemeEditorViewModel)document)
|
||||||
|
{
|
||||||
|
_activeThemeViewModel = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchActiveDocument(IDocument document)
|
public void SwitchActiveDocument(IDocument document)
|
||||||
|
|
|
@ -49,8 +49,6 @@ namespace Filtration.ViewModels
|
||||||
private readonly IUpdateCheckService _updateCheckService;
|
private readonly IUpdateCheckService _updateCheckService;
|
||||||
private readonly IUpdateAvailableViewModel _updateAvailableViewModel;
|
private readonly IUpdateAvailableViewModel _updateAvailableViewModel;
|
||||||
private readonly IMessageBoxService _messageBoxService;
|
private readonly IMessageBoxService _messageBoxService;
|
||||||
private bool _activeDocumentIsScript;
|
|
||||||
private bool _activeDocumentIsTheme;
|
|
||||||
|
|
||||||
public MainWindowViewModel(IItemFilterScriptRepository itemFilterScriptRepository,
|
public MainWindowViewModel(IItemFilterScriptRepository itemFilterScriptRepository,
|
||||||
IItemFilterScriptTranslator itemFilterScriptTranslator,
|
IItemFilterScriptTranslator itemFilterScriptTranslator,
|
||||||
|
@ -75,51 +73,51 @@ namespace Filtration.ViewModels
|
||||||
_messageBoxService = messageBoxService;
|
_messageBoxService = messageBoxService;
|
||||||
|
|
||||||
NewScriptCommand = new RelayCommand(OnNewScriptCommand);
|
NewScriptCommand = new RelayCommand(OnNewScriptCommand);
|
||||||
CopyScriptCommand = new RelayCommand(OnCopyScriptCommand, () => _activeDocumentIsScript);
|
CopyScriptCommand = new RelayCommand(OnCopyScriptCommand, () => ActiveDocumentIsScript);
|
||||||
OpenScriptCommand = new RelayCommand(OnOpenScriptCommand);
|
OpenScriptCommand = new RelayCommand(OnOpenScriptCommand);
|
||||||
OpenThemeCommand = new RelayCommand(OnOpenThemeCommand);
|
OpenThemeCommand = new RelayCommand(OnOpenThemeCommand);
|
||||||
|
|
||||||
SaveCommand = new RelayCommand(OnSaveDocumentCommand, ActiveDocumentIsEditable);
|
SaveCommand = new RelayCommand(OnSaveDocumentCommand, ActiveDocumentIsEditable);
|
||||||
SaveAsCommand = new RelayCommand(OnSaveAsCommand, ActiveDocumentIsEditable);
|
SaveAsCommand = new RelayCommand(OnSaveAsCommand, ActiveDocumentIsEditable);
|
||||||
CloseCommand = new RelayCommand(OnCloseDocumentCommand, () => AvalonDockWorkspaceViewModel.ActiveDocument != null);
|
CloseCommand = new RelayCommand(OnCloseDocumentCommand, ActiveDocumentIsEditable);
|
||||||
|
|
||||||
CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
CopyBlockStyleCommand = new RelayCommand(OnCopyBlockStyleCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
PasteCommand = new RelayCommand(OnPasteCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
PasteCommand = new RelayCommand(OnPasteCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
PasteBlockStyleCommand = new RelayCommand(OnPasteBlockStyleCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
PasteBlockStyleCommand = new RelayCommand(OnPasteBlockStyleCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
|
|
||||||
MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
|
|
||||||
AddBlockCommand = new RelayCommand(OnAddBlockCommand, () => _activeDocumentIsScript);
|
AddBlockCommand = new RelayCommand(OnAddBlockCommand, () => ActiveDocumentIsScript);
|
||||||
AddSectionCommand = new RelayCommand(OnAddSectionCommand, () => _activeDocumentIsScript);
|
AddSectionCommand = new RelayCommand(OnAddSectionCommand, () => ActiveDocumentIsScript);
|
||||||
DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => _activeDocumentIsScript && ActiveScriptHasSelectedBlock);
|
DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock);
|
||||||
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand,
|
DisableBlockCommand = new RelayCommand(OnDisableBlockCommand,
|
||||||
() => _activeDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
|
() => ActiveDocumentIsScript && ActiveScriptHasSelectedEnabledBlock);
|
||||||
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand,
|
EnableBlockCommand = new RelayCommand(OnEnableBlockCommand,
|
||||||
() => _activeDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
|
() => ActiveDocumentIsScript && ActiveScriptHasSelectedDisabledBlock);
|
||||||
OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
|
OpenAboutWindowCommand = new RelayCommand(OnOpenAboutWindowCommand);
|
||||||
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => _activeDocumentIsScript);
|
ReplaceColorsCommand = new RelayCommand(OnReplaceColorsCommand, () => ActiveDocumentIsScript);
|
||||||
|
|
||||||
CreateThemeCommand = new RelayCommand(OnCreateThemeCommand, () => _activeDocumentIsScript);
|
CreateThemeCommand = new RelayCommand(OnCreateThemeCommand, () => ActiveDocumentIsScript);
|
||||||
ApplyThemeToScriptCommand = new RelayCommand(OnApplyThemeToScriptCommand, () => _activeDocumentIsScript);
|
ApplyThemeToScriptCommand = new RelayCommand(OnApplyThemeToScriptCommand, () => ActiveDocumentIsScript);
|
||||||
EditMasterThemeCommand = new RelayCommand(OnEditMasterThemeCommand, () => _activeDocumentIsScript);
|
EditMasterThemeCommand = new RelayCommand(OnEditMasterThemeCommand, () => ActiveDocumentIsScript);
|
||||||
|
|
||||||
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => _activeDocumentIsTheme && ActiveThemeIsEditable);
|
AddTextColorThemeComponentCommand = new RelayCommand(OnAddTextColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
|
||||||
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => _activeDocumentIsTheme && ActiveThemeIsEditable);
|
AddBackgroundColorThemeComponentCommand = new RelayCommand(OnAddBackgroundColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
|
||||||
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => _activeDocumentIsTheme && ActiveThemeIsEditable);
|
AddBorderColorThemeComponentCommand = new RelayCommand(OnAddBorderColorThemeComponentCommand, () => ActiveDocumentIsTheme && ActiveThemeIsEditable);
|
||||||
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand,
|
DeleteThemeComponentCommand = new RelayCommand(OnDeleteThemeComponentCommand,
|
||||||
() =>
|
() =>
|
||||||
ActiveDocumentIsTheme && _activeDocumentIsTheme &&
|
ActiveDocumentIsTheme && ActiveDocumentIsTheme &&
|
||||||
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
|
_avalonDockWorkspaceViewModel.ActiveThemeViewModel.SelectedThemeComponent != null);
|
||||||
|
|
||||||
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => _activeDocumentIsScript);
|
ExpandAllBlocksCommand = new RelayCommand(OnExpandAllBlocksCommand, () => ActiveDocumentIsScript);
|
||||||
CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand, () => _activeDocumentIsScript);
|
CollapseAllBlocksCommand = new RelayCommand(OnCollapseAllBlocksCommand, () => ActiveDocumentIsScript);
|
||||||
|
|
||||||
ToggleShowAdvancedCommand = new RelayCommand<bool>(OnToggleShowAdvancedCommand, s => _activeDocumentIsScript);
|
ToggleShowAdvancedCommand = new RelayCommand<bool>(OnToggleShowAdvancedCommand, s => ActiveDocumentIsScript);
|
||||||
ClearFiltersCommand = new RelayCommand(OnClearFiltersCommand, () => _activeDocumentIsScript);
|
ClearFiltersCommand = new RelayCommand(OnClearFiltersCommand, () => ActiveDocumentIsScript);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(_itemFilterScriptRepository.GetItemFilterScriptDirectory()))
|
if (string.IsNullOrEmpty(_itemFilterScriptRepository.GetItemFilterScriptDirectory()))
|
||||||
{
|
{
|
||||||
|
@ -154,7 +152,8 @@ namespace Filtration.ViewModels
|
||||||
ApplyThemeToScriptCommand.RaiseCanExecuteChanged();
|
ApplyThemeToScriptCommand.RaiseCanExecuteChanged();
|
||||||
EditMasterThemeCommand.RaiseCanExecuteChanged();
|
EditMasterThemeCommand.RaiseCanExecuteChanged();
|
||||||
CreateThemeCommand.RaiseCanExecuteChanged();
|
CreateThemeCommand.RaiseCanExecuteChanged();
|
||||||
SetActiveDocumentStatusProperties();
|
RaisePropertyChanged("ActiveDocumentIsScript");
|
||||||
|
RaisePropertyChanged("ActiveDocumentIsTheme");
|
||||||
RaisePropertyChanged("ShowAdvancedStatus");
|
RaisePropertyChanged("ShowAdvancedStatus");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -171,8 +170,6 @@ namespace Filtration.ViewModels
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
CheckForUpdates();
|
CheckForUpdates();
|
||||||
ActiveDocumentIsScript = false;
|
|
||||||
ActiveDocumentIsTheme = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RelayCommand OpenScriptCommand { get; private set; }
|
public RelayCommand OpenScriptCommand { get; private set; }
|
||||||
|
@ -280,30 +277,14 @@ namespace Filtration.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetActiveDocumentStatusProperties()
|
|
||||||
{
|
|
||||||
ActiveDocumentIsScript = AvalonDockWorkspaceViewModel.ActiveDocument is ItemFilterScriptViewModel;
|
|
||||||
ActiveDocumentIsTheme = AvalonDockWorkspaceViewModel.ActiveDocument is ThemeEditorViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ActiveDocumentIsScript
|
public bool ActiveDocumentIsScript
|
||||||
{
|
{
|
||||||
get { return _activeDocumentIsScript; }
|
get { return _avalonDockWorkspaceViewModel.ActiveDocument != null && _avalonDockWorkspaceViewModel.ActiveDocument.IsScript; }
|
||||||
private set
|
|
||||||
{
|
|
||||||
_activeDocumentIsScript = value;
|
|
||||||
RaisePropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ActiveDocumentIsTheme
|
public bool ActiveDocumentIsTheme
|
||||||
{
|
{
|
||||||
get { return _activeDocumentIsTheme; }
|
get { return _avalonDockWorkspaceViewModel.ActiveDocument!= null && _avalonDockWorkspaceViewModel.ActiveDocument.IsTheme; }
|
||||||
private set
|
|
||||||
{
|
|
||||||
_activeDocumentIsTheme = value;
|
|
||||||
RaisePropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ActiveScriptHasSelectedBlock
|
public bool ActiveScriptHasSelectedBlock
|
||||||
|
|
Loading…
Reference in New Issue