UI changes, added commands

This commit is contained in:
2014-07-25 11:09:10 +03:00
parent f0d6b36e96
commit 1d44d69b94
17 changed files with 207 additions and 18 deletions

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Media;
namespace RainmeterEditor.UI
{
public class Command : ICommand
{
#region Private members
private Action<object> _execute;
private Func<object, bool> _canExecute;
private Action _executeNoParam;
private Func<bool> _canExecuteNoParam;
#endregion
#region Public properties
public string Name { get; set; }
public string DisplayText { get; set; }
public string Tooltip { get; set; }
public ImageSource Icon { get; set; }
public KeyGesture Shortcut { get; set; }
public string ShortcutText
{
get
{
string text = String.Empty;
if ((Shortcut.Modifiers & ModifierKeys.Windows) != 0)
text += "Win+";
if ((Shortcut.Modifiers & ModifierKeys.Control) != 0)
text += "Ctrl+";
if ((Shortcut.Modifiers & ModifierKeys.Alt) != 0)
text += "Alt+";
if ((Shortcut.Modifiers & ModifierKeys.Shift) != 0)
text += "Shift+";
text += Enum.GetName(typeof(Key), Shortcut.Key);
return text;
}
}
#endregion
public event EventHandler CanExecuteChanged;
public Command(string name = null, Action<object> execute = null, Func<object, bool> canExecute = null)
{
Name = name;
_execute = execute;
_canExecute = canExecute;
}
public Command(string name = null, Action execute = null, Func<bool> canExecute = null)
{
Name = name;
_executeNoParam = execute;
_canExecuteNoParam = canExecute;
}
public virtual bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute(parameter);
else if (_canExecuteNoParam != null)
return _canExecuteNoParam();
return true;
}
public virtual void Execute(object parameter)
{
if (_execute != null)
_execute(parameter);
else if (_executeNoParam != null)
_executeNoParam();
}
}
}

View File

@ -7,11 +7,19 @@ using RainmeterEditor.UI.Dialogs;
using RainmeterEditor.Model.Events;
using RainmeterEditor.Model;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace RainmeterEditor.UI.Controller
{
public class DocumentController
{
#region Commands
public Command DocumentCreateCommand { get; private set; }
#endregion
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
{
add
@ -23,19 +31,27 @@ namespace RainmeterEditor.UI.Controller
DocumentManager.Instance.DocumentOpened -= value;
}
}
public event EventHandler DocumentClosed;
public Window OwnerWindow { get; set; }
public DocumentController()
{
DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow())
{
DisplayText = Resources.Strings.DocumentCreateCommand_DisplayText,
Tooltip = Resources.Strings.DocumentCreateCommand_ToolTip,
Icon = new BitmapImage(new Uri("/Resources/Icons/page_white_star_16.png", UriKind.RelativeOrAbsolute)),
Shortcut = new KeyGesture(Key.N, ModifierKeys.Control)
};
}
public void Create(Window parent = null, DocumentFormat defaultFormat = null, string defaultPath = "")
public void CreateWindow(DocumentFormat defaultFormat = null, string defaultPath = "")
{
// Show dialog
var dialog = new CreateDocumentDialog()
{
Owner = parent,
Owner = OwnerWindow,
SelectedFormat = defaultFormat,
SelectedPath = defaultPath
};
@ -56,5 +72,6 @@ namespace RainmeterEditor.UI.Controller
// Call manager
DocumentManager.Instance.Create(format, path);
}
}
}

View File

@ -1,4 +1,4 @@
<Window x:Class="RainmeterEditor.MainWindow"
<Window x:Class="RainmeterEditor.UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:RainmeterEditor.UI"
@ -6,6 +6,11 @@
xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
Title="Rainmeter Studio" Height="350" Width="525"
ResizeMode="CanResizeWithGrip" >
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -21,7 +26,23 @@
<!-- Menu bar -->
<Menu Grid.Row="0" Grid.ColumnSpan="10">
<MenuItem Header="_File">
<MenuItem Header="_New Item..." Click="File_New_Click"/>
<MenuItem Header="_New">
<MenuItem Header="_File..."
DataContext="{DynamicResource DocumentCreateCommand}"
Command="{Binding}"
ToolTip="{Binding Tooltip}"
InputGestureText="{Binding ShortcutText}">
<MenuItem.Icon>
<Image DataContext="{DynamicResource DocumentCreateCommand}"
Source="{Binding Icon}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="_Project..." Command="{DynamicResource CreateFileCommand}">
<MenuItem.Icon>
<Image Source="/Resources/Icons/project_star_16.png" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
<MenuItem Header="_Open..." />
<Separator />
<MenuItem Header="_Close" />
@ -32,6 +53,17 @@
</Menu>
<!-- Toolbar -->
<ToolBarTray Grid.Row="1">
<ToolBar>
<Button Name="buttonBackward" ToolTip="Navigate backward">
<Image Width="16" Height="16" Source="/Resources/Icons/arrow_backward_16.png" />
</Button>
<Button Name="buttonForward" ToolTip="Navigate forward">
<Image Width="16" Height="16" Source="/Resources/Icons/arrow_forward_16.png" />
</Button>
<Separator />
</ToolBar>
</ToolBarTray>
<!-- Grid splitter -->
<GridSplitter Grid.Row="2" Grid.Column="1"

View File

@ -15,20 +15,38 @@ using RainmeterEditor.Model.Events;
using RainmeterEditor.UI.Controller;
using Xceed.Wpf.AvalonDock.Layout;
namespace RainmeterEditor
namespace RainmeterEditor.UI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
DocumentController documentController = new DocumentController();
private DocumentController documentController;
private IEnumerable<Command> Commands
{
get
{
yield return documentController.DocumentCreateCommand;
}
}
public MainWindow()
{
InitializeComponent();
documentController = new DocumentController();
documentController.OwnerWindow = this;
documentController.DocumentOpened += documentController_DocumentOpened;
foreach (var c in Commands)
{
Resources.Add(c.Name, c);
if (c.Shortcut != null)
InputBindings.Add(new KeyBinding(c, c.Shortcut));
}
}
void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
@ -58,10 +76,5 @@ namespace RainmeterEditor
return;
}
}
private void File_New_Click(object sender, RoutedEventArgs e)
{
documentController.Create(this);
}
}
}