mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Work on document manager
This commit is contained in:
48
RainmeterEditor/UI/Controller/DocumentController.cs
Normal file
48
RainmeterEditor/UI/Controller/DocumentController.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using RainmeterEditor.Business;
|
||||
using RainmeterEditor.UI.Dialogs;
|
||||
using RainmeterEditor.Model.Events;
|
||||
using RainmeterEditor.Model;
|
||||
|
||||
namespace RainmeterEditor.UI.Controller
|
||||
{
|
||||
public class DocumentController
|
||||
{
|
||||
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
|
||||
{
|
||||
add
|
||||
{
|
||||
DocumentManager.Instance.DocumentOpened += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
DocumentManager.Instance.DocumentOpened -= value;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler DocumentClosed;
|
||||
|
||||
public DocumentController()
|
||||
{
|
||||
}
|
||||
|
||||
public void Create()
|
||||
{
|
||||
// Show dialog
|
||||
var dialog = new CreateDocumentDialog();
|
||||
bool? res = dialog.ShowDialog();
|
||||
|
||||
if (!res.HasValue || !res.Value)
|
||||
return;
|
||||
|
||||
var format = dialog.SelectedFormat;
|
||||
var path = dialog.SelectedPath;
|
||||
|
||||
// Call manager
|
||||
DocumentManager.Instance.Create(format, path);
|
||||
}
|
||||
}
|
||||
}
|
61
RainmeterEditor/UI/Dialogs/CreateDocumentDialog.xaml
Normal file
61
RainmeterEditor/UI/Dialogs/CreateDocumentDialog.xaml
Normal file
@ -0,0 +1,61 @@
|
||||
<Window x:Class="RainmeterEditor.UI.Dialogs.CreateDocumentDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="CreateDocumentDialog" Height="250" Width="400">
|
||||
<Grid Background="WhiteSmoke">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListView Name="listFormats" Grid.Row="0">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DockPanel>
|
||||
<Image DockPanel.Dock="Left" Source="{Binding Icon}"
|
||||
Width="32" Height="32" Margin="2"
|
||||
Stretch="Uniform" VerticalAlignment="Top" />
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
|
||||
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
|
||||
<TextBlock Text="{Binding Description}" />
|
||||
</StackPanel>
|
||||
</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.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0">Path:</TextBlock>
|
||||
<TextBox Name="textPath" Grid.Row="0" Grid.Column="1"></TextBox>
|
||||
<Button Grid.Row="0" Grid.Column="2">...</Button>
|
||||
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<Button Name="buttonCreate" Click="buttonCreate_Click" IsDefault="True">Create</Button>
|
||||
<Button Name="buttonCancel" Click="buttonCancel_Click" IsCancel="True">Cancel</Button>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
83
RainmeterEditor/UI/Dialogs/CreateDocumentDialog.xaml.cs
Normal file
83
RainmeterEditor/UI/Dialogs/CreateDocumentDialog.xaml.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
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 RainmeterEditor.Business;
|
||||
using RainmeterEditor.Model;
|
||||
|
||||
namespace RainmeterEditor.UI.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateDocumentDialog.xaml
|
||||
/// </summary>
|
||||
public partial class CreateDocumentDialog : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected file format
|
||||
/// </summary>
|
||||
public DocumentFormat SelectedFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
return listFormats.SelectedItem as DocumentFormat;
|
||||
}
|
||||
set
|
||||
{
|
||||
listFormats.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path
|
||||
/// </summary>
|
||||
public string SelectedPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return textPath.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
textPath.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of CreateDocumentDialog
|
||||
/// </summary>
|
||||
public CreateDocumentDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
PopulateFormats();
|
||||
}
|
||||
|
||||
private void PopulateFormats()
|
||||
{
|
||||
listFormats.ItemsSource = DocumentManager.Instance.DocumentFormats;
|
||||
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listFormats.ItemsSource);
|
||||
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
DialogResult = false;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
xmlns:ui="clr-namespace:RainmeterEditor.UI"
|
||||
xmlns:ad="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock"
|
||||
xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
|
||||
Title="MainWindow" Height="350" Width="525">
|
||||
Title="Rainmeter Studio" Height="350" Width="525">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@ -20,7 +20,7 @@
|
||||
<!-- Menu bar -->
|
||||
<Menu Grid.Row="0" Grid.ColumnSpan="10">
|
||||
<MenuItem Header="_File">
|
||||
<MenuItem Header="_New Item..." />
|
||||
<MenuItem Header="_New Item..." Click="File_New_Click"/>
|
||||
<MenuItem Header="_Open..." />
|
||||
<Separator />
|
||||
<MenuItem Header="_Close" />
|
||||
|
@ -11,6 +11,9 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using RainmeterEditor.Model.Events;
|
||||
using RainmeterEditor.UI.Controller;
|
||||
using Xceed.Wpf.AvalonDock.Layout;
|
||||
|
||||
namespace RainmeterEditor
|
||||
{
|
||||
@ -19,9 +22,46 @@ namespace RainmeterEditor
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
DocumentController documentController = new DocumentController();
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
documentController.DocumentOpened += documentController_DocumentOpened;
|
||||
}
|
||||
|
||||
void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
|
||||
{
|
||||
// Spawn a new window
|
||||
LayoutDocument document = new LayoutDocument();
|
||||
document.Content = e.Editor.EditorUI;
|
||||
document.Title = e.Editor.Title;
|
||||
document.Closing += document_Closing;
|
||||
|
||||
documentPane.Children.Add(document);
|
||||
documentPane.SelectedContentIndex = documentPane.IndexOf(document);
|
||||
}
|
||||
|
||||
void document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
switch (MessageBox.Show("Are you sure?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
|
||||
{
|
||||
case MessageBoxResult.Yes:
|
||||
break;
|
||||
|
||||
case MessageBoxResult.No:
|
||||
break;
|
||||
|
||||
default:
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void File_New_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
documentController.Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace RainmeterEditor.UI
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var x = Rainmeter.Instance.Handle;
|
||||
//var x = Rainmeter.Instance.Handle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user