Skip to content

Commit

Permalink
add right click on text boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Dec 3, 2018
1 parent 67b6536 commit 2cdcc86
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 9 deletions.
18 changes: 18 additions & 0 deletions Cross-Platform/SignalGoTest.Desktop/App.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:SignalGoTest.Desktop.Converters"
xmlns:cmd="clr-namespace:SignalGoTest.Desktop.Helpers"
xmlns:self="clr-namespace:SignalGo.Shared.Models;assembly=SignalGo.Shared">
<Application.Resources>
<cmd:CommandsViewModel x:Key="CommandsViewModel"/>
</Application.Resources>
<Application.Styles>

<StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
<StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
<Style Selector="Button">
Expand Down Expand Up @@ -99,6 +104,19 @@
</Border>
</ControlTemplate>
</Setter>
<Setter Property="ContextMenu">
<Setter.Value>
<Template>
<ContextMenu x:Name="contextMenu">
<MenuItem Header="Cut" Command="{Binding CutCommand,Source={StaticResource CommandsViewModel}}" CommandParameter="{Binding ElementName=contextMenu}" />
<MenuItem Header="Copy" Command="{Binding CopyCommand,Source={StaticResource CommandsViewModel}}" CommandParameter="{Binding ElementName=contextMenu}" />
<MenuItem Header="Paste" Command="{Binding PasteCommand,Source={StaticResource CommandsViewModel}}" CommandParameter="{Binding ElementName=contextMenu}" />
<MenuItem Header="Clear" Command="{Binding ClearCommand,Source={StaticResource CommandsViewModel}}" CommandParameter="{Binding ElementName=contextMenu}" />
<!--<MenuItem Header="Select All" Command="{Binding SelctAllCommand,Source={StaticResource CommandsViewModel}}" CommandParameter="{Binding ElementName=contextMenu}" />-->
</ContextMenu>
</Template>
</Setter.Value>
</Setter>
</Style>

<Style Selector="TextBox.ReadOnly">
Expand Down
5 changes: 5 additions & 0 deletions Cross-Platform/SignalGoTest.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public void ContextMenu_Initialized(object sender, System.EventArgs e)
{

}
}
}
29 changes: 29 additions & 0 deletions Cross-Platform/SignalGoTest.Desktop/Helpers/CommandsHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Avalonia;
using Avalonia.Controls;

namespace SignalGoTest.Desktop.Helpers
{
public class CommandsHelper : AvaloniaObject
{
public static readonly AvaloniaProperty<string> AttachCommandProperty = AvaloniaProperty.Register<CommandsHelper, string>(nameof(AttachCommand), notifying: (obj, value) =>
{

});

public string AttachCommand
{
get { return GetValue(AttachCommandProperty); }
set { SetValue(AttachCommandProperty, value); }
}

public static string GetAttachCommand(Control control)
{
return (string)control.GetValue(AttachCommandProperty);
}

public static void SetAttachCommand(Control control, bool value)
{
control.SetValue(AttachCommandProperty, value);
}
}
}
48 changes: 48 additions & 0 deletions Cross-Platform/SignalGoTest.Desktop/Helpers/CommandsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Avalonia;
using Avalonia.Controls;
using MvvmGo.Commands;

