Ejemplo n.º 1
0
        private void _setSettings(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            List <DbAttribute> attributes;

            if (gdb.LayoutSearch != null)
            {
                attributes = gdb.LayoutSearch.ToList();
            }
            else
            {
                attributes = new DbAttribute[] { settings.AttId, settings.AttDisplay }.Concat(gdb.AttributeList.Attributes.Skip(2).Where(p => p.IsSearchable != null)).ToList();
            }

            if (attributes.Count % 2 != 0)
            {
                attributes.Add(null);
            }

            settings.SearchEngine.SetAttributes(attributes);
            settings.SearchEngine.SetSettings(settings.AttId, true);
            settings.SearchEngine.SetSettings(settings.AttDisplay, true);

            foreach (DbAttribute attribute in attributes)
            {
                if (attribute != null && attribute.IsSearchable == true)
                {
                    settings.SearchEngine.SetSettings(attribute, true);
                }
            }
        }
Ejemplo n.º 2
0
        public static GDbTab Instantiate <TKey>(GTabSettings <TKey, ReadableTuple <TKey> > settings, AbstractDb <TKey> db)
        {
            Table <TKey, ReadableTuple <TKey> >         table = db.Table;
            GDbTabWrapper <TKey, ReadableTuple <TKey> > tab   = new GDbTabWrapper <TKey, ReadableTuple <TKey> >();

            settings.Table = table;
            tab.Initialize(settings);
            return(tab);
        }
Ejemplo n.º 3
0
        public void InitAttributes(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            settings.AttributeList = gdb.AttributeList;
            settings.AttId         = gdb.AttributeList.PrimaryAttribute;
            settings.AttDisplay    = gdb.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? gdb.AttributeList.Attributes[1];

            if (typeof(TKey) == typeof(string))
            {
                settings.AttIdWidth = 120;
            }
        }
