diff --git a/RainmeterStudio/App.xaml b/RainmeterStudio/App.xaml index 2b40779e..980804b1 100644 --- a/RainmeterStudio/App.xaml +++ b/RainmeterStudio/App.xaml @@ -8,6 +8,39 @@ + + + + + + + + + + diff --git a/RainmeterStudio/Business/ProjectManager.cs b/RainmeterStudio/Business/ProjectManager.cs index 3a8bf75f..a44f0374 100644 --- a/RainmeterStudio/Business/ProjectManager.cs +++ b/RainmeterStudio/Business/ProjectManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using RainmeterStudio.Model; @@ -16,11 +17,6 @@ namespace RainmeterStudio.Business /// public Project ActiveProject { get; protected set; } - /// - /// Gets the currently opened project's path - /// - public string ActiveProjectPath { get; protected set; } - /// /// Gets or sets the project storage /// @@ -61,9 +57,10 @@ namespace RainmeterStudio.Business // Create project object ActiveProject = new Project(); ActiveProject.Name = name; + ActiveProject.Path = path; // Save to file - ActiveProjectPath = path; + Directory.CreateDirectory(Path.GetDirectoryName(path)); SaveActiveProject(); // Raise event @@ -83,7 +80,7 @@ namespace RainmeterStudio.Business // Open using storage ActiveProject = Storage.Load(path); - ActiveProjectPath = path; + ActiveProject.Path = path; // Raise event if (ActiveProjectChanged != null) @@ -100,7 +97,7 @@ namespace RainmeterStudio.Business throw new InvalidOperationException("Cannot save a project that is not opened."); // Save - Storage.Save(ActiveProjectPath, ActiveProject); + Storage.Save(ActiveProject.Path, ActiveProject); } /// @@ -109,7 +106,6 @@ namespace RainmeterStudio.Business public void Close() { ActiveProject = null; - ActiveProjectPath = null; // Raise event if (ActiveProjectChanged != null) diff --git a/RainmeterStudio/Documents/Text/TextEditorFactory.cs b/RainmeterStudio/Documents/Text/TextEditorFactory.cs index bdef5786..9122a800 100644 --- a/RainmeterStudio/Documents/Text/TextEditorFactory.cs +++ b/RainmeterStudio/Documents/Text/TextEditorFactory.cs @@ -29,7 +29,7 @@ namespace RainmeterStudio.Documents.Text Category = Resources.Strings.Category_Utility, DefaultExtension = ".txt", Description = Resources.Strings.DocumentFormat_TextFile_Description, - Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Resources/Icons/text_file_32.png", UriKind.RelativeOrAbsolute)), + Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri(Resources.Icons.DocumentTemplate_Text, UriKind.RelativeOrAbsolute)), Factory = this }; } diff --git a/RainmeterStudio/Model/Project.cs b/RainmeterStudio/Model/Project.cs index 088263f9..edc71b5c 100644 --- a/RainmeterStudio/Model/Project.cs +++ b/RainmeterStudio/Model/Project.cs @@ -6,21 +6,86 @@ using System.Xml.Serialization; namespace RainmeterStudio.Model { + /// + /// Defines a Rainmeter Studio project + /// public class Project { - [XmlElement("name")] - public string Name { get; set; } + #region Name property + private string _name; + + /// + /// Gets or sets the name of the project + /// + [XmlElement("name")] + public string Name + { + get + { + return _name; + } + set + { + _name = value; + + if (Root != null) + Root.Data = new Reference(Name, Path); + } + } + + private string _path; + + #endregion + + #region Path property + + /// + /// Gets or sets the file path of this project + /// + [XmlIgnore] + public string Path + { + get + { + return _path; + } + set + { + _path = value; + + if (Root != null) + Root.Data = new Reference(Name, Path); + } + } + + #endregion + + #region Author property + + /// + /// Gets or sets the author of the project + /// [XmlElement("author")] public string Author { get; set; } + #endregion + + #region Version property + + /// + /// Gets or sets the version of the project + /// [XmlIgnore] public Version Version { get; set; } + /// + /// Gets or sets the string representation of the project version + /// [XmlElement("version")] public string VersionString { - get + get { return Version.ToString(); } @@ -30,15 +95,39 @@ namespace RainmeterStudio.Model } } + #endregion + + #region Auto-load file property + + /// + /// Gets or sets the reference to the file to automatically load at package installation + /// [XmlElement("autoLoadFile")] public Reference AutoLoadFile { get; set; } + #endregion + + #region Variable files property + + /// + /// Gets or sets the list of variable files + /// [XmlArray("variableFiles")] public List VariableFiles { get; set; } + #endregion + + #region Minimum rainmeter & windows properties + + /// + /// Gets or sets the minimum rainmeter version + /// [XmlIgnore] public Version MinimumRainmeter { get; set; } + /// + /// Gets or sets the string representation of the minimum rainmeter version + /// [XmlElement("minimumRainmeter")] public string MinimumRainmeterString { @@ -52,9 +141,15 @@ namespace RainmeterStudio.Model } } + /// + /// Gets or sets the minimum Windows version + /// [XmlIgnore] public Version MinimumWindows { get; set; } + /// + /// Gets or sets the string representation of the minimum Windows version + /// [XmlElement("minimumWindows")] public string MinimumWindowsString { @@ -68,9 +163,23 @@ namespace RainmeterStudio.Model } } + #endregion + + #region Root property + + /// + /// Gets or sets the root node + /// [XmlElement("root")] public Tree Root { get; set; } + #endregion + + #region Constructor + + /// + /// Initializes a project + /// public Project() { Root = new Tree(); @@ -80,13 +189,17 @@ namespace RainmeterStudio.Model MinimumWindows = new Version("5.1"); } + #endregion + + #region Equals + public override bool Equals(object obj) { Project other = obj as Project; - + if (other == null) return false; - + bool res = String.Equals(Author, other.Author); res &= Reference.Equals(AutoLoadFile, other.AutoLoadFile); res &= Version.Equals(MinimumRainmeter, other.MinimumRainmeter); @@ -110,5 +223,7 @@ namespace RainmeterStudio.Model return hash; } + + #endregion } } diff --git a/RainmeterStudio/Model/Tree.cs b/RainmeterStudio/Model/Tree.cs index 262e9dcd..62466cf1 100644 --- a/RainmeterStudio/Model/Tree.cs +++ b/RainmeterStudio/Model/Tree.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Xml.Serialization; @@ -12,17 +13,17 @@ namespace RainmeterStudio.Model public T Data { get; set; } [XmlArray("children"), XmlArrayItem("child")] - public List> Children { get; set; } + public ObservableCollection> Children { get; set; } public Tree() { - Children = new List>(); + Children = new ObservableCollection>(); Data = default(T); } public Tree(T data) { - Children = new List>(); + Children = new ObservableCollection>(); Data = data; } diff --git a/RainmeterStudio/RainmeterStudio.csproj b/RainmeterStudio/RainmeterStudio.csproj index 4a6c233f..98c62880 100644 --- a/RainmeterStudio/RainmeterStudio.csproj +++ b/RainmeterStudio/RainmeterStudio.csproj @@ -110,6 +110,7 @@ + CreateDocumentDialog.xaml @@ -119,9 +120,10 @@ CreateProjectDialog.xaml - - SkinsPanel.xaml + + ProjectPanel.xaml + Designer MSBuild:Compile @@ -150,7 +152,7 @@ MainWindow.xaml Code - + Designer MSBuild:Compile @@ -199,27 +201,52 @@ - + - + - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RainmeterStudio/UI/ProjectPanel.xaml.cs b/RainmeterStudio/UI/ProjectPanel.xaml.cs new file mode 100644 index 00000000..35aa7505 --- /dev/null +++ b/RainmeterStudio/UI/ProjectPanel.xaml.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using RainmeterStudio.Interop; +using RainmeterStudio.Model; +using RainmeterStudio.Storage; +using RainmeterStudio.UI.Controller; +using RainmeterStudio.Utils; + +namespace RainmeterStudio.UI +{ + /// + /// Interaction logic for SkinsPanel.xaml + /// + public partial class ProjectPanel : UserControl + { + private ProjectController _controller; + public ProjectController Controller + { + get + { + return _controller; + } + set + { + // Unsubscribe from old project + if (_controller != null) + { + Controller.ActiveProjectChanged -= Controller_ActiveProjectChanged; + } + + // Set new project + _controller = value; + _controller.ActiveProjectChanged += Controller_ActiveProjectChanged; + Refresh(); + } + } + + private Command _syncWithActiveViewCommand; + public Command SyncWithActiveViewCommand + { + get + { + if (_syncWithActiveViewCommand == null) + { + _syncWithActiveViewCommand = new Command("ProjectPanel_SyncWithActiveViewCommand", SyncWithActiveView); + } + return _syncWithActiveViewCommand; + } + } + + 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(); + + this.DataContext = this; + Refresh(); + } + + void Controller_ActiveProjectChanged(object sender, EventArgs e) + { + Refresh(); + } + + private void SyncWithActiveView() + { + // TODO: implement + } + + private void Refresh() + { + if (Controller == null || Controller.ActiveProject == null) + { + this.IsEnabled = false; + } + else + { + this.IsEnabled = true; + + // Display all files in the project directory + 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); + } + + // Display only the project items + else + { + treeProjectItems.Items.Clear(); + treeProjectItems.Items.Add(Controller.ActiveProject.Root); + } + } + } + + private void toggleShowAllFiles_Checked(object sender, RoutedEventArgs e) + { + Refresh(); + } + + private void toggleShowAllFiles_Unchecked(object sender, RoutedEventArgs e) + { + Refresh(); + } + } +} diff --git a/RainmeterStudio/UI/SkinsPanel.xaml b/RainmeterStudio/UI/SkinsPanel.xaml deleted file mode 100644 index 95e255ca..00000000 --- a/RainmeterStudio/UI/SkinsPanel.xaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/RainmeterStudio/UI/SkinsPanel.xaml.cs b/RainmeterStudio/UI/SkinsPanel.xaml.cs deleted file mode 100644 index 30cf0c99..00000000 --- a/RainmeterStudio/UI/SkinsPanel.xaml.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using RainmeterStudio.Interop; -using RainmeterStudio.Storage; - -namespace RainmeterStudio.UI -{ - /// - /// Interaction logic for SkinsPanel.xaml - /// - public partial class SkinsPanel : UserControl - { - public SkinsPanel() - { - InitializeComponent(); - - //var x = Rainmeter.Instance.Handle; - } - } -} diff --git a/RainmeterStudio/Utils/DirectoryHelper.cs b/RainmeterStudio/Utils/DirectoryHelper.cs new file mode 100644 index 00000000..084cc99e --- /dev/null +++ b/RainmeterStudio/Utils/DirectoryHelper.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using RainmeterStudio.Model; + +namespace RainmeterStudio.Utils +{ + public static class DirectoryHelper + { + public static Tree GetFolderTree(string folder) + { + // Build tree object + Reference reference = new Reference(Path.GetFileName(folder), folder); + Tree tree = new Tree(reference); + + // Navigate folder structure + if (Directory.Exists(folder)) + { + foreach (var item in Directory.EnumerateDirectories(folder) + .Concat(Directory.EnumerateFiles(folder))) + { + tree.Add(GetFolderTree(item)); + } + } + + // Return tree + return tree; + } + } +}