forked from adzm/BusinessCats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhisperWindow.xaml.cs
110 lines (86 loc) · 3.14 KB
/
WhisperWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro;
namespace BusinessCats
{
/// <summary>
/// Interaction logic for WhisperWindow.xaml
/// </summary>
public partial class WhisperWindow : MetroWindow
{
public ICommand SendMessageCmd { get; set; }
protected void InitCommands()
{
SendMessageCmd = new CommandCat(() => {
string text = tbMessage.Text;
string cipherText = seriousBusiness.whisperCat.SendWhisper(conversation, participant, text);
if (string.IsNullOrEmpty(cipherText))
{
return;
}
TextBoxHelper.SetWatermark(tbMessage, "...");
tbMessage.Text = "";
AddWhisper(new Whisper(true, text, cipherText));
});
}
public WhisperWindow(Conversation conversation, Participant participant, SeriousBusinessCat seriousBusiness, string info)
{
this.conversation = conversation;
this.participant = participant;
this.seriousBusiness = seriousBusiness;
InitializeComponent();
this.DataContext = this;
InitCommands();
this.Activated += (s,e) => { FlashWindow.Stop(this); };
lbWhispers.ItemsSource = _whispers;
string bob = "neighbor cat";
if (participant != null)
{
bob = participant.Contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
}
textBlock.Text = bob;
if (!string.IsNullOrEmpty(info))
{
textBlock.ToolTip = info;
}
this.Title = $"Whispering with {bob}";
FocusManager.SetFocusedElement(this, tbMessage);
}
public Conversation conversation;
public Participant participant;
public WhisperCat whisperCat;
public SeriousBusinessCat seriousBusiness;
private ObservableCollection<Whisper> _whispers = new ObservableCollection<Whisper>();
public void AddWhisper(Whisper whisper)
{
this.Dispatcher.Invoke(() => {
_whispers.Add(whisper);
if (IsLoaded)
{
var border = (Border)VisualTreeHelper.GetChild(lbWhispers, 0);
var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
scrollViewer.ScrollToBottom();
if (!whisper.IsSelf && !this.IsActive)
{
FlashWindow.Flash(this);
}
}
});
}
}
}