Ejemplo n.º 4
0
        public static bool IsTabEnabled(GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            if (AllLoaders.DetectPath(settings.DbData) == null)
            {
                return(false);
            }

            if (gdb.Attached["IsEnabled"] != null && !(bool)gdb.Attached["IsEnabled"])
            {
                return(false);
            }

            if (!Boolean.Parse(ProjectConfiguration.ConfigAsker["[Server database editor - Enabled state - " + settings.DbData.DisplayName + "]", true.ToString()]))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        // TODO: The TabGenerator class works better than these custom generators
        public static GDbTab LoadSItemsTab <TKey>(GenericDatabase database, TabControl control, BaseDb gdb)
        {
            AbstractDb <TKey> db   = gdb.To <TKey>();
            AttributeList     list = ServerItemProperties.AttributeList;

            GDbTabWrapper <TKey, ReadableTuple <TKey> > tab      = new GDbTabWrapper <TKey, ReadableTuple <TKey> >();
            GTabSettings <TKey, ReadableTuple <TKey> >  settings = new GTabSettings <TKey, ReadableTuple <TKey> >(db);

            SInit(settings);
            settings.AttributeList = list;
            settings.AttId         = list.PrimaryAttribute;
            settings.AttDisplay    = ServerItemProperties.Name;

            DisplayableProperty <TKey, ReadableTuple <TKey> > generalProperties = new DisplayableProperty <TKey, ReadableTuple <TKey> >();

            generalProperties.Spacing = 0;

            int line = 0;

            Print(ref line, new SpecifiedRangeIndexProvider(new int[] {
                ServerItemProperties.Id.Index, 1,
                ServerItemProperties.Type.Index, 1,
                ServerItemProperties.AegisName.Index, 2,
                ServerItemProperties.Buy.Index, 2,
                ServerItemProperties.Weight.Index, 16
            }), generalProperties, list);

            generalProperties.AddCustomProperty(new CustomQueryViewerMobDroppedBy <TKey, ReadableTuple <TKey> >(line, 0, 1, 2));
            generalProperties.SetRow(line, new GridLength(1, GridUnitType.Star));

            Grid grid = PrintGrid(ref line, 3, 1, 2, new DefaultIndexProvider(ServerItemProperties.BindOnEquip.Index, 8), -1, 0, -1, 0, generalProperties, list);

            generalProperties.AddDeployAction(delegate {
                grid.Children[0].IsEnabled = false;
                grid.Children[1].IsEnabled = false;
                grid.Children[4].IsEnabled = false;
                grid.Children[5].IsEnabled = false;
            });

            settings.DisplayablePropertyMaker = generalProperties;
            settings.ClientDatabase           = database;
            settings.SearchEngine.SetAttributes(
                settings.AttId, settings.AttDisplay,
                ServerItemProperties.AegisName, null,
                ServerItemProperties.ApplicableJob, ServerItemProperties.Script,
                ServerItemProperties.OnEquipScript, ServerItemProperties.OnUnequipScript,
                ServerItemProperties.Type, ServerItemProperties.Gender
                );

            settings.SearchEngine.SetSettings(ServerItemProperties.Id, true);
            settings.SearchEngine.SetSettings(ServerItemProperties.Name, true);
            settings.SearchEngine.SetSettings(ServerItemProperties.AegisName, true);

            settings.SearchEngine.SetupImageDataGetter = delegate(ReadableTuple <TKey> tuple) {
                tuple.GetImageData = delegate {
                    try {
                        var cDb = database.GetTable <int>(ServerDbs.ClientResourceDb);

                        if (cDb == null)
                        {
                            return(null);
                        }

                        int id = tuple.GetKey <int>();

                        if (!cDb.ContainsKey(id))
                        {
                            return(null);
                        }

                        byte[] data = database.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(@"data\texture\À¯ÀúÀÎÅÍÆäÀ̽º\item\" + cDb.GetTuple(id).GetValue <string>(ClientResourceAttributes.ResourceName) + ".bmp"));

                        if (data != null)
                        {
                            GrfImage gimage = new GrfImage(ref data);
                            gimage.MakePinkTransparent();
                            return(gimage.Cast <BitmapSource>());
                        }

                        return(null);
                    }
                    catch {
                        return(null);
                    }
                };
            };

            settings.AddedCommands.Add(new GItemCommand <TKey, ReadableTuple <TKey> > {
                AllowMultipleSelection = true,
                DisplayName            = "Copy entries to clipboard (rAthena)",
                ImagePath          = "export.png",
                InsertIndex        = 3,
                Shortcut           = ApplicationShortcut.Copy,
                AddToCommandsStack = false,
                GenericCommand     = delegate(List <ReadableTuple <TKey> > items) {
                    StringBuilder builder = new StringBuilder();
                    DbWriterMethods.DbItemsWriterSub(builder, db, items.OrderBy(p => p.GetKey <TKey>()), ServerType.RAthena);
                    Clipboard.SetText(builder.ToString());
                }
            });

            settings.AddedCommands.Add(new GItemCommand <TKey, ReadableTuple <TKey> > {
                AllowMultipleSelection = true,
                DisplayName            = "Copy entries to clipboard (Hercules)",
                ImagePath          = "export.png",
                InsertIndex        = 4,
                Shortcut           = ApplicationShortcut.Copy2,
                AddToCommandsStack = false,
                GenericCommand     = delegate(List <ReadableTuple <TKey> > items) {
                    StringBuilder builder = new StringBuilder();
                    DbWriterMethods.DbItemsWriterSub(builder, db, items, ServerType.Hercules);
                    Clipboard.SetText(builder.ToString(), TextDataFormat.UnicodeText);
                }
            });

            settings.Table = db.Table;
            tab.Initialize(settings);
            AddTagGeneratorTabChangedEvent(control, tab, settings, gdb);
            return(tab);
        }
Ejemplo n.º 6
0
 public static void SInit <TKey>(GTabSettings <TKey, ReadableTuple <TKey> > settings)
 {
     SInit(null, settings, null);
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public static void SInit <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            settings.Style       = "TabItemStyledLess";
            settings.ContextMenu = new ContextMenu();
            var menuItem = new MenuItem {
                Header = "Select '" + settings.DbData.Filename.Replace("_", "__") + "' in explorer", Icon = new Image {
                    Source = (BitmapSource)ApplicationManager.PreloadResourceImage("arrowdown.png")
                }
            };

            menuItem.Click += delegate {
                if (settings.DbData != null)
                {
                    try {
                        string path = AllLoaders.DetectPath(settings.DbData);

                        if (path != null)
                        {
                            OpeningService.FilesOrFolders(path);
                        }
                        else
                        {
                            ErrorHandler.HandleException("File not found.");
                        }
                    }
                    catch (Exception err) {
                        ErrorHandler.HandleException(err);
                    }
                }
                else
                {
                    ErrorHandler.HandleException("File not found.");
                }
            };

            settings.ContextMenu.Items.Add(menuItem);

            settings.Loaded += _loaded;

            if (tab == null || gdb == null)
            {
                return;
            }

            if (gdb.AttributeList.Attributes.Any(p => p.IsSkippable))
            {
                foreach (var attributeIntern in gdb.AttributeList.Attributes.Where(p => p.IsSkippable))
                {
                    var attribute         = attributeIntern;
                    var menuItemSkippable = new MenuItem {
                        Header = attribute.DisplayName + " [" + attribute.AttributeName + ", " + attribute.Index + "]", Icon = new Image {
                            Source = (BitmapSource)ApplicationManager.PreloadResourceImage("add.png")
                        }
                    };
                    menuItemSkippable.IsEnabled = false;
                    menuItemSkippable.Click    += delegate {
                        gdb.Attached["EntireRewrite"]       = true;
                        gdb.Attached[attribute.DisplayName] = gdb.Attached[attribute.DisplayName] != null && !(bool)gdb.Attached[attribute.DisplayName];
                        gdb.To <TKey>().TabGenerator.OnTabVisualUpdate(tab, settings, gdb);
                    };
                    settings.ContextMenu.Items.Add(menuItemSkippable);
                }

                gdb.Attached.CollectionChanged += delegate {
                    int index = 2;

                    foreach (var attributeIntern in gdb.AttributeList.Attributes.Where(p => p.IsSkippable))
                    {
                        var attribute = attributeIntern;
                        int index1    = index;
                        settings.ContextMenu.Dispatch(delegate {
                            var menuItemSkippable       = (MenuItem)settings.ContextMenu.Items[index1];
                            menuItemSkippable.IsEnabled = true;
                            bool isSet = gdb.Attached[attribute.DisplayName] == null || (bool)gdb.Attached[attribute.DisplayName];

                            menuItemSkippable.Icon = new Image {
                                Source = (BitmapSource)ApplicationManager.PreloadResourceImage(isSet ? "delete.png" : "add.png")
                            };
                        });

                        index++;
                    }
                };
            }
        }
Ejemplo n.º 9
0
        public static void TgOnTabVisualUpdate(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            tab.Dispatch(delegate {
                ((UIElement)tab.Content).IsEnabled = IsTabEnabled(settings, gdb);
            });

            List <DbAttribute> attributes = settings.AttributeList.Attributes;

            if (gdb.LayoutIndexes != null)
            {
                AbstractProvider provider = AbstractProvider.GetProvider(gdb.LayoutIndexes);

                if (provider is GroupIndexProvider)
                {
                    return;
                }

                List <int> indexes = provider.GetIndexes();

                int row = 0;
                int column;

                for (int i = 0; i < indexes.Count; i += 2)
                {
                    column = 0;

                    if (indexes[i] > -1 && indexes[i] < attributes.Count)
                    {
                        var attribute = attributes[indexes[i]];
                        if (attribute.IsSkippable)
                        {
                            var  attached = gdb.Attached[attribute.DisplayName];
                            bool isSet    = attached == null || (bool)gdb.Attached[attribute.DisplayName];

                            tab.Dispatch(delegate {
                                var label   = tab._displayGrid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column);
                                var content = tab._displayGrid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column + 1);

                                if (label != null)
                                {
                                    label.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                    label.IsEnabled  = isSet;
                                }

                                if (content != null)
                                {
                                    content.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                    content.IsEnabled  = isSet;
                                }
                            });
                        }
                    }

                    column += 3;

                    if (i + 1 < indexes.Count)
                    {
                        if (indexes[i + 1] > -1 && indexes[i + 1] < attributes.Count)
                        {
                            var attribute = attributes[indexes[i + 1]];
                            if (attribute.IsSkippable)
                            {
                                var  attached = gdb.Attached[attribute.DisplayName];
                                bool isSet    = attached == null || (bool)gdb.Attached[attribute.DisplayName];

                                tab.Dispatch(delegate {
                                    var label   = tab._displayGrid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column);
                                    var content = tab._displayGrid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column + 1);

                                    if (label != null)
                                    {
                                        label.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                        label.IsEnabled  = isSet;
                                    }

                                    if (content != null)
                                    {
                                        content.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                        content.IsEnabled  = isSet;
                                    }
                                });
                            }
                        }
                    }

                    row += 2;
                }
            }
        }
