mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Using MenuButton in ExportImportControl. FTP accounts using ExportImport control too.
This commit is contained in:
parent
53e519ce62
commit
4707baad1b
7 changed files with 112 additions and 148 deletions
|
@ -31,6 +31,7 @@ You should have received a copy of the GNU General Public License
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Media;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
|
@ -845,5 +846,36 @@ public static Size MeasureText(string text, Font font, int width)
|
|||
return g.MeasureString(text, font, width).ToSize();
|
||||
}
|
||||
}
|
||||
|
||||
public static string SendPing(string host)
|
||||
{
|
||||
return SendPing(host, 1);
|
||||
}
|
||||
|
||||
public static string SendPing(string host, int count)
|
||||
{
|
||||
string[] status = new string[count];
|
||||
|
||||
using (Ping ping = new Ping())
|
||||
{
|
||||
PingReply reply;
|
||||
//byte[] buffer = Encoding.ASCII.GetBytes(new string('a', 32));
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
reply = ping.Send(host, 3000);
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
status[i] = reply.RoundtripTime.ToString() + " ms";
|
||||
}
|
||||
else
|
||||
{
|
||||
status[i] = "Timeout";
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join(", ", status);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,39 +28,18 @@ protected override void Dispose(bool disposing)
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.btnExport = new System.Windows.Forms.Button();
|
||||
this.btnImport = new System.Windows.Forms.Button();
|
||||
this.cmsExport = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.cmsExport = new System.Windows.Forms.ContextMenuStrip();
|
||||
this.tsmiExportClipboard = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tsmiExportFile = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.cmsImport = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.cmsImport = new System.Windows.Forms.ContextMenuStrip();
|
||||
this.tsmiImportClipboard = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.tsmiImportFile = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.btnImport = new HelpersLib.MenuButton();
|
||||
this.btnExport = new HelpersLib.MenuButton();
|
||||
this.cmsExport.SuspendLayout();
|
||||
this.cmsImport.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnExport
|
||||
//
|
||||
this.btnExport.Location = new System.Drawing.Point(0, 0);
|
||||
this.btnExport.Name = "btnExport";
|
||||
this.btnExport.Size = new System.Drawing.Size(64, 24);
|
||||
this.btnExport.TabIndex = 0;
|
||||
this.btnExport.Text = "Export";
|
||||
this.btnExport.UseVisualStyleBackColor = true;
|
||||
this.btnExport.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnExport_MouseUp);
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Location = new System.Drawing.Point(72, 0);
|
||||
this.btnImport.Name = "btnImport";
|
||||
this.btnImport.Size = new System.Drawing.Size(64, 24);
|
||||
this.btnImport.TabIndex = 1;
|
||||
this.btnImport.Text = "Import";
|
||||
this.btnImport.UseVisualStyleBackColor = true;
|
||||
this.btnImport.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnImport_MouseUp);
|
||||
//
|
||||
// cmsExport
|
||||
//
|
||||
this.cmsExport.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
|
@ -107,6 +86,30 @@ private void InitializeComponent()
|
|||
this.tsmiImportFile.Text = "From file...";
|
||||
this.tsmiImportFile.Click += new System.EventHandler(this.tsmiImportFile_Click);
|
||||
//
|
||||
// btnImport
|
||||
//
|
||||
this.btnImport.Location = new System.Drawing.Point(72, 0);
|
||||
this.btnImport.Menu = this.cmsImport;
|
||||
this.btnImport.MenuX0 = true;
|
||||
this.btnImport.Name = "btnImport";
|
||||
this.btnImport.Size = new System.Drawing.Size(64, 24);
|
||||
this.btnImport.TabIndex = 3;
|
||||
this.btnImport.Text = "Import";
|
||||
this.btnImport.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.btnImport.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnExport
|
||||
//
|
||||
this.btnExport.Location = new System.Drawing.Point(0, 0);
|
||||
this.btnExport.Menu = this.cmsExport;
|
||||
this.btnExport.MenuX0 = true;
|
||||
this.btnExport.Name = "btnExport";
|
||||
this.btnExport.Size = new System.Drawing.Size(64, 24);
|
||||
this.btnExport.TabIndex = 2;
|
||||
this.btnExport.Text = "Export";
|
||||
this.btnExport.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.btnExport.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ExportImportControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -123,13 +126,13 @@ private void InitializeComponent()
|
|||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button btnExport;
|
||||
private System.Windows.Forms.Button btnImport;
|
||||
private System.Windows.Forms.ContextMenuStrip cmsExport;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiExportClipboard;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiExportFile;
|
||||
private System.Windows.Forms.ContextMenuStrip cmsImport;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiImportClipboard;
|
||||
private System.Windows.Forms.ToolStripMenuItem tsmiImportFile;
|
||||
private MenuButton btnExport;
|
||||
private MenuButton btnImport;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,16 +54,6 @@ public ExportImportControl()
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnExport_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
cmsExport.Show(btnExport, e.Location);
|
||||
}
|
||||
|
||||
private void btnImport_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
cmsImport.Show(btnImport, e.Location);
|
||||
}
|
||||
|
||||
public string Export(object obj)
|
||||
{
|
||||
if (obj != null)
|
||||
|
|
|
@ -34,13 +34,16 @@ public class MenuButton : Button
|
|||
[DefaultValue(null)]
|
||||
public ContextMenuStrip Menu { get; set; }
|
||||
|
||||
[DefaultValue(false)]
|
||||
public bool MenuX0 { get; set; }
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs mevent)
|
||||
{
|
||||
base.OnMouseDown(mevent);
|
||||
|
||||
if (Menu != null && mevent.Button == MouseButtons.Left)
|
||||
{
|
||||
Menu.Show(this, mevent.Location);
|
||||
Menu.Show(this, MenuX0 ? 0 : mevent.X, this.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
44
UploadersLib/GUI/UploadersConfigForm.Designer.cs
generated
44
UploadersLib/GUI/UploadersConfigForm.Designer.cs
generated
|
@ -128,9 +128,7 @@ private void InitializeComponent()
|
|||
this.txtCopyPath = new System.Windows.Forms.TextBox();
|
||||
this.tpFTP = new System.Windows.Forms.TabPage();
|
||||
this.btnFtpClient = new System.Windows.Forms.Button();
|
||||
this.btnFTPExport = new System.Windows.Forms.Button();
|
||||
this.lblFtpFiles = new System.Windows.Forms.Label();
|
||||
this.btnFTPImport = new System.Windows.Forms.Button();
|
||||
this.lblFtpText = new System.Windows.Forms.Label();
|
||||
this.lblFtpImages = new System.Windows.Forms.Label();
|
||||
this.cboFtpImages = new System.Windows.Forms.ComboBox();
|
||||
|
@ -367,6 +365,7 @@ private void InitializeComponent()
|
|||
this.ucTwitterAccounts = new UploadersLib.AccountsControl();
|
||||
this.ttlvMain = new HelpersLib.TabToListView();
|
||||
this.actRapidShareAccountType = new UploadersLib.GUI.AccountTypeControl();
|
||||
this.eiFTP = new HelpersLib.UserControls.ExportImportControl();
|
||||
this.tpOtherUploaders.SuspendLayout();
|
||||
this.tcOtherUploaders.SuspendLayout();
|
||||
this.tpTwitter.SuspendLayout();
|
||||
|
@ -1442,10 +1441,9 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpFTP
|
||||
//
|
||||
this.tpFTP.Controls.Add(this.eiFTP);
|
||||
this.tpFTP.Controls.Add(this.btnFtpClient);
|
||||
this.tpFTP.Controls.Add(this.btnFTPExport);
|
||||
this.tpFTP.Controls.Add(this.lblFtpFiles);
|
||||
this.tpFTP.Controls.Add(this.btnFTPImport);
|
||||
this.tpFTP.Controls.Add(this.lblFtpText);
|
||||
this.tpFTP.Controls.Add(this.lblFtpImages);
|
||||
this.tpFTP.Controls.Add(this.cboFtpImages);
|
||||
|
@ -1462,7 +1460,7 @@ private void InitializeComponent()
|
|||
//
|
||||
// btnFtpClient
|
||||
//
|
||||
this.btnFtpClient.Location = new System.Drawing.Point(456, 48);
|
||||
this.btnFtpClient.Location = new System.Drawing.Point(584, 48);
|
||||
this.btnFtpClient.Name = "btnFtpClient";
|
||||
this.btnFtpClient.Size = new System.Drawing.Size(64, 24);
|
||||
this.btnFtpClient.TabIndex = 7;
|
||||
|
@ -1470,17 +1468,6 @@ private void InitializeComponent()
|
|||
this.btnFtpClient.UseVisualStyleBackColor = true;
|
||||
this.btnFtpClient.Click += new System.EventHandler(this.btnFtpClient_Click);
|
||||
//
|
||||
// btnFTPExport
|
||||
//
|
||||
this.btnFTPExport.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.btnFTPExport.Location = new System.Drawing.Point(664, 48);
|
||||
this.btnFTPExport.Name = "btnFTPExport";
|
||||
this.btnFTPExport.Size = new System.Drawing.Size(128, 24);
|
||||
this.btnFTPExport.TabIndex = 9;
|
||||
this.btnFTPExport.Text = "Export FTP accounts...";
|
||||
this.btnFTPExport.UseVisualStyleBackColor = true;
|
||||
this.btnFTPExport.Click += new System.EventHandler(this.btnFTPExport_Click);
|
||||
//
|
||||
// lblFtpFiles
|
||||
//
|
||||
this.lblFtpFiles.AutoSize = true;
|
||||
|
@ -1490,17 +1477,6 @@ private void InitializeComponent()
|
|||
this.lblFtpFiles.TabIndex = 4;
|
||||
this.lblFtpFiles.Text = "File:";
|
||||
//
|
||||
// btnFTPImport
|
||||
//
|
||||
this.btnFTPImport.ImeMode = System.Windows.Forms.ImeMode.NoControl;
|
||||
this.btnFTPImport.Location = new System.Drawing.Point(528, 48);
|
||||
this.btnFTPImport.Name = "btnFTPImport";
|
||||
this.btnFTPImport.Size = new System.Drawing.Size(128, 24);
|
||||
this.btnFTPImport.TabIndex = 8;
|
||||
this.btnFTPImport.Text = "Import FTP accounts...";
|
||||
this.btnFTPImport.UseVisualStyleBackColor = true;
|
||||
this.btnFTPImport.Click += new System.EventHandler(this.btnFTPImport_Click);
|
||||
//
|
||||
// lblFtpText
|
||||
//
|
||||
this.lblFtpText.AutoSize = true;
|
||||
|
@ -3932,6 +3908,7 @@ private void InitializeComponent()
|
|||
//
|
||||
this.eiCustomUploaders.Location = new System.Drawing.Point(8, 328);
|
||||
this.eiCustomUploaders.Name = "eiCustomUploaders";
|
||||
this.eiCustomUploaders.ObjectType = null;
|
||||
this.eiCustomUploaders.Size = new System.Drawing.Size(140, 26);
|
||||
this.eiCustomUploaders.TabIndex = 8;
|
||||
this.eiCustomUploaders.ExportRequested += new HelpersLib.UserControls.ExportImportControl.ExportEventHandler(this.eiCustomUploaders_ExportRequested);
|
||||
|
@ -3966,6 +3943,16 @@ private void InitializeComponent()
|
|||
this.actRapidShareAccountType.Size = new System.Drawing.Size(214, 29);
|
||||
this.actRapidShareAccountType.TabIndex = 16;
|
||||
//
|
||||
// eiFTP
|
||||
//
|
||||
this.eiFTP.Location = new System.Drawing.Point(656, 48);
|
||||
this.eiFTP.Name = "eiFTP";
|
||||
this.eiFTP.ObjectType = null;
|
||||
this.eiFTP.Size = new System.Drawing.Size(136, 24);
|
||||
this.eiFTP.TabIndex = 8;
|
||||
this.eiFTP.ExportRequested += new HelpersLib.UserControls.ExportImportControl.ExportEventHandler(this.eiFTP_ExportRequested);
|
||||
this.eiFTP.ImportRequested += new HelpersLib.UserControls.ExportImportControl.ImportEventHandler(this.eiFTP_ImportRequested);
|
||||
//
|
||||
// UploadersConfigForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -4192,9 +4179,7 @@ private void InitializeComponent()
|
|||
|
||||
public System.Windows.Forms.TabPage tpFTP;
|
||||
private System.Windows.Forms.Button btnFtpClient;
|
||||
internal System.Windows.Forms.Button btnFTPExport;
|
||||
private System.Windows.Forms.Label lblFtpFiles;
|
||||
internal System.Windows.Forms.Button btnFTPImport;
|
||||
private System.Windows.Forms.Label lblFtpText;
|
||||
private System.Windows.Forms.Label lblFtpImages;
|
||||
private System.Windows.Forms.ComboBox cboFtpImages;
|
||||
|
@ -4425,5 +4410,6 @@ private void InitializeComponent()
|
|||
private GUI.OAuth2Control oauth2Picasa;
|
||||
public System.Windows.Forms.TabControl tcUploaders;
|
||||
private HelpersLib.UserControls.ExportImportControl eiCustomUploaders;
|
||||
private HelpersLib.UserControls.ExportImportControl eiFTP;
|
||||
}
|
||||
}
|
|
@ -169,6 +169,7 @@ private void FormSettings()
|
|||
ucTwitterAccounts.btnTest.Click += TwitterAccountAuthButton_Click;
|
||||
ucTwitterAccounts.lbAccounts.SelectedIndexChanged += TwitterAccountSelectedIndexChanged;
|
||||
|
||||
eiFTP.ObjectType = typeof(FTPAccount);
|
||||
eiCustomUploaders.ObjectType = typeof(CustomUploaderItem);
|
||||
}
|
||||
|
||||
|
@ -1189,14 +1190,14 @@ private void btnFtpClient_Click(object sender, EventArgs e)
|
|||
FTPOpenClient();
|
||||
}
|
||||
|
||||
private void btnFTPImport_Click(object sender, EventArgs e)
|
||||
private object eiFTP_ExportRequested()
|
||||
{
|
||||
FTPAccountsImport();
|
||||
return GetSelectedFTPAccount();
|
||||
}
|
||||
|
||||
private void btnFTPExport_Click(object sender, EventArgs e)
|
||||
private void eiFTP_ImportRequested(object obj)
|
||||
{
|
||||
FTPAccountsExport();
|
||||
AddFTPAccount(obj as FTPAccount);
|
||||
}
|
||||
|
||||
private void FTPSetup(IEnumerable<FTPAccount> accs)
|
||||
|
@ -1234,10 +1235,7 @@ private void FTPSetup(IEnumerable<FTPAccount> accs)
|
|||
|
||||
private void FTPAccountAddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
FTPAccount acc = new FTPAccount();
|
||||
Config.FTPAccountList.Add(acc);
|
||||
ucFTPAccounts.AddItem(acc);
|
||||
FTPSetup(Config.FTPAccountList);
|
||||
AddFTPAccount(new FTPAccount());
|
||||
}
|
||||
|
||||
private void FTPAccountRemoveButton_Click(object sender, EventArgs e)
|
||||
|
@ -1254,14 +1252,12 @@ private void FTPAccountDuplicateButton_Click(object sender, EventArgs e)
|
|||
{
|
||||
FTPAccount src = (FTPAccount)ucFTPAccounts.lbAccounts.Items[ucFTPAccounts.lbAccounts.SelectedIndex];
|
||||
FTPAccount clone = (FTPAccount)src.Clone();
|
||||
Config.FTPAccountList.Add(clone);
|
||||
ucFTPAccounts.AddItem(clone);
|
||||
FTPSetup(Config.FTPAccountList);
|
||||
AddFTPAccount(clone);
|
||||
}
|
||||
|
||||
private void FTPAccountTestButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TestFTPAccountAsync(Config.FTPAccountList[ucFTPAccounts.lbAccounts.SelectedIndex]);
|
||||
TestFTPAccountAsync(GetSelectedFTPAccount());
|
||||
}
|
||||
|
||||
private void FtpAccountSettingsGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
|
||||
|
|
|
@ -972,6 +972,26 @@ public bool CheckFTPAccounts()
|
|||
return Config.FTPAccountList.IsValidIndex(Config.FTPSelectedImage);
|
||||
}
|
||||
|
||||
public FTPAccount GetSelectedFTPAccount()
|
||||
{
|
||||
if (CheckFTPAccounts())
|
||||
{
|
||||
return Config.FTPAccountList[ucFTPAccounts.lbAccounts.SelectedIndex];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddFTPAccount(FTPAccount account)
|
||||
{
|
||||
if (account != null)
|
||||
{
|
||||
Config.FTPAccountList.Add(account);
|
||||
ucFTPAccounts.AddItem(account);
|
||||
FTPSetup(Config.FTPAccountList);
|
||||
}
|
||||
}
|
||||
|
||||
public void TestFTPAccountAsync(FTPAccount acc)
|
||||
{
|
||||
if (acc != null)
|
||||
|
@ -991,36 +1011,11 @@ public void TestFTPAccountAsync(FTPAccount acc)
|
|||
|
||||
private void FTPOpenClient()
|
||||
{
|
||||
if (CheckFTPAccounts())
|
||||
{
|
||||
new FTPClientForm(Config.FTPAccountList[ucFTPAccounts.lbAccounts.SelectedIndex]).Show();
|
||||
}
|
||||
}
|
||||
FTPAccount account = GetSelectedFTPAccount();
|
||||
|
||||
private void FTPAccountsExport()
|
||||
{
|
||||
if (Config.FTPAccountList != null)
|
||||
if (account != null)
|
||||
{
|
||||
SaveFileDialog dlg = new SaveFileDialog
|
||||
{
|
||||
FileName = string.Format("{0}-{1}-accounts", Application.ProductName, DateTime.Now.ToString("yyyyMMdd")),
|
||||
Filter = "FTP Accounts(*.json)|*.json"
|
||||
};
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
//FTPAccountManager fam = new FTPAccountManager(Config.FTPAccountList);
|
||||
//fam.Save(dlg.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FTPAccountsImport()
|
||||
{
|
||||
OpenFileDialog dlg = new OpenFileDialog { Filter = "FTP Accounts(*.json)|*.json" };
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
//FTPAccountManager fam = FTPAccountManager.Read(dlg.FileName);
|
||||
//FTPSetup(fam.FTPAccounts);
|
||||
new FTPClientForm(account).Show();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1091,47 +1086,6 @@ public static void TestFTPAccount(FTPAccount account)
|
|||
MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
public static string SendPing(string host)
|
||||
{
|
||||
return SendPing(host, 1);
|
||||
}
|
||||
|
||||
public static string SendPing(string host, int count)
|
||||
{
|
||||
string[] status = new string[count];
|
||||
|
||||
using (Ping ping = new Ping())
|
||||
{
|
||||
PingReply reply;
|
||||
//byte[] buffer = Encoding.ASCII.GetBytes(new string('a', 32));
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
reply = ping.Send(host, 3000);
|
||||
if (reply.Status == IPStatus.Success)
|
||||
{
|
||||
status[i] = reply.RoundtripTime.ToString() + " ms";
|
||||
}
|
||||
else
|
||||
{
|
||||
status[i] = "Timeout";
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join(", ", status);
|
||||
}
|
||||
|
||||
public FTPAccount GetFtpAcctActive()
|
||||
{
|
||||
FTPAccount acc = null;
|
||||
if (CheckFTPAccounts())
|
||||
{
|
||||
acc = Config.FTPAccountList[Config.FTPSelectedImage];
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
#endregion FTP
|
||||
|
||||
#region SendSpace
|
||||
|
|
Loading…
Reference in a new issue