Clear() public méthode

public Clear ( ) : void
Résultat void
        /// <summary>
        /// Sets up a drop-down menu to allow file-system selection.
        /// </summary>
        private void _Setup(string Path, ToolStripMenuItem Item, _Mode Mode, Action<string> OnSelect)
        {
            if (Mode == _Mode.Save)
            {
                ToolStripTextBox textbox = new ToolStripTextBox();
                Item.DropDownItems.Add(textbox);
                textbox.ToolTipText = "Type a file name here. Press Enter to save, or Control + Enter to make a new folder.";
                textbox.KeyDown += delegate(object sender, KeyEventArgs e)
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        if (e.Control)
                        {
                            string dirname = textbox.Text;
                            string dirpath = Path + System.IO.Path.DirectorySeparatorChar + dirname;
                            Directory.CreateDirectory(dirpath);
                            ToolStripMenuItem item = new ToolStripMenuItem(dirname);
                            this._Setup(dirpath, item, _Mode.Save, OnSelect);
                            Item.DropDownItems.Insert(1, item);
                            textbox.Clear();
                        }
                        else
                        {
                            this.HideDropDown();
                            OnSelect(Path + System.IO.Path.DirectorySeparatorChar + textbox.Text + this.Extension);
                        }
                    }
                };

                Item.DropDownOpening += delegate
                {
                    this._Populate(Path, Item, Mode, OnSelect);
                };
                Item.DropDownClosed += delegate
                {
                    textbox.Clear();
                    Item.DropDownItems.Clear();
                    Item.DropDownItems.Add(textbox);
                };
            }
            else
            {
                ToolStripMenuItem dummy = new ToolStripMenuItem("(Nothing Here)");
                dummy.Enabled = false;
                Item.DropDownItems.Add(dummy);
                Item.DropDownOpening += delegate
                {
                    if (this._Populate(Path, Item, Mode, OnSelect))
                    {
                        Item.DropDownItems.Remove(dummy);
                    }
                };
                Item.DropDownClosed += delegate
                {
                    Item.DropDownItems.Clear();
                    Item.DropDownItems.Add(dummy);
                };
            }
        }
