More GUI stuff. Added input sanitization. Added GUI for actions.
This commit is contained in:
parent
ac666a5a94
commit
a9e5e14c9d
|
|
@ -42,14 +42,16 @@ namespace VDash
|
|||
|
||||
var ret = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Overlay);
|
||||
|
||||
#if !DEBUG
|
||||
if (initError != EVRInitError.None)
|
||||
{
|
||||
throw new Exception($"Error connecting to VR: {initError.ToString()}");
|
||||
}
|
||||
#endif
|
||||
|
||||
lvOverlays.ItemsSource = OverlayManager.Overlays;
|
||||
|
||||
#region Debug
|
||||
#region Debug
|
||||
|
||||
|
||||
//StartOverlayWindow("Discord");
|
||||
|
|
@ -75,7 +77,7 @@ namespace VDash
|
|||
//mo1.Create();
|
||||
//MonitorOverlay mo2= new MonitorOverlay("right", "Right Monitor", displays[2]);
|
||||
//mo2.Create();
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ using VDash.Utilities;
|
|||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
public class BringWindowToFrontAction : IOverlayAction
|
||||
[OverlayActionInfo("Bring Window to Front")]
|
||||
public class BringWindowToFrontAction : IWindowAction
|
||||
{
|
||||
/// <summary>
|
||||
/// Unminimize the window if it's minimized.
|
||||
|
|
@ -17,11 +18,18 @@ namespace VDash.Overlay.Actions
|
|||
public bool UnminimizeIfMinimized { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public Type Editor { get; } = null;
|
||||
|
||||
public BringWindowToFrontAction(bool unminimizeIfMinimized)
|
||||
{
|
||||
UnminimizeIfMinimized = unminimizeIfMinimized;
|
||||
}
|
||||
|
||||
public BringWindowToFrontAction()
|
||||
{
|
||||
UnminimizeIfMinimized = true;
|
||||
}
|
||||
|
||||
public void PreformAction(IOverlay intOverlay)
|
||||
{
|
||||
if (!Enabled) { return; }
|
||||
|
|
@ -50,5 +58,10 @@ namespace VDash.Overlay.Actions
|
|||
|
||||
User32.SetForegroundWindow(handle);
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
var attribute = (OverlayActionInfo)this.GetType().GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
return attribute.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
@ -11,4 +12,34 @@ namespace VDash.Overlay.Actions
|
|||
void PreformAction(IOverlay overlay);
|
||||
bool Enabled { get; set; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
|
||||
public class OverlayActionInfo : System.Attribute
|
||||
{
|
||||
public string Description { get; private set; }
|
||||
public Type EditorType { get; private set; }
|
||||
public OverlayActionInfo(string description, Type editorType)
|
||||
{
|
||||
Description = description;
|
||||
EditorType = editorType;
|
||||
}
|
||||
|
||||
public OverlayActionInfo(string description)
|
||||
{
|
||||
Description = description;
|
||||
EditorType = null;
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> GetTypesWithAttribute()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
if (type.GetCustomAttributes(typeof(OverlayActionInfo), true).Length > 0)
|
||||
{
|
||||
yield return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
public interface IWindowAction : IOverlayAction
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -8,10 +8,11 @@ using VDash.Utilities;
|
|||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
public class MaximizeWindowAction : IOverlayAction
|
||||
[OverlayActionInfo("Maximize Window")]
|
||||
public class MaximizeWindowAction : IWindowAction
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
|
||||
public void PreformAction(IOverlay intOverlay)
|
||||
{
|
||||
if (!Enabled) { return; }
|
||||
|
|
@ -30,5 +31,11 @@ namespace VDash.Overlay.Actions
|
|||
{
|
||||
User32.ShowWindow(handle, User32.ShowWindowCommands.Maximize);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var attribute = (OverlayActionInfo)this.GetType().GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
return attribute.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDash.Utilities;
|
||||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
[OverlayActionInfo("Minize Window")]
|
||||
public class MinimizeWIndowAction : IWindowAction
|
||||
{
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public void PreformAction(IOverlay intOverlay)
|
||||
{
|
||||
if (!Enabled) { return; }
|
||||
if (!intOverlay.GetType().IsAssignableFrom(typeof(WindowOverlay)))
|
||||
{
|
||||
Console.WriteLine("This action cannot be performed on a non-WindowOverlay overlay.");
|
||||
return;
|
||||
}
|
||||
|
||||
WindowOverlay overlay = (WindowOverlay)intOverlay;
|
||||
IntPtr handle = overlay.Config.Selector.GetWindowHandle();
|
||||
PreformAction(handle);
|
||||
}
|
||||
|
||||
public void PreformAction(IntPtr handle)
|
||||
{
|
||||
User32.ShowWindow(handle, User32.ShowWindowCommands.Minimize);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var attribute = (OverlayActionInfo)this.GetType().GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
return attribute.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,15 +3,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDash.UI.ActionEditors;
|
||||
using VDash.Utilities;
|
||||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
public class ResizeWindowAction : IOverlayAction
|
||||
[OverlayActionInfo("Resize Window", typeof(ResizeWindowActionEditor))]
|
||||
public class ResizeWindowAction : IWindowAction
|
||||
{
|
||||
public int NewWidth { get; set; }
|
||||
public int NewHeight { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public ResizeWindowAction(int newWidth, int newHeight)
|
||||
{
|
||||
|
|
@ -19,6 +21,8 @@ namespace VDash.Overlay.Actions
|
|||
NewHeight = newHeight;
|
||||
}
|
||||
|
||||
public ResizeWindowAction() { }
|
||||
|
||||
public void PreformAction(IOverlay intOverlay)
|
||||
{
|
||||
if (!Enabled) { return; }
|
||||
|
|
@ -43,5 +47,11 @@ namespace VDash.Overlay.Actions
|
|||
User32.SetWindowPosFlags.IgnoreMove | User32.SetWindowPosFlags.IgnoreZOrder |
|
||||
User32.SetWindowPosFlags.DoNotChangeOwnerZOrder);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var attribute = (OverlayActionInfo)this.GetType().GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
return $"{attribute.Description} ({NewWidth}x{NewHeight})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using VDash.Utilities;
|
|||
|
||||
namespace VDash.Overlay.Actions
|
||||
{
|
||||
public class RestoreWindowAction : IOverlayAction
|
||||
[OverlayActionInfo("Restore Window")]
|
||||
public class RestoreWindowAction : IWindowAction
|
||||
{
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public void PreformAction(IOverlay intOverlay)
|
||||
|
|
@ -30,6 +30,12 @@ namespace VDash.Overlay.Actions
|
|||
{
|
||||
User32.ShowWindow(handle, User32.ShowWindowCommands.Restore);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var attribute = (OverlayActionInfo)this.GetType().GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
return attribute.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDash.Overlay.Actions;
|
||||
using VDash.WindowSelectors;
|
||||
|
||||
namespace VDash.Overlay.Config
|
||||
|
|
@ -23,6 +25,9 @@ namespace VDash.Overlay.Config
|
|||
public string Name { get; set; }
|
||||
public string Key { get; set; }
|
||||
|
||||
public ObservableCollection<IWindowAction> OverlayShownActions { get; private set; } = new ObservableCollection<IWindowAction>();
|
||||
public ObservableCollection<IWindowAction> OverlayHiddenActions { get; private set; } = new ObservableCollection<IWindowAction>();
|
||||
|
||||
public IWindowSelector Selector {get; set; }
|
||||
public bool UpdateDashboardName { get; set; } = false;
|
||||
public bool DestroyOnNoWindowFound { get; set; } = false;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ namespace VDash.Overlay
|
|||
event EventHandler OverlayShown;
|
||||
event EventHandler OverlayHidden;
|
||||
|
||||
List<IOverlayAction> OverlayShownActions { get; }
|
||||
List<IOverlayAction> OverlayHiddenActions { get; }
|
||||
|
||||
ulong OverlayHandle { get; }
|
||||
IOverlayConfig OverlayConfig { get; }
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ namespace VDash.Overlay
|
|||
|
||||
//public IWindowSelector Selector { get; private set; } = null;
|
||||
|
||||
public List<IOverlayAction> OverlayShownActions { get; private set; } = new List<IOverlayAction>();
|
||||
public List<IOverlayAction> OverlayHiddenActions { get; private set; } = new List<IOverlayAction>();
|
||||
//public List<IOverlayAction> OverlayShownActions { get; private set; } = new List<IOverlayAction>();
|
||||
//public List<IOverlayAction> OverlayHiddenActions { get; private set; } = new List<IOverlayAction>();
|
||||
|
||||
char[] specialKeys = { '+', '^', '%', '~', '(', ')', '{', '}', '[', ']' };
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ namespace VDash.Overlay
|
|||
|
||||
if (Config.Selector.WindowExists())
|
||||
{
|
||||
foreach (var action in OverlayShownActions)
|
||||
foreach (var action in Config.OverlayShownActions)
|
||||
{
|
||||
action.PreformAction(this);
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ namespace VDash.Overlay
|
|||
|
||||
if (Config.Selector.WindowExists())
|
||||
{
|
||||
foreach (var action in OverlayHiddenActions)
|
||||
foreach (var action in Config.OverlayHiddenActions)
|
||||
{
|
||||
action.PreformAction(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDash.UI.ActionEditors
|
||||
{
|
||||
public interface IActionEditor
|
||||
{
|
||||
event EventHandler Submitted;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<UserControl x:Class="VDash.UI.ActionEditors.ResizeWindowActionEditor"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:VDash.UI.ActionEditors"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="250"
|
||||
Padding="4">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="27" />
|
||||
<RowDefinition Height="27" />
|
||||
<RowDefinition Height="27" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="60" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="60" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
PreviewTextInput="TextBlock_PreviewTextInput" PreviewKeyDown="TextBlock_PreviewKeyDown">Width:</TextBlock>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
PreviewTextInput="TextBlock_PreviewTextInput" PreviewKeyDown="TextBlock_PreviewKeyDown">Height:</TextBlock>
|
||||
|
||||
<TextBox x:Name="tbWidth" Grid.Row="0" Grid.Column="1" Margin="0,1,0,1" Text="{Binding NewWidth}" MinWidth="40"/>
|
||||
<TextBox x:Name="tbHeight" Grid.Row="0" Grid.Column="3" Margin="0,1,0,1" Text="{Binding NewHeight}" MinWidth="40"/>
|
||||
|
||||
<ComboBox x:Name="cbPresets" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" SelectedIndex="0" Margin="0,1,0,1" SelectionChanged="cbPresets_SelectionChanged"/>
|
||||
|
||||
<Button x:Name="btnOK" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,1,0,1" Click="btnOK_Click">OK</Button>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using VDash.Overlay.Actions;
|
||||
|
||||
namespace VDash.UI.ActionEditors
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ResizeWindowActionEditor.xaml
|
||||
/// </summary>
|
||||
public partial class ResizeWindowActionEditor : UserControl,IActionEditor
|
||||
{
|
||||
public event EventHandler Submitted;
|
||||
public ResizeWindowAction Action { get; private set; }
|
||||
|
||||
public static object[] Presets =
|
||||
{
|
||||
"Optional Presets...",
|
||||
new ResizePreset("Small (640x480)", 640, 480),
|
||||
new ResizePreset("Medium (1024x768)", 1024, 768),
|
||||
new ResizePreset("Large (1400x1050)", 1400, 1050)
|
||||
};
|
||||
|
||||
public ResizeWindowActionEditor(ResizeWindowAction action)
|
||||
{
|
||||
InitializeComponent();
|
||||
Action = action;
|
||||
DataContext = Action;
|
||||
cbPresets.ItemsSource = Presets;
|
||||
}
|
||||
|
||||
private void TextBlock_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
foreach (var letter in e.Text)
|
||||
{
|
||||
if (!Char.IsNumber(letter))
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBlock_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if(e.Key == Key.Space)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnOK_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(Action.NewWidth <= 50 || Action.NewHeight == 50)
|
||||
{
|
||||
MessageBox.Show("Please enter a valid width and height.", "Input error", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
Submitted?.Invoke(this, null);
|
||||
}
|
||||
|
||||
private void cbPresets_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
//Skip description
|
||||
if(cbPresets.SelectedItem.GetType() != typeof(ResizePreset))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = (ResizePreset)cbPresets.SelectedItem;
|
||||
|
||||
Action.NewWidth = item.Width;
|
||||
Action.NewHeight = item.Height;
|
||||
tbWidth.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
tbHeight.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
|
||||
}
|
||||
|
||||
internal class ResizePreset
|
||||
{
|
||||
public string Description { get; private set; }
|
||||
public int Width { get; private set; }
|
||||
public int Height { get; private set; }
|
||||
|
||||
public ResizePreset(string description, int width, int height)
|
||||
{
|
||||
Description = description;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,21 @@ namespace VDash.UI
|
|||
|
||||
private void btnCreate_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var editorControl = ((OverlayTypeWrapper)cbOverlayType.SelectedItem).Control;
|
||||
var intConrol = (IOverlayEditor)editorControl;
|
||||
string[] issues = intConrol.ValidateInput();
|
||||
if (issues.Count() != 0)
|
||||
{
|
||||
StringBuilder error = new StringBuilder();
|
||||
error.AppendLine("Please rectify the following issues:");
|
||||
foreach(var issue in issues)
|
||||
{
|
||||
error.AppendLine(issue);
|
||||
}
|
||||
MessageBox.Show(error.ToString(), "Input Error", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var wrapper = ((OverlayTypeWrapper)cbOverlayType.SelectedItem);
|
||||
var config = wrapper.Editor.Config;
|
||||
if (String.IsNullOrWhiteSpace(config.Key))
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@ namespace VDash.UI
|
|||
public interface IOverlayEditor
|
||||
{
|
||||
IOverlayConfig Config { get; }
|
||||
string[] ValidateInput();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDash.UI
|
||||
{
|
||||
public interface ISelectorEditor
|
||||
{
|
||||
string[] ValidateInput();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
<TextBox x:Name="tbName" Grid.Row="0" Grid.Column="1" Margin="0,0,0,3" Text="{Binding Name}"/>
|
||||
|
||||
<ComboBox x:Name="cbMontitor" Grid.Row="1" Grid.Column="1" SelectionChanged="cbMontitor_SelectionChanged"></ComboBox>
|
||||
<ComboBox x:Name="cbMontitor" Grid.Row="1" Grid.Column="1" SelectionChanged="cbMontitor_SelectionChanged" SelectedIndex="0"></ComboBox>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
|||
|
|
@ -46,5 +46,15 @@ namespace VDash.UI
|
|||
{
|
||||
OverlayConfig.MonitorName = ((DisplayInfo)cbMontitor.SelectedItem).MonitorInfo.DeviceName;
|
||||
}
|
||||
|
||||
public string[] ValidateInput()
|
||||
{
|
||||
List<string> issues = new List<string>();
|
||||
if(cbMontitor.SelectedItem == null)
|
||||
{
|
||||
issues.Add("Please select a monitor.");
|
||||
}
|
||||
return issues.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@
|
|||
<ColumnDefinition Width="60" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="bdrContent" Grid.Row="0" Grid.ColumnSpan="3"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center">Overlay Width:</TextBlock>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center">Overlay Width:</TextBlock>
|
||||
<Slider x:Name="slWidth" Maximum="10" Grid.Row="1" Grid.Column="1" Value="{Binding OverlayWidth}" VerticalAlignment="Center" Margin="5,0,5,0"/>
|
||||
<TextBox x:Name="tbWidth" Grid.Row="1" Grid.Column="2" PreviewTextInput="tbWidth_PreviewTextInput" Text="{Binding OverlayWidth}"/>
|
||||
<TextBox x:Name="tbWidth" Grid.Row="2" Grid.Column="2" PreviewTextInput="tbWidth_PreviewTextInput" PreviewKeyDown="tbWidth_PreviewKeyDown" Text="{Binding OverlayWidth}"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
|||
|
|
@ -35,8 +35,32 @@ namespace VDash.UI
|
|||
|
||||
private void tbWidth_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new Regex(@"^[1-9]\d*(\.\d+)?$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
var dotcount = tbWidth.Text.Count(x => x == '.');
|
||||
foreach(var letter in e.Text)
|
||||
{
|
||||
if(!Char.IsDigit(letter) && letter != '.')
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
if (dotcount >= 1 && e.Text.Contains("."))
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tbWidth_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if(e.Key == Key.Space)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] ValidateInput()
|
||||
{
|
||||
return Editor.ValidateInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace VDash.UI
|
|||
/// <summary>
|
||||
/// Interaction logic for ProcessSelectorEditor.xaml
|
||||
/// </summary>
|
||||
public partial class ProcessSelectorEditor : UserControl
|
||||
public partial class ProcessSelectorEditor : UserControl,ISelectorEditor
|
||||
{
|
||||
public FromProcessName Selector { get; private set; }
|
||||
public ProcessSelectorEditor(ref FromProcessName selector)
|
||||
|
|
@ -28,5 +28,16 @@ namespace VDash.UI
|
|||
Selector = selector;
|
||||
DataContext = Selector;
|
||||
}
|
||||
|
||||
public string[] ValidateInput()
|
||||
{
|
||||
List<string> issues = new List<string>();
|
||||
|
||||
if (String.IsNullOrWhiteSpace(Selector.ProcessName))
|
||||
{
|
||||
issues.Add("You must enter a process name.");
|
||||
}
|
||||
return issues.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition Height="40" />
|
||||
<RowDefinition Height="20" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
|
@ -42,5 +43,42 @@
|
|||
HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding UpdateDashboardName}"/>
|
||||
<CheckBox x:Name="chkDestroyNoWindow" Grid.Row="4" Grid.Column="1"
|
||||
HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding DestroyOnNoWindowFound}"/>
|
||||
|
||||
|
||||
<Grid Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="25" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="0" Margin="0,0,2,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">On Dashboard Open:</TextBlock>
|
||||
<Button x:Name="btnOnShowAdd" Grid.Column="1" Click="btnOnShowAdd_Click">Add</Button>
|
||||
<Button x:Name="btnOnShowRemove" Grid.Column="2" Click="btnOnShowRemove_Click">Remove</Button>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="0" Grid.Column="1" Margin="2,0,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center">On Dashboard Close:</TextBlock>
|
||||
<Button x:Name="btnOnHideAdd" Grid.Column="1" Click="btnOnHideAdd_Click">Add</Button>
|
||||
<Button x:Name="btnOnHideRemove" Grid.Column="2" Click="btnOnHideRemove_Click">Remove</Button>
|
||||
</Grid>
|
||||
|
||||
<ListView x:Name="lvOnOpenActions" Grid.Row="1" Grid.Column="0" Margin="0,0,2,0" MinHeight="200" ItemsSource="{Binding OverlayShownActions}"/>
|
||||
<ListView x:Name="lvOnCloseActions" Grid.Row="1" Grid.Column="1" Margin="2,0,0,0" ItemsSource="{Binding OverlayHiddenActions}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -12,7 +13,9 @@ using System.Windows.Media;
|
|||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using VDash.Overlay.Actions;
|
||||
using VDash.Overlay.Config;
|
||||
using VDash.UI.ActionEditors;
|
||||
using VDash.WindowSelectors;
|
||||
|
||||
namespace VDash.UI
|
||||
|
|
@ -22,7 +25,7 @@ namespace VDash.UI
|
|||
/// </summary>
|
||||
public partial class WindowOverlayEditor : UserControl,IOverlayEditor
|
||||
{
|
||||
public WindowOverlayConfig OverlayConfig { get; set; } = new WindowOverlayConfig();
|
||||
public WindowOverlayConfig OverlayConfig { get; set; }
|
||||
|
||||
public SelectorWrapper[] Selectors { get; private set; } =
|
||||
{
|
||||
|
|
@ -30,14 +33,14 @@ namespace VDash.UI
|
|||
new SelectorWrapper("By Window Title", typeof(FromWindowTitle), typeof(WindowSelectorEditor))
|
||||
};
|
||||
|
||||
|
||||
|
||||
public IOverlayConfig Config { get { return OverlayConfig; } }
|
||||
|
||||
|
||||
public WindowOverlayEditor()
|
||||
{
|
||||
InitializeComponent();
|
||||
OverlayConfig = new WindowOverlayConfig();
|
||||
OverlayConfig.OverlayShownActions.Add(new BringWindowToFrontAction(true));
|
||||
DataContext = OverlayConfig;
|
||||
|
||||
cbSelector.ItemsSource = Selectors;
|
||||
|
|
@ -100,5 +103,91 @@ namespace VDash.UI
|
|||
OverlayConfig.Selector = wrapper.Selector;
|
||||
bdrSelector.Child = wrapper.Editor;
|
||||
}
|
||||
|
||||
public string[] ValidateInput()
|
||||
{
|
||||
List<string> issues = new List<string>();
|
||||
if (String.IsNullOrWhiteSpace(Config.Name))
|
||||
{
|
||||
issues.Add("Please enter a name.");
|
||||
}
|
||||
|
||||
if((SelectorWrapper)cbSelector.SelectedItem == null)
|
||||
{
|
||||
issues.Add("Please select a window selector.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Type selectorType = ((SelectorWrapper)cbSelector.SelectedItem).Editor;
|
||||
var selectorEditor = (ISelectorEditor)((SelectorWrapper)cbSelector.SelectedItem).Editor;
|
||||
issues.AddRange(selectorEditor.ValidateInput());
|
||||
}
|
||||
return issues.ToArray();
|
||||
}
|
||||
|
||||
private void ContextMenuBuilder(Collection<IWindowAction> col)
|
||||
{
|
||||
List<MenuItem> items = new List<MenuItem>();
|
||||
ContextMenu menu = new ContextMenu();
|
||||
menu.ItemsSource = items;
|
||||
menu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
|
||||
|
||||
foreach(var actionType in OverlayActionInfo.GetTypesWithAttribute())
|
||||
{
|
||||
OverlayActionInfo attribute = (OverlayActionInfo)actionType.GetCustomAttributes(typeof(OverlayActionInfo), false).Single();
|
||||
if(attribute.EditorType == null)
|
||||
{
|
||||
var item = new MenuItem() { Header = attribute.Description };
|
||||
item.Click += (s, e) => {
|
||||
IWindowAction action = (IWindowAction)Activator.CreateInstance(actionType);
|
||||
col.Add(action);
|
||||
};
|
||||
items.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
var item = new MenuItem() { Header = attribute.Description };
|
||||
IWindowAction action = (IWindowAction)Activator.CreateInstance(actionType);
|
||||
IActionEditor editor = (IActionEditor)Activator.CreateInstance(attribute.EditorType, new object[] { action });
|
||||
item.ItemsSource = new object[] { new MenuItem() { Header = editor } };
|
||||
editor.Submitted += (s, e) =>
|
||||
{
|
||||
col.Add(action);
|
||||
menu.IsOpen = false;
|
||||
};
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
menu.IsOpen = true;
|
||||
}
|
||||
|
||||
private void btnOnShowAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ContextMenuBuilder(OverlayConfig.OverlayShownActions);
|
||||
}
|
||||
|
||||
private void btnOnShowRemove_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(lvOnOpenActions.SelectedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OverlayConfig.OverlayShownActions.Remove((IWindowAction)lvOnOpenActions.SelectedItem);
|
||||
}
|
||||
|
||||
private void btnOnHideAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
ContextMenuBuilder(OverlayConfig.OverlayHiddenActions);
|
||||
}
|
||||
|
||||
private void btnOnHideRemove_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (lvOnCloseActions.SelectedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OverlayConfig.OverlayHiddenActions.Remove((IWindowAction)lvOnCloseActions.SelectedItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace VDash.UI
|
|||
/// <summary>
|
||||
/// Interaction logic for WindowSelectorEditor.xaml
|
||||
/// </summary>
|
||||
public partial class WindowSelectorEditor : UserControl
|
||||
public partial class WindowSelectorEditor : UserControl,ISelectorEditor
|
||||
{
|
||||
public FromWindowTitle Selector { get; set; }
|
||||
|
||||
|
|
@ -36,5 +36,19 @@ namespace VDash.UI
|
|||
{
|
||||
Selector.SearchType = (FromWindowTitle.TitleSearchType)cbSearchType.SelectedItem;
|
||||
}
|
||||
|
||||
public string[] ValidateInput()
|
||||
{
|
||||
List<string> issues = new List<string>();
|
||||
if (cbSearchType.SelectedItem == null)
|
||||
{
|
||||
issues.Add("You must select a search type.");
|
||||
}
|
||||
if (String.IsNullOrWhiteSpace(Selector.TitleFilter))
|
||||
{
|
||||
issues.Add("You must enter search text.");
|
||||
}
|
||||
return issues.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@
|
|||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
@ -92,7 +95,9 @@
|
|||
<Compile Include="OverlayManager.cs" />
|
||||
<Compile Include="Overlay\Actions\BringWindowToFrontAction.cs" />
|
||||
<Compile Include="Overlay\Actions\IOverlayAction.cs" />
|
||||
<Compile Include="Overlay\Actions\IWindowAction.cs" />
|
||||
<Compile Include="Overlay\Actions\MaximizeWindowAction.cs" />
|
||||
<Compile Include="Overlay\Actions\MinimizeWIndowAction.cs" />
|
||||
<Compile Include="Overlay\Actions\ResizeWindowAction.cs" />
|
||||
<Compile Include="Overlay\Actions\RestoreWindowAction.cs" />
|
||||
<Compile Include="Overlay\Config\IOverlayConfig.cs" />
|
||||
|
|
@ -100,10 +105,15 @@
|
|||
<Compile Include="Overlay\IOverlay.cs" />
|
||||
<Compile Include="Overlay\MonitorOverlay.cs" />
|
||||
<Compile Include="Overlay\Config\WindowOverlayConfig.cs" />
|
||||
<Compile Include="UI\ActionEditors\IActionEditor.cs" />
|
||||
<Compile Include="UI\ActionEditors\ResizeWindowActionEditor.xaml.cs">
|
||||
<DependentUpon>ResizeWindowActionEditor.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\CreateNewOverlay.xaml.cs">
|
||||
<DependentUpon>CreateNewOverlay.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\IOverlayEditor.cs" />
|
||||
<Compile Include="UI\ISelectorEditor.cs" />
|
||||
<Compile Include="UI\MonitorOverlayEditor.xaml.cs">
|
||||
<DependentUpon>MonitorOverlayEditor.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
|
@ -136,6 +146,10 @@
|
|||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="UI\ActionEditors\ResizeWindowActionEditor.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="UI\CreateNewOverlay.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.8" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net45" />
|
||||
<package id="SharpDX" version="4.2.0" targetFramework="net45" />
|
||||
<package id="SharpDX.Direct3D11" version="4.2.0" targetFramework="net45" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue