Skip to content

Commit

Permalink
Add file dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Rolfe authored and Isaac Rolfe committed Aug 25, 2021
1 parent cbd6a84 commit d29eb46
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
21 changes: 21 additions & 0 deletions JdaTools.Studio/Helpers/DialogueHelper.cs
Original file line number Diff line number Diff line change
@@ -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<string> ShowInputDialogue(string title, string message)
{

return MainWindow.ShowInputAsync(title, message);
}
}
}
13 changes: 10 additions & 3 deletions JdaTools.Studio/ViewModels/FilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Xml.Serialization;
using Caliburn.Micro;
using JdaTools.Studio.Models;
using MahApps.Metro.SimpleChildWindow;

namespace JdaTools.Studio.ViewModels
{
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 31 additions & 6 deletions JdaTools.Studio/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
public class ShellViewModel : Screen, IHandle<string>
{
private readonly MocaClient _mocaClient;
private readonly SchemaExplorer _schemaExplorer;
Expand All @@ -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;
Expand All @@ -60,7 +73,11 @@ public LoginViewModel Login
public ObservableCollection<EditorViewModel> Editors
{
get => _editors;
set => SetProperty(ref _editors, value);
set
{
_editors = value;
NotifyOfPropertyChange(() => _editors);
}
}

private ICommand newEditorCommand;
Expand Down Expand Up @@ -114,7 +131,8 @@ public Visibility LoginVisibility
{
IsEnabled = true;
}
SetProperty(ref loginVisibility, value);
loginVisibility = value;
NotifyOfPropertyChange(() => loginVisibility);
}
}

Expand All @@ -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);
Expand Down

0 comments on commit d29eb46

Please sign in to comment.