Work on UI (commands)

This commit is contained in:
Tiberiu Chibici 2014-07-25 14:05:41 +03:00
parent 1d44d69b94
commit 3d0a028920
4 changed files with 19 additions and 23 deletions

View File

@ -70,7 +70,7 @@ namespace RainmeterEditor.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to New file.... /// Looks up a localized string similar to _File....
/// </summary> /// </summary>
internal static string DocumentCreateCommand_DisplayText { internal static string DocumentCreateCommand_DisplayText {
get { get {

View File

@ -121,7 +121,7 @@
<value>Utility</value> <value>Utility</value>
</data> </data>
<data name="DocumentCreateCommand_DisplayText" xml:space="preserve"> <data name="DocumentCreateCommand_DisplayText" xml:space="preserve">
<value>New file...</value> <value>_File...</value>
</data> </data>
<data name="DocumentCreateCommand_ToolTip" xml:space="preserve"> <data name="DocumentCreateCommand_ToolTip" xml:space="preserve">
<value>Creates a new file</value> <value>Creates a new file</value>

View File

@ -27,17 +27,14 @@
<Menu Grid.Row="0" Grid.ColumnSpan="10"> <Menu Grid.Row="0" Grid.ColumnSpan="10">
<MenuItem Header="_File"> <MenuItem Header="_File">
<MenuItem Header="_New"> <MenuItem Header="_New">
<MenuItem Header="_File..." <MenuItem DataContext="{Binding DocumentCreateCommand}"
DataContext="{DynamicResource DocumentCreateCommand}" Command="{Binding}" Header="{Binding DisplayText}" ToolTip="{Binding Tooltip}"
Command="{Binding}"
ToolTip="{Binding Tooltip}"
InputGestureText="{Binding ShortcutText}"> InputGestureText="{Binding ShortcutText}">
<MenuItem.Icon> <MenuItem.Icon>
<Image DataContext="{DynamicResource DocumentCreateCommand}" <Image Source="{Binding Icon}" />
Source="{Binding Icon}" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="_Project..." Command="{DynamicResource CreateFileCommand}"> <MenuItem Header="_Project..." Command="{Binding DocumentCreateCommand}">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/Resources/Icons/project_star_16.png" /> <Image Source="/Resources/Icons/project_star_16.png" />
</MenuItem.Icon> </MenuItem.Icon>
@ -62,6 +59,10 @@
<Image Width="16" Height="16" Source="/Resources/Icons/arrow_forward_16.png" /> <Image Width="16" Height="16" Source="/Resources/Icons/arrow_forward_16.png" />
</Button> </Button>
<Separator /> <Separator />
<Button DataContext="{Binding DocumentCreateCommand}"
Command="{Binding}" ToolTip="{Binding Tooltip}">
<Image Source="{Binding Icon}" />
</Button>
</ToolBar> </ToolBar>
</ToolBarTray> </ToolBarTray>

View File

@ -24,29 +24,24 @@ namespace RainmeterEditor.UI
{ {
private DocumentController documentController; private DocumentController documentController;
private IEnumerable<Command> Commands public Command DocumentCreateCommand { get { return documentController.DocumentCreateCommand; } }
{
get
{
yield return documentController.DocumentCreateCommand;
}
}
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = this;
documentController = new DocumentController(); documentController = new DocumentController();
documentController.OwnerWindow = this; documentController.OwnerWindow = this;
documentController.DocumentOpened += documentController_DocumentOpened; documentController.DocumentOpened += documentController_DocumentOpened;
AddKeyBinding(documentController.DocumentCreateCommand);
}
foreach (var c in Commands) private void AddKeyBinding(Command c)
{ {
Resources.Add(c.Name, c); if (c.Shortcut != null)
InputBindings.Add(new KeyBinding(c, c.Shortcut));
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)