mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Improved resource manager, plugin manager
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Linq;
|
||||
using RainmeterStudio.Business;
|
||||
using RainmeterStudio.Core.Documents;
|
||||
using RainmeterStudio.Core.Model.Events;
|
||||
using RainmeterStudio.UI.Dialogs;
|
||||
using RainmeterStudio.UI.ViewModel;
|
||||
|
||||
namespace RainmeterStudio.UI.Controller
|
||||
{
|
||||
@ -60,7 +63,7 @@ namespace RainmeterStudio.UI.Controller
|
||||
public void CreateWindow(DocumentTemplate defaultFormat = null, string defaultPath = "")
|
||||
{
|
||||
// Show dialog
|
||||
var dialog = new CreateDocumentDialog()
|
||||
var dialog = new CreateDocumentDialog(this)
|
||||
{
|
||||
Owner = OwnerWindow,
|
||||
SelectedTemplate = defaultFormat,
|
||||
@ -84,5 +87,15 @@ namespace RainmeterStudio.UI.Controller
|
||||
DocumentManager.Create(format);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of document templates view models
|
||||
/// </summary>
|
||||
public IEnumerable<DocumentTemplateViewModel> DocumentTemplates
|
||||
{
|
||||
get
|
||||
{
|
||||
return DocumentManager.DocumentTemplates.Select(t => new DocumentTemplateViewModel(t));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,29 +7,30 @@ using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using RainmeterStudio.Core.Model;
|
||||
using RainmeterStudio.Resources;
|
||||
|
||||
namespace RainmeterStudio.UI.Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides icons
|
||||
/// </summary>
|
||||
public static class IconProvider
|
||||
{
|
||||
private static Dictionary<string, ImageSource> _loadedImages = new Dictionary<string, ImageSource>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets an icon by resource name
|
||||
/// </summary>
|
||||
/// <param name="key">Resource name</param>
|
||||
/// <returns>The icon</returns>
|
||||
public static ImageSource GetIcon(string key)
|
||||
{
|
||||
if (!_loadedImages.ContainsKey(key))
|
||||
{
|
||||
// Try to get the icon file name
|
||||
string iconPath = Resources.Icons.ResourceManager.GetString(key);
|
||||
if (iconPath == null)
|
||||
return null;
|
||||
|
||||
// Load the image
|
||||
var uri = new Uri(iconPath, UriKind.RelativeOrAbsolute);
|
||||
_loadedImages.Add(key, new BitmapImage(uri));
|
||||
}
|
||||
return _loadedImages[key];
|
||||
return ResourceProvider.GetImage(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an icon by reference
|
||||
/// </summary>
|
||||
/// <param name="item">The reference</param>
|
||||
/// <returns>The icon</returns>
|
||||
public static ImageSource GetProjectItemIcon(Reference item)
|
||||
{
|
||||
// Resource name
|
||||
@ -51,6 +52,9 @@ namespace RainmeterStudio.UI.Controller
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Icon provider converter, for use in xaml
|
||||
/// </summary>
|
||||
public class IconProviderConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
|
@ -3,16 +3,29 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Create..." Height="250" Width="400"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
WindowStyle="ToolWindow" ShowInTaskbar="False">
|
||||
WindowStyle="ToolWindow" ShowInTaskbar="False"
|
||||
Background="WhiteSmoke" >
|
||||
|
||||
<Grid Background="WhiteSmoke">
|
||||
<Grid Margin="2px">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="2" />
|
||||
<ColumnDefinition Width="3*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListView Name="listCategories" Grid.Row="0" Grid.Column="0"
|
||||
SelectionChanged="listCategories_SelectionChanged"
|
||||
Margin="1px"/>
|
||||
|
||||
<ListView Name="listFormats" Grid.Row="0">
|
||||
<GridSplitter Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
|
||||
|
||||
<ListView Name="listFormats" Grid.Row="0" Grid.Column="2" Margin="1px">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DockPanel>
|
||||
@ -26,18 +39,9 @@
|
||||
</DockPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock FontWeight="Bold" FontSize="13pt" Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListView.GroupStyle>
|
||||
</ListView>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid Grid.Row="1" Grid.ColumnSpan="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
@ -49,15 +53,15 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0">Path:</TextBlock>
|
||||
<TextBox Name="textPath" Grid.Row="0" Grid.Column="1"></TextBox>
|
||||
<TextBox Name="textPath" Grid.Row="0" Grid.Column="1" Margin="1px"></TextBox>
|
||||
<Button Grid.Row="0" Grid.Column="2">...</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal"
|
||||
|
||||
<StackPanel Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<Button Name="buttonCreate" Click="buttonCreate_Click" IsDefault="True">Create</Button>
|
||||
<Button Name="buttonCancel" Click="buttonCancel_Click" IsCancel="True">Cancel</Button>
|
||||
<Button Name="buttonCreate" Click="buttonCreate_Click" IsDefault="True" Margin="1px">Create</Button>
|
||||
<Button Name="buttonCancel" Click="buttonCancel_Click" IsCancel="True" Margin="1px">Cancel</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
@ -13,6 +13,7 @@ using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using RainmeterStudio.Business;
|
||||
using RainmeterStudio.Core.Documents;
|
||||
using RainmeterStudio.UI.Controller;
|
||||
|
||||
namespace RainmeterStudio.UI.Dialogs
|
||||
{
|
||||
@ -21,6 +22,8 @@ namespace RainmeterStudio.UI.Dialogs
|
||||
/// </summary>
|
||||
public partial class CreateDocumentDialog : Window
|
||||
{
|
||||
private DocumentController _documentController;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected file format
|
||||
/// </summary>
|
||||
@ -54,20 +57,34 @@ namespace RainmeterStudio.UI.Dialogs
|
||||
/// <summary>
|
||||
/// Creates a new instance of CreateDocumentDialog
|
||||
/// </summary>
|
||||
public CreateDocumentDialog()
|
||||
public CreateDocumentDialog(DocumentController docCtrl)
|
||||
{
|
||||
InitializeComponent();
|
||||
_documentController = docCtrl;
|
||||
|
||||
PopulateFormats();
|
||||
PopulateCategories();
|
||||
RepopulateFormats();
|
||||
Validate();
|
||||
}
|
||||
|
||||
private void PopulateFormats()
|
||||
private void PopulateCategories()
|
||||
{
|
||||
//listFormats.ItemsSource = DocumentManager.Instance.DocumentFormats;
|
||||
listCategories.ItemsSource = _documentController.DocumentTemplates
|
||||
.Select(template => template.Category)
|
||||
.Where(cat => cat != null)
|
||||
.Distinct()
|
||||
.Concat(new[] { "All" });
|
||||
|
||||
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listFormats.ItemsSource);
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
|
||||
listCategories.SelectedIndex = listCategories.Items.Count - 1;
|
||||
}
|
||||
|
||||
private void RepopulateFormats()
|
||||
{
|
||||
if (Object.Equals(listCategories.SelectedItem, "All"))
|
||||
listFormats.ItemsSource = _documentController.DocumentTemplates;
|
||||
|
||||
else
|
||||
listFormats.ItemsSource = _documentController.DocumentTemplates.Where(x => Object.Equals(x.Category, listCategories.SelectedItem));
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, RoutedEventArgs e)
|
||||
@ -90,5 +107,10 @@ namespace RainmeterStudio.UI.Dialogs
|
||||
|
||||
buttonCreate.IsEnabled = res;
|
||||
}
|
||||
|
||||
private void listCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
RepopulateFormats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user