Skip to content

Commit f333264

Browse files
committed
added send message on enter option
1 parent 4269ead commit f333264

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

Signal-Windows.Lib/GlobalSettingsManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public enum ShowNotificationTextSettings
2626
private const string BlockScreenshots = "BlockScreenshots";
2727
private const string EnableReadReceipts = "EnableReadReceipts";
2828
private const string SpellCheck = "SpellCheck";
29+
private const string SendMessageWithEnter = "SendMessageWithEnter";
2930

3031
private static ApplicationDataContainer localSettings;
3132
private static IReadOnlyDictionary<string, ApplicationDataContainer> Containers
@@ -108,6 +109,18 @@ public static bool SpellCheckSetting
108109
}
109110
}
110111

112+
public static bool SendMessageWithEnterSetting
113+
{
114+
get
115+
{
116+
return GetSetting(Containers[ChatsAndMediaContainer], SendMessageWithEnter, true);
117+
}
118+
set
119+
{
120+
Containers[ChatsAndMediaContainer].Values[SendMessageWithEnter] = value;
121+
}
122+
}
123+
111124
private static T GetSetting<T>(ApplicationDataContainer container, string key, T defaultValue)
112125
{
113126
if (container.Values.ContainsKey(key))

Signal-Windows/Controls/Conversation.xaml.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ public bool SpellCheckEnabled
128128
set { spellCheckEnabled = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SpellCheckEnabled))); }
129129
}
130130

131+
private bool sendMessageWithEnterEnabled;
132+
public bool SendMessageWithEnterEnabled
133+
{
134+
get { return sendMessageWithEnterEnabled; }
135+
set { sendMessageWithEnterEnabled = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SendMessageWithEnterEnabled))); }
136+
}
137+
131138
public Conversation()
132139
{
133140
this.InitializeComponent();
@@ -210,6 +217,7 @@ public void Load(SignalConversation conversation)
210217
DisposeCurrentThread();
211218
UpdateHeader(conversation);
212219
SpellCheckEnabled = GlobalSettingsManager.SpellCheckSetting;
220+
SendMessageWithEnterEnabled = GlobalSettingsManager.SendMessageWithEnterSetting;
213221

214222
/*
215223
* When selecting a small (~650 messages) conversation after a bigger (~1800 messages) one,
@@ -219,7 +227,7 @@ public void Load(SignalConversation conversation)
219227
*/
220228
ConversationItemsControl.ItemsSource = new List<object>();
221229
UpdateLayout();
222-
Collection = new VirtualizedCollection(conversation);
230+
Collection = new VirtualizedCollection(conversation);
223231
ConversationItemsControl.ItemsSource = Collection;
224232
UpdateLayout();
225233
SendButtonEnabled = conversation.CanReceive;
@@ -304,8 +312,12 @@ public void HandleDeleteMesage(SignalMessage message)
304312

305313
private async void UserInputBar_OnEnterKeyPressed()
306314
{
307-
bool shift = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
308-
if (shift)
315+
CoreWindow corWindow = CoreWindow.GetForCurrentThread();
316+
bool shift = corWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
317+
bool control = corWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
318+
// If SendMessageWithEnterEnabled is true then add new if shift key is pressed.
319+
// If SendMessageWithEnterEnabled is false then send message if control key is pressed.
320+
if (SendMessageWithEnterEnabled ? shift : !control)
309321
{
310322
UserInputBar.AddLinefeed();
311323
}

Signal-Windows/ViewModels/ChatsAndMediaSettingsPageViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,27 @@ public bool SpellCheck
1717
set { spellCheck = value; RaisePropertyChanged(nameof(SpellCheck)); }
1818
}
1919

20+
private bool sendMessageWithEnter;
21+
public bool SendMessageWithEnter
22+
{
23+
get { return sendMessageWithEnter; }
24+
set { sendMessageWithEnter = value; RaisePropertyChanged(nameof(SendMessageWithEnter)); }
25+
}
26+
2027
public void OnNavigatedTo()
2128
{
2229
SpellCheck = GlobalSettingsManager.SpellCheckSetting;
30+
SendMessageWithEnter = GlobalSettingsManager.SendMessageWithEnterSetting;
2331
}
2432

2533
public void SpellCheckToggleSwitch_Toggled(bool value)
2634
{
2735
GlobalSettingsManager.SpellCheckSetting = value;
2836
}
37+
38+
public void SendMessageWithEnterToggleSwitch_Toggled(bool value)
39+
{
40+
GlobalSettingsManager.SendMessageWithEnterSetting = value;
41+
}
2942
}
3043
}

Signal-Windows/Views/ChatsAndMediaSettingsPage.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<RowDefinition Height="Auto"/>
2222
<RowDefinition Height="Auto"/>
2323
<RowDefinition Height="Auto"/>
24+
<RowDefinition Height="Auto"/>
2425
</Grid.RowDefinitions>
2526
<Grid>
2627
<Grid.RowDefinitions>
@@ -79,6 +80,14 @@
7980
<TextBlock Text="Spell Check" Style="{StaticResource SubtitleTextBlockStyle}"/>
8081
<ToggleSwitch x:Name="SpellCheckToggleSwitch" Grid.Row="1" Margin="0,8" IsOn="{x:Bind Vm.SpellCheck, Mode=TwoWay}" Toggled="SpellCheckToggleSwitch_Toggled"/>
8182
</Grid>
83+
<Grid Grid.Row="3" Margin="0,16,0,0">
84+
<Grid.RowDefinitions>
85+
<RowDefinition Height="Auto"/>
86+
<RowDefinition/>
87+
</Grid.RowDefinitions>
88+
<TextBlock Text="Send Message With Enter" Style="{StaticResource SubtitleTextBlockStyle}"/>
89+
<ToggleSwitch x:Name="SendMessageWithEnterToggleSwitch" Grid.Row="1" Margin="0,8" IsOn="{x:Bind Vm.SendMessageWithEnter, Mode=TwoWay}" Toggled="SendMessageWithEnterToggleSwitch_Toggled"/>
90+
</Grid>
8291
</Grid>
8392
</ScrollViewer>
8493
</Grid>

Signal-Windows/Views/ChatsAndMediaSettingsPage.xaml.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ private void SpellCheckToggleSwitch_Toggled(object sender, RoutedEventArgs e)
5757
var toggleSwitch = sender as ToggleSwitch;
5858
Vm.SpellCheckToggleSwitch_Toggled(toggleSwitch.IsOn);
5959
}
60+
61+
private void SendMessageWithEnterToggleSwitch_Toggled(object sender, RoutedEventArgs e)
62+
{
63+
var toggleSwitch = sender as ToggleSwitch;
64+
Vm.SendMessageWithEnterToggleSwitch_Toggled(toggleSwitch.IsOn);
65+
}
6066
}
6167
}

0 commit comments

Comments
 (0)