2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2019-09-16 08:51:25 +00:00
|
|
|
|
/// Copyright (c) 2013-2015 Senus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using System.Windows.Forms;
|
2015-12-04 16:17:20 +00:00
|
|
|
|
using Config.Entities;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
using TBF.Resources;
|
|
|
|
|
|
|
2019-09-16 08:51:25 +00:00
|
|
|
|
namespace TBF.UI.Shared
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
public partial class SharedButtons : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Masks to specify the enabled state and the visibility of buttons.
|
|
|
|
|
|
/// Unlock button is hard coded in this control, cannot be set from the parent.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum Buttons
|
|
|
|
|
|
{
|
|
|
|
|
|
None = 0,
|
2019-01-25 11:52:05 +00:00
|
|
|
|
Add = (1 << 0), /// optional
|
|
|
|
|
|
Remove = (1 << 1), /// optional
|
|
|
|
|
|
Up = (1 << 2), /// optional
|
|
|
|
|
|
Down = (1 << 3), /// optional
|
|
|
|
|
|
Edit = (1 << 4), /// optional
|
|
|
|
|
|
Copy = (1 << 5), /// optional
|
|
|
|
|
|
Export = (1 << 6), /// optional
|
|
|
|
|
|
Import = (1 << 7), /// optional
|
|
|
|
|
|
Compare = (1 << 8), /// optional
|
|
|
|
|
|
NewTab = (1 << 9), /// optional
|
|
|
|
|
|
RenameTab = (1 << 10), /// optional
|
|
|
|
|
|
RemoveTab = (1 << 11), /// optional
|
|
|
|
|
|
More = (1 << 12), /// optional
|
2019-10-01 11:45:21 +00:00
|
|
|
|
Custom1 = (1 << 13), /// optional
|
|
|
|
|
|
Custom2 = (1 << 14), /// optional
|
|
|
|
|
|
Custom3 = (1 << 15), /// optional
|
2017-03-31 16:14:21 +00:00
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2019-01-25 11:52:05 +00:00
|
|
|
|
readonly System.Windows.Forms.Button[] buttonCtrls;
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Optional buttons are Add, Remove, Up, Down, Edit and Copy.
|
|
|
|
|
|
/// OK and Cancel buttons are always visible (after unlock), but not always enabled.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Buttons OptionalButtons;
|
|
|
|
|
|
|
2019-10-01 11:45:21 +00:00
|
|
|
|
public string Custom1Caption { set { customButton1.Text = value; } }
|
|
|
|
|
|
public string Custom2Caption { set { customButton2.Text = value; } }
|
|
|
|
|
|
public string Custom3Caption { set { customButton3.Text = value; } }
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
public enum LockState
|
|
|
|
|
|
{
|
|
|
|
|
|
Locked, /// 'Unlock', 'Close' (=OK) are shown, all the othere are hidden
|
|
|
|
|
|
Unlocked, /// Unlock, Ok, Cancel, Add,Remove and all optional buttons are shown
|
|
|
|
|
|
}
|
|
|
|
|
|
LockState lockState;
|
|
|
|
|
|
|
2019-01-25 11:52:05 +00:00
|
|
|
|
bool buttonsRepositionsed;
|
|
|
|
|
|
|
2015-01-02 22:42:01 +00:00
|
|
|
|
public bool MoreActive;
|
2016-08-01 09:22:59 +00:00
|
|
|
|
public int MoreButtonTop;
|
2015-01-02 22:42:01 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used by controls to indicate which item is selected
|
|
|
|
|
|
/// and to appropriately update Remove, Up and Down Buttons.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public enum SelectedItemPos
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
First,
|
|
|
|
|
|
Last,
|
|
|
|
|
|
FirstAndLast,
|
|
|
|
|
|
Middle,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-09-24 12:15:04 +00:00
|
|
|
|
public Users.Grp.GID[] RequiredGroupMembership;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2017-09-26 05:52:48 +00:00
|
|
|
|
Users.Entities.User originalUser;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Default constructor
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public SharedButtons()
|
|
|
|
|
|
{
|
2019-01-25 11:52:05 +00:00
|
|
|
|
InitializeComponent();
|
2017-03-16 20:53:12 +00:00
|
|
|
|
originalUser = Users.GlobalData.CurrentUser;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
lockState = LockState.Locked;
|
2015-01-02 22:42:01 +00:00
|
|
|
|
MoreActive = false;
|
2018-09-24 12:15:04 +00:00
|
|
|
|
RequiredGroupMembership = null;
|
2019-01-25 11:52:05 +00:00
|
|
|
|
buttonCtrls = new System.Windows.Forms.Button[]
|
|
|
|
|
|
{
|
|
|
|
|
|
addButton, removeButton, upButton, downButton, editButton, copyButton,
|
|
|
|
|
|
exportButton, importButton, compareButton,
|
|
|
|
|
|
newTabButton, renameTabButton, removeTabButton, moreButton,
|
2019-10-01 11:45:21 +00:00
|
|
|
|
customButton1, customButton2, customButton3,
|
2019-01-25 11:52:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
OptionalButtons = Buttons.None;
|
|
|
|
|
|
buttonsRepositionsed = false;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initialize the buttons when the dialog is loaded
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
private void SharedDlgButtons_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
unlockButton.Text = Strings.UnlockBtnText;
|
|
|
|
|
|
okButton.Text = Strings.CloseBtnText;
|
|
|
|
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
|
|
addButton.Text = Strings.AddBtnText;
|
|
|
|
|
|
removeButton.Text = Strings.RemoveBtnText;
|
|
|
|
|
|
upButton.Text = Strings.UpBtnText;
|
|
|
|
|
|
downButton.Text = Strings.DownBtnText;
|
|
|
|
|
|
editButton.Text = Strings.EditBtnText;
|
|
|
|
|
|
copyButton.Text = Strings.CopyBtnText;
|
2019-01-25 11:52:05 +00:00
|
|
|
|
exportButton.Text = Strings.Export;
|
|
|
|
|
|
importButton.Text = Strings.Import;
|
|
|
|
|
|
compareButton.Text = Strings.Compare;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
newTabButton.Text = Strings.NewTabBtnText;
|
|
|
|
|
|
renameTabButton.Text = Strings.RenameTabBtnText;
|
|
|
|
|
|
removeTabButton.Text = Strings.RemoveTabBtnText;
|
2015-01-02 22:42:01 +00:00
|
|
|
|
moreButton.Text = Strings.MoreBtnText;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
cancelButton.Hide();
|
2019-01-25 11:52:05 +00:00
|
|
|
|
ShowOrHideButtons((Buttons)0x7FFFFFFF, false);
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-01-25 11:52:05 +00:00
|
|
|
|
void RepositionButtons(Buttons enabledButtons)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!buttonsRepositionsed)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttonsRepositionsed = true; /// Reposition buttons once
|
|
|
|
|
|
|
|
|
|
|
|
int spacing = unlockButton.Height + 3;
|
|
|
|
|
|
const int ExtraSpacing = 15;
|
|
|
|
|
|
int nextTop = cancelButton.Top + spacing + ExtraSpacing;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < buttonCtrls.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Buttons btn = (Buttons)(1 << i);
|
|
|
|
|
|
if ((OptionalButtons & btn) != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
buttonCtrls[i].Top = nextTop;
|
|
|
|
|
|
nextTop += spacing + ((btn == Buttons.Down || btn == Buttons.Compare || btn == Buttons.RemoveTab) ? ExtraSpacing : 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShowOrHideButtons(Buttons selectedButtons, bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < buttonCtrls.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((selectedButtons & (Buttons)(1 << i)) != 0) buttonCtrls[i].Visible = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EnableOrDisableButtons(Buttons selectedButtons, bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < buttonCtrls.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((selectedButtons & (Buttons)(1 << i)) != 0) buttonCtrls[i].Enabled = value;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-25 11:52:05 +00:00
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Update the visibility of buttons and OK button text when the dialog is unlocked
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void UnlockButtons()
|
|
|
|
|
|
{
|
2019-01-25 11:52:05 +00:00
|
|
|
|
RepositionButtons(OptionalButtons);
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
unlockButton.Enabled = false;
|
|
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
2019-01-25 11:52:05 +00:00
|
|
|
|
cancelButton.Visible = true;
|
|
|
|
|
|
ShowOrHideButtons(OptionalButtons, true);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
lockState = LockState.Unlocked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Enable specified buttons
|
|
|
|
|
|
/// </summary>
|
2019-01-25 11:52:05 +00:00
|
|
|
|
public void EnableButtons(Buttons selectedButtons)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2019-01-25 11:52:05 +00:00
|
|
|
|
EnableOrDisableButtons(selectedButtons, true);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Disable specified buttons
|
|
|
|
|
|
/// </summary>
|
2019-01-25 11:52:05 +00:00
|
|
|
|
public void DisableButtons(Buttons selectedButtons)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2019-01-25 11:52:05 +00:00
|
|
|
|
EnableOrDisableButtons(selectedButtons, false);
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RestoreUser()
|
|
|
|
|
|
{
|
2017-03-16 20:53:12 +00:00
|
|
|
|
Users.GlobalData.CurrentUser = originalUser;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
Program.MainWnd.UpdateUser();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Events invoked when buttons are clicked (and in case of Unlock kbutton also accepted)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public event EventHandler Unlocked;
|
|
|
|
|
|
public event EventHandler OKClicked;
|
|
|
|
|
|
public event EventHandler CancelClicked;
|
|
|
|
|
|
public event EventHandler AddClicked;
|
|
|
|
|
|
public event EventHandler RemoveClicked;
|
|
|
|
|
|
public event EventHandler UpClicked;
|
|
|
|
|
|
public event EventHandler DownClicked;
|
|
|
|
|
|
public event EventHandler EditClicked;
|
|
|
|
|
|
public event EventHandler CopyClicked;
|
|
|
|
|
|
public event EventHandler NewTabClicked;
|
|
|
|
|
|
public event EventHandler RenameTabClicked;
|
|
|
|
|
|
public event EventHandler RemoveTabClicked;
|
2017-03-31 16:14:21 +00:00
|
|
|
|
public event EventHandler ExportClicked;
|
|
|
|
|
|
public event EventHandler ImportClicked;
|
2017-07-14 14:28:18 +00:00
|
|
|
|
public event EventHandler CompareClicked;
|
2019-10-01 11:45:21 +00:00
|
|
|
|
public event EventHandler MoreClicked;
|
|
|
|
|
|
public event EventHandler Custom1Clicked;
|
|
|
|
|
|
public event EventHandler Custom2Clicked;
|
|
|
|
|
|
public event EventHandler Custom3Clicked;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 'Unlock' button handler
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
2015-08-13 06:36:28 +00:00
|
|
|
|
public void unlockBtn_Click(object sender, EventArgs e)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (lockState == LockState.Locked)
|
|
|
|
|
|
{
|
2017-03-16 20:53:12 +00:00
|
|
|
|
if (!Users.GlobalData.CurrentUser.IsMemberOf(RequiredGroupMembership))
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2017-03-15 11:56:53 +00:00
|
|
|
|
if ((new Users.Forms.LoginDlg(RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
|
|
|
|
|
return;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (Program.LocalSettings.AlwaysAskPasswdWhenUnlocking)
|
|
|
|
|
|
{
|
2017-03-16 20:53:12 +00:00
|
|
|
|
if ((new Users.Forms.LoginDlg(Users.GlobalData.CurrentUser.UserName, RequiredGroupMembership)).ShowDialog() != DialogResult.OK)
|
2017-03-15 11:56:53 +00:00
|
|
|
|
return;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-15 11:56:53 +00:00
|
|
|
|
if (Program.MainWnd != null) Program.MainWnd.UpdateUser();
|
|
|
|
|
|
|
|
|
|
|
|
UnlockButtons();
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
|
|
|
|
|
if (Unlocked != null) Unlocked(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 'OK'/'Close' button handler. Handled as 'Cancel' in the locked state ('Close' button).
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void okBtn_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lockState == LockState.Locked)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CancelClicked != null) CancelClicked(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OKClicked != null) OKClicked(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-02 22:42:01 +00:00
|
|
|
|
private void moreButton_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (MoreActive)
|
|
|
|
|
|
{
|
|
|
|
|
|
MoreActive = false;
|
|
|
|
|
|
moreButton.Text = Strings.MoreBtnText;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MoreActive = true;
|
|
|
|
|
|
moreButton.Text = Strings.LessBtnText;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (MoreClicked != null) MoreClicked(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 07:54:35 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// All remaining handlers:
|
|
|
|
|
|
///
|
2017-07-14 14:28:18 +00:00
|
|
|
|
private void cancelBtn_Click(object s, EventArgs e) { if (CancelClicked != null) CancelClicked(s, e); }
|
|
|
|
|
|
private void addBtn_Click(object s, EventArgs e) { if (AddClicked != null) AddClicked(s, e); }
|
|
|
|
|
|
private void removeBtn_Click(object s, EventArgs e) { if (RemoveClicked != null) RemoveClicked(s, e); }
|
|
|
|
|
|
private void upBtn_Click(object s, EventArgs e) { if (UpClicked != null) UpClicked(s, e); }
|
|
|
|
|
|
private void downBtn_Click(object s, EventArgs e) { if (DownClicked != null) DownClicked(s, e); }
|
|
|
|
|
|
private void editBtn_Click(object s, EventArgs e) { if (EditClicked != null) EditClicked(s, e); }
|
|
|
|
|
|
private void copyBtn_Click(object s, EventArgs e) { if (CopyClicked != null) CopyClicked(s, e); }
|
|
|
|
|
|
private void exportButton_Click(object s, EventArgs e) { if (ExportClicked != null) ExportClicked(s, e); }
|
|
|
|
|
|
private void importButton_Click(object s, EventArgs e) { if (ImportClicked != null) ImportClicked(s, e); }
|
|
|
|
|
|
private void compareButton_Click(object s, EventArgs e) { if (CompareClicked != null) CompareClicked(s, e); }
|
2019-01-25 11:52:05 +00:00
|
|
|
|
private void newTabButton_Click(object s, EventArgs e) { if (NewTabClicked != null) NewTabClicked(s, e); }
|
|
|
|
|
|
private void renameTabButton_Click(object s, EventArgs e) { if (RenameTabClicked != null) RenameTabClicked(s, e); }
|
|
|
|
|
|
private void removeTabButton_Click(object s, EventArgs e) { if (RemoveTabClicked != null) RemoveTabClicked(s, e); }
|
2019-10-01 11:45:21 +00:00
|
|
|
|
private void customButton1_Click(object s, EventArgs e) { if (Custom1Clicked != null) Custom1Clicked(s, e); }
|
|
|
|
|
|
private void customButton2_Click(object s, EventArgs e) { if (Custom2Clicked != null) Custom2Clicked(s, e); }
|
|
|
|
|
|
private void customButton3_Click(object s, EventArgs e) { if (Custom3Clicked != null) Custom3Clicked(s, e); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|