private void DeleteAuthTokenButton_Click(object sender, EventArgs e) { if (AuthTokensListBox.SelectedItem != null) { string item = AuthTokensListBox.SelectedItem as string; string host = item?.Split('|')[0].Trim(); Win32Registry.SetAuthToken(host, null); RefreshAuthTokensListBox(); DeleteRepoButton.Enabled = false; } }
private void NewAuthTokenButton_Click(object sender, EventArgs e) { // Inspired by https://stackoverflow.com/a/17546909/2422988 Form newAuthTokenPopup = new Form() { FormBorderStyle = FormBorderStyle.FixedToolWindow, StartPosition = FormStartPosition.CenterParent, ClientSize = new Size(300, 100), Text = "Add Authentication Token" }; Label hostLabel = new Label() { AutoSize = true, Location = new Point(3, 6), Size = new Size(271, 13), Text = "Host:" }; TextBox hostTextBox = new TextBox() { Location = new Point(45, 6), Size = new Size(newAuthTokenPopup.ClientSize.Width - 40 - 10, 23), Text = "" }; Label tokenLabel = new Label() { AutoSize = true, Location = new Point(3, 35), Size = new Size(271, 13), Text = "Token:" }; TextBox tokenTextBox = new TextBox() { Location = new Point(45, 35), Size = new Size(newAuthTokenPopup.ClientSize.Width - 40 - 10, 23), Text = "" }; Button acceptButton = new Button() { DialogResult = DialogResult.OK, Name = "okButton", Size = new Size(75, 23), Text = "&Accept", Location = new Point((newAuthTokenPopup.ClientSize.Width - 80 - 80) / 2, 64) }; acceptButton.Click += (origin, evt) => { newAuthTokenPopup.DialogResult = validNewAuthToken(hostTextBox.Text, tokenTextBox.Text) ? DialogResult.OK : DialogResult.None; }; Button cancelButton = new Button() { DialogResult = DialogResult.Cancel, Name = "cancelButton", Size = new Size(75, 23), Text = "&Cancel", Location = new Point(acceptButton.Location.X + acceptButton.Size.Width + 5, 64) }; newAuthTokenPopup.Controls.Add(hostLabel); newAuthTokenPopup.Controls.Add(hostTextBox); newAuthTokenPopup.Controls.Add(tokenLabel); newAuthTokenPopup.Controls.Add(tokenTextBox); newAuthTokenPopup.Controls.Add(acceptButton); newAuthTokenPopup.Controls.Add(cancelButton); newAuthTokenPopup.AcceptButton = acceptButton; newAuthTokenPopup.CancelButton = cancelButton; switch (newAuthTokenPopup.ShowDialog(this)) { case DialogResult.Abort: case DialogResult.Cancel: case DialogResult.Ignore: case DialogResult.No: // User cancelled out, so do nothing break; case DialogResult.OK: case DialogResult.Yes: Win32Registry.SetAuthToken(hostTextBox.Text, tokenTextBox.Text); RefreshAuthTokensListBox(); break; } }