Rewrote Reference class

This commit is contained in:
2014-08-30 10:24:01 +03:00
parent a3fdc31caa
commit 520eed12a6
18 changed files with 478 additions and 85 deletions

View File

@ -0,0 +1,41 @@
<Window x:Class="RainmeterStudio.UI.Dialogs.CloseUnsavedDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:RainmeterStudio.Resources"
Title="{x:Static r:Strings.CloseUnsavedDialog_Title}" Height="200" Width="320"
WindowStartupLocation="CenterOwner"
WindowStyle="ToolWindow" ShowInTaskbar="False"
Background="WhiteSmoke" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{x:Static r:Strings.CloseUnsavedDialog_Message }"
Margin="4"/>
<ScrollViewer Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<TextBlock Name="textFiles"
Margin="4" Padding="4"
Background="White"/>
</ScrollViewer>
<TextBlock Grid.Row="2" Text="{x:Static r:Strings.CloseUnsavedDialog_Question }"
Margin="4"/>
<StackPanel Grid.Row="3" Orientation="Horizontal"
HorizontalAlignment="Right">
<Button Name="buttonSave" Content="{x:Static r:Strings.Dialog_Save}" IsDefault="True" Margin="1px" Click="buttonSave_Click" />
<Button Name="buttonDoNotSave" Content="{x:Static r:Strings.Dialog_DoNotSave}" Margin="1px" Click="buttonDoNotSave_Click" />
<Button Name="buttonCancel" Content="{x:Static r:Strings.Dialog_Cancel}" IsCancel="True" Margin="1px" Click="buttonCancel_Click" />
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,103 @@
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.Shapes;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.UI.Dialogs
{
/// <summary>
/// Interaction logic for CloseUnsavedDialog.xaml
/// </summary>
public partial class CloseUnsavedDialog : Window
{
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static bool? ShowDialog(IEnumerable<IDocument> unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
return dialog.ShowDialog();
}
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="owner">Owner window</param>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static bool? ShowDialog(Window owner, IEnumerable<IDocument> unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.Owner = owner;
return dialog.ShowDialog();
}
/// <summary>
/// Displays the dialog and returns the result
/// </summary>
/// <param name="owner">Owner window</param>
/// <param name="unsavedDocuments">List of unsaved documents</param>
/// <returns>Dialog result</returns>
public static bool? ShowDialog(Window owner, params IDocument[] unsavedDocuments)
{
var dialog = new CloseUnsavedDialog(unsavedDocuments);
dialog.Owner = owner;
return dialog.ShowDialog();
}
/// <summary>
/// Initializes the dialog
/// </summary>
/// <param name="unsavedDocuments">List of unsaved documents</param>
public CloseUnsavedDialog(IEnumerable<IDocument> unsavedDocuments)
{
InitializeComponent();
textFiles.Inlines.AddRange(unsavedDocuments.SelectMany(GetInlines));
}
private IEnumerable<Inline> GetInlines(IDocument doc)
{
var folder = System.IO.Path.GetDirectoryName(doc.Reference.StoragePath);
yield return new Run(folder)
{
Foreground = Brushes.DarkGray
};
yield return new Run(doc.Reference.Name)
{
FontWeight = FontWeights.Bold
};
}
private void buttonSave_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
private void buttonDoNotSave_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = null;
Close();
}
}
}