Ejemplo n.º 10
0
        public static void LoadSItemGroupVisualUpdate(GDbTabWrapper <int, ReadableTuple <int> > tab, GTabSettings <int, ReadableTuple <int> > settings, BaseDb gdb)
        {
            List <DbAttribute> attributes = ServerItemGroupSubAttributes.AttributeList.Attributes;
            List <int>         indexes    = new SpecifiedIndexProvider(new int[] { 2, 3, 4, 5, 6, 7 }).GetIndexes();
            Grid grid = tab._displayGrid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == 0 && (int)p.GetValue(Grid.ColumnProperty) == 2) as Grid;

            if (grid == null)
            {
                return;
            }

            int row    = 2;
            int column = 0;

            for (int i = 0; i < indexes.Count; i++)
            {
                if (indexes[i] > -1 && indexes[i] < attributes.Count)
                {
                    var attribute = attributes[indexes[i]];

                    if (attribute.IsSkippable)
                    {
                        var  attached = gdb.Attached[attribute.DisplayName];
                        bool isSet    = attached != null && (bool)gdb.Attached[attribute.DisplayName];

                        tab.Dispatch(delegate {
                            var label   = grid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column);
                            var content = grid.Children.Cast <UIElement>().FirstOrDefault(p => (int)p.GetValue(Grid.RowProperty) == row && (int)p.GetValue(Grid.ColumnProperty) == column + 1);

                            if (label != null)
                            {
                                label.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                label.IsEnabled  = isSet;
                            }

                            if (content != null)
                            {
                                content.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed;
                                content.IsEnabled  = isSet;
                            }
                        });
                    }
                }

                row += 2;
            }
        }
