public SolutionExplorerViewModel(IUnityContainer unity, ISolutionManager solutionManager, IEventAggregator ea) { _unity = unity; _solutionManager = solutionManager; _ea = ea; _firstGeneration = new ObservableCollection<SolutionItemViewModel>(); foreach (var item in _solutionManager.Items) { Root.Add(new SolutionItemViewModel(item)); } _solutionManager.Items.CollectionChanged += (sender, args) => { foreach (var obj in args.NewItems) { Root.Add(new SolutionItemViewModel(obj as ISolutionItem)); } }; AddItem = new DelegateCommand(() => { ISolutionItem item = _unity.Resolve<INewItemService>().GetNewSolutionItem(); if (item != null) { if (_selected == null) unity.Resolve<ISolutionManager>().Items.Add(item); else _selected.Item.Items.Add(item); } }); SelectedItemChangedCommand = new DelegateCommand<SolutionItemViewModel>((ob) => { _selected = ob; }); RequestOpenItem = new DelegateCommand<SolutionItemViewModel>((item) => { if (!item.IsContainer) _ea.GetEvent<EventRequestOpenItem>().Publish(item.Item); }); GenerateSQL = new DelegateCommand(() => { if (_selected != null) { MetaSolutionSQL solution = new MetaSolutionSQL(_selected.Item.ExportSql); _ea.GetEvent<EventRequestOpenItem>().Publish(solution); } }); }
public RowPickerViewModel(ViewModelBase baseViewModel, ITaskRunner taskRunner, ISolutionItemSqlGeneratorRegistry queryGeneratorRegistry, IClipboardService clipboardService, IWindowManager windowManager, IEventAggregator eventAggregator, ISolutionItemEditorRegistry solutionItemEditorRegistry, ISessionService sessionService, IMessageBoxService messageBoxService, ISolutionTasksService solutionTasksService, bool noSaveMode = false) { this.baseViewModel = baseViewModel; this.solutionItemEditorRegistry = solutionItemEditorRegistry; this.sessionService = sessionService; this.messageBoxService = messageBoxService; this.noSaveMode = noSaveMode; Watch(baseViewModel, o => o.IsModified, nameof(Title)); ExecuteChangedCommand = noSaveMode ? AlwaysDisabledCommand.Command : new AsyncAutoCommand(async() => { baseViewModel.Save.Execute(null); eventAggregator.GetEvent <DatabaseTableChanged>().Publish(baseViewModel.TableDefinition.TableName); await taskRunner.ScheduleTask("Update session", async() => await sessionService.UpdateQuery(baseViewModel)); if (solutionTasksService.CanReloadRemotely) { await solutionTasksService.ReloadSolutionRemotelyTask(baseViewModel.SolutionItem); } }); CopyCurrentSqlCommand = new AsyncAutoCommand(async() => { await taskRunner.ScheduleTask("Generating SQL", async() => { clipboardService.SetText((await baseViewModel.GenerateQuery()).QueryString); }); }); GenerateCurrentSqlCommand = new AsyncAutoCommand(async() => { var sql = await baseViewModel.GenerateQuery(); var item = new MetaSolutionSQL(new JustQuerySolutionItem(sql.QueryString)); var editor = solutionItemEditorRegistry.GetEditor(item); await windowManager.ShowDialog((IDialog)editor); }); PickSelected = new AsyncAutoCommand(async() => { await AskIfSave(false); }); Cancel = new DelegateCommand(() => { CloseCancel?.Invoke(); }); Accept = PickSelected; }
public SqlEditorViewModel(IMySqlExecutor mySqlExecutor, IStatusBar statusBar, IDatabaseProvider databaseProvider, ITaskRunner taskRunner, ISolutionItemSqlGeneratorRegistry sqlGeneratorsRegistry, INativeTextDocument sql, MetaSolutionSQL item) : this(mySqlExecutor, statusBar, databaseProvider, taskRunner, sql) { IsLoading = true; taskRunner.ScheduleTask("Generating SQL", async() => { string sql = await sqlGeneratorsRegistry.GenerateSql(item.ItemToGenerate); Code.FromString(sql); IsLoading = false; }); }
public SolutionExplorerViewModel(ISolutionItemNameRegistry itemNameRegistry, ISolutionManager solutionManager, IEventAggregator ea, INewItemService newItemService, IStatusBar statusBar, ISolutionItemSqlGeneratorRegistry sqlGeneratorRegistry) { this.itemNameRegistry = itemNameRegistry; _solutionManager = solutionManager; _ea = ea; _statusBar = statusBar; _firstGeneration = new ObservableCollection <SolutionItemViewModel>(); _itemToViewmodel = new Dictionary <ISolutionItem, SolutionItemViewModel>(); foreach (var item in _solutionManager.Items) { AddItemToRoot(item); } _solutionManager.Items.CollectionChanged += (sender, args) => { if (args.NewItems != null) { int i = 0; foreach (var obj in args.NewItems) { AddItemToRoot(obj as ISolutionItem, args.NewStartingIndex + i); i++; } } if (args.OldItems != null) { foreach (var obj in args.OldItems) { var solutionItem = obj as ISolutionItem; Root.Remove(_itemToViewmodel[solutionItem]); _itemToViewmodel.Remove(solutionItem); } } }; AddItem = new DelegateCommand(() => { ISolutionItem item = newItemService.GetNewSolutionItem(); if (item != null) { if (_selected == null) { solutionManager.Items.Add(item); } else { _selected.Item.Items.Add(item); } } }); RemoveItem = new DelegateCommand(() => { if (_selected != null) { if (_selected.Parent == null) { _solutionManager.Items.Remove(_selected.Item); } else { _selected.Parent.Item.Items.Remove(_selected.Item); } } }); SelectedItemChangedCommand = new DelegateCommand <SolutionItemViewModel>((ob) => { _selected = ob; }); RequestOpenItem = new DelegateCommand <SolutionItemViewModel>((item) => { if (item != null && !item.IsContainer) { _ea.GetEvent <EventRequestOpenItem>().Publish(item.Item); } }); GenerateSQL = new DelegateCommand(() => { if (_selected != null) { MetaSolutionSQL solution = new MetaSolutionSQL(sqlGeneratorRegistry.GenerateSql(_selected.Item)); _ea.GetEvent <EventRequestOpenItem>().Publish(solution); } }); }