/// <summary>
        /// Invoked when a <see cref="MenuItem"/> for a <see cref="TimerWindow"/> is clicked.
        /// </summary>
        /// <param name="sender">The <see cref="MenuItem"/> where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private void WindowMenuItemClick(object sender, EventArgs e)
        {
            MenuItem    windowMenuItem = (MenuItem)sender;
            TimerWindow window         = (TimerWindow)windowMenuItem.Tag;

            window.BringToFrontAndActivate();
        }
        /// <summary>
        /// Invoked when the "New timer" <see cref="MenuItem"/> is clicked.
        /// </summary>
        /// <param name="sender">The <see cref="MenuItem"/> where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private void NewTimerMenuItemClick(object sender, EventArgs e)
        {
            TimerWindow window = new TimerWindow();

            window.RestoreFromSibling();
            window.Show();
        }
Пример #3
0
        /// <summary>
        /// Invoked when the "New timer" <see cref="MenuItem"/> is clicked.
        /// </summary>
        /// <param name="sender">The <see cref="MenuItem"/> where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        private void NewTimerMenuItemClick(object sender, RoutedEventArgs e)
        {
            TimerWindow window = new TimerWindow();

            window.RestoreFromWindow(this.timerWindow);
            window.Show();
        }
Пример #4
0
        /// <summary>
        /// Binds the <see cref="ContextMenu"/> to a <see cref="TimerWindow"/>.
        /// </summary>
        /// <param name="window">A <see cref="TimerWindow"/>.</param>
        public void Bind(TimerWindow window)
        {
            // Validate parameters
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            // Validate state
            if (this.timerWindow != null)
            {
                throw new InvalidOperationException();
            }

            // Initialize members
            this.timerWindow = window;

            this.timerWindow.ContextMenuOpening += this.WindowContextMenuOpening;
            this.timerWindow.ContextMenuClosing += this.WindowContextMenuClosing;
            this.timerWindow.ContextMenu         = this;

            this.dispatcherTimer          = new DispatcherTimer(DispatcherPriority.Normal, this.Dispatcher);
            this.dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
            this.dispatcherTimer.Tick    += this.DispatcherTimerTick;

            this.selectableThemeMenuItems = new List <MenuItem>();
            this.selectableSoundMenuItems = new List <MenuItem>();
            //this.selectableWindowTitleMenuItems = new List<MenuItem>();

            // Build the menu
            this.BuildMenu();
        }
        /// <summary>
        /// Invoked when the <see cref="dispatcherTimer"/> interval has elapsed.
        /// </summary>
        /// <param name="sender">The <see cref="DispatcherTimer"/>.</param>
        /// <param name="e">The event data.</param>
        private void DispatcherTimerTick(object sender, EventArgs e)
        {
            foreach (MenuItem menuItem in this.notifyIcon.ContextMenu.MenuItems)
            {
                TimerWindow window = menuItem.Tag as TimerWindow;
                if (window != null)
                {
                    if (!window.Timer.Disposed)
                    {
                        window.Timer.Update();
                    }

                    menuItem.Text = window.ToString();
                }
            }
        }