private void _textEditor_Drop(object sender, DragEventArgs e) { try { if (e.Is(DataFormats.FileDrop)) { _textEditor.Document.Replace(0, _textEditor.Document.TextLength, File.ReadAllText(e.Get <string>(DataFormats.FileDrop))); _rcm.AddRecentFile(e.Get <string>(DataFormats.FileDrop)); } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _menuItemOpenFrom_Click(object sender, RoutedEventArgs e) { try { string file = PathRequest.OpenFileMapcache("filter", "Dat Files (*.dat)|*.dat"); if (file != null) { if (File.Exists(file)) { _load(file); _recentFilesManager.AddRecentFile(file); } } } catch (Exception err) { ErrorHandler.HandleException(err); } }
public MapcacheDialog(string text) : base("Mapcache", "cache.png", SizeToContent.Manual, ResizeMode.CanResize) { InitializeComponent(); ShowInTaskbar = true; WindowStartupLocation = WindowStartupLocation.CenterOwner; Owner = WpfUtilities.TopWindow; _cache = new Mapcache(); _cache.Commands.ModifiedStateChanged += _commands_ModifiedStateChanged; _asyncOperation = new AsyncOperation(_progressBar); ListViewDataTemplateHelper.GenerateListViewTemplateNew(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Name", DisplayExpression = "MapName", SearchGetAccessor = "MapName", ToolTipBinding = "MapName", TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.Center, FixedWidth = 140 }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Width", DisplayExpression = "Xs", SearchGetAccessor = "Xs", ToolTipBinding = "Xs", TextAlignment = TextAlignment.Center, FixedWidth = 80 }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Height", DisplayExpression = "Ys", SearchGetAccessor = "Ys", ToolTipBinding = "Ys", TextAlignment = TextAlignment.Center, FixedWidth = 80 }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Size", DisplayExpression = "DisplaySize", SearchGetAccessor = "Len", ToolTipBinding = "DisplaySize", TextAlignment = TextAlignment.Center, FixedWidth = 150 }, }, new DefaultListViewComparer <MapInfo>(), new string[] { "Added", "{DynamicResource CellBrushAdded}" }); _tmbUndo.SetUndo(_cache.Commands); _tmbRedo.SetRedo(_cache.Commands); _commands_ModifiedStateChanged(null, null); _listView.ItemsSource = _cache.ViewMaps; ApplicationShortcut.Link(ApplicationShortcut.Save, () => _menuItemSave_Click(null, null), this); ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _cache.Commands.Undo(), this); ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _cache.Commands.Redo(), this); ApplicationShortcut.Link(ApplicationShortcut.New, () => _menuItemNew_Click(null, null), this); ApplicationShortcut.Link(ApplicationShortcut.Open, () => _menuItemOpenFrom_Click(null, null), this); ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _miDelete_Click(null, null), this); _recentFilesManager = new WpfRecentFiles(Configuration.ConfigAsker, 6, _menuItemRecentFiles, "Mapcache"); _recentFilesManager.FileClicked += _recentFilesManager_FileClicked; if (text != null) { _recentFilesManager.AddRecentFile(text); _load(text); } else { // Open the latest file if (_recentFilesManager.Files.Count > 0 && File.Exists(_recentFilesManager.Files[0])) { _load(_recentFilesManager.Files[0]); } } }