2014-07-27 13:21:06 +00:00
|
|
|
|
using System;
|
2014-09-16 18:57:15 +00:00
|
|
|
|
using System.Collections.Generic;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
2014-09-16 18:57:15 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Model;
|
|
|
|
|
using RainmeterStudio.Core.Utils;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
using RainmeterStudio.UI.Controller;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
using RainmeterStudio.UI.ViewModel;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-08-16 12:40:08 +00:00
|
|
|
|
namespace RainmeterStudio.UI.Panels
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for SkinsPanel.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ProjectPanel : UserControl
|
|
|
|
|
{
|
2014-09-16 18:57:15 +00:00
|
|
|
|
private ProjectController _projectController;
|
|
|
|
|
|
|
|
|
|
public ProjectController ProjectController
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2014-09-16 18:57:15 +00:00
|
|
|
|
return _projectController;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2014-08-16 12:40:08 +00:00
|
|
|
|
// Unsubscribe from old controller
|
2014-09-16 18:57:15 +00:00
|
|
|
|
if (_projectController != null)
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
2014-09-16 18:57:15 +00:00
|
|
|
|
ProjectController.ActiveProjectChanged -= Controller_ActiveProjectChanged;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set new project
|
2014-09-16 18:57:15 +00:00
|
|
|
|
_projectController = value;
|
|
|
|
|
_projectController.ActiveProjectChanged += Controller_ActiveProjectChanged;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-16 18:57:15 +00:00
|
|
|
|
public DocumentController DocumentController { get; set; }
|
|
|
|
|
|
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
|
|
|
|
|
|
2014-08-16 12:40:08 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the selected tree view item
|
|
|
|
|
/// </summary>
|
2014-08-31 11:41:24 +00:00
|
|
|
|
public Reference ActiveItem
|
2014-08-16 12:40:08 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var selected = treeProjectItems.SelectedItem as Tree<ReferenceViewModel>;
|
|
|
|
|
|
|
|
|
|
if (selected == null)
|
|
|
|
|
{
|
2014-09-16 18:57:15 +00:00
|
|
|
|
return ProjectController.ActiveProject.Root;
|
2014-08-16 12:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return selected.Data.Reference;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2014-08-16 12:40:08 +00:00
|
|
|
|
ExpandAllCommand.NotifyCanExecuteChanged();
|
|
|
|
|
CollapseAllCommand.NotifyCanExecuteChanged();
|
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()
|
|
|
|
|
{
|
2014-09-12 16:20:21 +00:00
|
|
|
|
// Clear current items
|
|
|
|
|
treeProjectItems.Items.Clear();
|
|
|
|
|
|
|
|
|
|
// No project
|
2014-09-16 18:57:15 +00:00
|
|
|
|
if (ProjectController == null || ProjectController.ActiveProject == null)
|
2014-07-27 13:21:06 +00:00
|
|
|
|
{
|
|
|
|
|
this.IsEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.IsEnabled = true;
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
// Get tree
|
2014-08-31 11:41:24 +00:00
|
|
|
|
Reference refTree;
|
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
if (toggleShowAllFiles.IsChecked.HasValue && toggleShowAllFiles.IsChecked.Value)
|
|
|
|
|
{
|
2014-08-31 11:41:24 +00:00
|
|
|
|
// Get directory name
|
2014-09-16 18:57:15 +00:00
|
|
|
|
string projectFolder = System.IO.Path.GetDirectoryName(ProjectController.ActiveProjectPath);
|
2014-08-31 11:41:24 +00:00
|
|
|
|
|
|
|
|
|
// Get folder tree
|
|
|
|
|
refTree = DirectoryHelper.GetFolderTree(projectFolder);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-09-16 18:57:15 +00:00
|
|
|
|
refTree = ProjectController.ActiveProject.Root;
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
// Add tree to tree view
|
2014-08-31 11:41:24 +00:00
|
|
|
|
treeProjectItems.Items.Add(new ReferenceViewModel(refTree));
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-28 17:18:18 +00:00
|
|
|
|
private void ExpandAll()
|
|
|
|
|
{
|
|
|
|
|
// Get tree
|
2014-08-31 11:41:24 +00:00
|
|
|
|
var tree = treeProjectItems.Items[0] as ReferenceViewModel;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
if (tree == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Expand all
|
2014-08-31 11:41:24 +00:00
|
|
|
|
tree.TreeExpand(true);
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
// Set can expand property
|
|
|
|
|
CanExpand = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CollapseAll()
|
|
|
|
|
{
|
|
|
|
|
// Get tree
|
2014-08-31 11:41:24 +00:00
|
|
|
|
var tree = treeProjectItems.Items[0] as ReferenceViewModel;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
if (tree == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Expand all
|
2014-08-31 11:41:24 +00:00
|
|
|
|
tree.TreeExpand(false);
|
2014-07-28 17:18:18 +00:00
|
|
|
|
|
|
|
|
|
// Set can expand property
|
|
|
|
|
CanExpand = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeViewItem_ExpandedOrCollapsed(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Get tree
|
2014-08-31 11:41:24 +00:00
|
|
|
|
var tree = treeProjectItems.Items[0] as ReferenceViewModel;
|
2014-07-28 17:18:18 +00:00
|
|
|
|
if (tree == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// We can expand if the root is not expanded
|
2014-08-31 11:41:24 +00:00
|
|
|
|
CanExpand = (!tree.IsExpanded);
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
2014-09-16 18:57:15 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2014-07-27 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|