2014-07-27 13:21:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
using System.ComponentModel;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
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;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
using RainmeterStudio.UI.ViewModel;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
using RainmeterStudio.Utils;
|
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.UI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for SkinsPanel.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
#region Commands
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
public Command SyncWithActiveViewCommand { get; private set; }
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
public Command RefreshCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Command ExpandAllCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Command CollapseAllCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Command ShowAllFilesCommand { get; private set; }
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private bool _canExpand = false;
|
|
|
|
|
private bool CanExpand
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
return _canExpand;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
2014-07-28 17:18:18 +00:00
|
|
|
|
set
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
_canExpand = value;
|
|
|
|
|
|
|
|
|
|
if (ExpandAllCommand != null)
|
|
|
|
|
ExpandAllCommand.NotifyCanExecuteChanged();
|
|
|
|
|
|
|
|
|
|
if (CollapseAllCommand != null)
|
|
|
|
|
CollapseAllCommand.NotifyCanExecuteChanged();
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
public ProjectPanel()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// Get tree
|
|
|
|
|
Tree<ReferenceViewModel> tree;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
if (toggleShowAllFiles.IsChecked.HasValue && toggleShowAllFiles.IsChecked.Value)
|
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
tree = GetAllFiles();
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
tree = GetProjectItems();
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
// Add tree to tree view
|
|
|
|
|
treeProjectItems.Items.Clear();
|
|
|
|
|
treeProjectItems.Items.Add(tree);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
private Tree<ReferenceViewModel> GetAllFiles()
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// 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));
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
private Tree<ReferenceViewModel> GetProjectItems()
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// 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);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|