mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Work on project panel, trees, added settings
This commit is contained in:
		@@ -94,11 +94,29 @@ namespace RainmeterStudio.UI
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Keyboard shortcut property
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        private KeyGesture _shortcut;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the keyboard shortcut of this command
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public KeyGesture Shortcut { get; set; }
 | 
			
		||||
        public KeyGesture Shortcut
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_shortcut == null)
 | 
			
		||||
                {
 | 
			
		||||
                    string str = SettingsProvider.GetSetting<string>(Name + "_Shortcut");
 | 
			
		||||
                    return GetKeyGestureFromString(str);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return _shortcut;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _shortcut = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the text representation of the keyboard shortcut
 | 
			
		||||
@@ -107,10 +125,12 @@ namespace RainmeterStudio.UI
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                string text = String.Empty;
 | 
			
		||||
 | 
			
		||||
                // Safety check
 | 
			
		||||
                if (Shortcut == null)
 | 
			
		||||
                    return text;
 | 
			
		||||
                    return null;
 | 
			
		||||
 | 
			
		||||
                // Build string
 | 
			
		||||
                string text = String.Empty;
 | 
			
		||||
 | 
			
		||||
                if ((Shortcut.Modifiers & ModifierKeys.Windows) != 0)
 | 
			
		||||
                    text += "Win+";
 | 
			
		||||
@@ -127,17 +147,56 @@ namespace RainmeterStudio.UI
 | 
			
		||||
                text += Enum.GetName(typeof(Key), Shortcut.Key);
 | 
			
		||||
                return text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                Shortcut = GetKeyGestureFromString(value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private KeyGesture GetKeyGestureFromString(string k)
 | 
			
		||||
        {
 | 
			
		||||
            // Safety check
 | 
			
		||||
            if (k == null)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            // Variables
 | 
			
		||||
            ModifierKeys mods = ModifierKeys.None;
 | 
			
		||||
            Key key = Key.None;
 | 
			
		||||
 | 
			
		||||
            // Parse each field
 | 
			
		||||
            foreach (var field in k.Split('+'))
 | 
			
		||||
            {
 | 
			
		||||
                // Trim surrounding white space
 | 
			
		||||
                string trimmed = field.Trim();
 | 
			
		||||
 | 
			
		||||
                // Parse
 | 
			
		||||
                if (trimmed.Equals("Win", StringComparison.InvariantCultureIgnoreCase))
 | 
			
		||||
                    mods |= ModifierKeys.Windows;
 | 
			
		||||
                if (trimmed.Equals("Ctrl", StringComparison.InvariantCultureIgnoreCase))
 | 
			
		||||
                    mods |= ModifierKeys.Control;
 | 
			
		||||
                if (trimmed.Equals("Alt", StringComparison.InvariantCultureIgnoreCase))
 | 
			
		||||
                    mods |= ModifierKeys.Alt;
 | 
			
		||||
                if (trimmed.Equals("Shift", StringComparison.InvariantCultureIgnoreCase))
 | 
			
		||||
                    mods |= ModifierKeys.Shift;
 | 
			
		||||
                else Enum.TryParse<Key>(field, out key);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new KeyGesture(key, mods);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #pragma warning disable 67
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public event EventHandler CanExecuteChanged;
 | 
			
		||||
        
 | 
			
		||||
        #pragma warning restore 67
 | 
			
		||||
 | 
			
		||||
        public void NotifyCanExecuteChanged()
 | 
			
		||||
        {
 | 
			
		||||
            if (CanExecuteChanged != null)
 | 
			
		||||
                CanExecuteChanged(this, new EventArgs());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes this command
 | 
			
		||||
 
 | 
			
		||||
@@ -23,10 +23,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            {
 | 
			
		||||
                if (_documentCreateCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _documentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow())
 | 
			
		||||
                    {
 | 
			
		||||
                        Shortcut = new KeyGesture(Key.N, ModifierKeys.Control)
 | 
			
		||||
                    };
 | 
			
		||||
                    _documentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return _documentCreateCommand;
 | 
			
		||||
 
 | 
			
		||||
@@ -55,10 +55,10 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
    {
 | 
			
		||||
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 | 
			
		||||
        {
 | 
			
		||||
            var tree = value as Tree<Reference>;
 | 
			
		||||
            if (tree != null)
 | 
			
		||||
            var reference = value as Reference;
 | 
			
		||||
            if (reference != null)
 | 
			
		||||
            {
 | 
			
		||||
                return IconProvider.GetProjectItemIcon(tree.Data);
 | 
			
		||||
                return IconProvider.GetProjectItemIcon(reference);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return null;
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using Microsoft.Win32;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using RainmeterStudio.UI.Dialogs;
 | 
			
		||||
@@ -71,22 +72,9 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        private Command _projectCreateCommand;
 | 
			
		||||
        public Command ProjectCreateCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_projectCreateCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _projectCreateCommand = new Command("ProjectCreateCommand", () => CreateProject())
 | 
			
		||||
                    {
 | 
			
		||||
                        Shortcut = new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift)
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
        public Command ProjectCreateCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
                return _projectCreateCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        public Command ProjectOpenCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
@@ -97,6 +85,9 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        public ProjectController(ProjectManager manager)
 | 
			
		||||
        {
 | 
			
		||||
            Manager = manager;
 | 
			
		||||
 | 
			
		||||
            ProjectCreateCommand = new Command("ProjectCreateCommand", () => CreateProject());
 | 
			
		||||
            ProjectOpenCommand = new Command("ProjectOpenCommand", () => OpenProject());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
@@ -133,7 +124,21 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        /// <param name="path"></param>
 | 
			
		||||
        public void OpenProject(string path = null)
 | 
			
		||||
        {
 | 
			
		||||
            // 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;
 | 
			
		||||
 | 
			
		||||
            // Call manager
 | 
			
		||||
            string filename = dialog.FileName;
 | 
			
		||||
            Manager.OpenProject(filename);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										49
									
								
								RainmeterStudio/UI/Controller/SettingsProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								RainmeterStudio/UI/Controller/SettingsProvider.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Configuration;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Controller
 | 
			
		||||
{
 | 
			
		||||
    public static class SettingsProvider
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Attempts to retrieve the setting of type T, where T is class
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="T">Any class type</typeparam>
 | 
			
		||||
        /// <param name="name">Name of setting</param>
 | 
			
		||||
        /// <returns>Retrieved setting, or null if not found</returns>
 | 
			
		||||
        public static T GetSetting<T> (string name) where T : class
 | 
			
		||||
        {
 | 
			
		||||
            var property = Properties.Settings.Default.Properties
 | 
			
		||||
                .OfType<SettingsProperty>()
 | 
			
		||||
                .FirstOrDefault(x => String.Equals(x.Name, name));
 | 
			
		||||
                
 | 
			
		||||
            return (property == null) ? null : (property.DefaultValue as T);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Attempts to retrieve the setting of type T
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <typeparam name="T">Any type</typeparam>
 | 
			
		||||
        /// <param name="name">Name of setting</param>
 | 
			
		||||
        /// <param name="value">Output value</param>
 | 
			
		||||
        /// <returns>True if attempt was successful</returns>
 | 
			
		||||
        public static bool TryGetSetting<T>(string name, out T value)
 | 
			
		||||
        {
 | 
			
		||||
            var property = Properties.Settings.Default.Properties.OfType<SettingsProperty>().FirstOrDefault(x => x.Name.Equals(name));
 | 
			
		||||
 | 
			
		||||
            if (property != null)
 | 
			
		||||
            {
 | 
			
		||||
                value = (T)property.DefaultValue;
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                value = default(T);
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
        xmlns:ui="clr-namespace:RainmeterStudio.UI"
 | 
			
		||||
        xmlns:ad="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock"
 | 
			
		||||
        xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
 | 
			
		||||
        xmlns:r="clr-namespace:RainmeterStudio.Resources"
 | 
			
		||||
        Title="Rainmeter Studio" Height="600" Width="800"
 | 
			
		||||
        ResizeMode="CanResizeWithGrip" >
 | 
			
		||||
 | 
			
		||||
@@ -21,8 +22,8 @@
 | 
			
		||||
 | 
			
		||||
        <!-- Menu bar -->
 | 
			
		||||
        <Menu Grid.Row="0" Grid.ColumnSpan="10">
 | 
			
		||||
            <MenuItem Header="_File">
 | 
			
		||||
                <MenuItem Header="_New">
 | 
			
		||||
            <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}" >
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
@@ -37,7 +38,15 @@
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                </MenuItem>
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <MenuItem Header="_Open..." />
 | 
			
		||||
                <MenuItem Header="{x:Static r:Strings.MainWindow_File_Open}">
 | 
			
		||||
                    <MenuItem DataContext="{Binding ProjectController.ProjectOpenCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                    <Separator />
 | 
			
		||||
                </MenuItem>
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <MenuItem Header="_Close" />
 | 
			
		||||
                <MenuItem Header="E_xit" />
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 | 
			
		||||
             xmlns:ctrl="clr-namespace:RainmeterStudio.UI.Controller"
 | 
			
		||||
             xmlns:ui="clr-namespace:RainmeterStudio.UI"
 | 
			
		||||
             mc:Ignorable="d" 
 | 
			
		||||
             d:DesignHeight="300" d:DesignWidth="300">
 | 
			
		||||
    <UserControl.Resources>
 | 
			
		||||
@@ -45,13 +46,16 @@
 | 
			
		||||
        <TreeView Grid.Row="2" Name="treeProjectItems">
 | 
			
		||||
            <TreeView.ItemContainerStyle>
 | 
			
		||||
                <Style TargetType="{x:Type TreeViewItem}">
 | 
			
		||||
                    <Setter Property="IsExpanded" Value="True" />
 | 
			
		||||
                    <Setter Property="IsExpanded" Value="{Binding Data.IsExpanded, Mode=TwoWay}" />
 | 
			
		||||
                    <Setter Property="IsSelected" Value="{Binding Data.IsSelected, Mode=TwoWay}" />
 | 
			
		||||
                    <EventSetter Event="Expanded" Handler="TreeViewItem_ExpandedOrCollapsed" />
 | 
			
		||||
                    <EventSetter Event="Collapsed" Handler="TreeViewItem_ExpandedOrCollapsed" />
 | 
			
		||||
                </Style>
 | 
			
		||||
            </TreeView.ItemContainerStyle>
 | 
			
		||||
            <TreeView.ItemTemplate>
 | 
			
		||||
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
 | 
			
		||||
                    <DockPanel LastChildFill="True">
 | 
			
		||||
                        <Image DockPanel.Dock="Left" Width="16" Height="16" Source="{Binding Converter={StaticResource IconConverter}}" />
 | 
			
		||||
                        <Image DockPanel.Dock="Left" Width="16" Height="16" Source="{Binding Data.Reference, Converter={StaticResource IconConverter}}" />
 | 
			
		||||
                        <TextBlock Text="{Binding Data.Name}" />
 | 
			
		||||
                    </DockPanel>
 | 
			
		||||
                </HierarchicalDataTemplate>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Collections.ObjectModel;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
using System.Text;
 | 
			
		||||
@@ -17,6 +18,7 @@ using RainmeterStudio.Interop;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using RainmeterStudio.Storage;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
using RainmeterStudio.UI.ViewModel;
 | 
			
		||||
using RainmeterStudio.Utils;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI
 | 
			
		||||
@@ -48,78 +50,50 @@ namespace RainmeterStudio.UI
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _syncWithActiveViewCommand;
 | 
			
		||||
        public Command SyncWithActiveViewCommand
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        public Command SyncWithActiveViewCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public Command RefreshCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public Command ExpandAllCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public Command CollapseAllCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public Command ShowAllFilesCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        private bool _canExpand = false;
 | 
			
		||||
        private bool CanExpand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_syncWithActiveViewCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _syncWithActiveViewCommand = new Command("ProjectPanel_SyncWithActiveViewCommand", SyncWithActiveView);
 | 
			
		||||
                }
 | 
			
		||||
                return _syncWithActiveViewCommand;
 | 
			
		||||
                return _canExpand;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _canExpand = value;
 | 
			
		||||
 | 
			
		||||
                if (ExpandAllCommand != null)
 | 
			
		||||
                    ExpandAllCommand.NotifyCanExecuteChanged();
 | 
			
		||||
 | 
			
		||||
                if (CollapseAllCommand != null)
 | 
			
		||||
                    CollapseAllCommand.NotifyCanExecuteChanged();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _refreshCommand;
 | 
			
		||||
        public Command RefreshCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_refreshCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _refreshCommand = new Command("ProjectPanel_RefreshCommand", SyncWithActiveView)
 | 
			
		||||
                    {
 | 
			
		||||
                        Shortcut = new KeyGesture(Key.F5)
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
                return _refreshCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _expandAllCommand;
 | 
			
		||||
        public Command ExpandAllCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_expandAllCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _expandAllCommand = new Command("ProjectPanel_ExpandAllCommand", SyncWithActiveView);
 | 
			
		||||
                }
 | 
			
		||||
                return _expandAllCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _collapseAllCommand;
 | 
			
		||||
        public Command CollapseAllCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_collapseAllCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _collapseAllCommand = new Command("ProjectPanel_CollapseAllCommand", SyncWithActiveView);
 | 
			
		||||
                }
 | 
			
		||||
                return _collapseAllCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _showAllFilesCommand;
 | 
			
		||||
        public Command ShowAllFilesCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_showAllFilesCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _showAllFilesCommand = new Command("ProjectPanel_ShowAllFilesCommand", SyncWithActiveView);
 | 
			
		||||
                }
 | 
			
		||||
                return _showAllFilesCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ProjectPanel()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            SyncWithActiveViewCommand = new Command("ProjectPanel_SyncWithActiveViewCommand", SyncWithActiveView);
 | 
			
		||||
            RefreshCommand = new Command("ProjectPanel_RefreshCommand", Refresh);
 | 
			
		||||
            ExpandAllCommand = new Command("ProjectPanel_ExpandAllCommand", ExpandAll, () => _canExpand);
 | 
			
		||||
            CollapseAllCommand = new Command("ProjectPanel_CollapseAllCommand", CollapseAll, () => !_canExpand);
 | 
			
		||||
            ShowAllFilesCommand = new Command("ProjectPanel_ShowAllFilesCommand", Refresh);
 | 
			
		||||
 | 
			
		||||
            this.DataContext = this;
 | 
			
		||||
            Refresh();
 | 
			
		||||
        }
 | 
			
		||||
@@ -144,34 +118,86 @@ namespace RainmeterStudio.UI
 | 
			
		||||
            {
 | 
			
		||||
                this.IsEnabled = true;
 | 
			
		||||
 | 
			
		||||
                // Display all files in the project directory
 | 
			
		||||
                // Get tree
 | 
			
		||||
                Tree<ReferenceViewModel> tree;
 | 
			
		||||
                if (toggleShowAllFiles.IsChecked.HasValue && toggleShowAllFiles.IsChecked.Value)
 | 
			
		||||
                {
 | 
			
		||||
                    string projectFolder = System.IO.Path.GetDirectoryName(Controller.ActiveProjectPath);
 | 
			
		||||
                    var tree = DirectoryHelper.GetFolderTree(projectFolder);
 | 
			
		||||
                    tree.Data = Controller.ActiveProject.Root.Data;
 | 
			
		||||
            
 | 
			
		||||
                    treeProjectItems.Items.Clear();
 | 
			
		||||
                    treeProjectItems.Items.Add(tree);
 | 
			
		||||
                    tree = GetAllFiles();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Display only the project items
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    treeProjectItems.Items.Clear();
 | 
			
		||||
                    treeProjectItems.Items.Add(Controller.ActiveProject.Root);
 | 
			
		||||
                    tree = GetProjectItems();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Add tree to tree view
 | 
			
		||||
                treeProjectItems.Items.Clear();
 | 
			
		||||
                treeProjectItems.Items.Add(tree);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void toggleShowAllFiles_Checked(object sender, RoutedEventArgs e)
 | 
			
		||||
        private Tree<ReferenceViewModel> GetAllFiles()
 | 
			
		||||
        {
 | 
			
		||||
            Refresh();
 | 
			
		||||
            // Get directory name
 | 
			
		||||
            string projectFolder = System.IO.Path.GetDirectoryName(Controller.ActiveProjectPath);
 | 
			
		||||
 | 
			
		||||
            // Get folder tree
 | 
			
		||||
            Tree<Reference> refTree = DirectoryHelper.GetFolderTree(projectFolder);
 | 
			
		||||
            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));
 | 
			
		||||
            refTree.Remove(project);
 | 
			
		||||
 | 
			
		||||
            // Transform to reference view model and return
 | 
			
		||||
            return refTree.TransformData<Reference, ReferenceViewModel>((data) => new ReferenceViewModel(data));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void toggleShowAllFiles_Unchecked(object sender, RoutedEventArgs e)
 | 
			
		||||
        private Tree<ReferenceViewModel> GetProjectItems()
 | 
			
		||||
        {
 | 
			
		||||
            Refresh();
 | 
			
		||||
            // Get project items
 | 
			
		||||
            Tree<Reference> refTree = Controller.ActiveProject.Root;
 | 
			
		||||
 | 
			
		||||
            // Transform to reference view model and return
 | 
			
		||||
            return refTree.TransformData<Reference, ReferenceViewModel>((data) => new ReferenceViewModel(data));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ExpandAll()
 | 
			
		||||
        {
 | 
			
		||||
            // Get tree
 | 
			
		||||
            var tree = treeProjectItems.Items[0] as Tree<ReferenceViewModel>;
 | 
			
		||||
            if (tree == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            // Expand all
 | 
			
		||||
            tree.Apply((node) => node.Data.IsExpanded = true);
 | 
			
		||||
 | 
			
		||||
            // Set can expand property
 | 
			
		||||
            CanExpand = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void CollapseAll()
 | 
			
		||||
        {
 | 
			
		||||
            // Get tree
 | 
			
		||||
            var tree = treeProjectItems.Items[0] as Tree<ReferenceViewModel>;
 | 
			
		||||
            if (tree == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            // Expand all
 | 
			
		||||
            tree.Apply((node) => node.Data.IsExpanded = false);
 | 
			
		||||
 | 
			
		||||
            // Set can expand property
 | 
			
		||||
            CanExpand = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void TreeViewItem_ExpandedOrCollapsed(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // Get tree
 | 
			
		||||
            var tree = treeProjectItems.Items[0] as Tree<ReferenceViewModel>;
 | 
			
		||||
            if (tree == null)
 | 
			
		||||
                return;
 | 
			
		||||
            
 | 
			
		||||
            // We can expand if the root is not expanded
 | 
			
		||||
            CanExpand = (!tree.Data.IsExpanded);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										125
									
								
								RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								RainmeterStudio/UI/ViewModel/ReferenceViewModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,125 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.ViewModel
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Contains the view model of a reference
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class ReferenceViewModel : INotifyPropertyChanged
 | 
			
		||||
    {
 | 
			
		||||
        #region Properties
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the linked reference
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Reference Reference { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the name
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Name
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Reference.Name;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                Reference.Name = value;
 | 
			
		||||
                
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("Name"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Path
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Reference.Path;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                Reference.Path = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("Path"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        private bool _isExpanded = true;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a property indicating if the tree view item is expanded
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsExpanded
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _isExpanded;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _isExpanded = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("IsExpanded"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool _isSelected;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets a property indicating if the tree view item is selected
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsSelected
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _isSelected;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _isSelected = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Events
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Event triggered when a property is changed
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event PropertyChangedEventHandler PropertyChanged;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Constructor
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates a new instance of reference view model
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="reference">Reference</param>
 | 
			
		||||
        public ReferenceViewModel(Reference reference)
 | 
			
		||||
        {
 | 
			
		||||
            Reference = reference;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user