mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Added project item commands, work on project manager, implemented project manager tests
This commit is contained in:
		@@ -13,7 +13,13 @@
 | 
			
		||||
            <Style TargetType="ToolBarTray">
 | 
			
		||||
                <Setter Property="Background" Value="Transparent" />
 | 
			
		||||
            </Style>
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            <Style x:Key="CommandContextMenuItemStyle" TargetType="MenuItem">
 | 
			
		||||
                <Setter Property="Command" Value="{Binding}" />
 | 
			
		||||
                <Setter Property="Header" Value="{Binding DisplayText}" />
 | 
			
		||||
                <Setter Property="ToolTip" Value="{Binding ToolTip}" />
 | 
			
		||||
            </Style>
 | 
			
		||||
 | 
			
		||||
            <Style x:Key="CommandMenuItemStyle" TargetType="MenuItem">
 | 
			
		||||
                <Setter Property="Command" Value="{Binding}" />
 | 
			
		||||
                <Setter Property="Header" Value="{Binding DisplayText}" />
 | 
			
		||||
 
 | 
			
		||||
@@ -114,7 +114,17 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            ProjectManager = projectManager;
 | 
			
		||||
 | 
			
		||||
            DocumentCreateCommand = new Command("DocumentCreate", Create, () => ProjectManager.ActiveProject != null);
 | 
			
		||||
            DocumentOpenCommand = new Command("DocumentOpen", Open);
 | 
			
		||||
            DocumentOpenCommand = new Command("DocumentOpen", arg =>
 | 
			
		||||
            {
 | 
			
		||||
                if (arg is Reference)
 | 
			
		||||
                {
 | 
			
		||||
                    Open((Reference)arg);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    Open(); 
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            DocumentSaveCommand = new Command("DocumentSave", () => Save(), HasActiveDocumentEditor);
 | 
			
		||||
            DocumentSaveAsCommand = new Command("DocumentSaveAs", () => SaveAs(), HasActiveDocumentEditor);
 | 
			
		||||
            DocumentSaveACopyCommand = new Command("DocumentSaveACopy", () => SaveACopy(), HasActiveDocumentEditor);
 | 
			
		||||
@@ -168,7 +178,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            if (!Directory.Exists(folder))
 | 
			
		||||
                folder = Path.GetDirectoryName(folder);
 | 
			
		||||
 | 
			
		||||
            var reference = new Reference(name, Path.Combine(folder, name), Reference.ReferenceTargetKind.File);
 | 
			
		||||
            var reference = new Reference(name, Path.Combine(folder, name), ReferenceTargetKind.File);
 | 
			
		||||
            editor.AttachedDocument.Reference = reference;
 | 
			
		||||
 | 
			
		||||
            // Save document
 | 
			
		||||
@@ -198,6 +208,15 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Opens the document pointed to by a reference
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="reference"></param>
 | 
			
		||||
        public void Open(Reference reference)
 | 
			
		||||
        {
 | 
			
		||||
            DocumentManager.Open(reference.StoragePath);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Saves the active document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            string key = "ProjectItem";
 | 
			
		||||
 | 
			
		||||
            // Is a file?
 | 
			
		||||
            if (item.TargetKind == Reference.ReferenceTargetKind.File || item.TargetKind == Reference.ReferenceTargetKind.Project)
 | 
			
		||||
            if (item.TargetKind == ReferenceTargetKind.File || item.TargetKind == ReferenceTargetKind.Project)
 | 
			
		||||
            {
 | 
			
		||||
                var extension = Path.GetExtension(item.StoragePath);
 | 
			
		||||
 | 
			
		||||
@@ -45,7 +45,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Not a file, try to figure out if a directory
 | 
			
		||||
            else if (item.TargetKind == Reference.ReferenceTargetKind.Directory)
 | 
			
		||||
            else if (item.TargetKind == ReferenceTargetKind.Directory)
 | 
			
		||||
            {
 | 
			
		||||
                key += "Directory";
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ using RainmeterStudio.Core.Model;
 | 
			
		||||
using RainmeterStudio.UI.Dialogs;
 | 
			
		||||
using RainmeterStudio.UI.ViewModel;
 | 
			
		||||
using RainmeterStudio.Properties;
 | 
			
		||||
using RainmeterStudio.Core.Utils;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Controller
 | 
			
		||||
{
 | 
			
		||||
@@ -97,6 +98,42 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectCloseCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Cut command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemCutCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Copy command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemCopyCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Paste command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemPasteCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Rename command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemRenameCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Delete command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemDeleteCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Open folder command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemOpenInExplorerCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Open folder command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Command ProjectItemOpenContainingFolderCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -111,9 +148,19 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            ProjectCreateCommand = new Command("ProjectCreate", CreateProject);
 | 
			
		||||
            ProjectOpenCommand = new Command("ProjectOpen", OpenProject);
 | 
			
		||||
            ProjectCloseCommand = new Command("ProjectClose", CloseProject, () => ActiveProject != null);
 | 
			
		||||
            ProjectItemCutCommand = new Command("ProjectItemCut", r => ProjectItemCutClipboard((Reference)r));
 | 
			
		||||
            ProjectItemCopyCommand = new Command("ProjectItemCopy", r => ProjectItemCopyClipboard((Reference)r));
 | 
			
		||||
            ProjectItemPasteCommand = new Command("ProjectItemPaste", r => ProjectItemPasteClipboard((Reference)r), r => Manager.HaveProjectItemInClipboard());
 | 
			
		||||
            ProjectItemRenameCommand = new Command("ProjectItemRename", r => ProjectItemRename((Reference)r));
 | 
			
		||||
            ProjectItemDeleteCommand = new Command("ProjectItemDelete", r => ProjectItemDelete((Reference)r));
 | 
			
		||||
            ProjectItemOpenInExplorerCommand = new Command("ProjectItemOpenInExplorer", r => ProjectItemOpenInExplorer((Reference)r));
 | 
			
		||||
            ProjectItemOpenContainingFolderCommand = new Command("ProjectItemOpenContainingFolder", r => ProjectItemOpenInExplorer((Reference)r));
 | 
			
		||||
 | 
			
		||||
            ActiveProjectChanged += new EventHandler((sender, e) => ProjectCloseCommand.NotifyCanExecuteChanged());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Project operations
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the 'create project' dialog and creates a new project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
@@ -167,5 +214,144 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        {
 | 
			
		||||
            Manager.Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Project item operations
 | 
			
		||||
 | 
			
		||||
        protected struct ClipboardData
 | 
			
		||||
        {
 | 
			
		||||
            public bool Cut;
 | 
			
		||||
            public Reference Ref;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Places a project item in the clipboard, and marks it for deletion
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Project item to cut</param>
 | 
			
		||||
        public void ProjectItemCutClipboard(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Manager.ProjectItemCutClipboard(@ref);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Places a project item in the clipboard
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Project item to copy</param>
 | 
			
		||||
        public void ProjectItemCopyClipboard(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Manager.ProjectItemCopyClipboard(@ref);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Pastes a project item from clipboard
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Destination</param>
 | 
			
		||||
        public void ProjectItemPasteClipboard(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Manager.ProjectItemPasteClipboard(@ref);
 | 
			
		||||
                Manager.SaveActiveProject();
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Renames a project item
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Reference to project item</param>
 | 
			
		||||
        public void ProjectItemRename(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            string initialValue = Path.GetFileName(@ref.StoragePath.TrimEnd('\\'));
 | 
			
		||||
 | 
			
		||||
            // Show an input dialog
 | 
			
		||||
            var newName = InputDialog.Show(Resources.Strings.RenameReferenceDialog_Prompt,
 | 
			
		||||
                Resources.Strings.RenameReferenceDialog_Caption,
 | 
			
		||||
                initialValue,
 | 
			
		||||
                PathHelper.IsFileNameValid,
 | 
			
		||||
                Resources.Strings.RenameReferenceDialog_OKCaption,
 | 
			
		||||
                Resources.Strings.Dialog_Cancel);
 | 
			
		||||
 | 
			
		||||
            if (newName != null)
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    Manager.ProjectItemRename(@ref, newName);
 | 
			
		||||
                    Manager.SaveActiveProject();
 | 
			
		||||
                }
 | 
			
		||||
                catch(Exception ex)
 | 
			
		||||
                {
 | 
			
		||||
                    MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Deletes a project item
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Reference to project item</param>
 | 
			
		||||
        public void ProjectItemDelete(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            var res = MessageBox.Show(Resources.Strings.DeleteReferenceDialog_Prompt,
 | 
			
		||||
                Resources.Strings.DeleteReferenceDialog_Caption,
 | 
			
		||||
                MessageBoxButton.YesNoCancel,
 | 
			
		||||
                MessageBoxImage.Question);
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                switch(res)
 | 
			
		||||
                {
 | 
			
		||||
                    case MessageBoxResult.Yes:
 | 
			
		||||
                        Manager.ProjectItemDelete(@ref, true);
 | 
			
		||||
                        Manager.SaveActiveProject();
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
                    case MessageBoxResult.No:
 | 
			
		||||
                        Manager.ProjectItemDelete(@ref, false);
 | 
			
		||||
                        Manager.SaveActiveProject();
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                MessageBox.Show(ex.Message, "Error");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Opens the containing folder if reference is a file, or folder if reference is a folder in windows explorer
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="ref">Reference</param>
 | 
			
		||||
        public void ProjectItemOpenInExplorer(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            if (@ref.TargetKind == ReferenceTargetKind.Directory)
 | 
			
		||||
            {
 | 
			
		||||
                System.Diagnostics.Process.Start(@ref.StoragePath);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                System.Diagnostics.Process.Start(Path.GetDirectoryName(@ref.StoragePath));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								RainmeterStudio/UI/Dialogs/InputDialog.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								RainmeterStudio/UI/Dialogs/InputDialog.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
<Window x:Class="RainmeterStudio.UI.Dialogs.InputDialog"
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:r="clr-namespace:RainmeterStudio.Resources"
 | 
			
		||||
        Height="100" Width="360"
 | 
			
		||||
        WindowStartupLocation="CenterOwner"
 | 
			
		||||
        WindowStyle="ToolWindow" ShowInTaskbar="False"
 | 
			
		||||
        Background="WhiteSmoke" >
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
        </Grid.RowDefinitions>
 | 
			
		||||
 | 
			
		||||
        <TextBlock Name="textPrompt" Grid.Row="0" 
 | 
			
		||||
                   Text="[placeholder]" Margin="4" Grid.ColumnSpan="2"/>
 | 
			
		||||
 | 
			
		||||
        <TextBox Name="textInput" Grid.Row="1" Margin="3"
 | 
			
		||||
                 TextChanged="textInput_TextChanged" Grid.ColumnSpan="2"/>
 | 
			
		||||
 | 
			
		||||
        <StackPanel Grid.Row="2" Orientation="Horizontal"
 | 
			
		||||
                    HorizontalAlignment="Right" Grid.Column="1">
 | 
			
		||||
            <Button Name="buttonOK" Content="{x:Static r:Strings.Dialog_OK}" IsDefault="True" Margin="1px" Click="buttonOK_Click" />
 | 
			
		||||
            <Button Name="buttonCancel" Content="{x:Static r:Strings.Dialog_Cancel}" IsCancel="True" Margin="1px" Click="buttonCancel_Click" />
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
							
								
								
									
										380
									
								
								RainmeterStudio/UI/Dialogs/InputDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										380
									
								
								RainmeterStudio/UI/Dialogs/InputDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,380 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
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.Resources;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for InputDialog.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class InputDialog : Window
 | 
			
		||||
    {
 | 
			
		||||
        private Func<string, bool> _validateFunction;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// A validate function that always returns true
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static readonly Func<string, bool> AlwaysValid = (str => true);
 | 
			
		||||
 | 
			
		||||
        #region Properties
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the prompt text
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Prompt
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textPrompt.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textPrompt.Text = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the text on the 'ok' button
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string OKCaption
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return (string)buttonOK.Content;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                buttonOK.Content = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the text on the 'cancel' button
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string CancelCaption
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return (string)buttonCancel.Content;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                buttonCancel.Content = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the text inputted by the user
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string InputText
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textInput.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textInput.Text = value;
 | 
			
		||||
                Validate();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a function used to validate the input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Func<string, bool> ValidateFunction
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _validateFunction;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _validateFunction = value;
 | 
			
		||||
                Validate();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        public InputDialog(string prompt)
 | 
			
		||||
            :this(prompt, String.Empty, String.Empty, AlwaysValid)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption)
 | 
			
		||||
            : this(prompt, caption, String.Empty, AlwaysValid)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, string okCaption, string cancelCaption)
 | 
			
		||||
            : this(prompt, caption, String.Empty, AlwaysValid, okCaption, cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, Func<string, bool> validateFunction)
 | 
			
		||||
            : this(prompt, caption, String.Empty, validateFunction)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, Func<string, bool> validateFunction, string okCaption, string cancelCaption)
 | 
			
		||||
            : this(prompt, caption, String.Empty, validateFunction, okCaption, cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, string initialValue)
 | 
			
		||||
            : this(prompt, caption, initialValue, AlwaysValid)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, string initialValue, string okCaption, string cancelCaption)
 | 
			
		||||
            : this(prompt, caption, initialValue, AlwaysValid, okCaption, cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, string initialValue, Func<string, bool> validateFunction)
 | 
			
		||||
            : this(prompt, caption, initialValue, validateFunction, Strings.Dialog_OK, Strings.Dialog_Cancel)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the input dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        public InputDialog(string prompt, string caption, string initialValue, Func<string, bool> validateFunction, string okCaption, string cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            Prompt = prompt;
 | 
			
		||||
            Title = caption;
 | 
			
		||||
            InputText = initialValue;
 | 
			
		||||
            ValidateFunction = validateFunction;
 | 
			
		||||
            OKCaption = okCaption;
 | 
			
		||||
            CancelCaption = cancelCaption;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonOK_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = true;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = false;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textInput_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            Validate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Validate()
 | 
			
		||||
        {
 | 
			
		||||
            bool res = true;
 | 
			
		||||
 | 
			
		||||
            if (ValidateFunction != null)
 | 
			
		||||
                res = ValidateFunction(textInput.Text);
 | 
			
		||||
 | 
			
		||||
            buttonOK.IsEnabled = res;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #region Static show
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, string okCaption, string cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, okCaption, cancelCaption));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, Func<string, bool> validateFunction)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, validateFunction));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, Func<string, bool> validateFunction, string okCaption, string cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, validateFunction, okCaption, cancelCaption));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, string initialValue)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, initialValue));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, string initialValue, string okCaption, string cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, initialValue, okCaption, cancelCaption));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, string initialValue, Func<string, bool> validateFunction)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, initialValue, validateFunction));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Shows a dialog prompting the user for input
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="prompt">Message displayed to user</param>
 | 
			
		||||
        /// <param name="caption">Title of dialog</param>
 | 
			
		||||
        /// <param name="initialValue">Initial value of the input dialog</param>
 | 
			
		||||
        /// <param name="validateFunction">Callback function which validates the inputted text</param>
 | 
			
		||||
        /// <param name="okCaption">Caption of the 'OK' button</param>
 | 
			
		||||
        /// <param name="cancelCaption">Caption of the 'Cancel' button</param>
 | 
			
		||||
        /// <returns>Input text, or null if canceled</returns>
 | 
			
		||||
        public static string Show(string prompt, string caption, string initialValue, Func<string, bool> validateFunction, string okCaption, string cancelCaption)
 | 
			
		||||
        {
 | 
			
		||||
            return ShowCommon(new InputDialog(prompt, caption, initialValue, validateFunction, okCaption, cancelCaption));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static string ShowCommon(InputDialog dialog)
 | 
			
		||||
        {
 | 
			
		||||
            bool? res = dialog.ShowDialog();
 | 
			
		||||
            if (res.HasValue && res.Value)
 | 
			
		||||
            {
 | 
			
		||||
                return dialog.InputText;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -34,13 +34,15 @@
 | 
			
		||||
            <MenuItem Header="{x:Static r:Strings.MainWindow_File}">
 | 
			
		||||
                <MenuItem Header="{x:Static r:Strings.MainWindow_File_New}">
 | 
			
		||||
                    <MenuItem DataContext="{Binding DocumentController.DocumentCreateCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}" >
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}" 
 | 
			
		||||
                              Header="{x:Static r:Strings.Command_DocumentCreate_AltDisplayText}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                    <MenuItem DataContext="{Binding ProjectController.ProjectCreateCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}">
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}"
 | 
			
		||||
                              Header="{x:Static r:Strings.Command_ProjectCreate_AltDisplayText}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
@@ -49,13 +51,15 @@
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <MenuItem Header="{x:Static r:Strings.MainWindow_File_Open}">
 | 
			
		||||
                    <MenuItem DataContext="{Binding DocumentController.DocumentOpenCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}">
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}"
 | 
			
		||||
                              Header="{x:Static r:Strings.Command_DocumentOpen_AltDisplayText}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                    <MenuItem DataContext="{Binding ProjectController.ProjectOpenCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}">
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}"
 | 
			
		||||
                              Header="{x:Static r:Strings.Command_ProjectOpen_AltDisplayText}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,8 @@ namespace RainmeterStudio.UI
 | 
			
		||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
 | 
			
		||||
            // Initialize panels
 | 
			
		||||
            projectPanel.Controller = ProjectController;
 | 
			
		||||
            projectPanel.ProjectController = ProjectController;
 | 
			
		||||
            projectPanel.DocumentController = DocumentController;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
 | 
			
		||||
 
 | 
			
		||||
