diff --git a/WDE.Blueprints/Editor/ViewModels/BlueprintEditorViewModel.cs b/WDE.Blueprints/Editor/ViewModels/BlueprintEditorViewModel.cs index e74f31cda..9fd5d0337 100644 --- a/WDE.Blueprints/Editor/ViewModels/BlueprintEditorViewModel.cs +++ b/WDE.Blueprints/Editor/ViewModels/BlueprintEditorViewModel.cs @@ -5,11 +5,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; using WDE.Blueprints.Data; +using WDE.Common.History; +using WDE.Common.Managers; +using WDE.Common.Utils; namespace WDE.Blueprints.Editor.ViewModels { - public class BlueprintEditorViewModel : BindableBase + public class BlueprintEditorViewModel : BindableBase, IDocument { private BlueprintSolutionItem solutionItem; @@ -47,5 +51,20 @@ public BlueprintEditorViewModel(BlueprintSolutionItem solutionItem, NodesViewMod GraphViewModel.AddElement(new NodeViewModel("Node 3", Enums.NodeType.Expression, 1, 1), 10200, 10000); GraphViewModel.AddElement(new NodeViewModel("Node 4", Enums.NodeType.Statement, 4, 1), 10300, 10000); } + + public void Dispose() + { + } + + public string Title { get; } = "Blueprints"; + public ICommand Undo { get; } = AlwaysDisabledCommand.Command; + public ICommand Redo { get; }= AlwaysDisabledCommand.Command; + public ICommand Copy { get; }= AlwaysDisabledCommand.Command; + public ICommand Cut { get; }= AlwaysDisabledCommand.Command; + public ICommand Paste { get; }= AlwaysDisabledCommand.Command; + public ICommand Save { get; }= AlwaysDisabledCommand.Command; + public ICommand CloseCommand { get; set; } = null; + public bool CanClose { get; } = true; + public IHistoryManager History { get; } = null; } } diff --git a/WDE.Blueprints/Providers/BlueprintItemEditorProvider.cs b/WDE.Blueprints/Providers/BlueprintItemEditorProvider.cs index 39f662eb5..7302e0ab1 100644 --- a/WDE.Blueprints/Providers/BlueprintItemEditorProvider.cs +++ b/WDE.Blueprints/Providers/BlueprintItemEditorProvider.cs @@ -18,20 +18,9 @@ public BlueprintItemEditorProvider(IBlueprintDefinitionsRegistry blueprintDefini this.blueprintDefinitionsRegistry = blueprintDefinitionsRegistry; } - public Document GetEditor(BlueprintSolutionItem item) + public IDocument GetEditor(BlueprintSolutionItem item) { - var view = new BlueprintEditorView(); - var vm = new BlueprintEditorViewModel(item, new NodesViewModel(blueprintDefinitionsRegistry)); - view.DataContext = vm; - - Document editor = new Document - { - Title = "Blueprints", - Content = view, - CanClose = true - }; - - return editor; + return new BlueprintEditorViewModel(item, new NodesViewModel(blueprintDefinitionsRegistry)); } } } diff --git a/WDE.HistoryWindow/HistoryWindowModule.cs b/WDE.HistoryWindow/HistoryWindowModule.cs index c7d012d22..115a8e626 100644 --- a/WDE.HistoryWindow/HistoryWindowModule.cs +++ b/WDE.HistoryWindow/HistoryWindowModule.cs @@ -12,6 +12,7 @@ using WDE.HistoryWindow.Views; using Prism.Ioc; using Prism.Events; +using WDE.Common.Managers; using WDE.Module.Attributes; using WDE.Module; @@ -27,17 +28,15 @@ public HistoryWindowModule(IEventAggregator eventAggregator) this.eventAggregator = eventAggregator; } - public ContentControl GetView() - { - var view = new HistoryView(); - view.DataContext = new HistoryViewModel(eventAggregator); - return view; - } - public bool AllowMultiple => false; public string Name => "History view"; + public ITool Provide() + { + return new HistoryViewModel(eventAggregator); + } + public bool CanOpenOnStart => false; } } diff --git a/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs b/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs index dc5e2143a..adfd322a5 100644 --- a/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs +++ b/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using WDE.Common.Events; using WDE.Common.History; using Prism.Ioc; @@ -21,19 +22,19 @@ internal class HistoryEvent public bool IsFromFuture { get; set; } } - internal class HistoryViewModel : BindableBase + internal class HistoryViewModel : BindableBase, ITool { public ObservableCollection Items { get; set; } = new ObservableCollection(); private IDocument previousDocument; - private string _title; - public string Title + public string Title => "History"; + private Visibility _visibility; + public Visibility Visibility { - get { return _title; } - set { SetProperty(ref _title, value); } + get => _visibility; + set => SetProperty(ref _visibility, value); } - public HistoryViewModel(IEventAggregator eventAggregator) { eventAggregator.GetEvent().Subscribe(doc => diff --git a/WDE.SQLEditor/Providers/MetaSqlSolutionItemEditorProvider.cs b/WDE.SQLEditor/Providers/MetaSqlSolutionItemEditorProvider.cs index e8facd36f..1427839c4 100644 --- a/WDE.SQLEditor/Providers/MetaSqlSolutionItemEditorProvider.cs +++ b/WDE.SQLEditor/Providers/MetaSqlSolutionItemEditorProvider.cs @@ -18,20 +18,9 @@ public MetaSqlSolutionItemEditorProvider(Lazy this.sqlGeneratorsRegistry = sqlGeneratorsRegistry; } - public Document GetEditor(MetaSolutionSQL item) + public IDocument GetEditor(MetaSolutionSQL item) { - var view = new SqlEditorView(); - var vm = new SqlEditorViewModel(sqlGeneratorsRegistry.Value.GenerateSql(item as MetaSolutionSQL)); - view.DataContext = vm; - - Document editor = new Document(); - editor.Title = "Sql output"; - editor.Content = view; - editor.CanClose = true; - editor.Undo = new DelegateCommand(() => { }, () => false); - editor.Redo = new DelegateCommand(() => { }, () => false); - - return editor; + return new SqlEditorViewModel(sqlGeneratorsRegistry.Value.GenerateSql(item as MetaSolutionSQL)); } } } diff --git a/WDE.SQLEditor/ViewModels/SqlEditorViewModel.cs b/WDE.SQLEditor/ViewModels/SqlEditorViewModel.cs index 2dba0b4f8..43667d437 100644 --- a/WDE.SQLEditor/ViewModels/SqlEditorViewModel.cs +++ b/WDE.SQLEditor/ViewModels/SqlEditorViewModel.cs @@ -1,12 +1,12 @@ -using Prism.Commands; +using System.Windows.Input; using Prism.Mvvm; -using System; -using System.Collections.Generic; -using System.Linq; +using WDE.Common.History; +using WDE.Common.Managers; +using WDE.Common.Utils; namespace WDE.SQLEditor.ViewModels { - public class SqlEditorViewModel : BindableBase + public class SqlEditorViewModel : BindableBase, IDocument { public string Code { get; set; } @@ -14,5 +14,20 @@ public SqlEditorViewModel(string sql) { Code = sql; } + + public void Dispose() + { + } + + public string Title { get; } = "SQL Output"; + public ICommand Undo { get; } = AlwaysDisabledCommand.Command; + public ICommand Redo { get; } = AlwaysDisabledCommand.Command; + public ICommand Copy { get; } = AlwaysDisabledCommand.Command; + public ICommand Cut { get; } = AlwaysDisabledCommand.Command; + public ICommand Paste { get; } = AlwaysDisabledCommand.Command; + public ICommand Save { get; } = AlwaysDisabledCommand.Command; + public ICommand CloseCommand { get; set; } = null; + public bool CanClose { get; } = true; + public IHistoryManager History { get; } = null; } } diff --git a/WDE.SmartScriptEditor/Editor/ViewModels/SmartScriptEditorViewModel.cs b/WDE.SmartScriptEditor/Editor/ViewModels/SmartScriptEditorViewModel.cs index 93aee7ca9..d855a6a17 100644 --- a/WDE.SmartScriptEditor/Editor/ViewModels/SmartScriptEditorViewModel.cs +++ b/WDE.SmartScriptEditor/Editor/ViewModels/SmartScriptEditorViewModel.cs @@ -21,11 +21,13 @@ using System.Diagnostics; using System.Windows; using System.Windows.Data; +using System.Windows.Input; +using WDE.Common.Managers; using WDE.SmartScriptEditor.Editor.UserControls; namespace WDE.SmartScriptEditor.Editor.ViewModels { - public class SmartScriptEditorViewModel : BindableBase, System.IDisposable + public class SmartScriptEditorViewModel : BindableBase, IDocument, System.IDisposable { private readonly IDatabaseProvider database; private readonly IHistoryManager history; @@ -44,7 +46,8 @@ public class SmartScriptEditorViewModel : BindableBase, System.IDisposable public ObservableCollection Events => script.Events; public CompositeCollection Together { get; }= new CompositeCollection(); - + + public bool CanClose { get; } = true; public IHistoryManager History => history; public SmartEvent SelectedItem => Events.FirstOrDefault(ev => ev.IsSelected); @@ -82,7 +85,24 @@ public class SmartScriptEditorViewModel : BindableBase, System.IDisposable public DelegateCommand SelectionLeft { get; set; } public DelegateCommand SelectAll { get; set; } - public SmartScriptEditorViewModel(IHistoryManager history, IDatabaseProvider database, IEventAggregator eventAggregator, ISmartDataManager smartDataManager, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, ISmartTypeListProvider smartTypeListProvider, ISolutionItemNameRegistry itemNameRegistry) + public string Title { get; set; } + public ICommand Undo => UndoCommand; + public ICommand Redo => RedoCommand; + + public ICommand Copy => CopyCommand; + public ICommand Cut => CutCommand; + public ICommand Paste => PasteCommand; + public ICommand Save => SaveCommand; + public ICommand CloseCommand { get; set; } + + public SmartScriptEditorViewModel(IHistoryManager history, + IDatabaseProvider database, + IEventAggregator eventAggregator, + ISmartDataManager smartDataManager, + ISmartFactory smartFactory, + IItemFromListProvider itemFromListProvider, + ISmartTypeListProvider smartTypeListProvider, + ISolutionItemNameRegistry itemNameRegistry) { this.history = history; this.database = database; @@ -91,7 +111,7 @@ public SmartScriptEditorViewModel(IHistoryManager history, IDatabaseProvider dat this.itemFromListProvider = itemFromListProvider; this.smartTypeListProvider = smartTypeListProvider; this.itemNameRegistry = itemNameRegistry; - + EditEvent = new DelegateCommand(EditEventCommand); DeselectActions = new DelegateCommand(() => { @@ -460,6 +480,7 @@ internal void SetSolutionItem(SmartScriptSolutionItem item) { Debug.Assert(_item == null); _item = item; + Title = itemNameRegistry.GetName(item); var lines = database.GetScriptFor(_item.Entry, _item.SmartType); script = new SmartScript(_item, smartFactory); diff --git a/WDE.SmartScriptEditor/Providers/SmartScriptEditorProvider.cs b/WDE.SmartScriptEditor/Providers/SmartScriptEditorProvider.cs index 512ab20d6..904a03c06 100644 --- a/WDE.SmartScriptEditor/Providers/SmartScriptEditorProvider.cs +++ b/WDE.SmartScriptEditor/Providers/SmartScriptEditorProvider.cs @@ -29,29 +29,12 @@ public SmartScriptEditorProvider(ISolutionItemNameRegistry solutionItemNameRegis this.containerProvider = containerProvider; } - public Document GetEditor(SmartScriptSolutionItem item) + public IDocument GetEditor(SmartScriptSolutionItem item) { - var view = new SmartScriptEditorView(); var vm = containerProvider.Resolve(); vm.SetSolutionItem(item); - view.DataContext = vm; - - Document editor = new Document - { - Title = solutionItemNameRegistry.GetName(item), - Content = view, - Undo = vm.UndoCommand, - Redo = vm.RedoCommand, - Save = vm.SaveCommand, - Copy = vm.CopyCommand, - Paste = vm.PasteCommand, - Cut = vm.CutCommand, - History = vm.History, - CanClose = true - }; - editor.OnDispose += () => vm.Dispose(); - - return editor; + + return vm; } } } diff --git a/WDE.Solutions/Explorer/ViewModels/SolutionExplorerViewModel.cs b/WDE.Solutions/Explorer/ViewModels/SolutionExplorerViewModel.cs index f88923d21..d0d644434 100644 --- a/WDE.Solutions/Explorer/ViewModels/SolutionExplorerViewModel.cs +++ b/WDE.Solutions/Explorer/ViewModels/SolutionExplorerViewModel.cs @@ -5,16 +5,17 @@ using System.Collections.ObjectModel; using System.Linq; using System.Windows; - +using System.Windows.Controls; using Prism.Events; using WDE.Common; using WDE.Common.Events; using WDE.Common.Solution; using Prism.Ioc; +using WDE.Common.Managers; namespace WDE.Solutions.Explorer.ViewModels { - public class SolutionExplorerViewModel : BindableBase + public class SolutionExplorerViewModel : BindableBase, ITool { private readonly ISolutionItemNameRegistry itemNameRegistry; private readonly ISolutionManager _solutionManager; @@ -113,5 +114,13 @@ private void AddItemToRoot(ISolutionItem item) _itemToViewmodel.Add(item, viewModel); Root.Add(viewModel); } + + public string Title { get; } = "Solution explorer"; + private Visibility _visibility; + public Visibility Visibility + { + get => _visibility; + set => SetProperty(ref _visibility, value); + } } } diff --git a/WDE.Solutions/Manager/SolutionItemEditorRegistry.cs b/WDE.Solutions/Manager/SolutionItemEditorRegistry.cs index 124bed08d..b90ad1e5e 100644 --- a/WDE.Solutions/Manager/SolutionItemEditorRegistry.cs +++ b/WDE.Solutions/Manager/SolutionItemEditorRegistry.cs @@ -27,13 +27,13 @@ private void Register(ISolutionItemEditorProvider provider) where T : ISol editorProviders.Add(typeof(T), provider); } - private Document GetEditor(T item) where T : ISolutionItem + private IDocument GetEditor(T item) where T : ISolutionItem { var x = editorProviders[item.GetType()] as ISolutionItemEditorProvider; return x.GetEditor(item); } - public Document GetEditor(ISolutionItem item) + public IDocument GetEditor(ISolutionItem item) { return GetEditor((dynamic)item); } diff --git a/WDE.Solutions/SolutionExplorer.cs b/WDE.Solutions/SolutionExplorer.cs index 2d77fdac2..a99c4b5f5 100644 --- a/WDE.Solutions/SolutionExplorer.cs +++ b/WDE.Solutions/SolutionExplorer.cs @@ -5,8 +5,10 @@ using System.Threading.Tasks; using System.Windows.Controls; using WDE.Common; +using WDE.Common.Managers; using WDE.Module.Attributes; using WDE.Common.Windows; +using WDE.Solutions.Explorer.ViewModels; using WDE.Solutions.Explorer.Views; namespace WDE.Solutions @@ -14,20 +16,21 @@ namespace WDE.Solutions [AutoRegister, SingleInstance] public class SolutionExplorer : ISolutionExplorer, IToolProvider { + private readonly SolutionExplorerViewModel _solutionExplorerViewModel; public bool AllowMultiple => false; public string Name => "Solution explorer"; - public bool CanOpenOnStart => true; - - public ContentControl GetSolutionExplorerView() + public SolutionExplorer(SolutionExplorerViewModel solutionExplorerViewModel) { - return new SolutionExplorerView(); + _solutionExplorerViewModel = solutionExplorerViewModel; } - - public ContentControl GetView() + + public ITool Provide() { - return GetSolutionExplorerView(); + return _solutionExplorerViewModel; } + + public bool CanOpenOnStart => true; } } diff --git a/WoWDatabaseEditor.Common b/WoWDatabaseEditor.Common index c933129a7..d741d3f37 160000 --- a/WoWDatabaseEditor.Common +++ b/WoWDatabaseEditor.Common @@ -1 +1 @@ -Subproject commit c933129a7932624f2d4e3dcd005706123426c46f +Subproject commit d741d3f3786fe14df7d1e843c89baa9b4864497c diff --git a/WoWDatabaseEditor/Managers/ViewModels/DocumentDecorator.cs b/WoWDatabaseEditor/Managers/ViewModels/DocumentDecorator.cs deleted file mode 100644 index bca1bf8a2..000000000 --- a/WoWDatabaseEditor/Managers/ViewModels/DocumentDecorator.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Prism.Commands; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Controls; -using System.Windows.Input; -using WDE.Common.History; -using WDE.Common.Managers; - -namespace WoWDatabaseEditor.Managers.ViewModels -{ - internal class DocumentDecorator : IDocument - { - private readonly IDocument document; - private readonly Action closeAction; - - public string Title => document.Title; - - public ICommand Undo => document.Undo; - - public ICommand Redo => document.Redo; - - public ICommand Save => document.Save; - - public ICommand Copy => document.Copy; - - public ICommand Paste => document.Paste; - - public ICommand Cut => document.Cut; - - public ICommand CloseCommand { get; private set; } - - public bool CanClose => document.CanClose; - - public IHistoryManager History => document.History; - - public ContentControl Content => document.Content; - - public System.Windows.Visibility Visibility { get; set; } - - public DocumentDecorator(IDocument document, Action closeAction) - { - this.document = document; - this.closeAction = closeAction; - CloseCommand = new DelegateCommand(Close); - - Visibility = System.Windows.Visibility.Visible; - } - - private void Close() - { - closeAction(this); - document.CloseCommand?.Execute(null); - } - - public void Dispose() - { - document.Dispose(); - } - } -} diff --git a/WoWDatabaseEditor/Managers/ViewModels/ToolWindow.cs b/WoWDatabaseEditor/Managers/ViewModels/ToolWindow.cs deleted file mode 100644 index 32cecc010..000000000 --- a/WoWDatabaseEditor/Managers/ViewModels/ToolWindow.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Prism.Commands; -using Prism.Mvvm; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using WDE.Common.Managers; - -namespace WoWDatabaseEditor.Managers.ViewModels -{ - internal class ToolWindow : BindableBase, ITool - { - public string Title { get; private set; } - - public ContentControl Content { get; private set; } - - public bool CanClose => false; - - public ICommand CloseCommand { get; private set; } - - private Visibility _visibility; - public Visibility Visibility - { - get => _visibility; - set => SetProperty(ref _visibility, value); - } - - public ToolWindow(string title, ContentControl content) - { - Title = title; - Content = content; - Visibility = System.Windows.Visibility.Visible; - CloseCommand = new DelegateCommand(() => { }); - } - } -} diff --git a/WoWDatabaseEditor/Managers/WindowManager.cs b/WoWDatabaseEditor/Managers/WindowManager.cs index 2e70ff9eb..02ad84be8 100644 --- a/WoWDatabaseEditor/Managers/WindowManager.cs +++ b/WoWDatabaseEditor/Managers/WindowManager.cs @@ -8,11 +8,8 @@ using WDE.Common.Events; using WDE.Common.Managers; using WDE.Common.Windows; -using Prism.Ioc; using Prism.Commands; -using System.Windows.Controls; using System.Windows.Input; -using WoWDatabaseEditor.Managers.ViewModels; namespace WoWDatabaseEditor.Managers { @@ -28,7 +25,6 @@ public WindowManager(IEventAggregator eventAggregator) } public DelegateCommand ActivateDocument { get; } - private IDocument? _activeDocument; public IDocument? ActiveDocument { @@ -36,8 +32,6 @@ public IDocument? ActiveDocument set { if (value == null && _activeDocument != null && OpenedDocuments.Contains(_activeDocument)) return; - if (value != null && documents.ContainsKey(value)) - value = documents[value]; SetProperty(ref _activeDocument, value); _eventAggregator.GetEvent().Publish(value); } @@ -45,29 +39,22 @@ public IDocument? ActiveDocument public ObservableCollection OpenedDocuments { get; } = new ObservableCollection(); public ObservableCollection OpenedTools { get; } = new ObservableCollection(); - private Dictionary Opened { get; } = new Dictionary(); + private Dictionary Opened { get; } = new Dictionary(); - private Dictionary documents = new(); - public void OpenDocument(IDocument editor) { - if (documents.ContainsKey(editor)) - ActiveDocument = documents[editor]; - else + if (!OpenedDocuments.Contains(editor)) { - var document = new DocumentDecorator(editor, doc => + var origCommand = editor.CloseCommand; + editor.CloseCommand = new Command(() => { - documents.Remove(editor); - OpenedDocuments.Remove(doc); - if (ActiveDocument == doc) - ActiveDocument = null; + origCommand?.Execute(null); + OpenedDocuments.Remove(editor); _eventAggregator.GetEvent().Publish(editor); - doc.Dispose(); - }); - documents[editor] = document; - OpenedDocuments.Add(document); - ActiveDocument = document; + }, () => origCommand?.CanExecute(null) ?? true); + OpenedDocuments.Add(editor); } + ActiveDocument = editor; } public void OpenTool(IToolProvider provider) @@ -81,14 +68,38 @@ public void OpenTool(IToolProvider provider) } } - var toolWindow = new ToolWindow(provider.Name, provider.GetView()); + var tool = provider.Provide(); if (!provider.AllowMultiple) - Opened.Add(provider.GetType(), toolWindow); + Opened.Add(provider.GetType(), tool); - OpenedTools.Add(toolWindow); + OpenedTools.Add(tool); } + private class Command : ICommand + { + public readonly Func canExecute; + public readonly Action action; + + public Command(Action action, Func canExecute) + { + this.action = action; + this.canExecute = canExecute; + } + + public bool CanExecute(object? parameter) + { + return canExecute.Invoke(); + } + + public void Execute(object? parameter) + { + action(); + } + + public event EventHandler? CanExecuteChanged; + } + public class DocumentClosedEvent : PubSubEvent {} } } \ No newline at end of file diff --git a/WoWDatabaseEditor/Themes/BlueTheme.xaml b/WoWDatabaseEditor/Themes/BlueTheme.xaml index ced79094c..d8e1fc38f 100644 --- a/WoWDatabaseEditor/Themes/BlueTheme.xaml +++ b/WoWDatabaseEditor/Themes/BlueTheme.xaml @@ -149,4 +149,7 @@ + + + \ No newline at end of file diff --git a/WoWDatabaseEditor/Themes/Controls/Menu.xaml b/WoWDatabaseEditor/Themes/Controls/Menu.xaml index bcfc63504..d5840385e 100644 --- a/WoWDatabaseEditor/Themes/Controls/Menu.xaml +++ b/WoWDatabaseEditor/Themes/Controls/Menu.xaml @@ -20,7 +20,7 @@ - + @@ -267,6 +267,7 @@ - - - - - - - - - - - - + @@ -99,18 +93,24 @@ - + WoW Database Editor + + - + + - + + @@ -127,9 +127,5 @@ -