ShareX/ShareX.UploadersLib/Controls/AccountsControl.cs

85 lines
2.7 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2017-01-11 21:39:40 +13:00
Copyright (c) 2007-2017 ShareX Team
2013-11-03 23:53:49 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib;
2013-11-03 23:53:49 +13:00
using System;
using System.Windows.Forms;
2014-12-11 09:25:20 +13:00
namespace ShareX.UploadersLib
2013-11-03 23:53:49 +13:00
{
public partial class AccountsControl : UserControl
{
public AccountsControl()
{
InitializeComponent();
}
2014-04-30 21:46:15 +12:00
public void AddItem(object item)
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
lbAccounts.Items.Add(item);
lbAccounts.SelectedIndex = lbAccounts.Items.Count - 1;
}
public bool RemoveItem(int selected)
{
if (selected.IsBetween(0, lbAccounts.Items.Count - 1))
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
lbAccounts.Items.RemoveAt(selected);
2013-11-03 23:53:49 +13:00
2014-04-30 21:46:15 +12:00
if (lbAccounts.Items.Count > 0)
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
lbAccounts.SelectedIndex = selected == lbAccounts.Items.Count ? lbAccounts.Items.Count - 1 : selected;
pgSettings.SelectedObject = lbAccounts.Items[lbAccounts.SelectedIndex];
2013-11-03 23:53:49 +13:00
}
else
{
2014-04-30 21:46:15 +12:00
pgSettings.SelectedObject = null;
2013-11-03 23:53:49 +13:00
}
2014-04-30 21:46:15 +12:00
2013-11-03 23:53:49 +13:00
return true;
}
return false;
}
2014-04-30 21:46:15 +12:00
private void pgSettings_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
if (lbAccounts.SelectedIndex > -1)
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
lbAccounts.Items[lbAccounts.SelectedIndex] = pgSettings.SelectedObject;
2013-11-03 23:53:49 +13:00
}
}
2014-04-30 21:46:15 +12:00
private void lbAccounts_SelectedIndexChanged(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
2014-04-30 21:46:15 +12:00
btnRemove.Enabled = btnDuplicate.Enabled = btnTest.Enabled = lbAccounts.SelectedIndex > -1;
if (lbAccounts.SelectedIndex > -1)
{
pgSettings.SelectedObject = lbAccounts.Items[lbAccounts.SelectedIndex];
}
2013-11-03 23:53:49 +13:00
}
}
}