@@ -44,12 +44,15 @@
 | 
			
		||||
        
 | 
			
		||||
        <!-- Project item tree  -->
 | 
			
		||||
        <TreeView Grid.Row="2" Name="treeProjectItems">
 | 
			
		||||
            
 | 
			
		||||
            <TreeView.ItemContainerStyle>
 | 
			
		||||
                <Style TargetType="{x:Type TreeViewItem}">
 | 
			
		||||
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
 | 
			
		||||
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
 | 
			
		||||
                    <EventSetter Event="Expanded" Handler="TreeViewItem_ExpandedOrCollapsed" />
 | 
			
		||||
                    <EventSetter Event="Collapsed" Handler="TreeViewItem_ExpandedOrCollapsed" />
 | 
			
		||||
                    <EventSetter Event="PreviewMouseRightButtonDown" Handler="TreeViewItem_PreviewMouseRightButtonDown" />
 | 
			
		||||
                    <EventSetter Event="PreviewMouseDoubleClick" Handler="TreeViewItem_PreviewMouseDoubleClick" />
 | 
			
		||||
                </Style>
 | 
			
		||||
            </TreeView.ItemContainerStyle>
 | 
			
		||||
            <TreeView.ItemTemplate>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,9 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Controls;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using RainmeterStudio.Core.Model;
 | 
			
		||||
