From a0dd4075a385b91ff9bc5265734bf9bbf4321a39 Mon Sep 17 00:00:00 2001 From: xantari Date: Sat, 27 Mar 2021 16:52:58 -0500 Subject: [PATCH] read/write to github updates --- PinCab.Configurator/AboutBoxForm.cs | 4 +- .../AddDatabaseForm.Designer.cs | 199 ++++++++++++++ PinCab.Configurator/AddDatabaseForm.cs | 101 +++++++ PinCab.Configurator/AddDatabaseForm.resx | 123 +++++++++ PinCab.Configurator/AddEditGameForm.cs | 2 + PinCab.Configurator/AddNewGameForm.cs | 2 + .../DatabaseBrowserForm.Designer.cs | 66 +++-- PinCab.Configurator/DatabaseBrowserForm.cs | 165 +++++++++-- PinCab.Configurator/DatabaseBrowserForm.resx | 2 +- .../EditDatabaseEntryForm.Designer.cs | 256 ++++++++++-------- PinCab.Configurator/EditDatabaseEntryForm.cs | 23 +- .../EditDatabaseEntryForm.resx | 9 - PinCab.Configurator/GameManagerForm.cs | 2 + PinCab.Configurator/IpdbBrowserForm.cs | 2 + PinCab.Configurator/MainForm.cs | 2 + PinCab.Configurator/MediaAuditForm.cs | 2 + PinCab.Configurator/PinMameRomBrowserForm.cs | 2 + .../PinMameRomSettingEditor.cs | 2 + .../Pincab.Configurator.csproj | 21 ++ PinCab.Configurator/RecordForm.cs | 2 + PinCab.Configurator/RenameGameForm.cs | 2 + .../SaveDatabaseForm.Designer.cs | 150 ++++++++++ PinCab.Configurator/SaveDatabaseForm.cs | 177 ++++++++++++ PinCab.Configurator/SaveDatabaseForm.resx | 120 ++++++++ PinCab.Configurator/ScreenResEditorForm.cs | 2 + PinCab.Configurator/SettingsForm.cs | 2 + PinCab.Configurator/packages.config | 1 + PinCab.Utils/Extensions/DatabaseExtensions.cs | 4 +- PinCab.Utils/Models/ContentDatabase.cs | 18 ++ PinCab.Utils/PinCab.Utils.csproj | 13 + PinCab.Utils/Utils/DatabaseManager.cs | 90 +++--- .../WinForms/TabOrder/TabOrderManager.cs | 193 +++++++++++++ .../TabOrder/TabSchemeProvider.Designer.cs | 37 +++ .../WinForms/TabOrder/TabSchemeProvider.bmp | Bin 0 -> 246 bytes .../WinForms/TabOrder/TabSchemeProvider.cs | 208 ++++++++++++++ PinCab.Utils/packages.config | 1 + 36 files changed, 1784 insertions(+), 221 deletions(-) create mode 100644 PinCab.Configurator/AddDatabaseForm.Designer.cs create mode 100644 PinCab.Configurator/AddDatabaseForm.cs create mode 100644 PinCab.Configurator/AddDatabaseForm.resx create mode 100644 PinCab.Configurator/SaveDatabaseForm.Designer.cs create mode 100644 PinCab.Configurator/SaveDatabaseForm.cs create mode 100644 PinCab.Configurator/SaveDatabaseForm.resx create mode 100644 PinCab.Utils/WinForms/TabOrder/TabOrderManager.cs create mode 100644 PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.Designer.cs create mode 100644 PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.bmp create mode 100644 PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.cs diff --git a/PinCab.Configurator/AboutBoxForm.cs b/PinCab.Configurator/AboutBoxForm.cs index 7967bd6..1a51126 100644 --- a/PinCab.Configurator/AboutBoxForm.cs +++ b/PinCab.Configurator/AboutBoxForm.cs @@ -1,4 +1,5 @@ -using System; +using PinCab.Utils.WinForms.TabOrder; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; @@ -20,6 +21,7 @@ public AboutBoxForm() this.labelCopyright.Text = AssemblyCopyright; this.labelCompanyName.Text = AssemblyCompany; this.textBoxDescription.Text = AssemblyDescription; + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } #region Assembly Attribute Accessors diff --git a/PinCab.Configurator/AddDatabaseForm.Designer.cs b/PinCab.Configurator/AddDatabaseForm.Designer.cs new file mode 100644 index 0000000..8132388 --- /dev/null +++ b/PinCab.Configurator/AddDatabaseForm.Designer.cs @@ -0,0 +1,199 @@ + +namespace PinCab.Configurator +{ + partial class AddDatabaseForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnCancel = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.cmbContentDatabaseType = new System.Windows.Forms.ComboBox(); + this.label18 = new System.Windows.Forms.Label(); + this.txtContentDatabaseName = new System.Windows.Forms.TextBox(); + this.label17 = new System.Windows.Forms.Label(); + this.label15 = new System.Windows.Forms.Label(); + this.txtContentDatabaseAccessToken = new System.Windows.Forms.TextBox(); + this.txtContentDatabaseUrl = new System.Windows.Forms.TextBox(); + this.label14 = new System.Windows.Forms.Label(); + this.btnFilePathDatabaseBrowser = new System.Windows.Forms.Button(); + this.btnContentDatabaseUrl = new System.Windows.Forms.Button(); + this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); + this.SuspendLayout(); + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(203, 121); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 9; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(97, 121); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 8; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // cmbContentDatabaseType + // + this.cmbContentDatabaseType.FormattingEnabled = true; + this.cmbContentDatabaseType.Location = new System.Drawing.Point(97, 6); + this.cmbContentDatabaseType.Name = "cmbContentDatabaseType"; + this.cmbContentDatabaseType.Size = new System.Drawing.Size(181, 21); + this.cmbContentDatabaseType.TabIndex = 0; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(53, 9); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(34, 13); + this.label18.TabIndex = 74; + this.label18.Text = "Type:"; + // + // txtContentDatabaseName + // + this.txtContentDatabaseName.Location = new System.Drawing.Point(97, 32); + this.txtContentDatabaseName.Name = "txtContentDatabaseName"; + this.txtContentDatabaseName.Size = new System.Drawing.Size(401, 20); + this.txtContentDatabaseName.TabIndex = 1; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(53, 35); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(38, 13); + this.label17.TabIndex = 72; + this.label17.Text = "Name:"; + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(12, 88); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(79, 13); + this.label15.TabIndex = 71; + this.label15.Text = "Access Token:"; + // + // txtContentDatabaseAccessToken + // + this.txtContentDatabaseAccessToken.Location = new System.Drawing.Point(97, 85); + this.txtContentDatabaseAccessToken.Name = "txtContentDatabaseAccessToken"; + this.txtContentDatabaseAccessToken.Size = new System.Drawing.Size(401, 20); + this.txtContentDatabaseAccessToken.TabIndex = 5; + // + // txtContentDatabaseUrl + // + this.txtContentDatabaseUrl.Location = new System.Drawing.Point(97, 58); + this.txtContentDatabaseUrl.Name = "txtContentDatabaseUrl"; + this.txtContentDatabaseUrl.Size = new System.Drawing.Size(401, 20); + this.txtContentDatabaseUrl.TabIndex = 2; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(35, 61); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(56, 13); + this.label14.TabIndex = 67; + this.label14.Text = "Url / Path:"; + // + // btnFilePathDatabaseBrowser + // + this.btnFilePathDatabaseBrowser.BackgroundImage = global::PinCab.Configurator.Properties.Resources.FolderOpened_75x; + this.btnFilePathDatabaseBrowser.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnFilePathDatabaseBrowser.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnFilePathDatabaseBrowser.ForeColor = System.Drawing.SystemColors.Control; + this.btnFilePathDatabaseBrowser.Location = new System.Drawing.Point(536, 55); + this.btnFilePathDatabaseBrowser.Name = "btnFilePathDatabaseBrowser"; + this.btnFilePathDatabaseBrowser.Size = new System.Drawing.Size(38, 23); + this.btnFilePathDatabaseBrowser.TabIndex = 7; + this.btnFilePathDatabaseBrowser.UseVisualStyleBackColor = true; + this.btnFilePathDatabaseBrowser.Click += new System.EventHandler(this.btnFilePathDatabaseBrowser_Click); + // + // btnContentDatabaseUrl + // + this.btnContentDatabaseUrl.BackgroundImage = global::PinCab.Configurator.Properties.Resources.BrowserLink_75x; + this.btnContentDatabaseUrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnContentDatabaseUrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnContentDatabaseUrl.ForeColor = System.Drawing.SystemColors.Control; + this.btnContentDatabaseUrl.Location = new System.Drawing.Point(504, 55); + this.btnContentDatabaseUrl.Name = "btnContentDatabaseUrl"; + this.btnContentDatabaseUrl.Size = new System.Drawing.Size(38, 23); + this.btnContentDatabaseUrl.TabIndex = 6; + this.btnContentDatabaseUrl.UseVisualStyleBackColor = true; + this.btnContentDatabaseUrl.Click += new System.EventHandler(this.btnContentDatabaseUrl_Click); + // + // AddDatabaseForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(588, 152); + this.Controls.Add(this.btnFilePathDatabaseBrowser); + this.Controls.Add(this.cmbContentDatabaseType); + this.Controls.Add(this.label18); + this.Controls.Add(this.txtContentDatabaseName); + this.Controls.Add(this.label17); + this.Controls.Add(this.label15); + this.Controls.Add(this.txtContentDatabaseAccessToken); + this.Controls.Add(this.btnContentDatabaseUrl); + this.Controls.Add(this.txtContentDatabaseUrl); + this.Controls.Add(this.label14); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnSave); + this.Name = "AddDatabaseForm"; + this.Text = "Add Database"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnFilePathDatabaseBrowser; + private System.Windows.Forms.ComboBox cmbContentDatabaseType; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.TextBox txtContentDatabaseName; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Label label15; + private System.Windows.Forms.TextBox txtContentDatabaseAccessToken; + private System.Windows.Forms.Button btnContentDatabaseUrl; + private System.Windows.Forms.TextBox txtContentDatabaseUrl; + private System.Windows.Forms.Label label14; + private System.Windows.Forms.SaveFileDialog saveFileDialog1; + } +} \ No newline at end of file diff --git a/PinCab.Configurator/AddDatabaseForm.cs b/PinCab.Configurator/AddDatabaseForm.cs new file mode 100644 index 0000000..31e3a4e --- /dev/null +++ b/PinCab.Configurator/AddDatabaseForm.cs @@ -0,0 +1,101 @@ +using PinCab.Utils.Extensions; +using PinCab.Utils.Models; +using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PinCab.Configurator +{ + public partial class AddDatabaseForm : Form + { + private readonly ProgramSettingsManager _settingManager = new ProgramSettingsManager(); + private ProgramSettings _settings { get; set; } + + public AddDatabaseForm() + { + InitializeComponent(); + + cmbContentDatabaseType.DataSource = EnumExtensions.GetEnumDescriptionList(); + _settings = _settingManager.LoadSettings(); + DialogResult = DialogResult.None; + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); + } + + private void btnCancel_Click(object sender, EventArgs e) + { + Close(); + } + + public ContentDatabase GetContentDatabaseFromForm() + { + var cd = new ContentDatabase() + { + AccessToken = txtContentDatabaseAccessToken.Text, + Name = txtContentDatabaseName.Text, + Url = txtContentDatabaseUrl.Text, + Type = cmbContentDatabaseType.SelectedItem.ToString().GetValueFromDescription() + }; + return cd; + } + + private bool ValidateForm() + { + var dbAlreadyExists = _settings.Databases.Any(c => c.Name.ToLower() == txtContentDatabaseName.Text.ToLower()); + if (dbAlreadyExists) + { + MessageBox.Show("Database already exists with this name: " + txtContentDatabaseName.Text); + return false; + } + if (string.IsNullOrEmpty(txtContentDatabaseName.Text)) + { + MessageBox.Show("Database name is required."); + return false; + } + if (string.IsNullOrEmpty(txtContentDatabaseUrl.Text)) + { + MessageBox.Show("Database path / url is required."); + return false; + } + return true; + } + + private void btnSave_Click(object sender, EventArgs e) + { + bool valid = ValidateForm(); + + if (valid) + { + var newCb = GetContentDatabaseFromForm(); + _settings.Databases.Add(newCb); + _settingManager.SaveSettings(_settings); + DialogResult = DialogResult.OK; + Close(); + } + } + + private void btnContentDatabaseUrl_Click(object sender, EventArgs e) + { + System.Diagnostics.Process.Start(txtContentDatabaseUrl.Text); + } + + private void btnFilePathDatabaseBrowser_Click(object sender, EventArgs e) + { + using (OpenFileDialog fileDialog = new OpenFileDialog()) + { + fileDialog.Filter = "JSON Files|*.json|All files (*.*)|*.*"; + fileDialog.RestoreDirectory = true; + var result = fileDialog.ShowDialog(this); + if (result == DialogResult.OK) + txtContentDatabaseUrl.Text = fileDialog.FileName; + } + } + } +} diff --git a/PinCab.Configurator/AddDatabaseForm.resx b/PinCab.Configurator/AddDatabaseForm.resx new file mode 100644 index 0000000..053da59 --- /dev/null +++ b/PinCab.Configurator/AddDatabaseForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/PinCab.Configurator/AddEditGameForm.cs b/PinCab.Configurator/AddEditGameForm.cs index 29a4404..cc50c58 100644 --- a/PinCab.Configurator/AddEditGameForm.cs +++ b/PinCab.Configurator/AddEditGameForm.cs @@ -3,6 +3,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -38,6 +39,7 @@ public AddEditGameForm(FrontEndGameViewModel setting, string databaseFile, Front if (_ipdbForm == null) _ipdbForm = new IpdbBrowserForm(txtTableName.Text, true); LoadForm(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadForm() diff --git a/PinCab.Configurator/AddNewGameForm.cs b/PinCab.Configurator/AddNewGameForm.cs index 4142cd9..1f79183 100644 --- a/PinCab.Configurator/AddNewGameForm.cs +++ b/PinCab.Configurator/AddNewGameForm.cs @@ -2,6 +2,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,6 +28,7 @@ public AddNewGameForm(FrontEnd frontEnd, string databaseFile, FrontEndManager ma _manager = manager; _frontEnd = frontEnd; LoadNewEntries(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadNewEntries() diff --git a/PinCab.Configurator/DatabaseBrowserForm.Designer.cs b/PinCab.Configurator/DatabaseBrowserForm.Designer.cs index 34a44cf..5634a11 100644 --- a/PinCab.Configurator/DatabaseBrowserForm.Designer.cs +++ b/PinCab.Configurator/DatabaseBrowserForm.Designer.cs @@ -29,13 +29,15 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + this.menuStripMain = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.utilieisToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.refreshDatabaseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.addDatabaseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveDatabasesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panelFilterCriteria = new System.Windows.Forms.Panel(); this.flowLayoutPanelTags = new System.Windows.Forms.FlowLayoutPanel(); @@ -90,7 +92,7 @@ private void InitializeComponent() this.toolStripStatusLabelSpacer = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripProgressBar = new System.Windows.Forms.ToolStripProgressBar(); this.statusStripBottom = new System.Windows.Forms.StatusStrip(); - this.menuStrip1.SuspendLayout(); + this.menuStripMain.SuspendLayout(); this.panelFilterCriteria.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewEntryList)).BeginInit(); this.contextMenuStripGridActions.SuspendLayout(); @@ -109,17 +111,18 @@ private void InitializeComponent() this.statusStripBottom.SuspendLayout(); this.SuspendLayout(); // - // menuStrip1 + // menuStripMain // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.utilieisToolStripMenuItem, + this.saveDatabasesToolStripMenuItem, this.helpToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1049, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; + this.menuStripMain.Location = new System.Drawing.Point(0, 0); + this.menuStripMain.Name = "menuStripMain"; + this.menuStripMain.Size = new System.Drawing.Size(1049, 24); + this.menuStripMain.TabIndex = 0; + this.menuStripMain.Text = "menuStripMain"; // // fileToolStripMenuItem // @@ -139,7 +142,8 @@ private void InitializeComponent() // utilieisToolStripMenuItem // this.utilieisToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.refreshDatabaseToolStripMenuItem}); + this.refreshDatabaseToolStripMenuItem, + this.addDatabaseToolStripMenuItem}); this.utilieisToolStripMenuItem.Name = "utilieisToolStripMenuItem"; this.utilieisToolStripMenuItem.Size = new System.Drawing.Size(58, 20); this.utilieisToolStripMenuItem.Text = "Utilities"; @@ -147,10 +151,24 @@ private void InitializeComponent() // refreshDatabaseToolStripMenuItem // this.refreshDatabaseToolStripMenuItem.Name = "refreshDatabaseToolStripMenuItem"; - this.refreshDatabaseToolStripMenuItem.Size = new System.Drawing.Size(164, 22); - this.refreshDatabaseToolStripMenuItem.Text = "Refresh Database"; + this.refreshDatabaseToolStripMenuItem.Size = new System.Drawing.Size(268, 22); + this.refreshDatabaseToolStripMenuItem.Text = "Refresh / Re-download All Databases"; this.refreshDatabaseToolStripMenuItem.Click += new System.EventHandler(this.refreshDatabaseToolStripMenuItem_Click); // + // addDatabaseToolStripMenuItem + // + this.addDatabaseToolStripMenuItem.Name = "addDatabaseToolStripMenuItem"; + this.addDatabaseToolStripMenuItem.Size = new System.Drawing.Size(268, 22); + this.addDatabaseToolStripMenuItem.Text = "Add Database"; + this.addDatabaseToolStripMenuItem.Click += new System.EventHandler(this.addDatabaseToolStripMenuItem_Click); + // + // saveDatabasesToolStripMenuItem + // + this.saveDatabasesToolStripMenuItem.Name = "saveDatabasesToolStripMenuItem"; + this.saveDatabasesToolStripMenuItem.Size = new System.Drawing.Size(99, 20); + this.saveDatabasesToolStripMenuItem.Text = "Save Databases"; + this.saveDatabasesToolStripMenuItem.Click += new System.EventHandler(this.saveDatabasesToolStripMenuItem_Click); + // // helpToolStripMenuItem // this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; @@ -357,8 +375,8 @@ private void InitializeComponent() // DatabaseTagsString // this.DatabaseTagsString.DataPropertyName = "DatabaseTagsString"; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.DatabaseTagsString.DefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.DatabaseTagsString.DefaultCellStyle = dataGridViewCellStyle3; this.DatabaseTagsString.HeaderText = "Tags"; this.DatabaseTagsString.Name = "DatabaseTagsString"; this.DatabaseTagsString.ReadOnly = true; @@ -549,8 +567,8 @@ private void InitializeComponent() // dataGridViewTextBoxColumn2 // this.dataGridViewTextBoxColumn2.DataPropertyName = "DatabaseTagsString"; - dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGridViewTextBoxColumn2.DefaultCellStyle = dataGridViewCellStyle4; this.dataGridViewTextBoxColumn2.HeaderText = "Tags"; this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; this.dataGridViewTextBoxColumn2.ReadOnly = true; @@ -675,14 +693,14 @@ private void InitializeComponent() this.ClientSize = new System.Drawing.Size(1049, 555); this.Controls.Add(this.splitContainerGridAndLog); this.Controls.Add(this.panelFilterCriteria); - this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.menuStripMain); this.Controls.Add(this.statusStripBottom); - this.MainMenuStrip = this.menuStrip1; + this.MainMenuStrip = this.menuStripMain; this.Name = "DatabaseBrowserForm"; this.Text = "Database Browser"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DatabaseBrowserForm_FormClosing); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.menuStripMain.ResumeLayout(false); + this.menuStripMain.PerformLayout(); this.panelFilterCriteria.ResumeLayout(false); this.panelFilterCriteria.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewEntryList)).EndInit(); @@ -709,7 +727,7 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.MenuStrip menuStripMain; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.Panel panelFilterCriteria; @@ -768,5 +786,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem addNewToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem addDatabaseToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveDatabasesToolStripMenuItem; } } \ No newline at end of file diff --git a/PinCab.Configurator/DatabaseBrowserForm.cs b/PinCab.Configurator/DatabaseBrowserForm.cs index dc6623d..88a2502 100644 --- a/PinCab.Configurator/DatabaseBrowserForm.cs +++ b/PinCab.Configurator/DatabaseBrowserForm.cs @@ -6,6 +6,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; using Serilog; using System; using System.Collections.Generic; @@ -29,6 +30,8 @@ public partial class DatabaseBrowserForm : Form private ProgramSettings _settings { get; set; } private bool notifiedOfSaveWarning = false; + private bool notifiedOfNewRowMissing = false; + private bool notifiedOfLike = false; public DatabaseBrowserForm() { @@ -52,10 +55,32 @@ public DatabaseBrowserForm() ConfigureGrid(); LoadDatabaseGrid(); _loading = false; + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); + } + + private void EnableContextMenus(bool enabled) + { + foreach (ToolStripItem itm in contextMenuStripGridActions.Items) + { + itm.Enabled = enabled; + } + + foreach (ToolStripItem itm in contextMenuStripChildEntries.Items) + { + itm.Enabled = enabled; + } + + saveDatabasesToolStripMenuItem.Enabled = enabled; + refreshDatabaseToolStripMenuItem.Enabled = enabled; + addDatabaseToolStripMenuItem.Enabled = enabled; + fileToolStripMenuItem.Enabled = enabled; + this.ControlBox = enabled; } private void ConfigureFilters() { + EnableContextMenus(false); + //Load from the last state (create a database form manager that persists filter selections to .json setting file) dateTimePickerBegin.Value = _settings.DatabaseBrowserSettings.BeginDate.BeginningOfDay(); dateTimePickerEnd.Value = _settings.DatabaseBrowserSettings.EndDate.EndOfDay(); @@ -211,11 +236,19 @@ private void txtSearch_TextChanged(object sender, EventArgs e) private List GetEntriesByFilterCriteria() { string searchTerm = txtSearch.Text.ToLower(); - IEnumerable list; - list = _dbManager.Entries.Where(p => //(p.Title.FuzzyMatch(txtSearch.Text) > .1) - p.Title.ToLower().Contains(searchTerm) - || p.Description.ToLower().Contains(searchTerm) - ); //Search by text + IEnumerable list = _dbManager.Entries; + if (cmbDatabase.SelectedItem != null && cmbDatabase.SelectedItem.ToString() != "All") + { + list = list.Where(p => p.DatabaseName == cmbDatabase.SelectedItem.ToString()); + } + + if (!string.IsNullOrWhiteSpace(searchTerm)) + { + list = list.Where(p => //(p.Title.FuzzyMatch(txtSearch.Text) > .1) + p.Title.ToLower().Contains(searchTerm) + || p.Description.ToLower().Contains(searchTerm) + ); //Search by text + } list = list.Where(p => p.LastUpdated <= dateTimePickerEnd.Value.EndOfDay() && p.LastUpdated >= dateTimePickerBegin.Value.BeginningOfDay()); @@ -225,10 +258,6 @@ private List GetEntriesByFilterCriteria() MajorCategory type = cmbType.SelectedValue.ToString().GetValueFromDescription(); list = list.Where(p => p.Type == type); } - if (cmbDatabase.SelectedItem != null && cmbDatabase.SelectedItem.ToString() != "All") - { - list = list.Where(p => p.DatabaseName == cmbDatabase.SelectedItem.ToString()); - } var tags = GetAllSelectedTags(); if (tags != null && tags.Count > 0) { @@ -322,6 +351,8 @@ private void backgroundWorkerProgressBar_RunWorkerCompleted(object sender, RunWo { var tags = result.Result as List; cmbTags.DataSource = tags; + EnableContextMenus(true); + } //else if (result.FunctionExecuted == DatabaseManagerBackgroundProgressAction.RebindDatabaseBrowserGrid.ToString()) //{ @@ -469,9 +500,13 @@ private void helpToolStripMenuItem_Click(object sender, EventArgs e) private void refreshDatabaseToolStripMenuItem_Click(object sender, EventArgs e) { - //Fake the system out by rolling back to a point where it thinks my local database is stale. - _dbManager.Settings.LastDatabaseRefreshTimeUtc = DateTime.UtcNow.AddDays(-365); - LoadDatabaseGrid(); + var response = MessageBox.Show("Any unsaved database entries will be overwritten. You should click Save Databases if you added or edited any entries as those entries only get written to a temporary location and that temporary location will get overwritten if you do not save your database first.", "Are you sure?", MessageBoxButtons.YesNo); + if (response == DialogResult.Yes) + { + //Fake the system out by rolling back to a point where it thinks my local database is stale. + _dbManager.Settings.LastDatabaseRefreshTimeUtc = DateTime.UtcNow.AddMinutes((_settings.DatabaseUpdateRecheckMinutes + 1) * -1); + LoadDatabaseGrid(); + } } private void dataGridViewEntryList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) @@ -572,11 +607,21 @@ private void dataGridViewEntryList_CellDoubleClick(object sender, DataGridViewCe { if (!string.IsNullOrEmpty(row.Url)) { + NotifyToLikeAndComment(); Process.Start(row.Url); } } } + private void NotifyToLikeAndComment() + { + if (!notifiedOfLike) + { + MessageBox.Show("Remember to thank the authors and star the download before downloading the content!", "Thank the authors!", MessageBoxButtons.OK, MessageBoxIcon.Information); + notifiedOfLike = true; + } + } + private void dataGridViewEntryList_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e) { var row = GetActiveRowEntry(); @@ -636,6 +681,7 @@ private void dataGridViewChildEntries_CellDoubleClick(object sender, DataGridVie { if (!string.IsNullOrEmpty(row.Url)) { + NotifyToLikeAndComment(); Process.Start(row.Url); } } @@ -695,14 +741,14 @@ private void editToolStripMenuItem_Click(object sender, EventArgs e) var row = GetActiveRow(); if (row != null) { - var entryForm = new EditDatabaseEntryForm(cmbDatabase.SelectedItem.ToString(), row, _dbManager, _ipdbForm); + var entryForm = new EditDatabaseEntryForm(row.DatabaseName, row, _dbManager, _ipdbForm); var result = entryForm.ShowDialog(this); if (result == DialogResult.OK) { //Reload the settings incase a new database was added _settings = _settingManager.LoadSettings(); - var contentDatabase = _settings.Databases.First(c => c.Name == cmbDatabase.SelectedItem.ToString()); + var contentDatabase = _settings.Databases.First(c => c.Name == row.DatabaseName); var dbFile = entryForm.GetUpdatedDatabaseEntry(); dbFile = _dbManager.SanitizeEntry(dbFile); @@ -710,18 +756,20 @@ private void editToolStripMenuItem_Click(object sender, EventArgs e) //var updatedDatabaseEntry = _dbManager.GetDatabaseBrowserEntry(contentDatabase, entryForm.GetUpdatedDatabaseEntry()); //Save the entry to the corresponding _dbManager.Databases (this happens automatically as we update the reference to it) - //var test = _dbManager.Databases[cmbDatabase.SelectedItem.ToString()].Entries.Where(c => c.Id == dbFile.Id); + //var test = _dbManager.Databases[ row.DatabaseName].Entries.Where(c => c.Id == dbFile.Id); var databasePath = _dbManager.GetFilesystemWorkPath(contentDatabase); - var databaseToSave = _dbManager.Databases[cmbDatabase.SelectedItem.ToString()]; + var databaseToSave = _dbManager.Databases[row.DatabaseName]; _dbManager.SaveDatabaseCache(databaseToSave, databasePath); //Save the actual database .json file //Save the pre-processed database to the file system - var existingEntry = _dbManager.Entries.FirstOrDefault(c => c.Id == dbFile.Id); + var existingEntry = _dbManager.Entries.FirstOrDefault(c => c.Id == dbFile.Id && c.DatabaseName == row.DatabaseName); _dbManager.MapDatabaseEntryToBrowserEntry(contentDatabase, dbFile, existingEntry); _dbManager.SaveDatabaseCache>(_dbManager.Entries, _dbManager.PreprocessedDatabasePath); //Refresh grid (will do that automatically) NotifyUserOfSaveWarning(); + dataGridViewEntryList.Refresh(); + dataGridViewChildEntries.Refresh(); } } } @@ -731,23 +779,38 @@ public void NotifyUserOfSaveWarning() if (!notifiedOfSaveWarning) { MessageBox.Show("Notice: Your entry has been saved to a temporary location. \r\n\r\n" + - "You must sync your changes before the entry is permanently saved.\r\n\r\n" + - "If you fail to sync your changes and exist the program your changes could get overwritten by the scheduled refresh interval.\r\n\r\n" + - "If you don't want this to happen you can set the refresh interval to a very large value and always do manual refreshes or just remember to sync your changes before exiting the database browser.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); + "You must save your database before the entry is permanently saved.\r\n\r\n" + + "If you fail to save your database your changes and exit the program your changes could get overwritten by the scheduled refresh interval.\r\n\r\n" + + "If you don't want this to happen you can set the refresh interval to a very large value and always do manual refreshes or just remember to save your database before exiting the database browser.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); notifiedOfSaveWarning = true; } } private void addNewToolStripMenuItem_Click(object sender, EventArgs e) { - var entryForm = new EditDatabaseEntryForm(cmbDatabase.SelectedItem.ToString(), null, _dbManager, _ipdbForm); + string database = cmbDatabase.SelectedItem.ToString(); + if (database == "All") + { + //Try determine the specific database by setting it to the row they have currently selected. + var row = GetActiveRow(); + if (row == null) //If no rows, force user to switch to a specific database + { + MessageBox.Show("Unable to determine database you want to add to. Switch to a specific database."); + return; + } + else + { + database = row.DatabaseName; + } + } + var entryForm = new EditDatabaseEntryForm(database, null, _dbManager, _ipdbForm); var result = entryForm.ShowDialog(this); if (result == DialogResult.OK) { //Reload the settings incase a new database was added _settings = _settingManager.LoadSettings(); - var contentDatabase = _settings.Databases.First(c => c.Name == cmbDatabase.SelectedItem.ToString()); + var contentDatabase = _settings.Databases.First(c => c.Name == database); var dbFile = entryForm.GetUpdatedDatabaseEntry(); dbFile = _dbManager.SanitizeEntry(dbFile); @@ -755,10 +818,18 @@ private void addNewToolStripMenuItem_Click(object sender, EventArgs e) //var updatedDatabaseEntry = _dbManager.GetDatabaseBrowserEntry(contentDatabase, entryForm.GetUpdatedDatabaseEntry()); //Save tne entry to the corresponding _dbManager.Databases (this happens automatically as we update the reference to it) - //var test = _dbManager.Databases[cmbDatabase.SelectedItem.ToString()].Entries.Where(c => c.Id == dbFile.Id); + //var test = _dbManager.Databases[database].Entries.Where(c => c.Id == dbFile.Id); var databasePath = _dbManager.GetFilesystemWorkPath(contentDatabase); - var databaseToSave = _dbManager.Databases[cmbDatabase.SelectedItem.ToString()]; + var databaseToSave = _dbManager.Databases[database]; + if (databaseToSave == null) //Brand new database + { + databaseToSave = new PinballDatabase(); + databaseToSave.LastRefreshDateUtc = DateTime.UtcNow; + databaseToSave.DatabaseFormatVersion = 1; + _dbManager.Databases[database] = databaseToSave; + } databaseToSave.Entries.Add(dbFile); + //Sync to the working path _dbManager.SaveDatabaseCache(databaseToSave, databasePath); //Save the actual database .json file //Save the pre-processed database to the file system @@ -771,6 +842,12 @@ private void addNewToolStripMenuItem_Click(object sender, EventArgs e) //Refresh grid RebindGridUsingFilter(); NotifyUserOfSaveWarning(); + + if (!notifiedOfNewRowMissing) + { + MessageBox.Show("Notice: If you do not see your new entry, check your filter criteria such as Dates, categorys, etc.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); + notifiedOfNewRowMissing = true; + } } } @@ -794,5 +871,45 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e) NotifyUserOfSaveWarning(); } } + + private void addDatabaseToolStripMenuItem_Click(object sender, EventArgs e) + { + var entryForm = new AddDatabaseForm(); + var result = entryForm.ShowDialog(this); + if (result == DialogResult.OK) + { + //Reload the settings incase a new database was added + _settings = _settingManager.LoadSettings(); + + var newEntry = entryForm.GetContentDatabaseFromForm(); + + //Refresh the database drop down + var currentSelectedItem = cmbDatabase.SelectedItem.ToString(); + //Load the database list + var databaseNames = _settings.Databases + .Where(c => c.Type == DatabaseType.PinballDatabase) + .OrderBy(c => c.Name).Select(c => c.Name).ToList(); + databaseNames.Insert(0, "All"); + cmbDatabase.DataSource = databaseNames; + + foreach (string type in cmbDatabase.Items) + { + if (type == currentSelectedItem) + cmbDatabase.SelectedItem = type; + } + + _dbManager.Databases.Add(newEntry.Name, null); + } + } + + private void saveDatabasesToolStripMenuItem_Click(object sender, EventArgs e) + { + var entryForm = new SaveDatabaseForm(_settings, _dbManager); + var result = entryForm.ShowDialog(this); + //if (result == DialogResult.OK) + //{ + + //} + } } } diff --git a/PinCab.Configurator/DatabaseBrowserForm.resx b/PinCab.Configurator/DatabaseBrowserForm.resx index 88f6a9b..d604b45 100644 --- a/PinCab.Configurator/DatabaseBrowserForm.resx +++ b/PinCab.Configurator/DatabaseBrowserForm.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 diff --git a/PinCab.Configurator/EditDatabaseEntryForm.Designer.cs b/PinCab.Configurator/EditDatabaseEntryForm.Designer.cs index ec3a089..90d8e5c 100644 --- a/PinCab.Configurator/EditDatabaseEntryForm.Designer.cs +++ b/PinCab.Configurator/EditDatabaseEntryForm.Designer.cs @@ -37,8 +37,6 @@ private void InitializeComponent() this.lblLocalTime = new System.Windows.Forms.Label(); this.cmbDatabase = new System.Windows.Forms.ComboBox(); this.label22 = new System.Windows.Forms.Label(); - this.btnIpdbUrl = new System.Windows.Forms.Button(); - this.btnUrl = new System.Windows.Forms.Button(); this.btnAddTag = new System.Windows.Forms.Button(); this.txtTag = new System.Windows.Forms.TextBox(); this.lblTags = new System.Windows.Forms.Label(); @@ -88,6 +86,16 @@ private void InitializeComponent() this.label24 = new System.Windows.Forms.Label(); this.btnAddRelatedEntry = new System.Windows.Forms.Button(); this.dataGridViewRelatedEntries = new System.Windows.Forms.DataGridView(); + this.label21 = new System.Windows.Forms.Label(); + this.dataGridViewScreenshotUrls = new System.Windows.Forms.DataGridView(); + this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label20 = new System.Windows.Forms.Label(); + this.label19 = new System.Windows.Forms.Label(); + this.dataGridViewAdditionalUrls = new System.Windows.Forms.DataGridView(); + this.Url = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.lblReadableFileSize = new System.Windows.Forms.Label(); + this.btnIpdbUrl = new System.Windows.Forms.Button(); + this.btnUrl = new System.Windows.Forms.Button(); this.idDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.majorCategoryDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.urlDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -108,14 +116,6 @@ private void InitializeComponent() this.ratingDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.lastModifiedDateUtcDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.databaseEntryBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.label21 = new System.Windows.Forms.Label(); - this.dataGridViewScreenshotUrls = new System.Windows.Forms.DataGridView(); - this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.label20 = new System.Windows.Forms.Label(); - this.label19 = new System.Windows.Forms.Label(); - this.dataGridViewAdditionalUrls = new System.Windows.Forms.DataGridView(); - this.Url = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.lblReadableFileSize = new System.Windows.Forms.Label(); this.tabControlGeneral.SuspendLayout(); this.tabPageGeneral.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericRating)).BeginInit(); @@ -125,9 +125,9 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.numericPlayers)).BeginInit(); this.tabPageAdditionalInfo.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewRelatedEntries)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.databaseEntryBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewScreenshotUrls)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewAdditionalUrls)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.databaseEntryBindingSource)).BeginInit(); this.SuspendLayout(); // // btnSave @@ -259,37 +259,11 @@ private void InitializeComponent() this.label22.TabIndex = 174; this.label22.Text = "Database"; // - // btnIpdbUrl - // - this.btnIpdbUrl.BackgroundImage = global::PinCab.Configurator.Properties.Resources.BrowserLink_75x; - this.btnIpdbUrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.btnIpdbUrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnIpdbUrl.ForeColor = System.Drawing.SystemColors.Control; - this.btnIpdbUrl.Location = new System.Drawing.Point(160, 453); - this.btnIpdbUrl.Name = "btnIpdbUrl"; - this.btnIpdbUrl.Size = new System.Drawing.Size(26, 23); - this.btnIpdbUrl.TabIndex = 173; - this.btnIpdbUrl.UseVisualStyleBackColor = true; - this.btnIpdbUrl.Click += new System.EventHandler(this.btnIpdbUrl_Click); - // - // btnUrl - // - this.btnUrl.BackgroundImage = global::PinCab.Configurator.Properties.Resources.BrowserLink_75x; - this.btnUrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.btnUrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.btnUrl.ForeColor = System.Drawing.SystemColors.Control; - this.btnUrl.Location = new System.Drawing.Point(499, 83); - this.btnUrl.Name = "btnUrl"; - this.btnUrl.Size = new System.Drawing.Size(26, 23); - this.btnUrl.TabIndex = 172; - this.btnUrl.UseVisualStyleBackColor = true; - this.btnUrl.Click += new System.EventHandler(this.btnUrl_Click); - // // btnAddTag // - this.btnAddTag.Location = new System.Drawing.Point(279, 559); + this.btnAddTag.Location = new System.Drawing.Point(279, 561); this.btnAddTag.Name = "btnAddTag"; - this.btnAddTag.Size = new System.Drawing.Size(75, 23); + this.btnAddTag.Size = new System.Drawing.Size(75, 22); this.btnAddTag.TabIndex = 171; this.btnAddTag.Text = "Add Tag"; this.btnAddTag.UseVisualStyleBackColor = true; @@ -320,6 +294,7 @@ private void InitializeComponent() // // btnFillFromIpdb // + this.btnFillFromIpdb.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnFillFromIpdb.Location = new System.Drawing.Point(192, 453); this.btnFillFromIpdb.Name = "btnFillFromIpdb"; this.btnFillFromIpdb.Size = new System.Drawing.Size(98, 23); @@ -761,6 +736,112 @@ private void InitializeComponent() this.dataGridViewRelatedEntries.Size = new System.Drawing.Size(576, 238); this.dataGridViewRelatedEntries.TabIndex = 136; // + // label21 + // + this.label21.AutoSize = true; + this.label21.Location = new System.Drawing.Point(11, 266); + this.label21.Name = "label21"; + this.label21.Size = new System.Drawing.Size(79, 13); + this.label21.TabIndex = 135; + this.label21.Text = "Related Entries"; + // + // dataGridViewScreenshotUrls + // + this.dataGridViewScreenshotUrls.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridViewScreenshotUrls.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.dataGridViewScreenshotUrls.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + this.dataGridViewScreenshotUrls.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewScreenshotUrls.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridViewTextBoxColumn1}); + this.dataGridViewScreenshotUrls.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.dataGridViewScreenshotUrls.Location = new System.Drawing.Point(9, 152); + this.dataGridViewScreenshotUrls.Name = "dataGridViewScreenshotUrls"; + this.dataGridViewScreenshotUrls.Size = new System.Drawing.Size(575, 100); + this.dataGridViewScreenshotUrls.TabIndex = 134; + this.dataGridViewScreenshotUrls.DoubleClick += new System.EventHandler(this.dataGridViewScreenshotUrls_DoubleClick); + // + // dataGridViewTextBoxColumn1 + // + this.dataGridViewTextBoxColumn1.HeaderText = "Url"; + this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + this.dataGridViewTextBoxColumn1.Width = 45; + // + // label20 + // + this.label20.AutoSize = true; + this.label20.Location = new System.Drawing.Point(8, 136); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(82, 13); + this.label20.TabIndex = 133; + this.label20.Text = "Screenshot Urls"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(8, 16); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(129, 13); + this.label19.TabIndex = 132; + this.label19.Text = "Additional Information Urls"; + // + // dataGridViewAdditionalUrls + // + this.dataGridViewAdditionalUrls.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridViewAdditionalUrls.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.dataGridViewAdditionalUrls.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; + this.dataGridViewAdditionalUrls.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewAdditionalUrls.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Url}); + this.dataGridViewAdditionalUrls.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; + this.dataGridViewAdditionalUrls.Location = new System.Drawing.Point(11, 32); + this.dataGridViewAdditionalUrls.Name = "dataGridViewAdditionalUrls"; + this.dataGridViewAdditionalUrls.Size = new System.Drawing.Size(573, 100); + this.dataGridViewAdditionalUrls.TabIndex = 131; + // + // Url + // + this.Url.HeaderText = "Url"; + this.Url.Name = "Url"; + this.Url.Width = 45; + // + // lblReadableFileSize + // + this.lblReadableFileSize.AutoSize = true; + this.lblReadableFileSize.Location = new System.Drawing.Point(203, 480); + this.lblReadableFileSize.Name = "lblReadableFileSize"; + this.lblReadableFileSize.Size = new System.Drawing.Size(96, 13); + this.lblReadableFileSize.TabIndex = 178; + this.lblReadableFileSize.Text = "(Readable Filesize)"; + // + // btnIpdbUrl + // + this.btnIpdbUrl.BackgroundImage = global::PinCab.Configurator.Properties.Resources.BrowserLink_75x; + this.btnIpdbUrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnIpdbUrl.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnIpdbUrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnIpdbUrl.ForeColor = System.Drawing.SystemColors.Control; + this.btnIpdbUrl.Location = new System.Drawing.Point(160, 453); + this.btnIpdbUrl.Name = "btnIpdbUrl"; + this.btnIpdbUrl.Size = new System.Drawing.Size(26, 23); + this.btnIpdbUrl.TabIndex = 173; + this.btnIpdbUrl.UseVisualStyleBackColor = true; + this.btnIpdbUrl.Click += new System.EventHandler(this.btnIpdbUrl_Click); + // + // btnUrl + // + this.btnUrl.BackgroundImage = global::PinCab.Configurator.Properties.Resources.BrowserLink_75x; + this.btnUrl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.btnUrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnUrl.ForeColor = System.Drawing.SystemColors.Control; + this.btnUrl.Location = new System.Drawing.Point(499, 83); + this.btnUrl.Name = "btnUrl"; + this.btnUrl.Size = new System.Drawing.Size(26, 23); + this.btnUrl.TabIndex = 172; + this.btnUrl.UseVisualStyleBackColor = true; + this.btnUrl.Click += new System.EventHandler(this.btnUrl_Click); + // // idDataGridViewTextBoxColumn // this.idDataGridViewTextBoxColumn.DataPropertyName = "Id"; @@ -784,6 +865,7 @@ private void InitializeComponent() this.urlDataGridViewTextBoxColumn.Name = "urlDataGridViewTextBoxColumn"; this.urlDataGridViewTextBoxColumn.ReadOnly = true; this.urlDataGridViewTextBoxColumn.Visible = false; + this.urlDataGridViewTextBoxColumn.Width = 45; // // titleDataGridViewTextBoxColumn // @@ -800,6 +882,7 @@ private void InitializeComponent() this.fileNameDataGridViewTextBoxColumn.Name = "fileNameDataGridViewTextBoxColumn"; this.fileNameDataGridViewTextBoxColumn.ReadOnly = true; this.fileNameDataGridViewTextBoxColumn.Visible = false; + this.fileNameDataGridViewTextBoxColumn.Width = 76; // // descriptionDataGridViewTextBoxColumn // @@ -808,6 +891,7 @@ private void InitializeComponent() this.descriptionDataGridViewTextBoxColumn.Name = "descriptionDataGridViewTextBoxColumn"; this.descriptionDataGridViewTextBoxColumn.ReadOnly = true; this.descriptionDataGridViewTextBoxColumn.Visible = false; + this.descriptionDataGridViewTextBoxColumn.Width = 85; // // changeLogDataGridViewTextBoxColumn // @@ -816,6 +900,7 @@ private void InitializeComponent() this.changeLogDataGridViewTextBoxColumn.Name = "changeLogDataGridViewTextBoxColumn"; this.changeLogDataGridViewTextBoxColumn.ReadOnly = true; this.changeLogDataGridViewTextBoxColumn.Visible = false; + this.changeLogDataGridViewTextBoxColumn.Width = 87; // // authorsDataGridViewTextBoxColumn // @@ -824,6 +909,7 @@ private void InitializeComponent() this.authorsDataGridViewTextBoxColumn.Name = "authorsDataGridViewTextBoxColumn"; this.authorsDataGridViewTextBoxColumn.ReadOnly = true; this.authorsDataGridViewTextBoxColumn.Visible = false; + this.authorsDataGridViewTextBoxColumn.Width = 68; // // versionDataGridViewTextBoxColumn // @@ -832,6 +918,7 @@ private void InitializeComponent() this.versionDataGridViewTextBoxColumn.Name = "versionDataGridViewTextBoxColumn"; this.versionDataGridViewTextBoxColumn.ReadOnly = true; this.versionDataGridViewTextBoxColumn.Visible = false; + this.versionDataGridViewTextBoxColumn.Width = 67; // // featuresDataGridViewTextBoxColumn // @@ -840,6 +927,7 @@ private void InitializeComponent() this.featuresDataGridViewTextBoxColumn.Name = "featuresDataGridViewTextBoxColumn"; this.featuresDataGridViewTextBoxColumn.ReadOnly = true; this.featuresDataGridViewTextBoxColumn.Visible = false; + this.featuresDataGridViewTextBoxColumn.Width = 73; // // manufacturerDataGridViewTextBoxColumn // @@ -848,6 +936,7 @@ private void InitializeComponent() this.manufacturerDataGridViewTextBoxColumn.Name = "manufacturerDataGridViewTextBoxColumn"; this.manufacturerDataGridViewTextBoxColumn.ReadOnly = true; this.manufacturerDataGridViewTextBoxColumn.Visible = false; + this.manufacturerDataGridViewTextBoxColumn.Width = 95; // // yearDataGridViewTextBoxColumn // @@ -856,6 +945,7 @@ private void InitializeComponent() this.yearDataGridViewTextBoxColumn.Name = "yearDataGridViewTextBoxColumn"; this.yearDataGridViewTextBoxColumn.ReadOnly = true; this.yearDataGridViewTextBoxColumn.Visible = false; + this.yearDataGridViewTextBoxColumn.Width = 54; // // playersDataGridViewTextBoxColumn // @@ -864,6 +954,7 @@ private void InitializeComponent() this.playersDataGridViewTextBoxColumn.Name = "playersDataGridViewTextBoxColumn"; this.playersDataGridViewTextBoxColumn.ReadOnly = true; this.playersDataGridViewTextBoxColumn.Visible = false; + this.playersDataGridViewTextBoxColumn.Width = 66; // // themeDataGridViewTextBoxColumn // @@ -872,6 +963,7 @@ private void InitializeComponent() this.themeDataGridViewTextBoxColumn.Name = "themeDataGridViewTextBoxColumn"; this.themeDataGridViewTextBoxColumn.ReadOnly = true; this.themeDataGridViewTextBoxColumn.Visible = false; + this.themeDataGridViewTextBoxColumn.Width = 65; // // ipdbNumberDataGridViewTextBoxColumn // @@ -880,6 +972,7 @@ private void InitializeComponent() this.ipdbNumberDataGridViewTextBoxColumn.Name = "ipdbNumberDataGridViewTextBoxColumn"; this.ipdbNumberDataGridViewTextBoxColumn.ReadOnly = true; this.ipdbNumberDataGridViewTextBoxColumn.Visible = false; + this.ipdbNumberDataGridViewTextBoxColumn.Width = 90; // // fileSizeBytesDataGridViewTextBoxColumn // @@ -888,6 +981,7 @@ private void InitializeComponent() this.fileSizeBytesDataGridViewTextBoxColumn.Name = "fileSizeBytesDataGridViewTextBoxColumn"; this.fileSizeBytesDataGridViewTextBoxColumn.ReadOnly = true; this.fileSizeBytesDataGridViewTextBoxColumn.Visible = false; + this.fileSizeBytesDataGridViewTextBoxColumn.Width = 94; // // downloadCountDataGridViewTextBoxColumn // @@ -896,6 +990,7 @@ private void InitializeComponent() this.downloadCountDataGridViewTextBoxColumn.Name = "downloadCountDataGridViewTextBoxColumn"; this.downloadCountDataGridViewTextBoxColumn.ReadOnly = true; this.downloadCountDataGridViewTextBoxColumn.Visible = false; + this.downloadCountDataGridViewTextBoxColumn.Width = 108; // // ratingDataGridViewTextBoxColumn // @@ -904,6 +999,7 @@ private void InitializeComponent() this.ratingDataGridViewTextBoxColumn.Name = "ratingDataGridViewTextBoxColumn"; this.ratingDataGridViewTextBoxColumn.ReadOnly = true; this.ratingDataGridViewTextBoxColumn.Visible = false; + this.ratingDataGridViewTextBoxColumn.Width = 63; // // lastModifiedDateUtcDataGridViewTextBoxColumn // @@ -912,90 +1008,12 @@ private void InitializeComponent() this.lastModifiedDateUtcDataGridViewTextBoxColumn.Name = "lastModifiedDateUtcDataGridViewTextBoxColumn"; this.lastModifiedDateUtcDataGridViewTextBoxColumn.ReadOnly = true; this.lastModifiedDateUtcDataGridViewTextBoxColumn.Visible = false; + this.lastModifiedDateUtcDataGridViewTextBoxColumn.Width = 132; // // databaseEntryBindingSource // this.databaseEntryBindingSource.DataSource = typeof(VirtualPinball.Database.Models.DatabaseEntry); // - // label21 - // - this.label21.AutoSize = true; - this.label21.Location = new System.Drawing.Point(11, 266); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(79, 13); - this.label21.TabIndex = 135; - this.label21.Text = "Related Entries"; - // - // dataGridViewScreenshotUrls - // - this.dataGridViewScreenshotUrls.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridViewScreenshotUrls.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; - this.dataGridViewScreenshotUrls.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; - this.dataGridViewScreenshotUrls.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridViewScreenshotUrls.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.dataGridViewTextBoxColumn1}); - this.dataGridViewScreenshotUrls.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.dataGridViewScreenshotUrls.Location = new System.Drawing.Point(9, 152); - this.dataGridViewScreenshotUrls.Name = "dataGridViewScreenshotUrls"; - this.dataGridViewScreenshotUrls.Size = new System.Drawing.Size(575, 100); - this.dataGridViewScreenshotUrls.TabIndex = 134; - this.dataGridViewScreenshotUrls.DoubleClick += new System.EventHandler(this.dataGridViewScreenshotUrls_DoubleClick); - // - // dataGridViewTextBoxColumn1 - // - this.dataGridViewTextBoxColumn1.HeaderText = "Url"; - this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; - this.dataGridViewTextBoxColumn1.Width = 45; - // - // label20 - // - this.label20.AutoSize = true; - this.label20.Location = new System.Drawing.Point(8, 136); - this.label20.Name = "label20"; - this.label20.Size = new System.Drawing.Size(82, 13); - this.label20.TabIndex = 133; - this.label20.Text = "Screenshot Urls"; - // - // label19 - // - this.label19.AutoSize = true; - this.label19.Location = new System.Drawing.Point(8, 16); - this.label19.Name = "label19"; - this.label19.Size = new System.Drawing.Size(129, 13); - this.label19.TabIndex = 132; - this.label19.Text = "Additional Information Urls"; - // - // dataGridViewAdditionalUrls - // - this.dataGridViewAdditionalUrls.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridViewAdditionalUrls.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; - this.dataGridViewAdditionalUrls.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; - this.dataGridViewAdditionalUrls.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridViewAdditionalUrls.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Url}); - this.dataGridViewAdditionalUrls.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; - this.dataGridViewAdditionalUrls.Location = new System.Drawing.Point(11, 32); - this.dataGridViewAdditionalUrls.Name = "dataGridViewAdditionalUrls"; - this.dataGridViewAdditionalUrls.Size = new System.Drawing.Size(573, 100); - this.dataGridViewAdditionalUrls.TabIndex = 131; - // - // Url - // - this.Url.HeaderText = "Url"; - this.Url.Name = "Url"; - this.Url.Width = 45; - // - // lblReadableFileSize - // - this.lblReadableFileSize.AutoSize = true; - this.lblReadableFileSize.Location = new System.Drawing.Point(203, 480); - this.lblReadableFileSize.Name = "lblReadableFileSize"; - this.lblReadableFileSize.Size = new System.Drawing.Size(96, 13); - this.lblReadableFileSize.TabIndex = 178; - this.lblReadableFileSize.Text = "(Readable Filesize)"; - // // EditDatabaseEntryForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1018,9 +1036,9 @@ private void InitializeComponent() this.tabPageAdditionalInfo.ResumeLayout(false); this.tabPageAdditionalInfo.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewRelatedEntries)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.databaseEntryBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewScreenshotUrls)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewAdditionalUrls)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.databaseEntryBindingSource)).EndInit(); this.ResumeLayout(false); } diff --git a/PinCab.Configurator/EditDatabaseEntryForm.cs b/PinCab.Configurator/EditDatabaseEntryForm.cs index 9d3853d..1f89636 100644 --- a/PinCab.Configurator/EditDatabaseEntryForm.cs +++ b/PinCab.Configurator/EditDatabaseEntryForm.cs @@ -4,6 +4,7 @@ using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -26,12 +27,14 @@ public partial class EditDatabaseEntryForm : Form private IpdbBrowserForm _ipdbForm = null; private bool isNewEntry = false; private DatabaseEntry _dbEntry { get; set; } + private string _currentDatabase { get; set; } public EditDatabaseEntryForm(string databaseName, DatabaseBrowserEntry entry, DatabaseManager manager, IpdbBrowserForm ipdbForm) { InitializeComponent(); _manager = manager; _ipdbForm = ipdbForm; _entry = entry; + _currentDatabase = databaseName; DialogResult = DialogResult.None; if (entry == null) { @@ -39,7 +42,7 @@ public EditDatabaseEntryForm(string databaseName, DatabaseBrowserEntry entry, Da _entry = new DatabaseBrowserEntry(); _dbEntry = new DatabaseEntry(); _dbEntry.Id = 1; - if (manager.Databases[databaseName].Entries.Count > 0) + if (manager.Databases[databaseName] != null && manager.Databases[databaseName].Entries.Count > 0) _dbEntry.Id = manager.Databases[databaseName].Entries.Max(c => c.Id) + 1; } else @@ -47,6 +50,7 @@ public EditDatabaseEntryForm(string databaseName, DatabaseBrowserEntry entry, Da _dbEntry = manager.Databases[entry.DatabaseName].Entries.First(c => c.Id == entry.Id); } LoadForm(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadForm() @@ -58,12 +62,12 @@ private void LoadForm() foreach (string databaseName in cmbDatabase.Items) { - if (databaseName == _entry.DatabaseName) + if (databaseName == _currentDatabase) cmbDatabase.SelectedItem = databaseName; } - if (!isNewEntry) - cmbDatabase.Enabled = false; //Do not allow saving an entry accross databases + //if (!isNewEntry) + cmbDatabase.Enabled = false; //Do not allow saving an entry accross databases, 3/27/2021 - Always set to readonly as we are always adding/editing based off of a specific database var categoryList = EnumExtensions.GetEnumDescriptionList(); cmbCategory.DataSource = categoryList; @@ -97,11 +101,14 @@ private void LoadForm() numericRating.Value = _dbEntry.Rating.HasValue ? _dbEntry.Rating.Value : 0; dateTimeModified.Value = _dbEntry.LastModifiedDateUtc.HasValue ? _dbEntry.LastModifiedDateUtc.Value : DateTime.UtcNow; - foreach (var tag in _dbEntry.Tags) + if (_dbEntry.Tags != null) { - TagObject tagwinforms = new TagObject(tag, null); - tagwinforms.Init(); - flowLayoutPanelTags.Controls.Add(tagwinforms); + foreach (var tag in _dbEntry.Tags) + { + TagObject tagwinforms = new TagObject(tag, null); + tagwinforms.Init(); + flowLayoutPanelTags.Controls.Add(tagwinforms); + } } flowLayoutPanelTags.Padding = new Padding(3, 3, 3, 3); diff --git a/PinCab.Configurator/EditDatabaseEntryForm.resx b/PinCab.Configurator/EditDatabaseEntryForm.resx index dd2b1e4..975af86 100644 --- a/PinCab.Configurator/EditDatabaseEntryForm.resx +++ b/PinCab.Configurator/EditDatabaseEntryForm.resx @@ -120,18 +120,9 @@ 17, 17 - - 17, 17 - True - - True - - - True - True diff --git a/PinCab.Configurator/GameManagerForm.cs b/PinCab.Configurator/GameManagerForm.cs index d9b492a..19662b4 100644 --- a/PinCab.Configurator/GameManagerForm.cs +++ b/PinCab.Configurator/GameManagerForm.cs @@ -4,6 +4,7 @@ using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; using Serilog; using System; using System.Collections.Generic; @@ -31,6 +32,7 @@ public GameManagerForm() InitForm(); //_loading = false; + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void InitForm() diff --git a/PinCab.Configurator/IpdbBrowserForm.cs b/PinCab.Configurator/IpdbBrowserForm.cs index 7e6e807..ce04ec2 100644 --- a/PinCab.Configurator/IpdbBrowserForm.cs +++ b/PinCab.Configurator/IpdbBrowserForm.cs @@ -4,6 +4,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,6 +28,7 @@ public IpdbBrowserForm(string startText = "", bool hideForm = false) LoadDatabase(); SearchGrid(startText); _hideForm = hideForm; + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadDatabase() diff --git a/PinCab.Configurator/MainForm.cs b/PinCab.Configurator/MainForm.cs index efa37cf..cd0d80b 100644 --- a/PinCab.Configurator/MainForm.cs +++ b/PinCab.Configurator/MainForm.cs @@ -13,6 +13,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils.PinballY; using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; namespace PinCab.Configurator { @@ -59,6 +60,7 @@ public MainForm() //var displays = new ScreenDetails().GetDisplays(); //panelMonitorDrawing.Refresh(); ValidateMonitorConfiguration(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void UpdateDisplayDetailsFromSettingsFile() diff --git a/PinCab.Configurator/MediaAuditForm.cs b/PinCab.Configurator/MediaAuditForm.cs index 966263b..c48d1f8 100644 --- a/PinCab.Configurator/MediaAuditForm.cs +++ b/PinCab.Configurator/MediaAuditForm.cs @@ -3,6 +3,7 @@ using PinCab.Utils.Models.PinballX; using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; +using PinCab.Utils.WinForms.TabOrder; using Serilog; using System; using System.Collections.Generic; @@ -26,6 +27,7 @@ public MediaAuditForm() InitializeComponent(); InitForm(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void InitForm() diff --git a/PinCab.Configurator/PinMameRomBrowserForm.cs b/PinCab.Configurator/PinMameRomBrowserForm.cs index b6de224..408cdaa 100644 --- a/PinCab.Configurator/PinMameRomBrowserForm.cs +++ b/PinCab.Configurator/PinMameRomBrowserForm.cs @@ -5,6 +5,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; using Serilog; using System; using System.Collections.Generic; @@ -29,6 +30,7 @@ public PinMameRomBrowserForm() ConfigureGrid(); LoadRomList(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadRomList() diff --git a/PinCab.Configurator/PinMameRomSettingEditor.cs b/PinCab.Configurator/PinMameRomSettingEditor.cs index 375a7fa..1469c20 100644 --- a/PinCab.Configurator/PinMameRomSettingEditor.cs +++ b/PinCab.Configurator/PinMameRomSettingEditor.cs @@ -1,6 +1,7 @@ using PinCab.Utils.Extensions; using PinCab.Utils.Models; using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -24,6 +25,7 @@ public PinMameRomSettingEditorForm(VpinMameRomSetting setting, VPinMAMELib.Contr _setting = setting; _controller = controller; LoadForm(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadForm() diff --git a/PinCab.Configurator/Pincab.Configurator.csproj b/PinCab.Configurator/Pincab.Configurator.csproj index 5aee717..9913b5f 100644 --- a/PinCab.Configurator/Pincab.Configurator.csproj +++ b/PinCab.Configurator/Pincab.Configurator.csproj @@ -119,6 +119,9 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Octokit.0.50.0\lib\net46\Octokit.dll + ..\packages\Serilog.2.10.0\lib\net46\Serilog.dll @@ -156,6 +159,12 @@ AboutBoxForm.cs + + Form + + + AddDatabaseForm.cs + Form @@ -232,6 +241,12 @@ + + Form + + + SaveDatabaseForm.cs + Form @@ -255,6 +270,9 @@ AboutBoxForm.cs + + AddDatabaseForm.cs + EditDatabaseEntryForm.cs @@ -301,6 +319,9 @@ Resources.resx True + + SaveDatabaseForm.cs + ScreenResEditorForm.cs diff --git a/PinCab.Configurator/RecordForm.cs b/PinCab.Configurator/RecordForm.cs index 9b9fe78..32274ea 100644 --- a/PinCab.Configurator/RecordForm.cs +++ b/PinCab.Configurator/RecordForm.cs @@ -1,5 +1,6 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -37,6 +38,7 @@ private void InitForm() } ConfigureGrid(); LoadDefaultsFromSavedSettings(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadDefaultsFromSavedSettings() diff --git a/PinCab.Configurator/RenameGameForm.cs b/PinCab.Configurator/RenameGameForm.cs index 3a9ce43..68f3303 100644 --- a/PinCab.Configurator/RenameGameForm.cs +++ b/PinCab.Configurator/RenameGameForm.cs @@ -2,6 +2,7 @@ using PinCab.Utils.Models; using PinCab.Utils.Utils; using PinCab.Utils.ViewModels; +using PinCab.Utils.WinForms.TabOrder; using System; using System.Collections.Generic; using System.ComponentModel; @@ -27,6 +28,7 @@ public RenameGameForm(FrontEndGameViewModel setting, string newName, FrontEndMan _setting = setting; _newName = newName; LoadData(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); } private void LoadData() diff --git a/PinCab.Configurator/SaveDatabaseForm.Designer.cs b/PinCab.Configurator/SaveDatabaseForm.Designer.cs new file mode 100644 index 0000000..1066c5e --- /dev/null +++ b/PinCab.Configurator/SaveDatabaseForm.Designer.cs @@ -0,0 +1,150 @@ + +namespace PinCab.Configurator +{ + partial class SaveDatabaseForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.checkedListBoxDatabases = new System.Windows.Forms.CheckedListBox(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnSave = new System.Windows.Forms.Button(); + this.txtLog = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtCommitMessage = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // checkedListBoxDatabases + // + this.checkedListBoxDatabases.CheckOnClick = true; + this.checkedListBoxDatabases.FormattingEnabled = true; + this.checkedListBoxDatabases.Location = new System.Drawing.Point(12, 58); + this.checkedListBoxDatabases.Name = "checkedListBoxDatabases"; + this.checkedListBoxDatabases.Size = new System.Drawing.Size(441, 139); + this.checkedListBoxDatabases.TabIndex = 1; + // + // btnCancel + // + this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btnCancel.Location = new System.Drawing.Point(118, 203); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 23); + this.btnCancel.TabIndex = 11; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(12, 203); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 23); + this.btnSave.TabIndex = 10; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // txtLog + // + this.txtLog.Location = new System.Drawing.Point(12, 251); + this.txtLog.Multiline = true; + this.txtLog.Name = "txtLog"; + this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.txtLog.Size = new System.Drawing.Size(760, 131); + this.txtLog.TabIndex = 12; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 235); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(28, 13); + this.label1.TabIndex = 13; + this.label1.Text = "Log:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 13); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(434, 39); + this.label2.TabIndex = 14; + this.label2.Text = "Select the databases you wish to save from the temporary location to the final re" + + "sting spot. \r\n\r\nNote: This only supports local file system and public/private Gi" + + "thub Repos."; + // + // txtCommitMessage + // + this.txtCommitMessage.Location = new System.Drawing.Point(472, 58); + this.txtCommitMessage.Multiline = true; + this.txtCommitMessage.Name = "txtCommitMessage"; + this.txtCommitMessage.Size = new System.Drawing.Size(287, 139); + this.txtCommitMessage.TabIndex = 15; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(472, 38); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(166, 13); + this.label3.TabIndex = 16; + this.label3.Text = "Commit Message (Only for Github)"; + // + // SaveDatabaseForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(784, 392); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtCommitMessage); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.txtLog); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.checkedListBoxDatabases); + this.MinimumSize = new System.Drawing.Size(800, 431); + this.Name = "SaveDatabaseForm"; + this.Text = "Save Database"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.CheckedListBox checkedListBoxDatabases; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.TextBox txtLog; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtCommitMessage; + private System.Windows.Forms.Label label3; + } +} \ No newline at end of file diff --git a/PinCab.Configurator/SaveDatabaseForm.cs b/PinCab.Configurator/SaveDatabaseForm.cs new file mode 100644 index 0000000..6e1b0d5 --- /dev/null +++ b/PinCab.Configurator/SaveDatabaseForm.cs @@ -0,0 +1,177 @@ +using Octokit; +using PinCab.Utils.Models; +using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; +using Serilog; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PinCab.Configurator +{ + public partial class SaveDatabaseForm : Form + { + private DatabaseManager _dbManager { get; set; } + private ProgramSettings _settings { get; set; } + + public SaveDatabaseForm(ProgramSettings settings, DatabaseManager dbManager) + { + InitializeComponent(); + DialogResult = DialogResult.None; + _dbManager = dbManager; + _settings = settings; + + LoadDatabases(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); + } + + private void LoadDatabases() + { + foreach (var database in _settings.Databases) + { + checkedListBoxDatabases.Items.Add(database); + } + } + + private async void btnSave_Click(object sender, EventArgs e) + { + txtLog.Text = string.Empty; + foreach (var selectedDatabase in checkedListBoxDatabases.SelectedItems) + { + var db = selectedDatabase as ContentDatabase; + var workPath = _dbManager.GetFilesystemWorkPath(db); + if (db.IsUrl()) //Upload to Github + { + //string message = $"Wrote file from: {workPath} to {finalLocation}"; + if (string.IsNullOrEmpty(txtCommitMessage.Text)) + { + txtLog.Text += $"Unable to update Git Repo: {db.Url}. You forgot to include a commit message.\r\n"; + continue; + } + try + { + var client = new GitHubClient(new ProductHeaderValue("pincab-configurator")); + var tokenAuth = new Credentials(db.AccessToken); + client.Credentials = tokenAuth; + + //Determine the Git url based off of the current fragement + var uri = new Uri(db.Url); + //Example: "https://github.com/xantari/DBRepoTest.git" + string username = uri.Segments[1].Replace("/", ""); + string repoName = uri.Segments[2].Replace("/", ""); + string branchName = uri.Segments[3].Replace("/", ""); + //Directory path is everything from segments[4] and beyond + string dirPathAndFile = string.Empty; + for (int i = 4; i < uri.Segments.Count(); i++) + { + dirPathAndFile += uri.Segments[i]; + } + string fileName = uri.Segments.Last().Replace("/", ""); + var gitCloneUrl = "https://github.com/" + uri.Segments[1] + uri.Segments[2].Replace("/", "") + ".git"; + + var repos = await client.Repository.GetAllForCurrent(); + var repo = repos.FirstOrDefault(c => c.CloneUrl.ToLower() == gitCloneUrl.ToLower()); + if (repo != null) + { + var parent = await client.Git.Reference.Get(username, repoName, "heads/" + branchName); + //var tree = await client.Git.Tree.GetRecursive(repo.NodeId, "Test"); + var latestCommit = await client.Git.Commit.Get(username, repoName, parent.Object.Sha); + var currentTree = await client.Git.Tree.GetRecursive(username, repoName, latestCommit.Tree.Sha); + var file = currentTree.Tree.FirstOrDefault(c => c.Path == dirPathAndFile); + if (file != null) + { + var blob = await client.Git.Blob.Get(username, repoName, file.Sha); + var newblob = new NewBlob(); + newblob.Encoding = EncodingType.Base64; + //string textContent = File.ReadAllText(workPath); + var plainTextBytes = File.ReadAllBytes(workPath); + var base64 = Convert.ToBase64String(plainTextBytes); + newblob.Content = base64; + var addBlob = await client.Git.Blob.Create(username, repoName, newblob); + var nt = new NewTree(); + //Code from here: https://github.com/octokit/octokit.net/issues/1610 + currentTree.Tree + .Where(x => x.Type != TreeType.Tree) + .Select(x => new NewTreeItem + { + Path = x.Path, + Mode = x.Mode, + Type = x.Type.Value, + Sha = x.Sha + }) + .ToList() + .ForEach(x => nt.Tree.Add(x)); + + //Remove the current file tree node + var treeNodeToRemove = nt.Tree.FirstOrDefault(c => c.Path == dirPathAndFile); + nt.Tree.Remove(treeNodeToRemove); + + //Now add a new tree node to the file + var treeItem = new NewTreeItem(); + treeItem.Path = file.Path; + treeItem.Mode = file.Mode; + treeItem.Type = TreeType.Blob; + treeItem.Sha = addBlob.Sha; + nt.Tree.Add(treeItem); + + var newTree = await client.Git.Tree.Create(username, repoName, nt); + var newCommit = new NewCommit(txtCommitMessage.Text, newTree.Sha, parent.Object.Sha); + var commit = await client.Git.Commit.Create(username, repoName, newCommit); + var reference = await client.Git.Reference.Update(username, repoName, "heads/" + branchName, new ReferenceUpdate(commit.Sha)); + Log.Information("Repository updated. {@repo}", reference); + txtLog.Text += $"Repository Updated. Repo: {repo.CloneUrl} Reference: {reference.Object.Sha}\r\n"; + } + else + { + Log.Information("Could not find file in repo. {repo}", db.Url); + txtLog.Text += $"Could not find file in repo. {db.Url}\r\n"; + } + //var currentBlob = await client.Git.Blob.Get(username, repoName,) + } + else + { + string message = $"Repo not found or you don't have access. Name: {db.Name} Repo: {db.Url}"; + txtLog.Text += message + "\r\n"; + Log.Warning(message); + } + } + catch (Exception ex) + { + Log.Error(ex, "Error occurred: {ex}", ex.Message); + txtLog.Text += ex.Message + "\r\n\r\n"; + } + } + else //Save to final file system location + { + var finalLocation = db.Url; + string message = $"Wrote file from: {workPath} to {finalLocation}"; + if (!File.Exists(workPath)) + { + message = $"Work file has not been created yet. Did you enter atleast one entry yet? Work file: {workPath}"; + txtLog.Text += message + "\r\n"; + Log.Warning(message); + continue; + } + Log.Information(message); + File.Copy(workPath, finalLocation, true); + txtLog.Text += message + "\r\n"; + } + } + + DialogResult = DialogResult.None; + return; + } + + private void btnCancel_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/PinCab.Configurator/SaveDatabaseForm.resx b/PinCab.Configurator/SaveDatabaseForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PinCab.Configurator/SaveDatabaseForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PinCab.Configurator/ScreenResEditorForm.cs b/PinCab.Configurator/ScreenResEditorForm.cs index 9f1faf2..f90d359 100644 --- a/PinCab.Configurator/ScreenResEditorForm.cs +++ b/PinCab.Configurator/ScreenResEditorForm.cs @@ -1,6 +1,7 @@ using PinCab.Utils; using PinCab.Utils.Models; using PinCab.Utils.Utils; +using PinCab.Utils.WinForms.TabOrder; using Serilog; using System; using System.Collections.Generic; @@ -25,6 +26,7 @@ public partial class ScreenResEditorForm : Form public ScreenResEditorForm() { InitializeComponent(); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); _settings = _settingsManager.LoadSettings(); LoadDisplayDetails(); diff --git a/PinCab.Configurator/SettingsForm.cs b/PinCab.Configurator/SettingsForm.cs index 77e7e67..4ef29c4 100644 --- a/PinCab.Configurator/SettingsForm.cs +++ b/PinCab.Configurator/SettingsForm.cs @@ -14,6 +14,7 @@ using System.IO; using PinCab.Utils.Extensions; using PinCab.Utils.WinForms; +using PinCab.Utils.WinForms.TabOrder; namespace PinCab.Configurator { @@ -36,6 +37,7 @@ public SettingsForm() //this.toolTip1.SetToolTip(this.btnFFMPegHelp, "Location of the ffmpeg.exe file if you wish to use the screen recording feature of this program."); //this.toolTip1.SetToolTip(this.btnRecordTimeSecondsHelp, "Number of seconds to record the video. 5 Second increments up to 200 seconds. Minimum 5 seconds."); + (new TabOrderManager(this)).SetTabOrder(TabOrderManager.TabScheme.DownFirst); } private void SettingsForm_Load(object sender, EventArgs e) diff --git a/PinCab.Configurator/packages.config b/PinCab.Configurator/packages.config index a907f2b..a16e35e 100644 --- a/PinCab.Configurator/packages.config +++ b/PinCab.Configurator/packages.config @@ -5,6 +5,7 @@ + diff --git a/PinCab.Utils/Extensions/DatabaseExtensions.cs b/PinCab.Utils/Extensions/DatabaseExtensions.cs index 18c1964..e43f72b 100644 --- a/PinCab.Utils/Extensions/DatabaseExtensions.cs +++ b/PinCab.Utils/Extensions/DatabaseExtensions.cs @@ -16,11 +16,11 @@ public static List ConvertTableInfoToTags(this DatabaseEntry info) { if (!string.IsNullOrEmpty(info.Manufacturer)) list.Add(info.Manufacturer); - if (info.Players.HasValue) + if (info.Players.HasValue && info.Players.Value > 0) list.Add(info.Players.Value == 1 ? "1 Player" : $"{info.Players.Value} Players"); if (!string.IsNullOrEmpty(info.Theme)) list.Add(info.Theme); - if (info.Year.HasValue) + if (info.Year.HasValue && info.Year.Value > 0) list.Add(info.Year.Value.ToString()); } return list; diff --git a/PinCab.Utils/Models/ContentDatabase.cs b/PinCab.Utils/Models/ContentDatabase.cs index ec34901..f53e0d0 100644 --- a/PinCab.Utils/Models/ContentDatabase.cs +++ b/PinCab.Utils/Models/ContentDatabase.cs @@ -14,5 +14,23 @@ public ContentDatabase() { } public string Name { get; set; } public string Url { get; set; } public string AccessToken { get; set; } + + public bool IsUrl() + { + Uri uri; + bool result = Uri.TryCreate(Url, UriKind.Absolute, out uri); + if (result) + { + if (uri.Scheme == "file") + return false; + return true; + } + return false; + } + + public override string ToString() + { + return Name + " (" + (IsUrl() ? "Github)" : "File System)"); + } } } diff --git a/PinCab.Utils/PinCab.Utils.csproj b/PinCab.Utils/PinCab.Utils.csproj index 10a7305..44f11a1 100644 --- a/PinCab.Utils/PinCab.Utils.csproj +++ b/PinCab.Utils/PinCab.Utils.csproj @@ -101,6 +101,9 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + ..\packages\Octokit.0.50.0\lib\net46\Octokit.dll + ..\packages\Serilog.2.10.0\lib\net46\Serilog.dll @@ -206,6 +209,13 @@ + + Component + + + TabSchemeProvider.cs + + Component @@ -228,6 +238,9 @@ + + + diff --git a/PinCab.Utils/Utils/DatabaseManager.cs b/PinCab.Utils/Utils/DatabaseManager.cs index 472afe0..9eb0107 100644 --- a/PinCab.Utils/Utils/DatabaseManager.cs +++ b/PinCab.Utils/Utils/DatabaseManager.cs @@ -106,6 +106,8 @@ public ToolResult RefreshAllDatabases() public void SanitizeAllDatabaseEntries(PinballDatabase database) { + if (database == null) + return; foreach (var file in database.Entries) SanitizeEntry(file); } @@ -171,25 +173,31 @@ public ToolResult DownloadDatabase(ContentDatabase database, bool forceDownload private bool DownloadDatabaseToFilesystem(ContentDatabase database, string downloadPath) { //If it's not a url, just consider it already downloaded - if (File.Exists(database.Url)) + if (File.Exists(database.Url)) //Local file system database + { + File.Copy(database.Url, downloadPath, true); return true; - try + } + else //Web URL content database { - using (WebClient wc = new WebClient()) + try { - if (database.Url.ToLower().Contains("github") && !string.IsNullOrEmpty(database.AccessToken)) + using (WebClient wc = new WebClient()) { - wc.Headers.Add("Authorization", "token " + database.AccessToken); + if (database.Url.ToLower().Contains("github") && !string.IsNullOrEmpty(database.AccessToken)) + { + wc.Headers.Add("Authorization", "token " + database.AccessToken); + } + //wc.DownloadProgressChanged += wc_DownloadProgressChanged; + var url = new Uri(database.Url); + wc.DownloadFile(url, downloadPath); } - //wc.DownloadProgressChanged += wc_DownloadProgressChanged; - var url = new Uri(database.Url); - wc.DownloadFile(url, downloadPath); + return true; + } + catch (Exception ex) + { + Log.Error(ex, "Error downloading file: {file}", database.Url); } - return true; - } - catch (Exception ex) - { - Log.Error(ex, "Error downloading file: {file}", database.Url); } return false; //failure } @@ -305,11 +313,22 @@ public List GetDatabaseVersionMessages() { foreach (var db in Databases) { - entries.Add(new ValidationMessage() + if (db.Value == null) //Brand new database + { + entries.Add(new ValidationMessage() + { + Level = MessageLevel.Information, + Message = db.Key + " New database detected. No entries yet." + }); + } + else { - Level = MessageLevel.Information, - Message = db.Key + " Database Last Updated (UTC): " + db.Value.LastRefreshDateUtc + " Local: " + db.Value.LastRefreshDateUtc.ToLocalTime() - }); + entries.Add(new ValidationMessage() + { + Level = MessageLevel.Information, + Message = db.Key + " Database Last Updated (UTC): " + db.Value.LastRefreshDateUtc + " Local: " + db.Value.LastRefreshDateUtc.ToLocalTime() + }); + } } } @@ -349,28 +368,31 @@ public List GetEntrysByDatabase(ContentDatabase database, private HashSet GetDatabaseBrowserEntries(ContentDatabase database) { HashSet entries = new HashSet(); - foreach (var databaseEntry in Databases[database.Name].Entries) + if (Databases[database.Name] != null) { - var entry = GetDatabaseBrowserEntry(database, databaseEntry); - if (IsValidBrowserEntry(entry)) - entries.Add(entry); - else - Log.Information("{tool}: Skipped adding {entry} because it didn't pass the data check.", ToolName, entry.Title); - - //Add the related entries - if (databaseEntry.RelatedEntries != null) + foreach (var databaseEntry in Databases[database.Name].Entries) { - foreach (var relatedEntry in databaseEntry.RelatedEntries) + var entry = GetDatabaseBrowserEntry(database, databaseEntry); + if (IsValidBrowserEntry(entry)) + entries.Add(entry); + else + Log.Information("{tool}: Skipped adding {entry} because it didn't pass the data check.", ToolName, entry.Title); + + //Add the related entries + if (databaseEntry.RelatedEntries != null) { - var relatedContentEntry = Databases[database.Name].Entries.FirstOrDefault(c => c.Id == relatedEntry); - var newEntry = GetDatabaseBrowserEntry(database, relatedContentEntry); - if (IsValidBrowserEntry(newEntry)) + foreach (var relatedEntry in databaseEntry.RelatedEntries) { - entry.RelatedEntries.Add(newEntry); - entry.Tags.UnionWith(newEntry.Tags); + var relatedContentEntry = Databases[database.Name].Entries.FirstOrDefault(c => c.Id == relatedEntry); + var newEntry = GetDatabaseBrowserEntry(database, relatedContentEntry); + if (IsValidBrowserEntry(newEntry)) + { + entry.RelatedEntries.Add(newEntry); + entry.Tags.UnionWith(newEntry.Tags); + } + else + Log.Information("{tool}: Skipped related entry adding {entry} because it didn't pass the data check.", ToolName, relatedContentEntry.Title); } - else - Log.Information("{tool}: Skipped related entry adding {entry} because it didn't pass the data check.", ToolName, relatedContentEntry.Title); } } } diff --git a/PinCab.Utils/WinForms/TabOrder/TabOrderManager.cs b/PinCab.Utils/WinForms/TabOrder/TabOrderManager.cs new file mode 100644 index 0000000..2809aaa --- /dev/null +++ b/PinCab.Utils/WinForms/TabOrder/TabOrderManager.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PinCab.Utils.WinForms.TabOrder +{ + /// + /// Dynamically determine and set a tab order for a container and children according to a given strategy. + /// https://www.codeproject.com/Articles/8406/Automatic-Runtime-Tab-Order-Management-for-Windows + /// + public class TabOrderManager + { + /// + /// Compare two controls in the selected tab scheme. + /// + private class TabSchemeComparer : IComparer + { + private TabScheme comparisonScheme; + + #region IComparer Members + + public int Compare(object x, object y) + { + Control control1 = x as Control; + Control control2 = y as Control; + + if (control1 == null || control2 == null) + { + Debug.Assert(false, "Attempting to compare a non-control"); + return 0; + } + + if (comparisonScheme == TabScheme.None) + { + // Nothing to do. + return 0; + } + + if (comparisonScheme == TabScheme.AcrossFirst) + { + // The primary direction to sort is the y direction (using the Top property). + // If two controls have the same y coordination, then we sort them by their x's. + if (control1.Top < control2.Top) + { + return -1; + } + else if (control1.Top > control2.Top) + { + return 1; + } + else + { + return (control1.Left.CompareTo(control2.Left)); + } + } + else // comparisonScheme = TabScheme.DownFirst + { + // The primary direction to sort is the x direction (using the Left property). + // If two controls have the same x coordination, then we sort them by their y's. + if (control1.Left < control2.Left) + { + return -1; + } + else if (control1.Left > control2.Left) + { + return 1; + } + else + { + return (control1.Top.CompareTo(control2.Top)); + } + } + } + + #endregion + + /// + /// Create a tab scheme comparer that compares using the given scheme. + /// + /// + public TabSchemeComparer(TabScheme scheme) + { + comparisonScheme = scheme; + } + } + + /// + /// The container whose tab order we manage. + /// + private Control container; + + /// + /// Hash of controls to schemes so that individual containers can have different ordering + /// strategies than their parents. + /// + private Hashtable schemeOverrides; + + /// + /// The tab index we start numbering from when the tab order is applied. + /// + private int curTabIndex = 0; + + /// + /// The general tab-ordering strategy (i.e. whether we tab across rows first, or down columns). + /// + public enum TabScheme + { + None, + AcrossFirst, + DownFirst + } + + /// + /// Constructor + /// + /// The container whose tab order we manage. + public TabOrderManager(Control container) + { + this.container = container; + this.curTabIndex = 0; + this.schemeOverrides = new Hashtable(); + } + + /// + /// Construct a tab order manager that starts numbering at the given tab index. + /// + /// The container whose tab order we manage. + /// Where to start numbering. + /// List of controls with explicitly defined schemes. + private TabOrderManager(Control container, int curTabIndex, Hashtable schemeOverrides) + { + this.container = container; + this.curTabIndex = curTabIndex; + this.schemeOverrides = schemeOverrides; + } + + /// + /// Explicitly set a tab order scheme for a given (presumably container) control. + /// + /// The control to set the scheme for. + /// The requested scheme. + public void SetSchemeForControl(Control c, TabScheme scheme) + { + schemeOverrides[c] = scheme; + } + + /// + /// Recursively set the tab order on this container and all of its children. + /// + /// The tab ordering strategy to apply. + /// The next tab index to be used. + public int SetTabOrder(TabScheme scheme) + { + // Tab order isn't important enough to ever cause a crash, so replace any exceptions + // with assertions. + try + { + ArrayList controlArraySorted = new ArrayList(); + controlArraySorted.AddRange(container.Controls); + controlArraySorted.Sort(new TabSchemeComparer(scheme)); + + foreach (Control c in controlArraySorted) + { + Debug.WriteLine("TabOrderManager: Changing tab index for " + c.Name); + + c.TabIndex = curTabIndex++; + if (c.Controls.Count > 0) + { + // Control has children -- recurse. + TabScheme childScheme = scheme; + if (schemeOverrides.Contains(c)) + { + childScheme = (TabScheme)schemeOverrides[c]; + } + curTabIndex = (new TabOrderManager(c, curTabIndex, schemeOverrides)).SetTabOrder(childScheme); + } + } + + return curTabIndex; + } + catch (Exception e) + { + Debug.Assert(false, "Exception in TabOrderManager.SetTabOrder: " + e.Message); + return 0; + } + } + } +} diff --git a/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.Designer.cs b/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.Designer.cs new file mode 100644 index 0000000..31c5788 --- /dev/null +++ b/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.Designer.cs @@ -0,0 +1,37 @@ + +namespace PinCab.Utils.WinForms.TabOrder +{ + partial class TabSchemeProvider + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.bmp b/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.bmp new file mode 100644 index 0000000000000000000000000000000000000000..28d16e6a932d32bb30a79293d7c3c9fe4d0b4358 GIT binary patch literal 246 zcmaJ)K@Na02&;+59ejrG@a}g!^E4hn;%_{eU;#~*9b`ah%eHO5P;n4e*7DYbISt8P z?emJ!VM3&Uog-A07=~xUJth`UNWq7=O`DmWJyJ=I)M3A09M6x ASpWb4 literal 0 HcmV?d00001 diff --git a/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.cs b/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.cs new file mode 100644 index 0000000..0765d81 --- /dev/null +++ b/PinCab.Utils/WinForms/TabOrder/TabSchemeProvider.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace PinCab.Utils.WinForms.TabOrder +{ + /// + /// Wrap the TabOrderManager class and supply extendee controls with a custom tab scheme. + /// + [ProvideProperty("TabScheme", typeof(Control))] + [Description("Wrap the TabOrderManager class and supply extendee controls with a custom tab scheme")] + [ToolboxBitmap(typeof(TabSchemeProvider), "TabSchemeProvider")] + public partial class TabSchemeProvider : Component, IExtenderProvider + { + + #region MEMBER VARIABLES + + /// + /// Hashtable to store the controls that use our extender property. + /// + private Hashtable extendees = new Hashtable(); + + /// + /// The form we're hosted on, which will be calculated by watching the extendees entering the control hierarchy. + /// + private Form topLevelForm = null; + + #endregion + + #region PUBLIC PROPERTIES + #endregion + + public TabSchemeProvider() + { + InitializeComponent(); + } + + public TabSchemeProvider(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + /// + /// Get whether or not we're managing a given control. + /// + /// + /// + [DefaultValue(TabOrderManager.TabScheme.None)] + public TabOrderManager.TabScheme GetTabScheme(Control c) + { + if (!extendees.Contains(c)) + { + return TabOrderManager.TabScheme.None; + } + + return (TabOrderManager.TabScheme)extendees[c]; + } + + /// + /// Hook up to the form load event and indicate that we've done so. + /// + private void HookFormLoad() + { + if (topLevelForm != null) + { + topLevelForm.Load += new EventHandler(TopLevelForm_Load); + } + } + + /// + /// Unhook from the form load event and indicate that we need to do so again before applying tab schemes. + /// + private void UnhookFormLoad() + { + if (topLevelForm != null) + { + topLevelForm.Load -= new EventHandler(TopLevelForm_Load); + topLevelForm = null; + } + } + + /// + /// Hook up to all of the parent changed events for this control and its ancestors so that we are informed + /// if and when they are added to the top-level form (whose load event we need). + /// It's not adequate to look at just the control, because it may have been added to its parent, but the parent + /// may not be descendent of the form -yet-. + /// + /// + private void HookParentChangedEvents(Control c) + { + while (c != null) + { + c.ParentChanged += new EventHandler(Extendee_ParentChanged); + c = c.Parent; + } + } + + /// + /// Set the tab scheme to use on a given control + /// + /// + /// + public void SetTabScheme(Control c, TabOrderManager.TabScheme val) + { + if (val != TabOrderManager.TabScheme.None) + { + extendees[c] = val; + + if (topLevelForm == null) + { + if (c.TopLevelControl != null) + { + // We're in luck. + // This is the form, or this control knows about it, so take the opportunity to grab it and wire up to its Load event. + topLevelForm = c.TopLevelControl as Form; + HookFormLoad(); + } + else + { + // Set up to wait around until this control or one of its ancestors is added to the form's control hierarchy. + HookParentChangedEvents(c); + } + } + } + else if (extendees.Contains(c)) + { + extendees.Remove(c); + + // If we no longer have any extendees, we don't need to be wired up to the form load event. + if (extendees.Count == 0) + { + UnhookFormLoad(); + } + } + } + + #region IExtenderProvider Members + + public bool CanExtend(object extendee) + { + return (extendee is Form || extendee is Panel || extendee is GroupBox || extendee is UserControl); + } + + #endregion + + private void TopLevelForm_Load(object sender, EventArgs e) + { + Form f = sender as Form; + + Debug.Assert(f != null, "We should never wire up to anything that's not a form."); + + TabOrderManager tom = new TabOrderManager(f); + + // Add an override for everything with a tab scheme set EXCEPT for the form, which + // serves as the root of the whole process. + TabOrderManager.TabScheme formScheme = TabOrderManager.TabScheme.None; + IDictionaryEnumerator extendeeEnumerator = extendees.GetEnumerator(); + while (extendeeEnumerator.MoveNext()) + { + Control c = (Control)extendeeEnumerator.Key; + TabOrderManager.TabScheme scheme = (TabOrderManager.TabScheme)extendeeEnumerator.Value; + if (c == f) + { + formScheme = scheme; + } + else + { + tom.SetSchemeForControl(c, scheme); + } + } + + tom.SetTabOrder(formScheme); + } + + /// + /// We track when each extendee's parent is changed, and also when their parents are changed, until + /// SOMEBODY finally changes their parent to the form, at which point we can hook the load to apply + /// the tab schemes. + /// + /// + /// + private void Extendee_ParentChanged(object sender, EventArgs e) + { + if (topLevelForm != null) + { + // We've already found the form and attached a load event handler, so there's nothing left to do. + return; + } + + Control c = sender as Control; + if (c.TopLevelControl != null && c.TopLevelControl is Form) + { + // We found the form, so we're done. + topLevelForm = c.TopLevelControl as Form; + HookFormLoad(); + } + } + } +} diff --git a/PinCab.Utils/packages.config b/PinCab.Utils/packages.config index 8bc8c43..dddb778 100644 --- a/PinCab.Utils/packages.config +++ b/PinCab.Utils/packages.config @@ -8,6 +8,7 @@ +