Exemple #1
0
        public override void AddNewItemRaw()
        {
            try {
                string defaultValue = Clipboard.ContainsText() ? Clipboard.GetText() : "";

                InputDialog dialog = new InputDialog("Paste the database lines here.", "Add new raw items", defaultValue, false, false);
                dialog.Owner = WpfUtilities.TopWindow;
                dialog.TextBoxInput.Loaded += delegate {
                    dialog.TextBoxInput.SelectAll();
                    dialog.TextBoxInput.Focus();
                };
                dialog.TextBoxInput.AcceptsReturn = true;
                dialog.TextBoxInput.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                dialog.TextBoxInput.TextWrapping = TextWrapping.NoWrap;
                dialog.TextBoxInput.Height       = 200;
                dialog.TextBoxInput.MinHeight    = 200;
                dialog.TextBoxInput.MaxHeight    = 200;
                dialog.TextBoxInput.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;

                dialog.ShowDialog();

                if (dialog.Result == MessageBoxResult.OK)
                {
                    try {
                        Table.Commands.BeginEdit(new GroupCommand <TKey, TValue>());

                        string text     = dialog.Input;
                        string tempPath = TemporaryFilesManager.GetTemporaryFilePath("db_tmp_{0:0000}.txt");
                        File.WriteAllText(tempPath, text);

                        GenericDatabase gdb = (GenericDatabase)Database;
                        gdb.GetDb <TKey>(Settings.DbData).LoadDb(tempPath);
                    }
                    catch {
                        Table.Commands.CancelEdit();
                    }
                    finally {
                        Table.Commands.EndEdit();
                    }

                    _listView_SelectionChanged(this, null);
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Exemple #2
0
        public override void ImportFromFile(string fileDefault = null)
        {
            try {
                string file = fileDefault ?? PathRequest.OpenFileCde("filter", "All db files|*.conf;*.txt");

                if (file == "clipboard")
                {
                    if (!Clipboard.ContainsText())
                    {
                        return;
                    }

                    file = TemporaryFilesManager.GetTemporaryFilePath("clipboard_{0:0000}.txt");
                    File.WriteAllText(file, Clipboard.GetText());
                }

                if (file != null)
                {
                    try {
                        Table.Commands.BeginEdit(new GroupCommand <TKey, TValue>());

                        GenericDatabase gdb = (GenericDatabase)Database;
                        gdb.GetDb <TKey>(Settings.DbData).LoadDb(file);
                    }
                    catch {
                        Table.Commands.CancelEdit();
                    }
                    finally {
                        Table.Commands.EndEdit();
                    }

                    _listView_SelectionChanged(this, null);
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Exemple #3
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);
        }