コード例 #1
0
        private void SaveDefaultFolder(NavigationGroups nav, NavigationFolder folder)
        {
            NavigationGroup group = null;

            foreach (NavigationGroup g in nav)
            {
                if (group == null)
                {
                    foreach (NavigationFolder f in g.NavigationFolders)
                    {
                        if (f == folder)
                        {
                            group = g;
                            break;
                        }
                    }
                }
            }

            // NOTE: this should be impossible, but don't crash.
            if (group == null)
            {
                return;
            }

            RegistryKey rKey = Registry.CurrentUser.CreateSubKey(REG_PATH);

            rKey.SetValue("DefaultGroup", group.Name);
            rKey.SetValue("DefaultFolder", folder.DisplayName);
        }
コード例 #2
0
        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
            }
                                              );
        }