using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using RainmeterStudio.Business;
using RainmeterStudio.Model;
using RainmeterStudio.UI.Dialogs;
namespace RainmeterStudio.UI.Controller
{
public class ProjectController
{
#region Properties
///
/// Gets the project manager
///
protected ProjectManager Manager { get; private set; }
///
/// Gets or sets the owner window. Used for creating dialogs.
///
public Window OwnerWindow { get; set; }
///
/// Gets the active project
///
public Project ActiveProject
{
get
{
return Manager.ActiveProject;
}
}
///
/// Gets the active project path
///
public string ActiveProjectPath
{
get
{
return Manager.ActiveProjectPath;
}
}
#endregion
#region Callbacks
///
/// Called when a project is opened or the active project closes.
///
public event EventHandler ActiveProjectChanged
{
add
{
Manager.ActiveProjectChanged += value;
}
remove
{
Manager.ActiveProjectChanged -= value;
}
}
#endregion
#region Commands
private Command _projectCreateCommand;
public Command ProjectCreateCommand
{
get
{
if (_projectCreateCommand == null)
{
_projectCreateCommand = new Command("ProjectCreateComand", () => CreateProject())
{
DisplayText = Resources.Strings.ProjectCreateCommand_DisplayText,
Tooltip = Resources.Strings.ProjectCreateCommand_ToolTip,
Icon = new BitmapImage(new Uri(Resources.Icons.ProjectCreateCommand_Icon, UriKind.RelativeOrAbsolute)),
Shortcut = new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift)
};
}
return _projectCreateCommand;
}
}
#endregion
///
/// Initializes the project controller
///
/// Project manager
public ProjectController(ProjectManager manager)
{
Manager = manager;
}
///
/// Displays the 'create project' dialog and creates a new project
///
public void CreateProject(string name = null, string path = null)
{
// Create dialog
var dialog = new CreateProjectDialog();
dialog.Owner = OwnerWindow;
dialog.SelectedLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rainmeter Studio Projects");
if (name != null)
dialog.Name = name;
if (path != null)
dialog.SelectedPath = path;
// Display
bool? res = dialog.ShowDialog();
if (!res.HasValue || !res.Value)
return;
string selectedPath = dialog.SelectedPath;
// Call manager
Manager.CreateProject(name, selectedPath); // TODO
}
///
/// Displays an 'open file' dialog and opens an existing project
///
///
public void OpenProject(string path = null)
{
}
///
/// Closes the active project
///
public void CloseProject()
{
}
}
}