private void AddBlock(object sender, RoutedEventArgs e) { try { // Uses Id as block type var blockType = ((MenuItem)(sender)).Tag.ToString(); var mimeTypes = _editor.GetSupportedAddBlockDataMimeTypes(blockType); var useDialog = (mimeTypes != null) && (mimeTypes.Count() > 0); if (!useDialog) { _editor.AddBlock(_lastPointerPosition.X, _lastPointerPosition.Y, blockType); } else { ImportDialog importDialog = new ImportDialog(this, "Add Content Block", mimeTypes); if (importDialog.ShowDialog() == true) { var idx = importDialog.SelectedMimeType; var data = importDialog.ResultText; if ((idx >= 0) && (idx < mimeTypes.Count()) && (String.IsNullOrWhiteSpace(data) == false)) { _editor.AddBlock(_lastPointerPosition.X, _lastPointerPosition.Y, blockType, mimeTypes[idx], data); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Import(object sender, RoutedEventArgs e) { var part = _editor.Part; if (part == null) { return; } if (_lastSelectedBlock == null) { return; } var mimeTypes = _editor.GetSupportedImportMimeTypes(_lastSelectedBlock); if (mimeTypes == null) { return; } if (mimeTypes.Count() == 0) { return; } ImportDialog importDialog = new ImportDialog(this, "Import", mimeTypes); if (importDialog.ShowDialog() == true) { var idx = importDialog.SelectedMimeType; var data = importDialog.ResultText; if ((idx >= 0) && (idx < mimeTypes.Count()) && (String.IsNullOrWhiteSpace(data) == false)) { try { _editor.Import_(mimeTypes[idx], data, _lastSelectedBlock); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } }