Example #1
0
        private static void _loaded <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            string property = "[Server database editor - Enabled state - " + settings.DbData.DisplayName + "]";

            Func <bool>   getConfig     = () => Boolean.Parse(ProjectConfiguration.ConfigAsker[property, true.ToString()]);
            Action <bool> setConfig     = v => ProjectConfiguration.ConfigAsker[property] = v.ToString();
            Func <string> getHeader     = () => getConfig() ? "Disable" : "Enable";
            Func <string> getFullHeader = () => String.Format("{0} '{1}'", getHeader(), settings.DbData.Filename.Replace("_", "__"));
            Func <Image>  getIcon       = () => getConfig() ? new Image {
                Source = (BitmapSource)ApplicationManager.PreloadResourceImage("error16.png")
            } : new Image {
                Source = (BitmapSource)ApplicationManager.PreloadResourceImage("validity.png")
            };

            var menuItem = new MenuItem {
                Header = getFullHeader(), Icon = getIcon()
            };

            menuItem.IsEnabled = false;

            menuItem.Click += delegate {
                if (settings.DbData != null)
                {
                    try {
                        setConfig(!getConfig());
                        gdb.Attached["IsEnabled"] = getConfig();
                        TabGenerator <TKey> .TgOnTabVisualUpdate(tab, settings, gdb);

                        menuItem.Dispatch(delegate {
                            menuItem.Header = getFullHeader();
                            menuItem.Icon   = getIcon();
                        });
                    }
                    catch (Exception err) {
                        ErrorHandler.HandleException(err);
                    }
                }
                else
                {
                    ErrorHandler.HandleException("File not found.");
                }
            };

            tab.Database.Reloaded += delegate {
                menuItem.Dispatch(delegate {
                    menuItem.IsEnabled = true;

                    if (!getConfig())
                    {
                        gdb.Attached["IsEnabled"] = false;
                    }

                    menuItem.Header = getFullHeader();
                    menuItem.Icon   = getIcon();
                });
            };

            settings.ContextMenu.Items.Insert(1, menuItem);
        }
Example #2
0
        static GTabsMaker()
        {
            CopyEntriesToClipboardFunctionInt = new GItemCommand <int, ReadableTuple <int> > {
                AllowMultipleSelection = true,
                DisplayName            = "Copy entries to clipboard",
                ImagePath          = "export.png",
                InsertIndex        = 3,
                Shortcut           = ApplicationShortcut.Copy,
                AddToCommandsStack = false,
                GenericCommand     = delegate(List <ReadableTuple <int> > items) {
                    StringBuilder builder = new StringBuilder();

                    for (int i = 0; i < items.Count; i++)
                    {
                        ReadableTuple <int> item = items[i];
                        builder.AppendLine(string.Join(",", item.GetRawElements().Select(p => (p ?? "").ToString()).ToArray()));
                    }

                    Clipboard.SetText(builder.ToString());
                }
            };

            CopyEntriesToClipboardFunctionString = new GItemCommand <string, ReadableTuple <string> > {
                AllowMultipleSelection = true,
                DisplayName            = "Copy entries to clipboard",
                ImagePath          = "export.png",
                Shortcut           = ApplicationShortcut.Copy,
                InsertIndex        = 3,
                AddToCommandsStack = false,
                GenericCommand     = delegate(List <ReadableTuple <string> > items) {
                    StringBuilder builder = new StringBuilder();

                    for (int i = 0; i < items.Count; i++)
                    {
                        ReadableTuple <string> item = items[i];
                        builder.AppendLine(string.Join(",", item.GetRawElements().Select(p => (p ?? "").ToString()).ToArray()));
                    }

                    Clipboard.SetText(builder.ToString());
                }
            };

            SelectFromMobDb               = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.Mobs, tab));
            SelectFromItemDb              = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.Items, tab));
            SelectFromSkillDb             = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.Skills, tab));
            SelectFromMobDbString         = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.Mobs, tab, ServerMobSkillAttributes.MobId));
            SelectFromSkillDbString       = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.Skills, tab, ServerMobSkillAttributes.SkillId));
            SelectFromSkillRequirementsDb = (tab, settings, gdb) => settings.AddedCommands.Add(GenerateSelectFrom(ServerDbs.SkillsRequirement, tab));
        }