public static void CheckAttributeRestrictions <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { foreach (var attributeS in settings.AttributeList.Attributes) { DbAttribute attribute = attributeS; if (attribute.Requirements.Renewal == RenewalType.Both && attribute.Requirements.Server == ServerType.Both) { continue; } tab.PropertiesGrid.Dispatch(delegate { var gridAttributes = GetAll(tab.PropertiesGrid, attribute); RenewalType rType = DbPathLocator.GetIsRenewal() ? RenewalType.Renewal : RenewalType.PreRenewal; ServerType sType = DbPathLocator.GetServerType(); gridAttributes.ForEach(p => p.IsEnabled = false); if ((attribute.Requirements.Renewal & rType) == rType && (attribute.Requirements.Server & sType) == sType) { gridAttributes.ForEach(p => p.IsEnabled = true); } else { gridAttributes.ForEach(p => p.IsEnabled = false); } }); } }
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(1).Where(p => p.IsSearchable != null && p != settings.AttId && p != settings.AttDisplay)).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); } } }
public void ApplyDicoCommand(GDbTabWrapper <TKey, TValue> tab, ListView lv, TValue tupleParent, DbAttribute attributeTable, TValue tuple, DbAttribute attribute, object value, bool reversable = true) { try { if (tab.ItemsEventsDisabled) { return; } if (SdeAppConfiguration.EnableMultipleSetters && lv.SelectedItems.Count > 1) { tab.Table.Commands.SetDico(tupleParent, lv.SelectedItems.Cast <TValue>().ToList(), attribute, value); } else { if (tupleParent == null) { return; } var before = tab.Table.Commands.CommandIndex; var beforeGlobal = tab.ProjectDatabase.Commands.CommandIndex; tab.Table.Commands.SetDico(tupleParent, attributeTable, tuple, attribute, value, reversable); var after = tab.Table.Commands.CommandIndex; var afterGlobal = tab.ProjectDatabase.Commands.CommandIndex; if (before > after && beforeGlobal == afterGlobal) { tab.ProjectDatabase.Commands.RemoveCommands(1); } } } catch (Exception err) { ErrorHandler.HandleException(err); } }
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; } }
public static void TgOnTabVisualUpdate(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { Exception exception = null; bool success = tab.Dispatch(delegate { try { UIElement content = (UIElement)tab.Content; // (UIElement)(tab.Content ?? ((Window)tab.AttachedProperty["AttachedWindow"]).Content); if (gdb.To <TKey>().TabGenerator == null || gdb.To <TKey>().TabGenerator.IsTabEnabledMethod == null) { content.IsEnabled = IsTabEnabled(settings, gdb); } else { content.IsEnabled = gdb.To <TKey>().TabGenerator.IsTabEnabledMethod(settings, gdb); } return(true); } catch (Exception err) { exception = err; return(false); } }); if (!success) { throw exception; } List <DbAttribute> attributes = settings.AttributeList.Attributes; if (gdb.LayoutIndexes != null) { foreach (var attribute in attributes) { if (attribute.IsSkippable) { bool isSet = _isAttributeEnabled(attribute, gdb); tab.Dispatch(delegate { var elements = DisplayablePropertyHelper.GetAll(tab.PropertiesGrid, attribute.DisplayName); foreach (var element in elements) { element.Visibility = isSet ? Visibility.Visible : Visibility.Collapsed; element.IsEnabled = isSet; } }); } } } }
private void _orderTabs(GDbTabWrapper <TKey, TValue> tab) { var grid = tab.PropertiesGrid; int index = 0; List <Type> allowedTypes = new List <Type> { typeof(TextEditor), typeof(TextBox) }; //, typeof (ComboBox), typeof (CheckBox)}; foreach (UIElement element in grid.Children.OfType <UIElement>().OrderBy(p => (int)p.GetValue(Grid.RowProperty) * 1000 + (int)p.GetValue(Grid.ColumnProperty))) { if (allowedTypes.Any(p => element.GetType() == p)) { _setTabIndexAndEvent(element, ref index); } if (!(element is Grid)) { continue; } foreach (UIElement sub in ((Grid)element).Children.OfType <UIElement>().OrderBy(p => (int)p.GetValue(Grid.RowProperty) * 1000 + (int)p.GetValue(Grid.ColumnProperty))) { if (allowedTypes.Any(p => sub.GetType() == p)) { _setTabIndexAndEvent(sub, ref index); } if (!(sub is Grid)) { continue; } foreach (UIElement sub2 in ((Grid)sub).Children.OfType <UIElement>().OrderBy(p => (int)p.GetValue(Grid.RowProperty) * 1000 + (int)p.GetValue(Grid.ColumnProperty))) { if (allowedTypes.Any(p => sub2.GetType() == p)) { _setTabIndexAndEvent(sub2, ref index); } } } } }
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(); List <int> toRemove = (from attribute in gdb.AttributeList.Attributes.OrderByDescending(p => p.Index) where attribute.IsSkippable && !_isAttributeEnabled(attribute, gdb) select attribute.Index).ToList(); for (int i = 0; i < items.Count; i++) { ReadableTuple <TKey> item = items[i]; List <string> objs = item.GetRawElements().Skip(StartIndexInCustomMethods).Take(max).Select(p => (p ?? "").ToString()).ToList(); foreach (var index in toRemove) { objs.RemoveAt(index); } builder.AppendLine(string.Join(",", objs.ToArray())); } Clipboard.SetDataObject(builder.ToString()); } }); }
public void InitStyle(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { GTabsMaker.SInit(tab, settings, gdb); }
private void _onPreviewTabInitialize(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { }
private GDbTab _gDbTabMaker(SdeDatabase 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; Settings.Control = control; Settings.Gdb = gdb; Settings.Tab = tab; Settings.Table = table; Settings.Database = database; 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; Settings.GeneralProperties = generalProperties; SdeEditor.Instance.SelectionChanged += new SdeEditor.SdeSelectionChangedEventHandler((sender, oldTab, newTab) => { try { TabItem item = newTab; 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); } if (OnTabRefreshed != null) { OnTabRefreshed(Settings); } } } 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); } if (OnTabRefreshed != null) { OnTabRefreshed(Settings); } } } } catch (Exception err) { ErrorHandler.HandleException(err); } }); database.PreviewReloaded += delegate { if (OnPreviewDatabaseReloaded != null) { OnPreviewDatabaseReloaded(tab, settings, gdb); } }; database.Reloaded += delegate { //if (OnPreviewTabVisualUpdate != null) OnPreviewTabVisualUpdate(tab, settings, gdb); //if (OnTabVisualUpdate != null) OnTabVisualUpdate(tab, settings, gdb); DisplayablePropertyHelper.CheckAttributeRestrictions(tab, settings, gdb); if (OnDatabaseReloaded != null) { OnDatabaseReloaded(tab, settings, gdb); } if (OnTabRefreshed != null) { OnTabRefreshed(Settings); } }; int line = 0; if (OnPreviewGenerateGrid != null) { OnPreviewGenerateGrid(ref line, Settings); } if (GenerateGrid != null) { GenerateGrid(ref line, Settings); } if (OnGenerateGrid != null) { OnGenerateGrid(ref line, Settings); } 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); if (OnAfterTabInitialize != null) { OnAfterTabInitialize(tab, settings, gdb); } return(tab); }
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 { ApplyCommand(tab, x.Item1, element.Text); }; } 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 += (sender, args) => ApplyCommand(tab, x.Item1, true, false); element.Unchecked += (sender, args) => ApplyCommand(tab, x.Item1, false, false); } 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 { ApplyCommand(tab, x.Item1, element.Text); }; } 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 { ApplyCommand(tab, x.Item1, values[element.SelectedIndex], false); } 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); } _orderTabs(tab); OnDeployed(); }
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; } }; }
public void Init(DbSearchPanel panel, GDbTabWrapper <TKey, TValue> tab) { Init(panel, tab.List, tab.Table); }