61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows.Input;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using mbts;
|
|
using mbts.ui;
|
|
using mbts.ui.shell;
|
|
|
|
namespace mbts.ui.shell
|
|
{
|
|
public class WorkspacesDialogViewModel : ViewModelBaseWithValidation
|
|
{
|
|
private WorkspacesModel _work_model;
|
|
|
|
public WorkspacesDialogViewModel(WorkspacesModel wm)
|
|
{
|
|
_work_model = wm;
|
|
}
|
|
|
|
public ObservableCollection<WorkspaceViewModel> Workspaces { get { return _work_model.Workspaces; } }
|
|
public string SaveName { get; set; }
|
|
public bool IsPublicWorkspace { get; set; }
|
|
public bool ShowWorkspaces { get; set; }
|
|
|
|
public ICommand SaveWorkspace
|
|
{
|
|
get
|
|
{
|
|
return new DelegateCommand(arg => {
|
|
// Check for errors in the input
|
|
if (string.IsNullOrEmpty(SaveName))
|
|
{
|
|
set_error("SaveName", "Workspace must be named");
|
|
return;
|
|
}
|
|
if (SaveName.Contains(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX))
|
|
{
|
|
set_error("SaveName", "Workspace name cannot contains '{0}'".fmt(WorkspacesModel.ACTIVE_WORKSPACE_PREFIX));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
clear_error("SaveName");
|
|
}
|
|
var save_candidate_already_exists = Workspaces.Any(x => x.Name == SaveName);
|
|
// Save
|
|
_work_model.save_workspace(SaveName, ispublic: IsPublicWorkspace);
|
|
|
|
// if we just overwrote something, have the vm reflect it
|
|
if (save_candidate_already_exists)
|
|
Workspaces.Where(x => x.Name == SaveName).ForEach(x => x.VisualState = "Overridden");
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|