Example #1
0
        void ExecAiEdit()
        {
            if (!(AddinsList.SelectedItem is Addin sai))
            {
                return;
            }

            var ai = sai.Clone();

            var aibox = new AddinBox(CurrentEnvironment.FNames)
            {
                Title       = "Edit Addin",
                DataContext = ai
            };

            aibox.Closing += (sender, args) => {
                var aib = (AddinBox)sender;

                if (aib.DialogResult != true)
                {
                    return;
                }

                string msg = null;

                var any = Addins.Where(a => !a.Equals(sai)).Where(a => a.QFileName.Equals(ai.QFileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (any != null)
                {
                    msg = new StringBuilder("Addin '")
                          .Append(any.QFileName)
                          .Append("'")
                          .Append(String.IsNullOrWhiteSpace(any.Key) ? String.Empty : $"\n(alias '{any.Key}')")
                          .Append(" already exists.")
                          .ToString()
                    ;
                }

                if (msg == null)
                {
                    any = Addins.Where(a => !a.Equals(sai)).Where(a => a.Id.Equals(ai.Id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    if (any != null)
                    {
                        msg = new StringBuilder("Addin key '")
                              .Append(any.Id)
                              .Append("'\nis already used by '")
                              .Append(any.QFileName)
                              .Append("'.")
                              .ToString()
                        ;
                    }
                }

                if (msg != null)
                {
                    MessageBox.Show(
                        msg,
                        Strings.APP_NAME,
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    args.Cancel = true;
                }
            };

            if (aibox.ShowDialog() != true)
            {
                return;
            }

            if ((ai.Framework == sai.Framework) && (ai.Arch == sai.Arch))
            {
                sai.SetValue(ai);
                AddinsList.Items.Refresh();
            }
            else
            {
                CurrentEnvironment.Remove(sai);
                CurrentEnvironment.Add(ai, null);
                CurrentEnvironment.Render(Addins);
                AddinsList.SelectedItem = Addins.First(a => a.Path == ai.Path);
            }
            CurrentEnvironment.Dirty = true;

            UpdateColumnWidths(AddinsList);
        }
Example #2
0
        void ExecAiAdd()
        {
            var sai = (Addin)AddinsList.SelectedItem;

            var ai = new Addin {
                Framework = sai?.Framework,
                ReadOnly  = true
            };

            var aibox = new AddinBox(CurrentEnvironment.FNames, sai?.Path)
            {
                Title       = "Add Addin",
                DataContext = ai
            };

            aibox.Closing += (sender, args) => {
                var aib = (AddinBox)sender;

                if (aib.DialogResult != true)
                {
                    return;
                }

                string msg = null;

                var any = Addins.Where(a => a.QFileName.Equals(ai.QFileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (any != null)
                {
                    msg = new StringBuilder("Addin '")
                          .Append(any.QFileName)
                          .Append("'")
                          .Append(String.IsNullOrWhiteSpace(any.Key) ? String.Empty : $"\n(alias '{any.Key}')")
                          .Append(" already exists.")
                          .ToString()
                    ;
                }

                if (msg == null)
                {
                    any = Addins.Where(a => a.Id.Equals(ai.Id, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    if (any != null)
                    {
                        msg = new StringBuilder("Addin key '")
                              .Append(any.Id)
                              .Append("'\nis already used by '")
                              .Append(any.QFileName)
                              .Append("'.")
                              .ToString()
                        ;
                    }
                }

                if (msg != null)
                {
                    MessageBox.Show(
                        msg,
                        Strings.APP_NAME,
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    args.Cancel = true;
                }
            };

            if (aibox.ShowDialog() != true)
            {
                return;
            }

            CurrentEnvironment.Add(ai, sai);
            CurrentEnvironment.Render(Addins);
            UpdateColumnWidths(AddinsList);
            AddinsList.SelectedItem = Addins.First(a => a.Path == ai.Path);
        }
Example #3
0
        void ExecGaiAdd()
        {
            var sai = (GlobalAddin)GAList.SelectedItem;

            var ai = new GlobalAddin {
                Active   = true,
                ReadOnly = true
            };

            var aibox = new AddinBox(Array.Empty <string>(), sai?.Path, true)
            {
                Title       = "Add Global Addin",
                DataContext = ai
            };

            aibox.Closing += (sender, args) => {
                var aib = (AddinBox)sender;

                if (aib.DialogResult != true)
                {
                    return;
                }

                string msg = null;

                var any = globalAddins.Where(a => a.FileName.Equals(ai.FileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                if (any != null)
                {
                    msg = new StringBuilder("Global addin '")
                          .Append(any.FileName)
                          .Append("'")
                          .Append(String.IsNullOrWhiteSpace(any.Key) ? String.Empty : $"\n(alias '{any.Key}')")
                          .Append(" already exists.")
                          .ToString()
                    ;
                }

                if (msg == null)
                {
                    any = globalAddins.Where(a => a.DisplayName.Equals(ai.DisplayName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    if (any != null)
                    {
                        msg = new StringBuilder("Global addin alias '")
                              .Append(any.DisplayName)
                              .Append("'\nis already used by '")
                              .Append(any.FileName)
                              .Append("'.")
                              .ToString()
                        ;
                    }
                }

                if (msg != null)
                {
                    MessageBox.Show(
                        msg,
                        Strings.APP_NAME,
                        MessageBoxButton.OK,
                        MessageBoxImage.Error
                        );
                    args.Cancel = true;
                }
            };

            if (aibox.ShowDialog() != true)
            {
                return;
            }

            globalAddins.Add(ai);
            GAList.SelectedItem = ai;
        }