Exemple #1
0
        private void RenameInstanceMenu_Click(object sender, EventArgs e)
        {
            var result = InputBox.Show(this, "", "Rename Instance", InstanceName, InputBox_Validating);
            if (!result.Ok) return;

            using (var parentKey = Registry.CurrentUser.OpenSubKey("Software\\" + Application.CompanyName + "\\" + Application.ProductName, true))
            {
                if (parentKey == null) return;

                RegistryHelper.RenameSubKey(parentKey, InstanceName, result.Text);
                string oldInstanceName = InstanceName;
                InstanceName = result.Text;
                Preferences = new InstancePreferences(InstanceName);

                OnInstanceRenamed(this, new InstanceRenamedEventArgs(oldInstanceName, InstanceName));
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads user preferences from registry and applies them.
        /// </summary>
        private void LoadSettings()
        {
            // create a new instance of the preferences class
            Preferences = new InstancePreferences(InstanceName);

            // There should ne no reason other than first run as to why the Store and Entry IDs are
            // empty.
            if (string.IsNullOrEmpty(Preferences.OutlookFolderStoreId))
            {
                // Set the Mapi Folder Details and the IDs.
                Preferences.OutlookFolderName = FolderViewType.Calendar.ToString();
                Preferences.OutlookFolderStoreId = GetFolderFromViewType(FolderViewType.Calendar).StoreID;
                Preferences.OutlookFolderEntryId = GetFolderFromViewType(FolderViewType.Calendar).EntryID;
            }

            SetMAPIFolder();

            // Sets the opacity of the instance.
            try
            {
                Opacity = Preferences.Opacity;
            }
            catch (Exception ex)
            {
                // use default if there was a problem
                Opacity = InstancePreferences.DefaultOpacity;
                Logger.Error(ex, "Error setting opacity.");
                MessageBox.Show(this, Resources.ErrorSettingOpacity, Resources.ErrorCaption, MessageBoxButtons.OK,
                                MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            TransparencySlider.Value = (int)(Preferences.Opacity * 100);

            // Sets the position of the instance.
            try
            {
                Left = Preferences.Left;
                Top = Preferences.Top;
                Width = Preferences.Width;
                Height = Preferences.Height;
            }
            catch (Exception ex)
            {
                // use defaults if there was a problem
                Left = InstancePreferences.DefaultTopPosition;
                Top = InstancePreferences.DefaultLeftPosition;
                Width = InstancePreferences.DefaultWidth;
                Height = InstancePreferences.DefaultHeight;
                Logger.Error(ex, "Error setting window position.");
                MessageBox.Show(this, Resources.ErrorSettingDimensions, Resources.ErrorCaption, MessageBoxButtons.OK,
                                MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }

            // Checks the menuitem of the current folder.
            if (Preferences.OutlookFolderName == FolderViewType.Calendar.ToString())
            {
                CalendarMenu.Checked = true;
                ShowCalendarButtons(true);
            }
            else if (Preferences.OutlookFolderName == FolderViewType.Contacts.ToString())
            {
                ShowCalendarButtons(false);
                ContactsMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == FolderViewType.Inbox.ToString())
            {
                ShowCalendarButtons(false);
                InboxMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == FolderViewType.Notes.ToString())
            {
                ShowCalendarButtons(false);
                NotesMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == FolderViewType.Tasks.ToString())
            {
                ShowCalendarButtons(false);
                TasksMenu.Checked = true;
            }
            else
            {
                // custom folder
                _customFolder = Preferences.OutlookFolderName;
                string folderName = GetFolderNameFromFullPath(_customFolder);
                TrayMenu.Items.Insert(GetSelectFolderMenuLocation() + 1,
                                      new ToolStripMenuItem(folderName, null, CustomFolderMenu_Click));
                _customMenu = (ToolStripMenuItem)TrayMenu.Items[GetSelectFolderMenuLocation() + 1];
                _customMenu.Checked = true;

                // store the custom folder defintion in case the user wants to switch back to it and we need to reload it.
                _customFolderDefinition.OutlookFolderName = Preferences.OutlookFolderName;
                _customFolderDefinition.OutlookFolderStoreId = Preferences.OutlookFolderStoreId;
                _customFolderDefinition.OutlookFolderEntryId = Preferences.OutlookFolderEntryId;
            }

            // Sets the viewcontrol folder from preferences.
            OutlookViewControl.Folder = Preferences.OutlookFolderName;

            // Sets the selected view from preferences.
            try
            {
                OutlookViewControl.View = Preferences.OutlookFolderView;
            }
            catch
            {
                // if we get an exception here, it means the view stored doesn't apply to the current folder view,
                // so just reset it.
                Preferences.OutlookFolderView = string.Empty;
            }

            // If the view is a calendar view, use the stored ViewXML to restore their day/week/month view setting.
            if (Preferences.OutlookFolderName == FolderViewType.Calendar.ToString())
            {
                if (!string.IsNullOrEmpty(Preferences.ViewXml))
                {
                    OutlookViewControl.ViewXML = Preferences.ViewXml;
                }
                else
                {
                    SetViewXml(Resources.MonthXML);
                }
            }

            // Get a copy of the possible outlook views for the selected folder and populate the context menu for this instance.
            UpdateOutlookViewsList();

            // Sets whether the instance is allowed to be edited or not
            if (Preferences.DisableEditing)
            {
                DisableEnableEditing();
            }
        }