public SingleFileDto(SingleFileDtoViewModel viewModel) { InitializeComponent(); _viewModel = viewModel; _viewModel.PropertyChanged += OnViewModelPropertyChanged; DataContextChanged += OnDataContextChanged; DataContext = viewModel; KeyDown += OnKeyDown; }
public void Run(bool calledFromCodeEditor = false) { var selectedItem = calledFromCodeEditor ? getCodeEditorItem() : getSelectedSolutionExplorerItem(); var filePath = selectedItem.Properties.Item("FullPath").Value.ToString(); if (!string.IsNullOrWhiteSpace(filePath)) { _projects.Clear(); var selectedProject = selectedItem.ContainingProject; var allSources = getAllProjectItems(selectedProject.ProjectItems) .Where(v => v.Name.Contains(".cs")) .Select(s => s.Properties.Item("FullPath").Value.ToString()) .Except(new[] { filePath }); var allProjects = getAllSolutionProjects(selectedProject); SingleFileDto singleFileDialog = null; Action <string, string> saveFile = (projectName, dtoFilePath) => { if (!string.IsNullOrWhiteSpace(dtoFilePath)) { try { var dtoProject = _projects[projectName]; dtoProject.ProjectItems.AddFromFile(dtoFilePath); } catch (Exception ex) { var message = ex.Message; } finally { singleFileDialog?.Close(); } } }; var viewModel = new SingleFileDtoViewModel( new SingleFileProcessor(), new CodeGenerator(), filePath, allProjects, allSources, saveFile); singleFileDialog = new SingleFileDto(viewModel); singleFileDialog.ShowModal(); } }