2014-07-26 07:12:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
using RainmeterStudio.Business;
|
2014-08-30 07:24:01 +00:00
|
|
|
|
using RainmeterStudio.Core.Documents;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Model.Events;
|
2014-07-26 10:49:11 +00:00
|
|
|
|
using RainmeterStudio.Storage;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
using RainmeterStudio.UI.Controller;
|
2014-08-16 12:40:08 +00:00
|
|
|
|
using RainmeterStudio.UI.Panels;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
using Xceed.Wpf.AvalonDock.Layout;
|
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.UI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
2014-07-26 10:49:11 +00:00
|
|
|
|
public DocumentController DocumentController { get; set; }
|
|
|
|
|
public ProjectController ProjectController { get; set; }
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
2014-08-16 12:40:08 +00:00
|
|
|
|
public ProjectPanel ProjectPanel { get { return projectPanel; } }
|
|
|
|
|
|
2014-08-30 07:24:01 +00:00
|
|
|
|
private Dictionary<LayoutDocument, IDocumentEditor> _openedDocuments = new Dictionary<LayoutDocument, IDocumentEditor>();
|
|
|
|
|
|
2014-07-29 20:35:59 +00:00
|
|
|
|
public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2014-07-29 20:35:59 +00:00
|
|
|
|
// Set fields
|
|
|
|
|
DataContext = this;
|
|
|
|
|
DocumentController = docCtrl;
|
|
|
|
|
ProjectController = projCtrl;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
2014-07-29 20:35:59 +00:00
|
|
|
|
// Add key bindings
|
2014-07-27 13:21:06 +00:00
|
|
|
|
this.AddKeyBinding(ProjectController.ProjectCreateCommand);
|
2014-07-29 20:35:59 +00:00
|
|
|
|
this.AddKeyBinding(DocumentController.DocumentCreateCommand);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-07-29 20:35:59 +00:00
|
|
|
|
// Subscribe to events
|
2014-07-26 10:49:11 +00:00
|
|
|
|
DocumentController.DocumentOpened += documentController_DocumentOpened;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
// Initialize panels
|
|
|
|
|
projectPanel.Controller = ProjectController;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
|
|
|
|
|
{
|
2014-08-30 07:24:01 +00:00
|
|
|
|
// Create a new panel
|
2014-07-26 07:12:56 +00:00
|
|
|
|
LayoutDocument document = new LayoutDocument();
|
2014-08-30 07:24:01 +00:00
|
|
|
|
_openedDocuments.Add(document, e.Editor);
|
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
document.Content = e.Editor.EditorUI;
|
|
|
|
|
document.Closing += document_Closing;
|
2014-08-30 07:24:01 +00:00
|
|
|
|
document.Closed += document_Closed;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
documentPane.Children.Add(document);
|
|
|
|
|
documentPane.SelectedContentIndex = documentPane.IndexOf(document);
|
2014-08-30 07:24:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e.Document.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((obj, args) =>
|
|
|
|
|
{
|
|
|
|
|
string documentName;
|
|
|
|
|
|
|
|
|
|
if (!e.Document.Reference.IsInProject())
|
|
|
|
|
{
|
|
|
|
|
documentName = e.Document.Reference.StoragePath;
|
|
|
|
|
|
|
|
|
|
if (documentName == null)
|
|
|
|
|
documentName = "New document";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
documentName = e.Document.Reference.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Document.IsDirty)
|
|
|
|
|
documentName += "*";
|
|
|
|
|
|
|
|
|
|
document.Title = documentName;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void document_Closed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var layoutDocument = (LayoutDocument)sender;
|
|
|
|
|
|
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
|
|
{
|
2014-08-30 07:24:01 +00:00
|
|
|
|
|
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
switch (MessageBox.Show("Are you sure?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
|
|
|
|
|
{
|
|
|
|
|
case MessageBoxResult.Yes:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MessageBoxResult.No:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-23 20:27:14 +00:00
|
|
|
|
}
|