2014-07-26 10:49:11 +00:00
|
|
|
|
using System;
|
2014-08-15 21:39:31 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows;
|
2014-08-15 21:39:31 +00:00
|
|
|
|
using System.Linq;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
using Microsoft.Win32;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
using RainmeterStudio.Business;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Model;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
using RainmeterStudio.UI.Dialogs;
|
2014-08-15 21:39:31 +00:00
|
|
|
|
using RainmeterStudio.UI.ViewModel;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.UI.Controller
|
|
|
|
|
{
|
|
|
|
|
public class ProjectController
|
|
|
|
|
{
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the project manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected ProjectManager Manager { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the owner window. Used for creating dialogs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Window OwnerWindow { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the active project
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Project ActiveProject
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Manager.ActiveProject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the active project path
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ActiveProjectPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-07-27 13:21:06 +00:00
|
|
|
|
return Manager.ActiveProject.Path;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-15 21:39:31 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the project templates
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IEnumerable<ProjectTemplateViewModel> ProjectTemplates
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Manager.ProjectTemplates.Select(pt => new ProjectTemplateViewModel(pt));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-26 10:49:11 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Callbacks
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when a project is opened or the active project closes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event EventHandler ActiveProjectChanged
|
|
|
|
|
{
|
|
|
|
|
add
|
|
|
|
|
{
|
|
|
|
|
Manager.ActiveProjectChanged += value;
|
|
|
|
|
}
|
|
|
|
|
remove
|
|
|
|
|
{
|
|
|
|
|
Manager.ActiveProjectChanged -= value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Commands
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
public Command ProjectCreateCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Command ProjectOpenCommand { get; private set; }
|
2014-07-26 10:49:11 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes the project controller
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="manager">Project manager</param>
|
|
|
|
|
public ProjectController(ProjectManager manager)
|
|
|
|
|
{
|
|
|
|
|
Manager = manager;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
ProjectCreateCommand = new Command("ProjectCreateCommand", () => CreateProject());
|
|
|
|
|
ProjectOpenCommand = new Command("ProjectOpenCommand", () => OpenProject());
|
2014-07-26 10:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays the 'create project' dialog and creates a new project
|
|
|
|
|
/// </summary>
|
2014-08-16 10:55:07 +00:00
|
|
|
|
public void CreateProject()
|
2014-07-26 10:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
// Create dialog
|
2014-08-15 21:39:31 +00:00
|
|
|
|
var dialog = new CreateProjectDialog(this);
|
2014-07-26 10:49:11 +00:00
|
|
|
|
dialog.Owner = OwnerWindow;
|
2014-08-16 08:05:26 +00:00
|
|
|
|
|
2014-07-26 10:49:11 +00:00
|
|
|
|
// Display
|
|
|
|
|
bool? res = dialog.ShowDialog();
|
|
|
|
|
if (!res.HasValue || !res.Value)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
string selectedName = dialog.SelectedName;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
string selectedPath = dialog.SelectedPath;
|
|
|
|
|
|
|
|
|
|
// Call manager
|
2014-07-27 13:21:06 +00:00
|
|
|
|
Manager.CreateProject(selectedName, selectedPath);
|
2014-07-26 10:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Displays an 'open file' dialog and opens an existing project
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
public void OpenProject(string path = null)
|
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// Open dialog
|
|
|
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
|
|
|
dialog.Filter = Resources.Strings.Dialog_FileType_Project + "|*.rsproj|"
|
|
|
|
|
+ Resources.Strings.Dialog_FileType_AllFiles + "|*.*";
|
|
|
|
|
dialog.Title = Resources.Strings.Dialog_OpenProject_Title;
|
|
|
|
|
dialog.Multiselect = false;
|
|
|
|
|
|
|
|
|
|
// Show dialog
|
|
|
|
|
bool? res = dialog.ShowDialog(OwnerWindow);
|
|
|
|
|
if (!res.HasValue || !res.Value)
|
|
|
|
|
return;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// Call manager
|
|
|
|
|
string filename = dialog.FileName;
|
|
|
|
|
Manager.OpenProject(filename);
|
2014-07-26 10:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Closes the active project
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void CloseProject()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|