private void CopyToClipboard(object sender, RoutedEventArgs e) { try { MimeType[] mimeTypes = null; if (_lastSelectedBlock != null) { mimeTypes = _editor.GetSupportedExportMimeTypes(_lastSelectedBlock); } if (mimeTypes != null && mimeTypes.Contains(MimeType.OFFICE_CLIPBOARD)) { // export block to a file var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var clipboardPath = Path.Combine(localFolder, "MyScript", "tmp/clipboard.gvml"); var drawer = new ImageDrawer(); drawer.ImageLoader = UcEditor.ImageLoader; _editor.Export_(_lastSelectedBlock, clipboardPath.ToString(), MimeType.OFFICE_CLIPBOARD, drawer); // read back exported data var clipboardData = File.ReadAllBytes(clipboardPath); var clipboardStream = new MemoryStream(clipboardData); // store the data into clipboard Clipboard.SetData(MimeTypeF.GetTypeName(MimeType.OFFICE_CLIPBOARD), clipboardStream); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ImportDialog(Window parent, string title, MimeType[] mimeTypes) { InitializeComponent(); Owner = parent; Title = title; ResultTextBox.Text = ""; MimeTypeComboBox.Items.Clear(); foreach (var mimeType in mimeTypes) { MimeTypeComboBox.Items.Add(MimeTypeF.GetTypeName(mimeType)); } MimeTypeComboBox.SelectedIndex = 0; }
private async void Popup_CommandHandler_OfficeClipboard(FlyoutCommand command) { try { MimeType[] mimeTypes = null; if (_lastSelectedBlock != null) { mimeTypes = _editor.GetSupportedExportMimeTypes(_lastSelectedBlock); } if (mimeTypes != null && mimeTypes.Contains(MimeType.OFFICE_CLIPBOARD)) { // export block to a file var localFolder = ApplicationData.Current.LocalFolder.Path; var clipboardPath = System.IO.Path.Combine(localFolder.ToString(), "tmp/clipboard.gvml"); var drawer = new ImageDrawer(_editor.Renderer.DpiX, _editor.Renderer.DpiY); drawer.ImageLoader = UcEditor.ImageLoader; _editor.Export_(_lastSelectedBlock, clipboardPath.ToString(), MimeType.OFFICE_CLIPBOARD, drawer); // read back exported data var clipboardData = File.ReadAllBytes(clipboardPath); var clipboardStream = new MemoryStream(clipboardData); // store the data into clipboard Windows.ApplicationModel.DataTransfer.Clipboard.Clear(); var clipboardContent = new Windows.ApplicationModel.DataTransfer.DataPackage(); clipboardContent.SetData(MimeTypeF.GetTypeName(MimeType.OFFICE_CLIPBOARD), clipboardStream.AsRandomAccessStream()); Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(clipboardContent); } } catch (Exception ex) { MessageDialog msgDialog = new MessageDialog(ex.ToString()); await msgDialog.ShowAsync(); } }
private async System.Threading.Tasks.Task <string> ChooseExportFilename(MimeType[] mimeTypes) { var mimeTypeTextBlock = new TextBlock { Text = "Choose a mime type", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0), Width = 300, }; var mimeTypeComboBox = new ComboBox { IsTextSearchEnabled = true, SelectedIndex = -1, Margin = new Thickness(0, 5, 0, 0), Width = 300 }; foreach (var mimeType in mimeTypes) { mimeTypeComboBox.Items.Add(MimeTypeF.GetTypeName(mimeType)); } mimeTypeComboBox.SelectedIndex = 0; var nameTextBlock = new TextBlock { Text = "Enter Export File Name", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 10, 0, 0), Width = 300 }; var nameTextBox = new TextBox { Text = "", AcceptsReturn = false, MaxLength = 1024 * 1024, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 5, 0, 10), Width = 300 }; var panel = new StackPanel { Margin = new Thickness(10), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; panel.Children.Add(mimeTypeTextBlock); panel.Children.Add(mimeTypeComboBox); panel.Children.Add(nameTextBlock); panel.Children.Add(nameTextBox); var dialog = new ContentDialog { Title = "Export", Content = panel, PrimaryButtonText = "OK", SecondaryButtonText = "Cancel", IsPrimaryButtonEnabled = true, IsSecondaryButtonEnabled = true }; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var fileName = nameTextBox.Text; var extIndex = mimeTypeComboBox.SelectedIndex; var extensions = MimeTypeF.GetFileExtensions(mimeTypes[extIndex]).Split(','); int ext; for (ext = 0; ext < extensions.Count(); ++ext) { if (fileName.EndsWith(extensions[ext], StringComparison.OrdinalIgnoreCase)) { break; } } if (ext >= extensions.Count()) { fileName += extensions[0]; } return(fileName); } return(null); }
private async System.Threading.Tasks.Task <Tuple <int, string> > EnterImportData(string title, MimeType[] mimeTypes) { var mimeTypeTextBlock = new TextBlock { Text = "Choose a mime type", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0), Width = 300, }; var mimeTypeComboBox = new ComboBox { IsTextSearchEnabled = true, SelectedIndex = -1, Margin = new Thickness(0, 5, 0, 0), Width = 300 }; foreach (var mimeType in mimeTypes) { mimeTypeComboBox.Items.Add(MimeTypeF.GetTypeName(mimeType)); } mimeTypeComboBox.SelectedIndex = 0; var dataTextBlock = new TextBlock { Text = "Enter some text", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 10, 0, 0), Width = 300 }; var dataTextBox = new TextBox { Text = "", AcceptsReturn = false, MaxLength = 1024 * 1024, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 5, 0, 10), Width = 300 }; var panel = new StackPanel { Margin = new Thickness(10), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; panel.Children.Add(mimeTypeTextBlock); panel.Children.Add(mimeTypeComboBox); panel.Children.Add(dataTextBlock); panel.Children.Add(dataTextBox); var dialog = new ContentDialog { Title = title, Content = panel, PrimaryButtonText = "OK", SecondaryButtonText = "Cancel", IsPrimaryButtonEnabled = true, IsSecondaryButtonEnabled = true }; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { return(new Tuple <int, string>(mimeTypeComboBox.SelectedIndex, dataTextBox.Text)); } return(null); }
private async System.Threading.Tasks.Task <Tuple <int, string> > EnterImportData(string title, MimeType[] mimeTypes) { const bool defaultWrapping = false; const double defaultWidth = 400; var mimeTypeTextBlock = new TextBlock { Text = "Choose a mime type", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0), Width = defaultWidth, }; var mimeTypeComboBox = new ComboBox { IsTextSearchEnabled = true, SelectedIndex = -1, Margin = new Thickness(0, 5, 0, 5), Width = defaultWidth }; foreach (var mimeType in mimeTypes) { mimeTypeComboBox.Items.Add(MimeTypeF.GetTypeName(mimeType)); } mimeTypeComboBox.SelectedIndex = 0; var dataTextBlock = new TextBlock { Text = "Enter some text", MaxLines = 1, TextWrapping = TextWrapping.NoWrap, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 5, 0, 0), Width = defaultWidth }; var dataTextBox = new TextBox { Text = "", AcceptsReturn = true, TextWrapping = (defaultWrapping ? TextWrapping.Wrap : TextWrapping.NoWrap), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, FontSize = 12, Margin = new Thickness(0), Width = defaultWidth, Height = 200, }; ScrollViewer.SetVerticalScrollBarVisibility(dataTextBox, ScrollBarVisibility.Auto); ScrollViewer.SetHorizontalScrollBarVisibility(dataTextBox, ScrollBarVisibility.Auto); var dataWrappingCheckBox = new CheckBox { Content = "Wrapping", HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 5), Width = defaultWidth, IsChecked = defaultWrapping, }; dataWrappingCheckBox.Checked += new RoutedEventHandler((sender, e) => { dataTextBox.TextWrapping = TextWrapping.Wrap; }); dataWrappingCheckBox.Unchecked += new RoutedEventHandler((sender, e) => { dataTextBox.TextWrapping = TextWrapping.NoWrap; }); var panel = new StackPanel { Margin = new Thickness(10), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; panel.Children.Add(mimeTypeTextBlock); panel.Children.Add(mimeTypeComboBox); panel.Children.Add(dataTextBlock); panel.Children.Add(dataTextBox); panel.Children.Add(dataWrappingCheckBox); var dialog = new ContentDialog { Title = title, Content = panel, PrimaryButtonText = "OK", SecondaryButtonText = "Cancel", IsPrimaryButtonEnabled = true, IsSecondaryButtonEnabled = true }; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { // Convert '\r' to '\n' // https://stackoverflow.com/questions/42867242/uwp-textbox-puts-r-only-how-to-set-linebreak var text = dataTextBox.Text.Replace('\r', '\n'); return(new Tuple <int, string>(mimeTypeComboBox.SelectedIndex, text)); } return(null); }