public static MessageBoxResult ShowModalDialog(AskForHelpViewModel vm) { AskForHelpForm window = new AskForHelpForm(); window.ViewModel = vm; window.ShowDialog(); return(vm.Result); }
public void ShowAskForHelp(object sender, EventArgs e) { var cacheItem = _cache[StringConstants.AuthenticationCacheKey]; if (cacheItem != null && string.IsNullOrEmpty(cacheItem.ToString())) { MessageBox.Show("You must be logged into OSBLE+ in order to access this window."); return; } var vm = new AskForHelpViewModel(); //find current text selection var dte = (DTE2)GetService(typeof(SDTE)); if (dte != null) { dynamic selection = dte.ActiveDocument.Selection; if (selection != null) { try { vm.Code = selection.Text; } catch (Exception) { // ignored } } } //AC: Restrict "ask for help" to approx 20 lines if (vm.Code.Length > 750) { vm.Code = vm.Code.Substring(0, 750); } //show message dialog var result = AskForHelpForm.ShowModalDialog(vm); if (result == MessageBoxResult.OK) { var generator = EventGenerator.GetInstance(); var evt = new AskForHelpEvent { Code = vm.Code, UserComment = vm.UserText }; generator.SubmitEvent(evt); MessageBox.Show("Your question has been logged and will show up in the activity stream shortly."); } }