mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Rewrote Reference class
This commit is contained in:
		@@ -34,6 +34,8 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
 | 
			
		||||
        public Command DocumentOpenCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -65,6 +67,11 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            ProjectManager.ActiveProjectChanged += new EventHandler((obj, e) => DocumentCreateCommand.NotifyCanExecuteChanged());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Document operations
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows the new item dialog, and creates a new document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void Create()
 | 
			
		||||
        {
 | 
			
		||||
            // Show dialog
 | 
			
		||||
@@ -83,7 +90,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            // Set the reference
 | 
			
		||||
            var name = dialog.SelectedName;
 | 
			
		||||
 | 
			
		||||
            string folder = OwnerWindow.ProjectPanel.ActiveItem.Data.Path;
 | 
			
		||||
            string folder = OwnerWindow.ProjectPanel.ActiveItem.Data.StoragePath;
 | 
			
		||||
            if (!Directory.Exists(folder))
 | 
			
		||||
                folder = Path.GetDirectoryName(folder);
 | 
			
		||||
 | 
			
		||||
@@ -97,12 +104,59 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            OwnerWindow.ProjectPanel.ActiveItem.Add(reference);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Create(IDocumentTemplate format)
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Saves the document opened in specified editor
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="editor">Editor</param>
 | 
			
		||||
        public void Save(IDocumentEditor editor)
 | 
			
		||||
        {
 | 
			
		||||
            // Call manager
 | 
			
		||||
            DocumentManager.Create(format);
 | 
			
		||||
            if (!editor.AttachedDocument.Reference.IsOnStorage())
 | 
			
		||||
            {
 | 
			
		||||
                SaveAs(editor);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // TODO
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void SaveAs(IDocumentEditor editor)
 | 
			
		||||
        {
 | 
			
		||||
            // TODO
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Closes an active document.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="editor">The document editor attached</param>
 | 
			
		||||
        /// <returns>True if closed successfully</returns>
 | 
			
		||||
        /// <remarks>Shows the 'are you sure' prompt if there are unsaved edits.</remarks>
 | 
			
		||||
        public bool Close(IDocumentEditor editor)
 | 
			
		||||
        {
 | 
			
		||||
            // Show the 'are you sure' prompt if necesary
 | 
			
		||||
            if (editor.AttachedDocument.IsDirty)
 | 
			
		||||
            {
 | 
			
		||||
                bool? res = CloseUnsavedDialog.ShowDialog(OwnerWindow, editor.AttachedDocument);
 | 
			
		||||
                if (res.HasValue)
 | 
			
		||||
                {
 | 
			
		||||
                    // Save
 | 
			
		||||
                    if (res.Value)
 | 
			
		||||
                    {
 | 
			
		||||
                        Save(editor);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Close
 | 
			
		||||
            DocumentManager.Close(editor);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a list of document templates view models
 | 
			
		||||
        /// </summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -32,11 +32,11 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            // Resource name
 | 
			
		||||
            string key = "ProjectItem";
 | 
			
		||||
 | 
			
		||||
            if (Directory.Exists(item.Path))
 | 
			
		||||
            if (Directory.Exists(item.StoragePath))
 | 
			
		||||
                key += "Directory";
 | 
			
		||||
 | 
			
		||||
            else if (File.Exists(item.Path))
 | 
			
		||||
                key += "_" + Path.GetExtension(item.Path).Substring(1);
 | 
			
		||||
            else if (File.Exists(item.StoragePath))
 | 
			
		||||
                key += "_" + Path.GetExtension(item.StoragePath).Substring(1);
 | 
			
		||||
 | 
			
		||||
            else key += "None";
 | 
			
		||||
 | 
			
		||||
@@ -55,10 +55,9 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
    {
 | 
			
		||||
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 | 
			
		||||
        {
 | 
			
		||||
            var reference = value as Reference;
 | 
			
		||||
            if (reference != null)
 | 
			
		||||
            if (value is Reference)
 | 
			
		||||
            {
 | 
			
		||||
                return IconProvider.GetProjectItemIcon(reference);
 | 
			
		||||
                return IconProvider.GetProjectItemIcon((Reference)value);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return null;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										41
									
								
								RainmeterStudio/UI/Dialogs/CloseUnsavedDialog.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								RainmeterStudio/UI/Dialogs/CloseUnsavedDialog.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
<Window x:Class="RainmeterStudio.UI.Dialogs.CloseUnsavedDialog"
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:r="clr-namespace:RainmeterStudio.Resources"
 | 
			
		||||
        Title="{x:Static r:Strings.CloseUnsavedDialog_Title}" Height="200" Width="320"
 | 
			
		||||
        WindowStartupLocation="CenterOwner"
 | 
			
		||||
        WindowStyle="ToolWindow" ShowInTaskbar="False"
 | 
			
		||||
        Background="WhiteSmoke" >
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
        </Grid.RowDefinitions>
 | 
			
		||||
        
 | 
			
		||||
        <TextBlock Grid.Row="0" Text="{x:Static r:Strings.CloseUnsavedDialog_Message }"
 | 
			
		||||
                   Margin="4"/>
 | 
			
		||||
 | 
			
		||||
        <ScrollViewer Grid.Row="1" 
 | 
			
		||||
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
 | 
			
		||||
                      ScrollViewer.VerticalScrollBarVisibility="Auto">
 | 
			
		||||
            
 | 
			
		||||
            <TextBlock Name="textFiles" 
 | 
			
		||||
                       Margin="4" Padding="4" 
 | 
			
		||||
                       Background="White"/>
 | 
			
		||||
            
 | 
			
		||||
        </ScrollViewer>
 | 
			
		||||
 | 
			
		||||
        <TextBlock Grid.Row="2" Text="{x:Static r:Strings.CloseUnsavedDialog_Question }"
 | 
			
		||||
                   Margin="4"/>
 | 
			
		||||
 | 
			
		||||
        <StackPanel Grid.Row="3" Orientation="Horizontal"
 | 
			
		||||
                    HorizontalAlignment="Right">
 | 
			
		||||
            <Button Name="buttonSave" Content="{x:Static r:Strings.Dialog_Save}" IsDefault="True" Margin="1px" Click="buttonSave_Click" />
 | 
			
		||||
            <Button Name="buttonDoNotSave" Content="{x:Static r:Strings.Dialog_DoNotSave}" Margin="1px" Click="buttonDoNotSave_Click" />
 | 
			
		||||
            <Button Name="buttonCancel" Content="{x:Static r:Strings.Dialog_Cancel}" IsCancel="True" Margin="1px" Click="buttonCancel_Click" />
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
							
								
								
									
										103
									
								
								RainmeterStudio/UI/Dialogs/CloseUnsavedDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								RainmeterStudio/UI/Dialogs/CloseUnsavedDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
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.Shapes;
 | 
			
		||||
using RainmeterStudio.Core.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for CloseUnsavedDialog.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class CloseUnsavedDialog : Window
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the dialog and returns the result
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="unsavedDocuments">List of unsaved documents</param>
 | 
			
		||||
        /// <returns>Dialog result</returns>
 | 
			
		||||
        public static bool? ShowDialog(IEnumerable<IDocument> unsavedDocuments)
 | 
			
		||||
        {
 | 
			
		||||
            var dialog = new CloseUnsavedDialog(unsavedDocuments);
 | 
			
		||||
            return dialog.ShowDialog();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the dialog and returns the result
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="owner">Owner window</param>
 | 
			
		||||
        /// <param name="unsavedDocuments">List of unsaved documents</param>
 | 
			
		||||
        /// <returns>Dialog result</returns>
 | 
			
		||||
        public static bool? ShowDialog(Window owner, IEnumerable<IDocument> unsavedDocuments)
 | 
			
		||||
        {
 | 
			
		||||
            var dialog = new CloseUnsavedDialog(unsavedDocuments);
 | 
			
		||||
            dialog.Owner = owner;
 | 
			
		||||
            return dialog.ShowDialog();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the dialog and returns the result
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="owner">Owner window</param>
 | 
			
		||||
        /// <param name="unsavedDocuments">List of unsaved documents</param>
 | 
			
		||||
        /// <returns>Dialog result</returns>
 | 
			
		||||
        public static bool? ShowDialog(Window owner, params IDocument[] unsavedDocuments)
 | 
			
		||||
        {
 | 
			
		||||
            var dialog = new CloseUnsavedDialog(unsavedDocuments);
 | 
			
		||||
            dialog.Owner = owner;
 | 
			
		||||
            return dialog.ShowDialog();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="unsavedDocuments">List of unsaved documents</param>
 | 
			
		||||
        public CloseUnsavedDialog(IEnumerable<IDocument> unsavedDocuments)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            textFiles.Inlines.AddRange(unsavedDocuments.SelectMany(GetInlines));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private IEnumerable<Inline> GetInlines(IDocument doc)
 | 
			
		||||
        {
 | 
			
		||||
            var folder = System.IO.Path.GetDirectoryName(doc.Reference.StoragePath);
 | 
			
		||||
            
 | 
			
		||||
            yield return new Run(folder)
 | 
			
		||||
            {
 | 
			
		||||
                Foreground = Brushes.DarkGray
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            yield return new Run(doc.Reference.Name)
 | 
			
		||||
            {
 | 
			
		||||
                FontWeight = FontWeights.Bold
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonSave_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = true;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonDoNotSave_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = false;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = null;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,6 +12,7 @@ using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Navigation;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Core.Documents;
 | 
			
		||||
using RainmeterStudio.Core.Model.Events;
 | 
			
		||||
using RainmeterStudio.Storage;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
@@ -30,6 +31,8 @@ namespace RainmeterStudio.UI
 | 
			
		||||
 | 
			
		||||
        public ProjectPanel ProjectPanel { get { return projectPanel; } }
 | 
			
		||||
 | 
			
		||||
        private Dictionary<LayoutDocument, IDocumentEditor> _openedDocuments = new Dictionary<LayoutDocument, IDocumentEditor>();
 | 
			
		||||
 | 
			
		||||
        public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
@@ -52,18 +55,52 @@ namespace RainmeterStudio.UI
 | 
			
		||||
 | 
			
		||||
        void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // Spawn a new window
 | 
			
		||||
            // Create a new panel
 | 
			
		||||
            LayoutDocument document = new LayoutDocument();
 | 
			
		||||
            _openedDocuments.Add(document, e.Editor);
 | 
			
		||||
 | 
			
		||||
            document.Content = e.Editor.EditorUI;
 | 
			
		||||
            document.Title = (e.Editor.AttachedDocument.Reference == null) ? "New document" : e.Editor.AttachedDocument.Reference.Name;
 | 
			
		||||
            document.Closing += document_Closing;
 | 
			
		||||
            document.Closed += document_Closed;
 | 
			
		||||
 | 
			
		||||
            documentPane.Children.Add(document);
 | 
			
		||||
            documentPane.SelectedContentIndex = documentPane.IndexOf(document);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            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;
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            switch (MessageBox.Show("Are you sure?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
 | 
			
		||||
            {
 | 
			
		||||
                case MessageBoxResult.Yes:
 | 
			
		||||
 
 | 
			
		||||
@@ -162,7 +162,7 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
            refTree.Data = Controller.ActiveProject.Root.Data;
 | 
			
		||||
 | 
			
		||||
            // Remove the project file from the list
 | 
			
		||||
            Tree<Reference> project = refTree.First(x => DirectoryHelper.PathsEqual(x.Data.Path, Controller.ActiveProjectPath));
 | 
			
		||||
            Tree<Reference> project = refTree.First(x => DirectoryHelper.PathsEqual(x.Data.StoragePath, Controller.ActiveProjectPath));
 | 
			
		||||
            refTree.Remove(project);
 | 
			
		||||
 | 
			
		||||
            // Transform to reference view model and return
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,7 @@ namespace RainmeterStudio.UI.ViewModel
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Reference.Data.Path;
 | 
			
		||||
                return Reference.Data.StoragePath;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user