using RainmeterStudio.Core.Utils;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
@@ -13,28 +16,31 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class ProjectPanel : UserControl
 | 
			
		||||
    {
 | 
			
		||||
        private ProjectController _controller;
 | 
			
		||||
        public ProjectController Controller
 | 
			
		||||
        private ProjectController _projectController;
 | 
			
		||||
 | 
			
		||||
        public ProjectController ProjectController
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _controller;
 | 
			
		||||
                return _projectController;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                // Unsubscribe from old controller
 | 
			
		||||
                if (_controller != null)
 | 
			
		||||
                if (_projectController != null)
 | 
			
		||||
                {
 | 
			
		||||
                    Controller.ActiveProjectChanged -= Controller_ActiveProjectChanged;
 | 
			
		||||
                    ProjectController.ActiveProjectChanged -= Controller_ActiveProjectChanged;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Set new project
 | 
			
		||||
                _controller = value;
 | 
			
		||||
                _controller.ActiveProjectChanged += Controller_ActiveProjectChanged;
 | 
			
		||||
                _projectController = value;
 | 
			
		||||
                _projectController.ActiveProjectChanged += Controller_ActiveProjectChanged;
 | 
			
		||||
                Refresh();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DocumentController DocumentController { get; set; }
 | 
			
		||||
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        public Command SyncWithActiveViewCommand { get; private set; }
 | 
			
		||||
@@ -60,7 +66,7 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
 | 
			
		||||
                if (selected == null)
 | 
			
		||||
                {
 | 
			
		||||
                    return Controller.ActiveProject.Root;
 | 
			
		||||
                    return ProjectController.ActiveProject.Root;
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
@@ -85,7 +91,6 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public ProjectPanel()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
@@ -116,7 +121,7 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
            treeProjectItems.Items.Clear();
 | 
			
		||||
 | 
			
		||||
            // No project
 | 
			
		||||
            if (Controller == null || Controller.ActiveProject == null)
 | 
			
		||||
            if (ProjectController == null || ProjectController.ActiveProject == null)
 | 
			
		||||
            {
 | 
			
		||||
                this.IsEnabled = false;
 | 
			
		||||
            }
 | 
			
		||||
@@ -130,14 +135,14 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
                if (toggleShowAllFiles.IsChecked.HasValue && toggleShowAllFiles.IsChecked.Value)
 | 
			
		||||
                {
 | 
			
		||||
                    // Get directory name
 | 
			
		||||
                    string projectFolder = System.IO.Path.GetDirectoryName(Controller.ActiveProjectPath);
 | 
			
		||||
                    string projectFolder = System.IO.Path.GetDirectoryName(ProjectController.ActiveProjectPath);
 | 
			
		||||
 | 
			
		||||
                    // Get folder tree
 | 
			
		||||
                    refTree = DirectoryHelper.GetFolderTree(projectFolder);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    refTree = Controller.ActiveProject.Root;
 | 
			
		||||
                    refTree = ProjectController.ActiveProject.Root;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Add tree to tree view
 | 
			
		||||
@@ -183,5 +188,106 @@ namespace RainmeterStudio.UI.Panels
 | 
			
		||||
            // We can expand if the root is not expanded
 | 
			
		||||
            CanExpand = (!tree.IsExpanded);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void TreeViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            var treeViewItem = sender as TreeViewItem;
 | 
			
		||||
            var referenceViewModel = treeViewItem.Header as ReferenceViewModel;
 | 
			
		||||
 | 
			
		||||
            if (referenceViewModel != null)
 | 
			
		||||
            {
 | 
			
		||||
                treeViewItem.ContextMenu = new ContextMenu();
 | 
			
		||||
                treeViewItem.ContextMenu.ItemsSource = GetContextMenuItems(referenceViewModel.Reference);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void TreeViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            var treeViewItem = sender as TreeViewItem;
 | 
			
		||||
            var refViewModel = treeViewItem.Header as ReferenceViewModel;
 | 
			
		||||
 | 
			
		||||
            if (refViewModel != null)
 | 
			
		||||
            {
 | 
			
		||||
                Command command = GetDefaultCommand(refViewModel.Reference);
 | 
			
		||||
                command.Execute(refViewModel.Reference);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the default command (double click) for a specific reference
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="reference">The reference</param>
 | 
			
		||||
        /// <returns>The command</returns>
 | 
			
		||||
        public Command GetDefaultCommand(Reference reference)
 | 
			
		||||
        {
 | 
			
		||||
            switch (reference.TargetKind)
 | 
			
		||||
            {
 | 
			
		||||
                case ReferenceTargetKind.File:
 | 
			
		||||
                    return DocumentController.DocumentOpenCommand;
 | 
			
		||||
 | 
			
		||||
                case ReferenceTargetKind.Project:
 | 
			
		||||
                    return DocumentController.DocumentOpenCommand;
 | 
			
		||||
 | 
			
		||||
                case ReferenceTargetKind.Directory:
 | 
			
		||||
                    return null; // TODO: expand command
 | 
			
		||||
 | 
			
		||||
                default:
 | 
			
		||||
                    return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private MenuItem GetMenuItem(Command cmd, Reference reference)
 | 
			
		||||
        {
 | 
			
		||||
            var icon = new Image();
 | 
			
		||||
            icon.Source = cmd.Icon;
 | 
			
		||||
            icon.Width = 16;
 | 
			
		||||
            icon.Height = 16;
 | 
			
		||||
 | 
			
		||||
            var menuItem = new MenuItem();
 | 
			
		||||
            menuItem.DataContext = cmd;
 | 
			
		||||
            menuItem.Style = Application.Current.TryFindResource("CommandContextMenuItemStyle") as Style;
 | 
			
		||||
            menuItem.Icon = icon;
 | 
			
		||||
            menuItem.CommandParameter = reference;
 | 
			
		||||
 | 
			
		||||
            if (GetDefaultCommand(reference) == cmd)
 | 
			
		||||
                menuItem.FontWeight = FontWeights.Bold;
 | 
			
		||||
 | 
			
		||||
            return menuItem;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerable<UIElement> GetContextMenuItems(Reference @ref)
 | 
			
		||||
        {
 | 
			
		||||
            if (@ref.TargetKind == ReferenceTargetKind.File || @ref.TargetKind == ReferenceTargetKind.Project)
 | 
			
		||||
            {
 | 
			
		||||
                yield return GetMenuItem(DocumentController.DocumentOpenCommand, @ref);
 | 
			
		||||
            }
 | 
			
		||||
            if (@ref.TargetKind == ReferenceTargetKind.Directory || @ref.TargetKind == ReferenceTargetKind.Project)
 | 
			
		||||
            {
 | 
			
		||||
                // TODO: expand command
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            yield return new Separator();
 | 
			
		||||
 | 
			
		||||
            if (@ref.TargetKind != ReferenceTargetKind.Project)
 | 
			
		||||
            {
 | 
			
		||||
                yield return GetMenuItem(ProjectController.ProjectItemCutCommand, @ref);
 | 
			
		||||
                yield return GetMenuItem(ProjectController.ProjectItemCopyCommand, @ref);
 | 
			
		||||
 | 
			
		||||
                if (@ref.TargetKind == ReferenceTargetKind.Directory)
 | 
			
		||||
                    yield return GetMenuItem(ProjectController.ProjectItemPasteCommand, @ref);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            yield return GetMenuItem(ProjectController.ProjectItemRenameCommand, @ref);
 | 
			
		||||
 | 
			
		||||
            if (@ref.TargetKind != ReferenceTargetKind.Project)
 | 
			
		||||
                yield return GetMenuItem(ProjectController.ProjectItemDeleteCommand, @ref);
 | 
			
		||||
 | 
			
		||||
            yield return new Separator();
 | 
			
		||||
 | 
			
		||||
            if (@ref.TargetKind == ReferenceTargetKind.Directory)
 | 
			
		||||
                yield return GetMenuItem(ProjectController.ProjectItemOpenInExplorerCommand, @ref);
 | 
			
		||||
            else
 | 
			
		||||
                yield return GetMenuItem(ProjectController.ProjectItemOpenContainingFolderCommand, @ref);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user