void onNewFile(object sender, EventArgs e) { MenuItem item = sender as MenuItem; ContextMenu menu = item.CommandParameter as ContextMenu; FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem; { Dlg.NewFileDlg d = new Dlg.NewFileDlg(target.Path); bool? result = d.ShowDialog(); if (result.HasValue && result.Value) { ideTabs.OpenFile(new FileBaseItem { Path = d.Path, Name = System.IO.Path.GetFileName(d.Path) }); } } }
public NewFileDlg(string path) { InitializeComponent(); dgFileTypes.ItemsSource = FileSpecItem.ConstructFileSpecItems(); if (lastIndex == -1) { dgFileTypes.SelectedIndex = 0; } else { dgFileTypes.SelectedIndex = lastIndex; } txtFileName.Focus(); NewFileDlg me = this; Buttons = new Button[] { createBtn = new Button { Content = "Create", Style = FindResource("StyledButton") as Style, Command = new RelayCommand(o => { FileSpecItem fi = dgFileTypes.SelectedItem as FileSpecItem; string fileName = txtFileName.Text.Trim().Replace(fi.Ext, ""); lastIndex = dgFileTypes.SelectedIndex; Path = System.IO.Path.Combine(path, fileName + fi.Ext); System.IO.File.WriteAllText(Path, fi.ContentTemplate.Replace("{FILENAME}", fileName)); DialogResult = true; Close(); }, (p) => { if (txtFileName.Text.Trim().Length != 0 && dgFileTypes.SelectedIndex != -1) { return(true); } return(false); }) }, CancelButton }; }
void onNewFile(object sender, EventArgs e) { MenuItem item = sender as MenuItem; ContextMenu menu = item.CommandParameter as ContextMenu; FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem; { Dlg.NewFileDlg d = new Dlg.NewFileDlg(target.Path); bool? result = d.ShowDialog(); if (result.HasValue && result.Value) ideTabs.OpenFile(new FileBaseItem { Path = d.Path, Name = System.IO.Path.GetFileName(d.Path) }); } }