namespace SignalGoTest.Desktop.Helpers
{
public class CommandsViewModel
{
public CommandsViewModel()
{
CopyCommand = new Command<ContextMenu>(async (contextMenu) =>
{
TextBox textBox = contextMenu.Parent.Parent as TextBox;
await Application.Current.Clipboard.SetTextAsync(textBox.Text);
});
CutCommand = new Command<ContextMenu>(async (contextMenu) =>
{
TextBox textBox = contextMenu.Parent.Parent as TextBox;
await Application.Current.Clipboard.SetTextAsync(textBox.Text);
textBox.Text = "";
});
SelctAllCommand = new Command<ContextMenu>((contextMenu) =>
{
TextBox textBox = contextMenu.Parent.Parent as TextBox;
textBox.SelectionStart = 0;
textBox.SelectionEnd = textBox.Text.Length;
});
PasteCommand = new Command<ContextMenu>(async (contextMenu) =>
{
TextBox textBox = contextMenu.Parent.Parent as TextBox;

textBox.Text = await Application.Current.Clipboard.GetTextAsync();
});

ClearCommand = new Command<ContextMenu>((contextMenu) =>
{
TextBox textBox = contextMenu.Parent.Parent as TextBox;

textBox.Text = "";
});
}
public Command<ContextMenu> CutCommand { get; set; }
public Command<ContextMenu> CopyCommand { get; set; }
public Command<ContextMenu> PasteCommand { get; set; }
public Command<ContextMenu> ClearCommand { get; set; }
public Command<ContextMenu> SelctAllCommand { get; set; }
}
}
2 changes: 1 addition & 1 deletion Cross-Platform/SignalGoTest.Desktop/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SignalGoTest.Desktop.Views"
xmlns:viewmodels="clr-namespace:SignalGoTest.ViewModels;assembly=SignalGoTest.ViewModels"
Title="SignalGoTest.Desktop">
Title="SignalGoTest.Desktop" FontFamily="Tahoma">
<Window.DataContext>
<viewmodels:MainViewModel/>
</Window.DataContext>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<!--<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>-->
<!--<TargetFramework>netcoreapp2.0</TargetFramework>-->
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion Cross-Platform/SignalGoTest.Desktop/Views/AddNewView.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewmodels="clr-namespace:SignalGoTest.ViewModels;assembly=SignalGoTest.ViewModels">
xmlns:viewmodels="clr-namespace:SignalGoTest.ViewModels;assembly=SignalGoTest.ViewModels" FontFamily="Tahoma">
<UserControl.DataContext>
<viewmodels:AddNewViewModel/>
</UserControl.DataContext>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="Tahoma">
<Grid>
<Grid>
<Grid x:Name="ChildGrid">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
xmlns:self="clr-namespace:SignalGo.Shared.Models;assembly=SignalGo.Shared"
xmlns:local="clr-namespace:SignalGoTest.Desktop.Views"
xmlns:conv="clr-namespace:SignalGoTest.Desktop.Converters"
xmlns:cmd="clr-namespace:SignalGoTest.Desktop.Helpers"
xmlns:types="clr-namespace:SignalGo.Shared.Helpers;assembly=SignalGo.Shared"
xmlns:viewmodels="clr-namespace:SignalGoTest.ViewModels;assembly=SignalGoTest.ViewModels">
xmlns:viewmodels="clr-namespace:SignalGoTest.ViewModels;assembly=SignalGoTest.ViewModels" FontFamily="Tahoma">
<UserControl.Resources>
<viewmodels:ConnectionInfoViewModel x:Key="ConnectionInfoViewModel"/>
</UserControl.Resources>
Expand All @@ -20,7 +21,9 @@
</Grid.RowDefinitions>
<StackPanel Grid.ColumnSpan="2">
<TextBlock Text="Server Address:"/>
<TextBox x:Name="txtAddress" Text="{Binding CurrentConnectionInfo.ServerAddress}" Margin="0,5,0,0"/>
<TextBox x:Name="txtAddress" Text="{Binding CurrentConnectionInfo.ServerAddress}" Margin="0,5,0,0">

</TextBox>
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<Button Command="{Binding ConnectCommand}" Content="Connect" />
<Button x:Name="btndisconnect" Command="{Binding DisconnectCommand}" IsEnabled="False" Content="Disconncet" Margin="5,0,0,0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ConnectionInfoView()
InitializeComponent();
}


private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="JsonTemplateWindow" Width="500" MaxHeight="500">
<TextBox x:Name="TxtJson" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True">
Title="JsonTemplateWindow" Width="500" MaxHeight="500" FontFamily="Tahoma">
<TextBox x:Name="TxtJson" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True" >

</TextBox>
</Window>
51 changes: 51 additions & 0 deletions Cross-Platform/SignalGoTestPro.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalGo.Client", "D:\Signa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalGo.Shared", "D:\SignalGo\Github\SignalGo-full-net\SignalGo.Shared\SignalGo.Shared.csproj", "{4EF33042-BFDC-4507-9FCD-15621E572E7F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalGo.CodeGenerator", "..\..\SignalGoAddServiceReference\SignalGo.CodeGenerator\SignalGo.CodeGenerator.csproj", "{C6BE992F-BF02-4871-BA99-6CABED429DD6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -337,6 +339,54 @@ Global
{4EF33042-BFDC-4507-9FCD-15621E572E7F}.Release|x64.Build.0 = Release|Any CPU
{4EF33042-BFDC-4507-9FCD-15621E572E7F}.Release|x86.ActiveCfg = Release|Any CPU
{4EF33042-BFDC-4507-9FCD-15621E572E7F}.Release|x86.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|ARM.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|x64.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|Any CPU.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|ARM.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|ARM.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|iPhone.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|iPhone.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|x64.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|x64.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|x86.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.AppStore|x86.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|ARM.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|iPhone.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|x64.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|x64.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|x86.ActiveCfg = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Debug|x86.Build.0 = Debug|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|Any CPU.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|ARM.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|ARM.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|iPhone.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|iPhone.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|x64.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|x64.Build.0 = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|x86.ActiveCfg = Release|Any CPU
{C6BE992F-BF02-4871-BA99-6CABED429DD6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -348,6 +398,7 @@ Global
{3086B5CD-6DCE-4C21-9EE0-397906205D4E} = {D1E3BB4F-F610-4687-9D6A-B60F167BB8DE}
{DA4F99A9-69E4-48F1-8850-5298F7762AB9} = {D1E3BB4F-F610-4687-9D6A-B60F167BB8DE}
{4EF33042-BFDC-4507-9FCD-15621E572E7F} = {D1E3BB4F-F610-4687-9D6A-B60F167BB8DE}
{C6BE992F-BF02-4871-BA99-6CABED429DD6} = {D1E3BB4F-F610-4687-9D6A-B60F167BB8DE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {966188CC-4E87-4738-A75A-CA91BC0E95D3}
Expand Down

0 comments on commit 2cdcc86

Please sign in to comment.