Example #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);
                }
            }
        }
Example #2
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 #3
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);
        }
        public static void ValidateUndo(GDbTabWrapper <TKey, TValue> tab, string text, DbAttribute attribute)
        {
            try {
                if (tab.List.SelectedItem != null && !tab.ItemsEventsDisabled)
                {
                    TValue tuple = (TValue)tab.List.SelectedItem;
                    ITableCommand <TKey, TValue> command = tab.Table.Commands.Last();

                    if (command is ChangeTupleProperty <TKey, TValue> )
                    {
                        ChangeTupleProperty <TKey, TValue> changeCommand = (ChangeTupleProperty <TKey, TValue>)command;
                        IGenericDbCommand last = tab.GenericDatabase.Commands.Last();

                        if (last != null)
                        {
                            if (last is GenericDbCommand <TKey> )
                            {
                                GenericDbCommand <TKey> nLast = (GenericDbCommand <TKey>)last;

                                if (ReferenceEquals(nLast.Table, tab.Table))
                                {
                                    // The last command of the table is being edited

                                    if (changeCommand.Tuple != tuple || changeCommand.Attribute.Index != attribute.Index)
                                    {
                                        //tab.Table.Commands.Set(tuple, attribute, text);
                                    }
                                    else
                                    {
                                        changeCommand.NewValue = text;
                                        changeCommand.Execute(tab.Table);

                                        if (changeCommand.NewValue.ToString() == changeCommand.OldValue.ToString())
                                        {
                                            nLast.Undo();
                                            tab.GenericDatabase.Commands.RemoveCommands(1);
                                            tab.Table.Commands.RemoveCommands(1);
                                        }

                                        return;
                                    }
                                }
                            }
                        }

                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                    else
                    {
                        tab.Table.Commands.Set(tuple, attribute, text);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Example #5
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;
            }
        }
Example #6
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());
                }
            });
        }
Example #7
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;
            }
        }
Example #8
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());
                }
            });
        }
Example #9
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);
        }
Example #10
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++;
                    }
                };
            }
        }
Example #11
0
 public void Init(Grid searchDrop, TextBox searchBox, GDbTabWrapper <TKey, TValue> tab)
 {
     Init(searchDrop, searchBox, tab.List, tab.Table);
 }
Example #12
0
 private void _onPreviewTabInitialize(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
 {
 }
Example #13
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);
        }
Example #14
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;
                }
            }
        }
        public static void RemoveUndoAndRedoEvents(FrameworkElement box, GDbTabWrapper <TKey, TValue> tab)
        {
            box.PreviewKeyDown += delegate(object sender, KeyEventArgs args) {
                if (ApplicationShortcut.Is(ApplicationShortcut.UndoGlobal))
                {
                    tab.Undo();
                    args.Handled = true;
                }

                if (ApplicationShortcut.Is(ApplicationShortcut.RedoGlobal))
                {
                    tab.Redo();
                    args.Handled = true;
                }

                if (ApplicationShortcut.Is(ApplicationShortcut.Undo))
                {
                    TextBox    tBox = box as TextBox;
                    TextEditor eBox = box as TextEditor;

                    if (tBox != null)
                    {
                        if (!tBox.CanRedo && !tBox.CanUndo)
                        {
                            tab.Undo();
                        }
                        else if (tBox.CanUndo)
                        {
                            tBox.Undo();
                        }
                    }
                    else if (eBox != null)
                    {
                        if (!eBox.CanRedo && !eBox.CanUndo)
                        {
                            tab.Undo();
                        }
                        else if (eBox.CanUndo)
                        {
                            eBox.Undo();
                        }
                    }
                    else
                    {
                        tab.Undo();
                    }

                    args.Handled = true;
                }

                if (ApplicationShortcut.Is(ApplicationShortcut.Redo))
                {
                    TextBox    tBox = box as TextBox;
                    TextEditor eBox = box as TextEditor;

                    if (tBox != null)
                    {
                        if (!tBox.CanRedo && !tBox.CanRedo)
                        {
                            tab.Redo();
                        }
                        else if (tBox.CanRedo)
                        {
                            tBox.Redo();
                        }
                    }
                    else if (eBox != null)
                    {
                        if (!eBox.CanRedo && !eBox.CanRedo)
                        {
                            tab.Redo();
                        }
                        else if (eBox.CanRedo)
                        {
                            eBox.Redo();
                        }
                    }
                    else
                    {
                        tab.Redo();
                    }

                    args.Handled = true;
                }
            };
        }
Example #16
0
 public void InitStyle(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb)
 {
     GTabsMaker.SInit(tab, settings, gdb);
 }
Example #17
0
 public static GItemCommand <TKey, ReadableTuple <TKey> > GenerateSelectFrom <TKey>(ServerDbs serverDb, GDbTabWrapper <TKey, ReadableTuple <TKey> > tab)
 {
     return(new GItemCommand <TKey, ReadableTuple <TKey> > {
         AllowMultipleSelection = false,
         DisplayName = String.Format("Select in [{0}]", serverDb.DisplayName),
         ImagePath = "arrowdown.png",
         InsertIndex = 4,
         AddToCommandsStack = false,
         GenericCommand = items => TabNavigation.SelectList(serverDb, items.Select(p => p.GetKey <TKey>()))
     });
 }
        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);
            }
        }