diff --git a/JdaTools.Studio/Helpers/DialogueHelper.cs b/JdaTools.Studio/Helpers/DialogueHelper.cs new file mode 100644 index 0000000..fa0d837 --- /dev/null +++ b/JdaTools.Studio/Helpers/DialogueHelper.cs @@ -0,0 +1,21 @@ +using System.Threading.Tasks; +using System.Windows; +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; +using MahApps.Metro.SimpleChildWindow; + +namespace JdaTools.Studio.Helpers +{ + public static class DialogueHelper + { + public static MetroWindow MainWindow => (MetroWindow) Application.Current.MainWindow; + public static Task ShowChildWindowAsync(ChildWindow childWindow) => + MainWindow.ShowChildWindowAsync(childWindow); + + public static Task ShowInputDialogue(string title, string message) + { + + return MainWindow.ShowInputAsync(title, message); + } + } +} \ No newline at end of file diff --git a/JdaTools.Studio/ViewModels/FilesViewModel.cs b/JdaTools.Studio/ViewModels/FilesViewModel.cs index e6aeff4..2eae4ce 100644 --- a/JdaTools.Studio/ViewModels/FilesViewModel.cs +++ b/JdaTools.Studio/ViewModels/FilesViewModel.cs @@ -13,6 +13,7 @@ using System.Xml.Serialization; using Caliburn.Micro; using JdaTools.Studio.Models; +using MahApps.Metro.SimpleChildWindow; namespace JdaTools.Studio.ViewModels { @@ -145,12 +146,18 @@ internal async void OpenFile(MocaFile file) vm.NewEditor(text, false, file.FileName); } - public void NewFile() + public async void NewFile() { var shellView = App.Current.MainWindow; var vm = (ShellViewModel)shellView.DataContext; - - vm.NewEditor("", false, "NEW FILE"); + var fileName = await Helpers.DialogueHelper.ShowInputDialogue("NEW FILE", "Enter new file name"); + Files.Add(new MocaFile + { + FileName = fileName, + PathName = Path.Combine(CurrentPath, fileName), + Type = "F" + }); + vm.NewEditor("", false, fileName); } public async Task HandleAsync(string message, CancellationToken cancellationToken) diff --git a/JdaTools.Studio/ViewModels/ShellViewModel.cs b/JdaTools.Studio/ViewModels/ShellViewModel.cs index 6645661..d9f9f69 100644 --- a/JdaTools.Studio/ViewModels/ShellViewModel.cs +++ b/JdaTools.Studio/ViewModels/ShellViewModel.cs @@ -18,10 +18,13 @@ using System.Threading; using System.Windows.Forms; using JdaTools.Studio.Models; +using JdaTools.Studio.Views; +using MahApps.Metro.SimpleChildWindow; +using Screen = Caliburn.Micro.Screen; namespace JdaTools.Studio.ViewModels { - public class ShellViewModel : ViewModelBase, IHandle + public class ShellViewModel : Screen, IHandle { private readonly MocaClient _mocaClient; private readonly SchemaExplorer _schemaExplorer; @@ -40,9 +43,19 @@ public ShellViewModel(MocaClient mocaClient, SchemaExplorer schemaExplorer, IEve Tools.Add(new FilesViewModel(_mocaClient, _schemaExplorer, _eventAggregator)); Tools.Add(new CommandsViewModel(_mocaClient, _schemaExplorer, _eventAggregator)); Login = new LoginViewModel(_mocaClient, _eventAggregator); + } - - + + private async void ShowLogin() + { + var viewModel = new LoginViewModel(_mocaClient, _eventAggregator); + var view = ViewLocator.LocateForModel(viewModel, null, null); + ViewModelBinder.Bind(viewModel, view, null); + var mainWindow = Helpers.DialogueHelper.MainWindow; + await mainWindow.ShowChildWindowAsync((ChildWindow)view); + } + + public LoginViewModel Login { get => _loginViewModel; @@ -60,7 +73,11 @@ public LoginViewModel Login public ObservableCollection Editors { get => _editors; - set => SetProperty(ref _editors, value); + set + { + _editors = value; + NotifyOfPropertyChange(() => _editors); + } } private ICommand newEditorCommand; @@ -114,7 +131,8 @@ public Visibility LoginVisibility { IsEnabled = true; } - SetProperty(ref loginVisibility, value); + loginVisibility = value; + NotifyOfPropertyChange(() => loginVisibility); } } @@ -132,7 +150,14 @@ private async void ExecuteCurrentTab() private bool isEnabled; - public bool IsEnabled { get => isEnabled; set => SetProperty(ref isEnabled, value); } + public bool IsEnabled { + get => isEnabled; + set + { + isEnabled = value; + NotifyOfPropertyChange(() => isEnabled); + } + } private ICommand executeCommand; public ICommand ExecuteCommand => executeCommand ??= new RelayCommand(ExecuteCurrentTab);