mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
minor tweaks to the import form
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -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<ICredentialRepository> GetProvider(Guid id);
|
||||
|
||||
bool Contains(ICredentialRepositoryConfig repositoryConfig);
|
||||
|
||||
IEnumerable<ICredentialRecord> GetCredentialRecords();
|
||||
|
||||
@@ -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<ICredentialRepository> GetProvider(Guid id)
|
||||
{
|
||||
return _credentialProviders
|
||||
.FirstOrDefault(repo => repo.Config.Id.Equals(id))
|
||||
.ToOptional();
|
||||
}
|
||||
|
||||
public bool Contains(ICredentialRepositoryConfig repositoryConfig)
|
||||
{
|
||||
return _credentialProviders.Any(repo =>
|
||||
|
||||
16
mRemoteV1/UI/Forms/CredAndRepoModel.cs
Normal file
16
mRemoteV1/UI/Forms/CredAndRepoModel.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs
generated
42
mRemoteV1/UI/Forms/CredentialImportForm.Designer.cs
generated
@@ -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";
|
||||
|
||||
@@ -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<ICredentialRecord> _credentialRecords;
|
||||
private List<CredAndRepoModel> _importedCredentialRecords;
|
||||
|
||||
public List<ICredentialRecord> CredentialRecords
|
||||
public CredentialService CredentialService { get; set; }
|
||||
public List<ICredentialRecord> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,6 +506,7 @@
|
||||
<Compile Include="UI\Forms\CompositeCredentialRepoUnlockerForm.Designer.cs">
|
||||
<DependentUpon>CompositeCredentialRepoUnlockerForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\Forms\CredAndRepoModel.cs" />
|
||||
<Compile Include="UI\Forms\CredentialImportForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user