Ejemplo n.º 11
0
 public void InitStyle(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
 {
     GTabsMaker.SInit(tab, settings, gdb);
 }
Ejemplo n.º 12
0
        private void _onSetCustomCommands(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            int max = MaxElementsToCopyInCustomMethods < 0 ? settings.AttributeList.Attributes.Count - StartIndexInCustomMethods : MaxElementsToCopyInCustomMethods;

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

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

                    Clipboard.SetText(builder.ToString());
                }
            });
        }
Ejemplo n.º 13
0
 private void _onPreviewTabInitialize(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
 {
 }
Ejemplo n.º 14
0
        private GDbTab _gDbTabMaker(GenericDatabase database, TabControl control, BaseDb gdb)
        {
            GTabSettings <TKey, ReadableTuple <TKey> >  settings = new GTabSettings <TKey, ReadableTuple <TKey> >(gdb);
            GDbTabWrapper <TKey, ReadableTuple <TKey> > tab      = new GDbTabWrapper <TKey, ReadableTuple <TKey> >();
            Table <TKey, ReadableTuple <TKey> >         table    = gdb.To <TKey>().Table;

            settings.Table   = table;
            settings.Control = control;

            InitStyle(tab, settings, gdb);
            InitAttributes(tab, settings, gdb);
            if (OnInitSettings != null)
            {
                OnInitSettings(tab, settings, gdb);
            }

            DisplayableProperty <TKey, ReadableTuple <TKey> > generalProperties = new DisplayableProperty <TKey, ReadableTuple <TKey> >();

            generalProperties.Spacing = DefaultSpacing;

            control.SelectionChanged += delegate(object sender, SelectionChangedEventArgs e) {
                if (e == null || e.RemovedItems.Count <= 0 || e.RemovedItems[0] as TabItem == null || (e.AddedItems.Count > 0 && e.AddedItems[0] as TabItem == null))
                {
                    return;
                }

                if (e.AddedItems.Count <= 0)
                {
                    return;
                }

                TabItem item = e.AddedItems[0] as TabItem;

                if (gdb.DbSource.AlternativeName != null)
                {
                    if (WpfUtilities.IsTab(item, gdb.DbSource.Filename) || WpfUtilities.IsTab(item, gdb.DbSource.AlternativeName))
                    {
                        if (generalProperties.OnTabVisible != null)
                        {
                            generalProperties.OnTabVisible(this);
                        }
                        if (OnPreviewTabVisualUpdate != null)
                        {
                            OnPreviewTabVisualUpdate(tab, settings, gdb);
                        }
                        if (OnTabVisualUpdate != null)
                        {
                            OnTabVisualUpdate(tab, settings, gdb);
                        }
                    }
                }
                else
                {
                    if (WpfUtilities.IsTab(item, gdb.DbSource))
                    {
                        if (generalProperties.OnTabVisible != null)
                        {
                            generalProperties.OnTabVisible(this);
                        }
                        if (OnPreviewTabVisualUpdate != null)
                        {
                            OnPreviewTabVisualUpdate(tab, settings, gdb);
                        }
                        if (OnTabVisualUpdate != null)
                        {
                            OnTabVisualUpdate(tab, settings, gdb);
                        }
                    }
                }
            };

            database.Reloaded += delegate {
                if (OnDatabaseReloaded != null)
                {
                    OnDatabaseReloaded(tab, settings, gdb);
                }
            };

            int line = 0;

            if (OnPreviewGenerateGrid != null)
            {
                OnPreviewGenerateGrid(ref line, database, control, generalProperties, gdb);
            }
            if (GenerateGrid != null)
            {
                GenerateGrid(ref line, database, control, generalProperties, gdb);
            }
            if (OnGenerateGrid != null)
            {
                OnGenerateGrid(ref line, database, control, generalProperties, gdb);
            }

            settings.DisplayablePropertyMaker = generalProperties;
            settings.ClientDatabase           = database;

            if (SetSettings != null)
            {
                SetSettings(tab, settings, gdb);
            }
            if (OnSetCustomCommands != null)
            {
                OnSetCustomCommands(tab, settings, gdb);
            }
            if (OnPreviewTabInitialize != null)
            {
                OnPreviewTabInitialize(tab, settings, gdb);
            }
            tab.Initialize(settings);
            return(tab);
        }
Ejemplo n.º 15
0
        public static void AddTagGeneratorTabChangedEvent <TKey>(TabControl control, GDbTab tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
        {
            control.SelectionChanged += delegate(object sender, SelectionChangedEventArgs e) {
                if (e == null || e.RemovedItems.Count <= 0 || e.RemovedItems[0] as TabItem == null || (e.AddedItems.Count > 0 && e.AddedItems[0] as TabItem == null))
                {
                    return;
                }

                if (e.AddedItems.Count <= 0)
                {
                    return;
                }

                TabItem item = e.AddedItems[0] as TabItem;

                if (gdb.DbSource.AlternativeName != null)
                {
                    if (WpfUtilities.IsTab(item, gdb.DbSource.Filename) || WpfUtilities.IsTab(item, gdb.DbSource.AlternativeName))
                    {
                        gdb.To <TKey>().TabGenerator.OnTabVisualUpdate((GDbTabWrapper <TKey, ReadableTuple <TKey> >)tab, settings, gdb);
                    }
                }
                else
                {
                    if (WpfUtilities.IsTab(item, gdb.DbSource))
                    {
                        gdb.To <TKey>().TabGenerator.OnTabVisualUpdate((GDbTabWrapper <TKey, ReadableTuple <TKey> >)tab, settings, gdb);
                    }
                }
            };
        }
Ejemplo n.º 16
0
        public static void AdvancedCustomCommands(GDbTabWrapper <int, ReadableTuple <int> > tab, GTabSettings <int, ReadableTuple <int> > settings, BaseDb gdb)
        {
            settings.AddedCommands.Add(new GItemCommand <int, ReadableTuple <int> > {
                AllowMultipleSelection = true,
                DisplayName            = "Copy entries to clipboard",
                ImagePath          = "export.png",
                InsertIndex        = 3,
                AddToCommandsStack = false,
                Shortcut           = ApplicationShortcut.Copy,
                GenericCommand     = delegate(List <ReadableTuple <int> > items) {
                    StringBuilder builder = new StringBuilder();
                    var db = gdb.To <int>();

                    List <DbAttribute> attributesToRemove = new List <DbAttribute>();
                    List <DbAttribute> attributes         = new List <DbAttribute>(gdb.AttributeList.Attributes);
                    attributes.Reverse();

                    foreach (DbAttribute attribute in attributes)
                    {
                        if (db.Attached[attribute.DisplayName] != null)
                        {
                            bool isLoaded = (bool)db.Attached[attribute.DisplayName];

                            if (!isLoaded)
                            {
                                attributesToRemove.Add(attribute);
                            }
                        }
                    }

                    for (int i = 0; i < items.Count; i++)
                    {
                        ReadableTuple <int> item  = items[i];
                        List <object> rawElements = item.GetRawElements().Skip(db.TabGenerator.StartIndexInCustomMethods).Take(db.TabGenerator.MaxElementsToCopyInCustomMethods).ToList();

                        foreach (var attribute in attributesToRemove)
                        {
                            rawElements.RemoveAt(attribute.Index);
                        }

                        builder.AppendLine(string.Join(",", rawElements.Select(p => (p ?? "").ToString()).ToArray()));
                    }

                    Clipboard.SetText(builder.ToString());
                }
            });
        }
Ejemplo n.º 17
0
 public GSearchEngine(string tabName, GTabSettings <TKey, TValue> settings)
 {
     _settings            = settings;
     _itemsSearchSettings = new GSearchSettings(ProjectConfiguration.ConfigAsker, tabName);
 }
Ejemplo n.º 18
0
        public void Initialize(GTabSettings <TKey, TValue> settings)
        {
            Settings = settings;
            _unclickableBorder.Init(_cbSubMenu);
            Database     = settings.ClientDatabase;
            DbComponent  = GenericDatabase.GetDb <TKey>(settings.DbData);
            Table        = Settings.Table;
            Header       = Settings.TabName;
            Style        = TryFindResource(settings.Style) as Style ?? Style;
            SearchEngine = settings.SearchEngine;
            SearchEngine.Init(_gridSearchContent, _searchTextBox, this);

            if (Settings.SearchEngine.SetupImageDataGetter != null)
            {
                Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
                    new ListViewDataTemplateHelper.GeneralColumnInfo {
                        Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]"
                    },
                    new ListViewDataTemplateHelper.ImageColumnInfo {
                        Header = "", DisplayExpression = "DataImage", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = 26, MaxHeight = 24
                    },
                    new ListViewDataTemplateHelper.RangeColumnInfo {
                        Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap
                    }
                }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" }, "generateStyle", "false");
            }
            else
            {
                Extensions.GenerateListViewTemplate(_listView, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
                    new ListViewDataTemplateHelper.GeneralColumnInfo {
                        Header = Settings.AttId.DisplayName, DisplayExpression = "[" + Settings.AttId.Index + "]", SearchGetAccessor = Settings.AttId.AttributeName, FixedWidth = Settings.AttIdWidth, TextAlignment = TextAlignment.Right, ToolTipBinding = "[" + Settings.AttId.Index + "]"
                    },
                    new ListViewDataTemplateHelper.RangeColumnInfo {
                        Header = Settings.AttDisplay.DisplayName, DisplayExpression = "[" + Settings.AttDisplay.Index + "]", SearchGetAccessor = Settings.AttDisplay.AttributeName, IsFill = true, ToolTipBinding = "[" + Settings.AttDisplay.Index + "]", MinWidth = 100, TextWrapping = TextWrapping.Wrap
                    }
                }, new DatabaseItemSorter(Settings.AttributeList), new string[] { "Deleted", "Red", "Modified", "Green", "Added", "Blue", "Normal", "Black" }, "generateStyle", "false");
            }

