Skip to content

Commit

Permalink
add initial focus to filename, save on enter #9
Browse files Browse the repository at this point in the history
  • Loading branch information
EslaMx7 committed Sep 19, 2018
1 parent b852390 commit ac8c9fb
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 141 deletions.
31 changes: 16 additions & 15 deletions PasteIntoFile/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

260 changes: 134 additions & 126 deletions PasteIntoFile/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,130 +15,138 @@

namespace PasteAsFile
{
public partial class frmMain : Form
{
public string CurrentLocation { get; set; }
public bool IsText { get; set; }
public frmMain()
{
InitializeComponent();
}
public frmMain(string location)
{
InitializeComponent();
this.CurrentLocation = location;
}
private void frmMain_Load(object sender, EventArgs e)
{
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";

if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null)
{
if (MessageBox.Show("Seems that you are running this application for the first time,\nDo you want to Register it with your system Context Menu ?", "Paste Into File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Program.RegisterApp();
}
}

if (Clipboard.ContainsText())
{
lblType.Text = "Text File";
comExt.SelectedItem = "txt";
IsText = true;
txtContent.Text = Clipboard.GetText();
return;
}

if (Clipboard.ContainsImage())
{
lblType.Text = "Image";
comExt.SelectedItem = "png";
imgContent.Image = Clipboard.GetImage();
return;
}

lblType.Text = "Unknown File";
btnSave.Enabled = false;


}

private void btnSave_Click(object sender, EventArgs e)
{
string location = txtCurrentLocation.Text;
location = location.EndsWith("\\") ? location : location + "\\";
string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString() ;
if (IsText)
{

File.WriteAllText(location+filename,txtContent.Text,Encoding.UTF8);
this.Text += " : File Saved :)";
}
else
{
switch (comExt.SelectedItem.ToString())
{
case "png":
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
case "ico":
imgContent.Image.Save(location + filename, ImageFormat.Icon);
break;
case "jpg":
imgContent.Image.Save(location + filename, ImageFormat.Jpeg);
break;
case "bmp":
imgContent.Image.Save(location + filename, ImageFormat.Bmp);
break;
case "gif":
imgContent.Image.Save(location + filename, ImageFormat.Gif);
break;
default:
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
}

this.Text += " : Image Saved :)";
}

Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
Environment.Exit(0);
});
}

private void btnBrowseForFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select a folder for saving this file ";
if (fbd.ShowDialog() == DialogResult.OK)
{
txtCurrentLocation.Text = fbd.SelectedPath;
}
}

private void lblWebsite_Click(object sender, EventArgs e)
{
Process.Start("http://eslamx.com");
}

private void lblMe_Click(object sender, EventArgs e)
{
Process.Start("http://twitter.com/EslaMx7");
}

private void lblHelp_Click(object sender, EventArgs e)
{
string msg = "Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself";
msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg";
msg += "\nto Unregister the application use this argument : /unreg\n";
msg += "\n--------------------\nSend Feedback to : [email protected]\n\nThanks :)";
MessageBox.Show(msg,"Paste As File Help",MessageBoxButtons.OK,MessageBoxIcon.Information);



}
}
public partial class frmMain : Form
{
public string CurrentLocation { get; set; }
public bool IsText { get; set; }
public frmMain()
{
InitializeComponent();
}
public frmMain(string location)
{
InitializeComponent();
this.CurrentLocation = location;
}
private void frmMain_Load(object sender, EventArgs e)
{
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";

if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null)
{
if (MessageBox.Show("Seems that you are running this application for the first time,\nDo you want to Register it with your system Context Menu ?", "Paste Into File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Program.RegisterApp();
}
}

if (Clipboard.ContainsText())
{
lblType.Text = "Text File";
comExt.SelectedItem = "txt";
IsText = true;
txtContent.Text = Clipboard.GetText();
return;
}

if (Clipboard.ContainsImage())
{
lblType.Text = "Image";
comExt.SelectedItem = "png";
imgContent.Image = Clipboard.GetImage();
return;
}

lblType.Text = "Unknown File";
btnSave.Enabled = false;


}

private void btnSave_Click(object sender, EventArgs e)
{
string location = txtCurrentLocation.Text;
location = location.EndsWith("\\") ? location : location + "\\";
string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString();
if (IsText)
{

File.WriteAllText(location + filename, txtContent.Text, Encoding.UTF8);
this.Text += " : File Saved :)";
}
else
{
switch (comExt.SelectedItem.ToString())
{
case "png":
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
case "ico":
imgContent.Image.Save(location + filename, ImageFormat.Icon);
break;
case "jpg":
imgContent.Image.Save(location + filename, ImageFormat.Jpeg);
break;
case "bmp":
imgContent.Image.Save(location + filename, ImageFormat.Bmp);
break;
case "gif":
imgContent.Image.Save(location + filename, ImageFormat.Gif);
break;
default:
imgContent.Image.Save(location + filename, ImageFormat.Png);
break;
}

this.Text += " : Image Saved :)";
}

Task.Factory.StartNew(() =>
{
Thread.Sleep(1000);
Environment.Exit(0);
});
}

private void btnBrowseForFolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = "Select a folder for saving this file ";
if (fbd.ShowDialog() == DialogResult.OK)
{
txtCurrentLocation.Text = fbd.SelectedPath;
}
}

private void lblWebsite_Click(object sender, EventArgs e)
{
Process.Start("http://eslamx.com");
}

private void lblMe_Click(object sender, EventArgs e)
{
Process.Start("http://twitter.com/EslaMx7");
}

private void lblHelp_Click(object sender, EventArgs e)
{
string msg = "Paste Into File helps you paste any text or images in your system clipboard into a file directly instead of creating new file yourself";
msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg";
msg += "\nto Unregister the application use this argument : /unreg\n";
msg += "\n--------------------\nSend Feedback to : [email protected]\n\nThanks :)";
MessageBox.Show(msg, "Paste As File Help", MessageBoxButtons.OK, MessageBoxIcon.Information);



}

private void txtFilename_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
btnSave_Click(sender, null);
}
}
}
}

0 comments on commit ac8c9fb

Please sign in to comment.