From 89bb4d45b3434631dea6a98f259459636c709802 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sun, 27 Jan 2019 16:58:39 -0600 Subject: [PATCH] minor tweaks to the import form --- .../Config/Import/MRemoteNGCsvImporter.cs | 3 +- .../Credential/ICredentialRepositoryList.cs | 3 + .../Repositories/CredentialRepositoryList.cs | 8 +++ mRemoteV1/UI/Forms/CredAndRepoModel.cs | 16 +++++ .../UI/Forms/CredentialImportForm.Designer.cs | 42 +++++------ mRemoteV1/UI/Forms/CredentialImportForm.cs | 69 ++++++++++++++++--- mRemoteV1/mRemoteV1.csproj | 1 + 7 files changed, 112 insertions(+), 30 deletions(-) create mode 100644 mRemoteV1/UI/Forms/CredAndRepoModel.cs diff --git a/mRemoteV1/Config/Import/MRemoteNGCsvImporter.cs b/mRemoteV1/Config/Import/MRemoteNGCsvImporter.cs index a9831b78..3fe15c2f 100644 --- a/mRemoteV1/Config/Import/MRemoteNGCsvImporter.cs +++ b/mRemoteV1/Config/Import/MRemoteNGCsvImporter.cs @@ -29,7 +29,8 @@ namespace mRemoteNG.Config.Import var credentialImportForm = new CredentialImportForm { - CredentialRecords = serializationResult.ConnectionToCredentialMap.DistinctCredentialRecords.ToList() + ImportedCredentialRecords = serializationResult.ConnectionToCredentialMap.DistinctCredentialRecords.ToList(), + CredentialService = Runtime.CredentialService }; credentialImportForm.ShowDialog(); diff --git a/mRemoteV1/Credential/ICredentialRepositoryList.cs b/mRemoteV1/Credential/ICredentialRepositoryList.cs index 04c4ae51..f8a63b95 100644 --- a/mRemoteV1/Credential/ICredentialRepositoryList.cs +++ b/mRemoteV1/Credential/ICredentialRepositoryList.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using mRemoteNG.Credential.Repositories; +using mRemoteNG.Tools; using mRemoteNG.Tools.CustomCollections; namespace mRemoteNG.Credential @@ -13,6 +14,8 @@ namespace mRemoteNG.Credential void RemoveProvider(ICredentialRepository credentialProvider); + Optional GetProvider(Guid id); + bool Contains(ICredentialRepositoryConfig repositoryConfig); IEnumerable GetCredentialRecords(); diff --git a/mRemoteV1/Credential/Repositories/CredentialRepositoryList.cs b/mRemoteV1/Credential/Repositories/CredentialRepositoryList.cs index 51b5223d..87552e0d 100644 --- a/mRemoteV1/Credential/Repositories/CredentialRepositoryList.cs +++ b/mRemoteV1/Credential/Repositories/CredentialRepositoryList.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using mRemoteNG.Tools; using mRemoteNG.Tools.CustomCollections; namespace mRemoteNG.Credential.Repositories @@ -35,6 +36,13 @@ namespace mRemoteNG.Credential.Repositories RaiseRepositoriesUpdatedEvent(ActionType.Removed, new[] { credentialProvider }); } + public Optional GetProvider(Guid id) + { + return _credentialProviders + .FirstOrDefault(repo => repo.Config.Id.Equals(id)) + .ToOptional(); + } + public bool Contains(ICredentialRepositoryConfig repositoryConfig) { return _credentialProviders.Any(repo => diff --git a/mRemoteV1/UI/Forms/CredAndRepoModel.cs b/mRemoteV1/UI/Forms/CredAndRepoModel.cs new file mode 100644 index 00000000..83024475 --- /dev/null +++ b/mRemoteV1/UI/Forms/CredAndRepoModel.cs @@ -0,0 +1,16 @@ +using mRemoteNG.Credential; + +namespace mRemoteNG.UI.Forms +{ + public class CredAndRepoModel + { + public ICredentialRecord CredentialRecord { get; set; } + + public ICredentialRepository AssignedRepository { get; set; } + + public CredAndRepoModel(ICredentialRecord credentialRecord) + { + CredentialRecord = credentialRecord; + } + } +} diff --git a/mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs b/mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs index c2065ae6..21967b3f 100644 --- a/mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs +++ b/mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs @@ -29,10 +29,10 @@ private void InitializeComponent() { this.olvCredentials = new BrightIdeasSoftware.ObjectListView(); - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.colUsername = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.colDomain = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.colRepo = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.buttonAccept = new mRemoteNG.UI.Controls.Base.NGButton(); ((System.ComponentModel.ISupportInitialize)(this.olvCredentials)).BeginInit(); this.tableLayoutPanel1.SuspendLayout(); @@ -43,6 +43,8 @@ this.olvCredentials.AllColumns.Add(this.colUsername); this.olvCredentials.AllColumns.Add(this.colDomain); this.olvCredentials.AllColumns.Add(this.colRepo); + this.olvCredentials.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick; + this.olvCredentials.CellEditUseWholeCell = false; this.olvCredentials.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.colUsername, this.colDomain, @@ -54,27 +56,11 @@ this.olvCredentials.Location = new System.Drawing.Point(3, 3); this.olvCredentials.Name = "olvCredentials"; this.olvCredentials.ShowGroups = false; - this.olvCredentials.Size = new System.Drawing.Size(794, 399); + this.olvCredentials.Size = new System.Drawing.Size(408, 296); this.olvCredentials.TabIndex = 0; this.olvCredentials.UseCompatibleStateImageBehavior = false; this.olvCredentials.View = System.Windows.Forms.View.Details; // - // tableLayoutPanel1 - // - this.tableLayoutPanel1.ColumnCount = 2; - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 80F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); - this.tableLayoutPanel1.Controls.Add(this.olvCredentials, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.buttonAccept, 1, 1); - this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 2; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 90F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(800, 450); - this.tableLayoutPanel1.TabIndex = 1; - // // colUsername // this.colUsername.Text = "Username"; @@ -88,11 +74,27 @@ this.colRepo.FillsFreeSpace = true; this.colRepo.Text = "Repository"; // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 80F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F)); + this.tableLayoutPanel1.Controls.Add(this.olvCredentials, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.buttonAccept, 1, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(414, 331); + this.tableLayoutPanel1.TabIndex = 1; + // // buttonAccept // this.buttonAccept._mice = mRemoteNG.UI.Controls.Base.NGButton.MouseState.HOVER; this.buttonAccept.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAccept.Location = new System.Drawing.Point(722, 424); + this.buttonAccept.Location = new System.Drawing.Point(336, 305); this.buttonAccept.Name = "buttonAccept"; this.buttonAccept.Size = new System.Drawing.Size(75, 23); this.buttonAccept.TabIndex = 1; @@ -104,7 +106,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(414, 331); this.Controls.Add(this.tableLayoutPanel1); this.Name = "CredentialImportForm"; this.Text = "CredentialImportForm"; diff --git a/mRemoteV1/UI/Forms/CredentialImportForm.cs b/mRemoteV1/UI/Forms/CredentialImportForm.cs index f4ed3f81..b333f2c4 100644 --- a/mRemoteV1/UI/Forms/CredentialImportForm.cs +++ b/mRemoteV1/UI/Forms/CredentialImportForm.cs @@ -1,20 +1,24 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; +using BrightIdeasSoftware; using mRemoteNG.Credential; namespace mRemoteNG.UI.Forms { public partial class CredentialImportForm : Form { - private List _credentialRecords; + private List _importedCredentialRecords; - public List CredentialRecords + public CredentialService CredentialService { get; set; } + public List ImportedCredentialRecords { - get => _credentialRecords; + get => _importedCredentialRecords.Select(model => model.CredentialRecord).ToList(); set { - _credentialRecords = value; - olvCredentials.SetObjects(_credentialRecords); + _importedCredentialRecords = value.Select(r => new CredAndRepoModel(r)).ToList(); + olvCredentials.SetObjects(_importedCredentialRecords); } } @@ -22,13 +26,60 @@ namespace mRemoteNG.UI.Forms { InitializeComponent(); - colUsername.AspectName = nameof(ICredentialRecord.Username); - colDomain.AspectName = nameof(ICredentialRecord.Domain); + olvCredentials.CellEditStarting += OlvCredentialsOnCellEditStarting; + olvCredentials.CellEditFinishing += OlvCredentialsOnCellEditFinishing; + colUsername.AspectGetter = rowObject => (rowObject as CredAndRepoModel)?.CredentialRecord?.Username; + colDomain.AspectGetter = rowObject => (rowObject as CredAndRepoModel)?.CredentialRecord?.Domain; + colRepo.AspectGetter = rowObject => (rowObject as CredAndRepoModel)?.AssignedRepository?.Title; + } + + private void OlvCredentialsOnCellEditFinishing(object sender, CellEditEventArgs e) + { + //if (e.Column != colRepo) + // return; + + //if ((e.Control as ComboBox)?.SelectedValue is Guid repoId) + // e.NewValue = CredentialService.RepositoryList.GetProvider(repoId).FirstOrDefault(); + } + + private void OlvCredentialsOnCellEditStarting(object sender, CellEditEventArgs e) + { + if (e.Column != colRepo) + return; + + e.Control = CreateRepoListDropdownControl(e); + } + + private Control CreateRepoListDropdownControl(CellEditEventArgs e) + { + var comboBox = new ComboBox + { + Bounds = e.CellBounds, + Left = e.CellBounds.Left + 1, + Width = e.CellBounds.Width - 1, + DropDownStyle = ComboBoxStyle.DropDownList, + DisplayMember = nameof(ICredentialRepository.Config.Title), + ValueMember = nameof(ICredentialRepository.Config.Id), + DataSource = CredentialService.RepositoryList.ToList(), + AutoCompleteSource = AutoCompleteSource.ListItems, + AutoCompleteMode = AutoCompleteMode.SuggestAppend + }; + + comboBox.Update(); + return comboBox; + } + + private void AddCredentialsToAssignedRepos() + { + foreach (var importedCred in _importedCredentialRecords) + { + importedCred.AssignedRepository.CredentialRecords.Add(importedCred.CredentialRecord); + } } private void buttonAccept_Click(object sender, System.EventArgs e) { - + AddCredentialsToAssignedRepos(); } } } diff --git a/mRemoteV1/mRemoteV1.csproj b/mRemoteV1/mRemoteV1.csproj index 333ca6fc..dedfb180 100644 --- a/mRemoteV1/mRemoteV1.csproj +++ b/mRemoteV1/mRemoteV1.csproj @@ -506,6 +506,7 @@ CompositeCredentialRepoUnlockerForm.cs + Form