private void ResetInput() { SelectedFile = null; UserInputBar.InputText = string.Empty; UpdateSendButtonIcon(); AddedAttachmentDisplay.HideAttachment(); }
private async void UserInputBar_OnSendMessageButtonClicked() { if (string.IsNullOrEmpty(UserInputBar.InputText) && SelectedFile == null) { var filePicker = new FileOpenPicker(); filePicker.FileTypeFilter.Add("*"); // Without this the file picker throws an exception, this is not documented SelectedFile = await filePicker.PickSingleFileAsync(); if (SelectedFile != null) { AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name); UpdateSendButtonIcon(); UserInputBar.FocusTextBox(); } else { AddedAttachmentDisplay.HideAttachment(); } } else { bool sendMessageResult = await GetMainPageVm().SendMessage(UserInputBar.InputText, SelectedFile); if (sendMessageResult) { ResetInput(); } } }
/// <summary> /// Set file as attatchment in UI. /// </summary> /// <param name="file">Attatchment to set in UI and save</param> private void SetSelectedFile(StorageFile file) { SelectedFile = file; if (SelectedFile == null) { AddedAttachmentDisplay.HideAttachment(); } else { AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name); } UpdateSendButtonIcon(); }
private async void Grid_Drop(object sender, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems)) { var storageItems = await e.DataView.GetStorageItemsAsync(); var storageItem = storageItems[0]; SelectedFile = storageItem as StorageFile; if (SelectedFile != null) { AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name); UpdateSendButtonIcon(); } } }
private async void Grid_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == VirtualKey.V) { bool ctrl = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); if (ctrl) { var dataPackageView = Clipboard.GetContent(); if (dataPackageView.Contains(StandardDataFormats.StorageItems)) { var pastedFiles = await dataPackageView.GetStorageItemsAsync(); var pastedFile = pastedFiles[0]; SelectedFile = pastedFile as StorageFile; AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name); UpdateSendButtonIcon(); } else if (dataPackageView.Contains(StandardDataFormats.Bitmap)) { RandomAccessStreamReference pastedBitmap = await dataPackageView.GetBitmapAsync(); var pastedBitmapStream = await pastedBitmap.OpenReadAsync(); var tmpFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Signal-Windows-Screenshot.png", CreationCollisionOption.GenerateUniqueName); using (var tmpFileStream = await tmpFile.OpenAsync(FileAccessMode.ReadWrite)) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(pastedBitmapStream); var pixels = await decoder.GetPixelDataAsync(); BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, tmpFileStream); encoder.SetPixelData(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore, // Alpha is not used decoder.OrientedPixelWidth, decoder.OrientedPixelHeight, decoder.DpiX, decoder.DpiY, pixels.DetachPixelData()); await encoder.FlushAsync(); } SelectedFile = tmpFile; AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name); UpdateSendButtonIcon(); } } } }
private void AddedAttachmentDisplay_OnCancelAttachmentButtonClicked() { AddedAttachmentDisplay.HideAttachment(); SelectedFile = null; UpdateSendButtonIcon(); }