예제 #1
0
        public MailTray(GmailDataHelper gdh)
        {
            this.gdh = gdh;
            LoadImage();
            ni = new NotifyIcon();

            try
            {
                ni.Icon = EmptyIco;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to retreive the Icon " + ex.Message);
                ni.Icon = new Icon(SystemIcons.Application, 40, 40);
            }

            #region Left Click
            niMenuLeftClick = new System.Windows.Forms.ContextMenuStrip();
            niMenuLeftClick.Items.Add(gdh.Datas.Login, peopleIM);
            niMenuLeftClick.Items.Add("-");
            niMenuLeftClick.Items.Add(new ToolStripMenuItem("Update", mailUpdateIM, (s, ee) =>
            {
                gdh.UpdateData();
            }));
            niMenuLeftClick.Items.Add(new ToolStripMenuItem("Again", mailAgainIM, (s, ee) =>
            {
                foreach (var mail in gdh.Datas.Mails)
                {
                    gdh.NotifyMail(mail);
                }
            }));
            niMenuLeftClick.Items.Add(new ToolStripMenuItem("Open", mailViewIM, (s, ee) =>
            {
                System.Diagnostics.Process.Start(gdh.Datas.Link);
            }));
            niMenuLeftClick.Items.Add("-");
            niMenuLeftClick.Items.Add(new ToolStripMenuItem("Quit", closeIM, (s, ee) =>
            {
                if (System.Windows.Forms.Application.MessageLoop)
                {
                    // WinForms app
                    System.Windows.Forms.Application.Exit();
                }
                else
                {
                    // Console app
                    System.Environment.Exit(1);
                }
            }));
            #endregion

            #region Right Click
            niMenuRightClick    = new System.Windows.Forms.ContextMenuStrip();
            ni.ContextMenuStrip = niMenuRightClick;


            ni.ContextMenuStrip.Items.Add(new ToolStripMenuItem("About", infoIM, (s, ee) => {
                if (Wabout == null)
                {
                    Wabout          = new AboutWindow();
                    Wabout.Closing += (ss, e) =>
                    {
                        e.Cancel = true;
                        Wabout.Hide();
                    };
                    Wabout.Show();
                }
                else
                {
                    UIUtil.BringToFrontWindow(Wabout);
                }
            }));

            ni.ContextMenuStrip.Items.Add(new ToolStripMenuItem("Config", gearIM, (s, ee) =>
            {
                if (Wsettings == null)
                {
                    Wsettings             = new SettingsWindow();
                    Wsettings.DataContext = new SettingsVM(gdh.Datas.Login, gdh.Settings);
                    Wsettings.Closing    += (ss, e) =>
                    {
                        e.Cancel = true;
                        Wsettings.Hide();
                    };
                    Wsettings.Show();
                }
                else
                {
                    UIUtil.BringToFrontWindow(Wsettings);
                }
            }));
            #endregion

            gdh.Datas.PropertyChanged         += gdh_PropertyChanged;
            gdh.Datas.Mails.CollectionChanged += Mails_CollectionChanged;

            ni.MouseClick += new MouseEventHandler(ni_MouseClick);
            ni.Visible     = true;
            ni.Text        = gdh.ToString();
        }