Exemple #2
0
        public Main()
        {
            this.Text = "ServerManager";
            this.Size = new Size(0, 0);
            this.FormBorderStyle = FormBorderStyle.None;
            this.ShowInTaskbar = false;
            this.ShowIcon = false;
            this.BackColor = Color.Magenta;
            this.TransparencyKey = Color.Magenta;
            this.Opacity = 0;

            Form f = new Form();
            f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            f.ShowInTaskbar = false;
            this.Owner = f;

            notifyIcon = new NotifyIcon();
            menu = new ContextMenuStrip();
            demarrer = new ToolStripMenuItem();
            arreter = new ToolStripMenuItem();
            options = new ToolStripMenuItem();
            executer = new ToolStripMenuItem();
            command = new ToolStripTextBox();
            isvisible = new ToolStripMenuItem();
            rebootonfail = new ToolStripMenuItem();
            remote = new ToolStripMenuItem();
            information = new ToolStripMenuItem();
            quitter = new ToolStripMenuItem();

            demarrer.Text = "Démarrer";
            demarrer.BackColor = c;
            demarrer.Image = ServerManager.Properties.Resources.start;
            demarrer.Click += (ob, ev) =>
            {
                isvisible.Image = ServerManager.Properties.Resources.visible;
                Server.Start();
            };

            arreter.Text = "Arrêter";
            arreter.BackColor = c;
            arreter.Image = ServerManager.Properties.Resources.shutdown;
            arreter.Click += (ob, ev) =>
            {
                isvisible.Image = ServerManager.Properties.Resources.invisible;
                if (Server.IsReady)
                {
                    Server.Stopping = true;
                    Utility.Sendkeys.Send(Server.Handle, "quit~");
                    Server.Process.WaitForExit(2500);
                }

                Server.Stop();
            };

            remote.Text = "Contrôle à distance";
            remote.BackColor = c;
            remote.Image = ServerManager.Properties.Resources.remote;
            remote.Checked = Program.Config.Values.Remote.Activated;
            remote.CheckOnClick = true;
            remote.Click += (ob, ev) =>
            {
                Program.Config.Values.Remote.Activated = remote.Checked;
                Server.Remote.ListenConnection = remote.Checked;
            };

            rebootonfail.Text = "Redémarrer en cas d'échec";
            rebootonfail.BackColor = c;
            rebootonfail.Image = ServerManager.Properties.Resources.restart;
            rebootonfail.Checked = Program.Config.Values.Connection.AutoRestart;
            rebootonfail.CheckOnClick = true;
            rebootonfail.Click += (ob, ev) =>
            {
                Program.Config.Values.Connection.AutoRestart = rebootonfail.Checked;
            };

            options.Text = "Options";
            options.BackColor = c;
            options.Image = ServerManager.Properties.Resources.settings;
            options.DropDown.Items.Add(rebootonfail);
            options.DropDown.Items.Add(remote);

            command.Text = "Commande ici";
            command.ForeColor = Color.Gray;
            command.GotFocus += (ob, ev) =>
            {
                if (command.Text == "Commande ici")
                    command.Text = "";
                command.ForeColor = Color.Black;
            };
            command.LostFocus += (ob, ev) =>
            {
                if (command.Text == "")
                    command.Text = "Commande ici";
                command.ForeColor = Color.Gray;
            };
            command.KeyDown += (ob, ev) =>
            {
                if (ev.KeyCode == Keys.Enter)
                {
                    Utility.Sendkeys.Send(Server.Handle, command.Text + "~");
                    command.Clear();
                    ev.Handled = ev.SuppressKeyPress = true;
                }
            };

            executer.Text = "Exécuter";
            executer.BackColor = c;
            executer.Image = ServerManager.Properties.Resources.execute;
            executer.DropDown.Items.Add(command);

            isvisible.Text = "Visibilité";
            isvisible.BackColor = c;
            isvisible.Image = ServerManager.Properties.Resources.invisible;
            isvisible.Click += (ob, ev) =>
            {
                isvisible.Image = Utility.View.ChangeVisibility(Server.Handle) ? ServerManager.Properties.Resources.visible : ServerManager.Properties.Resources.invisible;
            };

            information.Text = "Informations";
            information.BackColor = c;
            information.Image = ServerManager.Properties.Resources.information;
            information.Click += (ob, ev) =>
            {
                if (Server.IsReady && info != "" && title != "")
                    MessageBox.Show(this, info, title, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            };

            quitter.Text = "Quitter";
            quitter.BackColor = c;
            quitter.Image = ServerManager.Properties.Resources.exit;
            quitter.Click += (ob, ev) =>
            {
                if (!Server.IsAlive)
                    Dispose();
                else
                {
                    DialogResult dr = MessageBox.Show("Voulez-vous arrêter le server en même temps?", "Confirmation", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                    if (dr == DialogResult.Yes)
                    {
                        if (Server.IsReady)
                            arreter.PerformClick();

                        Server.Stop();
                        Dispose();
                    }
                    else if (dr == DialogResult.No)
                        Dispose();
                    else if (dr == DialogResult.Cancel)
                        return;
                    Server.Stats.Save();
                }

                Program.Config.Save();
                Environment.Exit(0);
            };

            menu.Items.Add(demarrer);
            menu.Items.Add(arreter);
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(options);
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(executer);
            menu.Items.Add(isvisible);
            menu.Items.Add(information);
            menu.Items.Add(new ToolStripSeparator());
            menu.Items.Add(quitter);

            foreach (ToolStripItem tsi in menu.Items)
                tsi.Enabled = false;
            demarrer.Enabled = true;
            options.Enabled = true;
            quitter.Enabled = true;

            notifyIcon.DoubleClick += (ob, ev) =>
            {
                if (!Server.IsAlive && title == "" && info == "")
                    Server.Start();
                else
                    isvisible.PerformClick();
            };

            t = new Thread(RefreshValues);
            this.Load += (ob, ev) => { t.Start(); };

            notifyIcon.Icon = disconnected;
            notifyIcon.ContextMenuStrip = menu;
            notifyIcon.Text = "ServerManager :: " + Path.GetFileName(Program.Config.Path);
            notifyIcon.Visible = true;
        }