Skip to content
This repository has been archived by the owner on May 30, 2021. It is now read-only.

Commit

Permalink
Save as feature + Timer (Work needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonichigo committed Dec 28, 2020
1 parent 3ade0f0 commit bb83944
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 32 deletions.
61 changes: 40 additions & 21 deletions Tango Browser/Main_Tab.Designer.cs

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

29 changes: 22 additions & 7 deletions Tango Browser/Main_Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Net;
using Tango_Browser.Properties;
using CefSharp.Example.Handlers;

using System.Diagnostics;

namespace Tango_Browser
{
Expand Down Expand Up @@ -301,16 +301,18 @@ async private void chromiumBrowser_FrameLoadEnd_1(object sender, FrameLoadEndEve
var filter = Builders<BsonDocument>.Filter.Eq("url", Address_textBox.Text);
if (pinif.CountDocuments(filter) != 0)
{
Pic_pin.Image = Resources.pinned;
pinned = true;
}

Pic_pin.Image = Resources.pinned;
pinned = true;
}

timer1.Stop();
this.label4.Text = timer1.ToString();
//Console.WriteLine(timer1[1]);
}

async private void chromiumBrowser_FrameLoadStart(object sender, FrameLoadStartEventArgs e)
{

timer1.Start();


Pic_load.Image = Resources.cancel;
Expand Down Expand Up @@ -394,7 +396,6 @@ private void chromiumBrowser_AddressChanged(object sender, AddressChangedEventAr
/*Invoke(new Action(() => Icon = Resources.DefaultIcon));*/
}
}

Invoke(new Action(() => Parent.Refresh()));
faviconLoaded = true;
}
Expand Down Expand Up @@ -886,5 +887,19 @@ private void tabPage1_Click(object sender, EventArgs e)
{

}

private void label4_TextChanged(object sender, PaintEventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Address_textBox.Text);

System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

timer.Stop();

TimeSpan timeTaken = timer.Elapsed;
}
}
}
5 changes: 4 additions & 1 deletion Tango Browser/Main_Tab.resx
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,11 @@
<metadata name="DPSelect.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>270, 8</value>
</metadata>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>403, 8</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>147</value>
<value>74</value>
</metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
63 changes: 60 additions & 3 deletions Tango Browser/MyCustomMenuHandler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System;
using CefSharp;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.Diagnostics;

public class MyCustomMenuHandler : IContextMenuHandler
{
public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
Expand All @@ -21,13 +26,17 @@ public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IF
// Add a new item to the list using the AddItem method of the model
model.AddItem((CefMenuCommand)26504, "Save As");
model.AddItem((CefMenuCommand)26505, "Show DevTools");


// Add a separator


// Add another example item

model.AddItem((CefMenuCommand)113, "Copy");
model.AddItem((CefMenuCommand)100, "Back");
model.AddItem((CefMenuCommand)101, "Forward");
model.AddItem((CefMenuCommand)102, "Reload");
model.AddItem((CefMenuCommand)103, "Reload No Cache");
}

public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
Expand All @@ -40,9 +49,41 @@ public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, I
}
if (commandId == (CefMenuCommand)26504)
{
MessageBox.Show("Save as feature");
if (parameters.LinkUrl.Length > 0)
{

Clipboard.SetText(parameters.LinkUrl);

}
if (parameters.MediaType == ContextMenuMediaType.Image)
{
Clipboard.SetText(parameters.SourceUrl);

string subPath = @"C:\temp";

string fn = @"C:\temp\image.jpeg";

System.IO.Directory.CreateDirectory(subPath);

SaveImage(parameters.SourceUrl, fn, ImageFormat.Jpeg);

Process.Start(fn);
}
MessageBox.Show("Saved as Image");
return true;
}
if (commandId == (CefMenuCommand)113) // Copy
{

if (parameters.LinkUrl.Length > 0)
{
Clipboard.SetText(parameters.LinkUrl);
}
if (parameters.MediaType == ContextMenuMediaType.Image)
{
Clipboard.SetText(parameters.SourceUrl);
}
}


// Any new item should be handled through a new if statement
Expand All @@ -61,4 +102,20 @@ public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame
{
return false;
}
public void SaveImage(string imageUrl, string filename, ImageFormat format)
{
System.Net.WebClient client = new WebClient();
System.IO.Stream stream = client.OpenRead(imageUrl);
Bitmap bitmap; bitmap = new Bitmap(stream);

if (bitmap != null)
{
bitmap.Save(filename, format);
}

stream.Flush();
stream.Close();
client.Dispose();
}

}

0 comments on commit bb83944

Please sign in to comment.