Пример #1
0
        /// <summary>
        /// Sets up the form for the current instance.
        /// </summary>
        /// <param name="instanceName">The name of the instance to display.</param>
        public MainForm(string instanceName)
        {
            try
            {
                InitializeComponent();
            }
            catch (COMException loE)
            {
                _logger.Error("Error initializing main view: {0}", loE);
                if ((uint)loE.ErrorCode == 0x80040154)
                {
                    MessageBox.Show(this, Resources.Incorrect_bittedness_of_OotD, Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw;
                }
            }

            try
            {
                InstanceName = instanceName;
                Preferences  = new InstancePreferences(InstanceName);

                // Uniquely identify the previous/next buttons for use in an ugly hack below.
                ButtonNext.Tag     = Guid.NewGuid();
                ButtonPrevious.Tag = Guid.NewGuid();

                SuspendLayout();
                LoadSettings();
                ResumeLayout();
                SendWindowToBack();

                // hook up sticky window instance and events to let us know when resizing/moving
                // has ended so we can update the form dimensions in the preferences.
                _stickyWindow            = new StickyWindow(this);
                _stickyWindow.MoveEnded += (sender, args) =>
                {
                    _movingOrResizing = false;
                    SaveFormDimensions();
                };
                _stickyWindow.ResizeEnded += (sender, args) =>
                {
                    _movingOrResizing = false;
                    SaveFormDimensions();
                };

                // hook up event to keep the date in the header bar up to date
                OutlookViewControl.SelectionChange += OnAxOutlookViewControlOnSelectionChange;
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error initializing window.");
                MessageBox.Show(this, Resources.ErrorInitializingApp + Environment.NewLine + ex.Message, Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
Пример #2
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));
            }
        }
Пример #3
0
        private void RenameInstanceMenu_Click(object sender, EventArgs e)
        {
            InputBoxResult result = InputBox.Show(this, "", "Rename Instance", InstanceName, InputBox_Validating);
            if (result.Ok)
            {
                using (
                    RegistryKey parentKey =
                        Registry.CurrentUser.OpenSubKey(
                            "Software\\" + Application.CompanyName + "\\" +
                            Application.ProductName, true))
                {
                    if (parentKey != null)
                    {
                        RegistryHelper.RenameSubKey(parentKey, InstanceName, result.Text);
                        String oldInstanceName = InstanceName;
                        InstanceName = result.Text;
                        Preferences = new InstancePreferences(InstanceName);

                        OnInstanceRenamed(this, new InstanceRenamedEventArgs(oldInstanceName, InstanceName));
                    }
                }
            }
        }
Пример #4
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 be 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 == GetFolderFromViewType(FolderViewType.Calendar).Name)
            {
                CalendarMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == GetFolderFromViewType(FolderViewType.Contacts).Name)
            {
                ContactsMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == GetFolderFromViewType(FolderViewType.Inbox).Name)
            {
                InboxMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == GetFolderFromViewType(FolderViewType.Notes).Name)
            {
                NotesMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == GetFolderFromViewType(FolderViewType.Tasks).Name)
            {
                TasksMenu.Checked = true;
            }
            else if (Preferences.OutlookFolderName == GetFolderFromViewType(FolderViewType.Todo).Name)
            {
                TodosMenu.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 definition 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();
            }
        }
Пример #5
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)
            {
                // use default if there was a problem
                Opacity = InstancePreferences.DefaultOpacity;
                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)
            {
                // use defaults if there was a problem
                Left = InstancePreferences.DefaultTopPosition;
                Top = InstancePreferences.DefaultLeftPosition;
                Width = InstancePreferences.DefaultWidth;
                Height = InstancePreferences.DefaultHeight;
                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;
            }

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

            // Sets the selected view from preferences.
            try
            {
                axOutlookViewControl.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())
            {
                axOutlookViewControl.ViewXML = Preferences.ViewXml;
            }

            // 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();
            }
        }