public static void AskUserForFolder(Outlook.NavigationGroups nav, Action <Outlook.NavigationFolder, bool> SuccessCallback, System.Action CancelCallback) { var t = new Thread(() => { SelectFolderForm frm = new SelectFolderForm(nav); frm.ShowDialog(); // TODO: get the hwnd for this instance of outlook // NOTE: looks like this is not possible, we could easily // attach to the wrong explorer in the right process // and end up focusing a window poorly and confusing the user app.Run(); // NOTE: Run() will block until Exit() if (frm.DialogResult == DialogResult.OK) { SuccessCallback(frm.Result, frm.chk.Checked); } else { CancelCallback(); } }); t.SetApartmentState(ApartmentState.STA); // Required for UI t.Start(); }
private void SelectFolder(Action <NavigationFolder> Callback) { var exp = this.Application.ActiveExplorer(); var nav = (TasksModule)exp.NavigationPane.Modules.GetNavigationModule(OlNavigationModuleType.olModuleTasks); NavigationFolder def = LoadDefaultFolder(nav.NavigationGroups); if (def != null) { // if CTRL is down, always display the selection dialog if (!IsKeyPushedDown(Keys.ControlKey)) { Callback(def); return; } } // We don't have a default selection, so invoke the selection dialog SelectFolderForm.AskUserForFolder(nav.NavigationGroups, (folder, save) => // success { try { if (save) { SaveDefaultFolder(nav.NavigationGroups, folder); } else { // NOTE: clear out the old folder, since this might be an // override using CTRL, and we'll need to respect new settings ClearDefaultFolder(); } } catch (System.Exception ex) { // if we can't save, just log the error and continue Debug.WriteLine(ex); } Callback(folder); }, () => // cancelled { // the user canceled the dialog } ); }