Skip to content

Commit ac8c9fb

Browse files
committed
add initial focus to filename, save on enter #9
1 parent b852390 commit ac8c9fb

File tree

2 files changed

+150
-141
lines changed

2 files changed

+150
-141
lines changed

PasteIntoFile/frmMain.Designer.cs

Lines changed: 16 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PasteIntoFile/frmMain.cs

Lines changed: 134 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -15,130 +15,138 @@
1515

1616
namespace PasteAsFile
1717
{
18-
public partial class frmMain : Form
19-
{
20-
public string CurrentLocation { get; set; }
21-
public bool IsText { get; set; }
22-
public frmMain()
23-
{
24-
InitializeComponent();
25-
}
26-
public frmMain(string location)
27-
{
28-
InitializeComponent();
29-
this.CurrentLocation = location;
30-
}
31-
private void frmMain_Load(object sender, EventArgs e)
32-
{
33-
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
34-
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";
35-
36-
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null)
37-
{
38-
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)
39-
{
40-
Program.RegisterApp();
41-
}
42-
}
43-
44-
if (Clipboard.ContainsText())
45-
{
46-
lblType.Text = "Text File";
47-
comExt.SelectedItem = "txt";
48-
IsText = true;
49-
txtContent.Text = Clipboard.GetText();
50-
return;
51-
}
52-
53-
if (Clipboard.ContainsImage())
54-
{
55-
lblType.Text = "Image";
56-
comExt.SelectedItem = "png";
57-
imgContent.Image = Clipboard.GetImage();
58-
return;
59-
}
60-
61-
lblType.Text = "Unknown File";
62-
btnSave.Enabled = false;
63-
64-
65-
}
66-
67-
private void btnSave_Click(object sender, EventArgs e)
68-
{
69-
string location = txtCurrentLocation.Text;
70-
location = location.EndsWith("\\") ? location : location + "\\";
71-
string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString() ;
72-
if (IsText)
73-
{
74-
75-
File.WriteAllText(location+filename,txtContent.Text,Encoding.UTF8);
76-
this.Text += " : File Saved :)";
77-
}
78-
else
79-
{
80-
switch (comExt.SelectedItem.ToString())
81-
{
82-
case "png":
83-
imgContent.Image.Save(location + filename, ImageFormat.Png);
84-
break;
85-
case "ico":
86-
imgContent.Image.Save(location + filename, ImageFormat.Icon);
87-
break;
88-
case "jpg":
89-
imgContent.Image.Save(location + filename, ImageFormat.Jpeg);
90-
break;
91-
case "bmp":
92-
imgContent.Image.Save(location + filename, ImageFormat.Bmp);
93-
break;
94-
case "gif":
95-
imgContent.Image.Save(location + filename, ImageFormat.Gif);
96-
break;
97-
default:
98-
imgContent.Image.Save(location + filename, ImageFormat.Png);
99-
break;
100-
}
101-
102-
this.Text += " : Image Saved :)";
103-
}
104-
105-
Task.Factory.StartNew(() =>
106-
{
107-
Thread.Sleep(1000);
108-
Environment.Exit(0);
109-
});
110-
}
111-
112-
private void btnBrowseForFolder_Click(object sender, EventArgs e)
113-
{
114-
FolderBrowserDialog fbd = new FolderBrowserDialog();
115-
fbd.Description = "Select a folder for saving this file ";
116-
if (fbd.ShowDialog() == DialogResult.OK)
117-
{
118-
txtCurrentLocation.Text = fbd.SelectedPath;
119-
}
120-
}
121-
122-
private void lblWebsite_Click(object sender, EventArgs e)
123-
{
124-
Process.Start("http://eslamx.com");
125-
}
126-
127-
private void lblMe_Click(object sender, EventArgs e)
128-
{
129-
Process.Start("http://twitter.com/EslaMx7");
130-
}
131-
132-
private void lblHelp_Click(object sender, EventArgs e)
133-
{
134-
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";
135-
msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg";
136-
msg += "\nto Unregister the application use this argument : /unreg\n";
137-
msg += "\n--------------------\nSend Feedback to : [email protected]\n\nThanks :)";
138-
MessageBox.Show(msg,"Paste As File Help",MessageBoxButtons.OK,MessageBoxIcon.Information);
139-
140-
141-
142-
}
143-
}
18+
public partial class frmMain : Form
19+
{
20+
public string CurrentLocation { get; set; }
21+
public bool IsText { get; set; }
22+
public frmMain()
23+
{
24+
InitializeComponent();
25+
}
26+
public frmMain(string location)
27+
{
28+
InitializeComponent();
29+
this.CurrentLocation = location;
30+
}
31+
private void frmMain_Load(object sender, EventArgs e)
32+
{
33+
txtFilename.Text = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss");
34+
txtCurrentLocation.Text = CurrentLocation ?? @"C:\";
35+
36+
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Paste Into File\command", "", null) == null)
37+
{
38+
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)
39+
{
40+
Program.RegisterApp();
41+
}
42+
}
43+
44+
if (Clipboard.ContainsText())
45+
{
46+
lblType.Text = "Text File";
47+
comExt.SelectedItem = "txt";
48+
IsText = true;
49+
txtContent.Text = Clipboard.GetText();
50+
return;
51+
}
52+
53+
if (Clipboard.ContainsImage())
54+
{
55+
lblType.Text = "Image";
56+
comExt.SelectedItem = "png";
57+
imgContent.Image = Clipboard.GetImage();
58+
return;
59+
}
60+
61+
lblType.Text = "Unknown File";
62+
btnSave.Enabled = false;
63+
64+
65+
}
66+
67+
private void btnSave_Click(object sender, EventArgs e)
68+
{
69+
string location = txtCurrentLocation.Text;
70+
location = location.EndsWith("\\") ? location : location + "\\";
71+
string filename = txtFilename.Text + "." + comExt.SelectedItem.ToString();
72+
if (IsText)
73+
{
74+
75+
File.WriteAllText(location + filename, txtContent.Text, Encoding.UTF8);
76+
this.Text += " : File Saved :)";
77+
}
78+
else
79+
{
80+
switch (comExt.SelectedItem.ToString())
81+
{
82+
case "png":
83+
imgContent.Image.Save(location + filename, ImageFormat.Png);
84+
break;
85+
case "ico":
86+
imgContent.Image.Save(location + filename, ImageFormat.Icon);
87+
break;
88+
case "jpg":
89+
imgContent.Image.Save(location + filename, ImageFormat.Jpeg);
90+
break;
91+
case "bmp":
92+
imgContent.Image.Save(location + filename, ImageFormat.Bmp);
93+
break;
94+
case "gif":
95+
imgContent.Image.Save(location + filename, ImageFormat.Gif);
96+
break;
97+
default:
98+
imgContent.Image.Save(location + filename, ImageFormat.Png);
99+
break;
100+
}
101+
102+
this.Text += " : Image Saved :)";
103+
}
104+
105+
Task.Factory.StartNew(() =>
106+
{
107+
Thread.Sleep(1000);
108+
Environment.Exit(0);
109+
});
110+
}
111+
112+
private void btnBrowseForFolder_Click(object sender, EventArgs e)
113+
{
114+
FolderBrowserDialog fbd = new FolderBrowserDialog();
115+
fbd.Description = "Select a folder for saving this file ";
116+
if (fbd.ShowDialog() == DialogResult.OK)
117+
{
118+
txtCurrentLocation.Text = fbd.SelectedPath;
119+
}
120+
}
121+
122+
private void lblWebsite_Click(object sender, EventArgs e)
123+
{
124+
Process.Start("http://eslamx.com");
125+
}
126+
127+
private void lblMe_Click(object sender, EventArgs e)
128+
{
129+
Process.Start("http://twitter.com/EslaMx7");
130+
}
131+
132+
private void lblHelp_Click(object sender, EventArgs e)
133+
{
134+
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";
135+
msg += "\n--------------------\nTo Register the application to your system Context Menu run the program as Administrator with this argument : /reg";
136+
msg += "\nto Unregister the application use this argument : /unreg\n";
137+
msg += "\n--------------------\nSend Feedback to : [email protected]\n\nThanks :)";
138+
MessageBox.Show(msg, "Paste As File Help", MessageBoxButtons.OK, MessageBoxIcon.Information);
139+
140+
141+
142+
}
143+
144+
private void txtFilename_KeyPress(object sender, KeyPressEventArgs e)
145+
{
146+
if (e.KeyChar == (char)Keys.Enter)
147+
{
148+
btnSave_Click(sender, null);
149+
}
150+
}
151+
}
144152
}

0 commit comments

Comments
 (0)