#if SDE_DEBUG
            CLHelper.WA = CLHelper.CP(-10);
#endif
            if (!Settings.CanBeDelayed || Settings.AttributeList.Attributes.Any(p => p.IsSkippable))
            {
                _deployTabControls();
            }
#if SDE_DEBUG
            CLHelper.WA = ", deploy time : " + CLHelper.CS(-10) + CLHelper.CD(-10) + "ms";
#endif
            _initTableEvents();

            if (Settings.ContextMenu != null)
            {
                if (Header is Control)
                {
                    ((Control)Header).ContextMenu = Settings.ContextMenu;
                }
            }

            if (Settings.Loaded != null)
            {
                Settings.Loaded((GDbTabWrapper <TKey, ReadableTuple <TKey> >)(object) this, (GTabSettings <TKey, ReadableTuple <TKey> >)(object) Settings, ((GenericDatabase)Database).GetDb <TKey>(Settings.DbData));
            }

            if (Settings.DisplayablePropertyMaker.OnTabVisible != null)
            {
                Settings.DisplayablePropertyMaker.OnTabVisible(this);
            }

            Loaded += delegate {
                TabControl parent = WpfUtilities.FindParentControl <TabControl>(this);

                if (parent != null)
                {
                    parent.SelectionChanged += new SelectionChangedEventHandler(_parent_SelectionChanged);
                }
            };

            _listView.PreviewMouseDown += delegate {
                _listView.Focus();
            };

            ApplicationShortcut.Link(ApplicationShortcut.Paste, () => ImportFromFile("clipboard"), _listView);
            ApplicationShortcut.Link(ApplicationShortcut.Cut, () => _miCut_Click(null, null), _listView);
        }
