UI changes, added commands

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

View File

@ -29,7 +29,7 @@ namespace RainmeterEditor.Documents.Text
Category = Resources.Strings.Category_Utility, Category = Resources.Strings.Category_Utility,
DefaultExtension = ".txt", DefaultExtension = ".txt",
Description = Resources.Strings.DocumentFormat_TextFile_Description, Description = Resources.Strings.DocumentFormat_TextFile_Description,
Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Resources/Icons/text-x-generic-32.png", UriKind.RelativeOrAbsolute)), Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Resources/Icons/text_file_32.png", UriKind.RelativeOrAbsolute)),
Factory = this Factory = this
}; };
} }

View File

@ -98,6 +98,7 @@
</Compile> </Compile>
<Compile Include="Model\IDocumentStorage.cs" /> <Compile Include="Model\IDocumentStorage.cs" />
<Compile Include="Storage\SkinDirectory.cs" /> <Compile Include="Storage\SkinDirectory.cs" />
<Compile Include="UI\Command.cs" />
<Compile Include="UI\Dialogs\CreateDocumentDialog.xaml.cs"> <Compile Include="UI\Dialogs\CreateDocumentDialog.xaml.cs">
<DependentUpon>CreateDocumentDialog.xaml</DependentUpon> <DependentUpon>CreateDocumentDialog.xaml</DependentUpon>
</Compile> </Compile>
@ -175,14 +176,28 @@
<AppDesigner Include="Properties\" /> <AppDesigner Include="Properties\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="Resources\Icons\page_white_text.png" /> <Resource Include="Resources\Icons\text_file_32.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\text-x-generic-32.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<SplashScreen Include="Resources\splash.png" /> <SplashScreen Include="Resources\splash.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\arrow_left_16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\arrow_right_16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\arrow_backward_16.png" />
<Resource Include="Resources\Icons\arrow_forward_16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\page_white_star_16.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\project_16.png" />
<Resource Include="Resources\Icons\project_star_16.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 742 B

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -69,6 +69,24 @@ namespace RainmeterEditor.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to New file....
/// </summary>
internal static string DocumentCreateCommand_DisplayText {
get {
return ResourceManager.GetString("DocumentCreateCommand_DisplayText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Creates a new file.
/// </summary>
internal static string DocumentCreateCommand_ToolTip {
get {
return ResourceManager.GetString("DocumentCreateCommand_ToolTip", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Text Editor. /// Looks up a localized string similar to Text Editor.
/// </summary> /// </summary>

View File

@ -120,6 +120,12 @@
<data name="Category_Utility" xml:space="preserve"> <data name="Category_Utility" xml:space="preserve">
<value>Utility</value> <value>Utility</value>
</data> </data>
<data name="DocumentCreateCommand_DisplayText" xml:space="preserve">
<value>New file...</value>
</data>
<data name="DocumentCreateCommand_ToolTip" xml:space="preserve">
<value>Creates a new file</value>
</data>
<data name="DocumentEditor_Text_Name" xml:space="preserve"> <data name="DocumentEditor_Text_Name" xml:space="preserve">
<value>Text Editor</value> <value>Text Editor</value>
</data> </data>

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.Events;
using RainmeterEditor.Model; using RainmeterEditor.Model;
using System.Windows; using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
namespace RainmeterEditor.UI.Controller namespace RainmeterEditor.UI.Controller
{ {
public class DocumentController public class DocumentController
{ {
#region Commands
public Command DocumentCreateCommand { get; private set; }
#endregion
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
{ {
add add
@ -23,19 +31,27 @@ namespace RainmeterEditor.UI.Controller
DocumentManager.Instance.DocumentOpened -= value; DocumentManager.Instance.DocumentOpened -= value;
} }
} }
public event EventHandler DocumentClosed; public event EventHandler DocumentClosed;
public Window OwnerWindow { get; set; }
public DocumentController() 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 // Show dialog
var dialog = new CreateDocumentDialog() var dialog = new CreateDocumentDialog()
{ {
Owner = parent, Owner = OwnerWindow,
SelectedFormat = defaultFormat, SelectedFormat = defaultFormat,
SelectedPath = defaultPath SelectedPath = defaultPath
}; };
@ -56,5 +72,6 @@ namespace RainmeterEditor.UI.Controller
// Call manager // Call manager
DocumentManager.Instance.Create(format, path); 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="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="clr-namespace:RainmeterEditor.UI" xmlns:ui="clr-namespace:RainmeterEditor.UI"
@ -6,6 +6,11 @@
xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock" xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
Title="Rainmeter Studio" Height="350" Width="525" Title="Rainmeter Studio" Height="350" Width="525"
ResizeMode="CanResizeWithGrip" > ResizeMode="CanResizeWithGrip" >
<Window.Resources>
</Window.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@ -21,7 +26,23 @@
<!-- Menu bar --> <!-- Menu bar -->
<Menu Grid.Row="0" Grid.ColumnSpan="10"> <Menu Grid.Row="0" Grid.ColumnSpan="10">
<MenuItem Header="_File"> <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..." /> <MenuItem Header="_Open..." />
<Separator /> <Separator />
<MenuItem Header="_Close" /> <MenuItem Header="_Close" />
@ -32,6 +53,17 @@
</Menu> </Menu>
<!-- Toolbar --> <!-- 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 --> <!-- Grid splitter -->
<GridSplitter Grid.Row="2" Grid.Column="1" <GridSplitter Grid.Row="2" Grid.Column="1"

View File

@ -15,20 +15,38 @@ using RainmeterEditor.Model.Events;
using RainmeterEditor.UI.Controller; using RainmeterEditor.UI.Controller;
using Xceed.Wpf.AvalonDock.Layout; using Xceed.Wpf.AvalonDock.Layout;
namespace RainmeterEditor namespace RainmeterEditor.UI
{ {
/// <summary> /// <summary>
/// Interaction logic for MainWindow.xaml /// Interaction logic for MainWindow.xaml
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
DocumentController documentController = new DocumentController(); private DocumentController documentController;
private IEnumerable<Command> Commands
{
get
{
yield return documentController.DocumentCreateCommand;
}
}
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
documentController = new DocumentController();
documentController.OwnerWindow = this;
documentController.DocumentOpened += documentController_DocumentOpened; 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) void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
@ -58,10 +76,5 @@ namespace RainmeterEditor
return; return;
} }
} }
private void File_New_Click(object sender, RoutedEventArgs e)
{
documentController.Create(this);
}
} }
} }