Пример #1
0
        private void OnNotifyMenuOpening(Object sender, CancelEventArgs args)
        {
            Point point = Control.MousePosition;

            using (new WaitCursor(this))
            {
                this.notifyMenu.Items.Clear();

                if (!this.Visible)
                {
                    IEnumerable <EnvironmentVariable> variables =
                        EnvironmentSerializer.Load(EnvironmentVariableTarget.User)
                        .Concat(EnvironmentSerializer.Load(EnvironmentVariableTarget.Machine))
                        .Where(x => x.Shift != null && x.Shift.Length > 0);

                    foreach (EnvironmentVariable variable in variables)
                    {
                        ToolStripMenuItem strip = new ToolStripMenuItem(variable.Label)
                        {
                            Tag = variable.Scope,
                        };

                        foreach (String shift in variable.Shift)
                        {
                            ToolStripMenuItem child = new ToolStripMenuItem(shift)
                            {
                                Checked = String.Compare(shift, variable.Value) == 0
                            };

                            child.Click += this.OnNotifyItemClicked;
                            strip.DropDownItems.Add(child);
                        }

                        this.notifyMenu.Items.Add(strip);
                    }

                    if (variables.Any())
                    {
                        this.notifyMenu.Items.Add(this.cmiSeparator1);
                    }

                    this.notifyMenu.Items.Add(this.cmiShow);
                }
                else
                {
                    this.notifyMenu.Items.Add(this.cmiHide);
                }

                this.notifyMenu.Items.Add(this.cmiExit);
            }

            this.notifyMenu.Show(point, ToolStripDropDownDirection.AboveLeft);
        }
Пример #2
0
        private void OnSaveClicked(Object sender, EventArgs args)
        {
            String message = "Possibly dangerous operation! Do you really want to apply the environment changes you made?";

            if (DialogResult.Yes == MessageBox.Show(this, message, this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
            {
                IList <Exception> exceptions = new List <Exception>();

                using (new WaitCursor(this))
                {
                    if (!EnvironmentSerializer.Save(this.GetModifiedVariables(this.lsvUser), ref exceptions))
                    {
                        Program.Logger.Fatal("Error occurred while serializing user scope environment.");
                    }

                    this.SetupListView(this.lsvUser, EnvironmentSerializer.Load(EnvironmentVariableTarget.User));

                    if (PermissionCheck.IsRunAsAdmin)
                    {
                        if (!EnvironmentSerializer.Save(this.GetModifiedVariables(this.lsvMachine), ref exceptions))
                        {
                            Program.Logger.Fatal("Error occurred while serializing machine scope environment.");
                        }

                        this.SetupListView(this.lsvMachine, EnvironmentSerializer.Load(EnvironmentVariableTarget.Machine));
                    }

                    foreach (Exception exception in exceptions)
                    {
                        Program.Logger.Error(exception);
                    }

                    Program.SaveSettings();
                }
            }
        }