Ejemplo n.º 19
0
        public void Deploy(GDbTabWrapper <TKey, TValue> tab, GTabSettings <TKey, TValue> settings, bool noUpdate = false)
        {
            foreach (Tuple <FrameworkElement, FrameworkElement> element in _deployControls)
            {
                Grid             grid     = element.Item2 as Grid;
                FrameworkElement fElement = element.Item1;

                if (grid == null)
                {
                    grid = tab.PropertiesGrid;
                }

                if (fElement is TextBox || fElement is TextEditor)
                {
                    RemoveUndoAndRedoEvents(fElement, tab);
                }

                int gridRow = (int)fElement.GetValue(Grid.RowProperty);

                while (grid.RowDefinitions.Count <= gridRow)
                {
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = new GridLength(-1, GridUnitType.Auto)
                    });
                }

                if (fElement.Parent == null)
                {
                    grid.Children.Add(fElement);
                }
            }

            foreach (Action <Grid> command in _deployCommands)
            {
                command(tab.PropertiesGrid);
            }

            if (noUpdate)
            {
                return;
            }

            foreach (Tuple <DbAttribute, FrameworkElement> v in _update)
            {
                Tuple <DbAttribute, FrameworkElement> x = v;

                if (x.Item1.DataType == typeof(int))
                {
                    TextBox element = (TextBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(
                                                               delegate {
                        Debug.Ignore(() => element.Text = item.GetValue <int>(x.Item1).ToString(CultureInfo.InvariantCulture));
                        element.UndoLimit = 0;
                        element.UndoLimit = int.MaxValue;
                    })));

                    element.TextChanged += delegate {
                        if (tab.ItemsEventsDisabled)
                        {
                            return;
                        }

                        try {
                            if (tab.List.SelectedItem != null)
                            {
                                tab.Table.Commands.Set((TValue)tab.List.SelectedItem, x.Item1, element.Text);
                            }
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };
                }
                else if (x.Item1.DataType == typeof(bool))
                {
                    CheckBox element = (CheckBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(p => Debug.Ignore(() => p.IsChecked = item.GetValue <bool>(x.Item1)))));

                    element.Checked += delegate {
                        if (tab.ItemsEventsDisabled)
                        {
                            return;
                        }

                        try {
                            if (tab.List.SelectedItem != null)
                            {
                                tab.Table.Commands.Set((TValue)tab.List.SelectedItem, x.Item1, true);
                            }
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };

                    element.Unchecked += delegate {
                        if (tab.ItemsEventsDisabled)
                        {
                            return;
                        }

                        try {
                            if (tab.List.SelectedItem != null)
                            {
                                tab.Table.Commands.Set((TValue)tab.List.SelectedItem, x.Item1, false);
                            }
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };
                }
                else if (x.Item1.DataType == typeof(string))
                {
                    TextBox element = (TextBox)x.Item2;
                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(
                                                               delegate {
                        try {
                            string val = item.GetValue <string>(x.Item1);

                            if (val == element.Text)
                            {
                                return;
                            }

                            element.Text      = item.GetValue <string>(x.Item1);
                            element.UndoLimit = 0;
                            element.UndoLimit = int.MaxValue;
                        }
                        catch {
                        }
                    })));

                    element.TextChanged += delegate {
                        ValidateUndo(tab, element.Text, x.Item1);
                    };
                }
                else if (x.Item1.DataType.BaseType == typeof(Enum))
                {
                    ComboBox   element = (ComboBox)x.Item2;
                    List <int> values  = Enum.GetValues(x.Item1.DataType).Cast <int>().ToList();

                    _updateActions.Add(new Action <TValue>(item => element.Dispatch(delegate {
                        try {
                            element.SelectedIndex = values.IndexOf(item.GetValue <int>(x.Item1));
                        }
                        catch {
                            element.SelectedIndex = -1;
                        }
                    })));

                    element.SelectionChanged += delegate {
                        if (tab.ItemsEventsDisabled)
                        {
                            return;
                        }

                        try {
                            if (tab.List.SelectedItem != null)
                            {
                                tab.Table.Commands.Set((TValue)tab.List.SelectedItem, x.Item1, values[element.SelectedIndex]);
                            }
                        }
                        catch (Exception err) {
                            ErrorHandler.HandleException(err);
                        }
                    };
                }
            }

            foreach (ICustomControl <TKey, TValue> property in _customProperties)
            {
                property.Init(tab, this);
            }

            foreach (FormatConverter <TKey, TValue> property in _formattedProperties)
            {
                property.Init(tab, this);
            }
        }