Added GitHub Personal Access Token support
Improving Image Search and Description
This commit is contained in:
parent
a23857c6eb
commit
3e9fdb90e6
5 changed files with 72 additions and 102 deletions
|
|
@ -144,6 +144,16 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
private Vector2 widgetDownPosition;
|
||||
|
||||
public void AddObject3DControls(Object3DControlsLayer object3DControlsLayer)
|
||||
{
|
||||
EnsureTracedPositionControl(object3DControlsLayer);
|
||||
|
||||
object3DControlsLayer.Object3DControls.Modify((list) =>
|
||||
{
|
||||
list.Add(tracedPositionControl);
|
||||
});
|
||||
}
|
||||
|
||||
private void EnsureTracedPositionControl(Object3DControlsLayer object3DControlsLayer)
|
||||
{
|
||||
if (tracedPositionControl == null)
|
||||
{
|
||||
|
|
@ -164,11 +174,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
object3DControlsLayer.Object3DControls.Modify((list) =>
|
||||
{
|
||||
list.Add(tracedPositionControl);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Remove(UndoBuffer undoBuffer)
|
||||
|
|
@ -229,6 +234,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
public void DrawEditor(Object3DControlsLayer controlLayer, List<Object3DView> transparentMeshes, DrawEventArgs e)
|
||||
{
|
||||
EnsureTracedPositionControl(controlLayer);
|
||||
|
||||
var world = controlLayer.World;
|
||||
|
||||
if (!PositionHasBeenSet)
|
||||
|
|
@ -237,7 +244,6 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
LocalPosition = new Vector3(aabb.MinXYZ.X, aabb.MaxXYZ.Y, aabb.MaxXYZ.Z);
|
||||
}
|
||||
|
||||
|
||||
var start = worldPosition;
|
||||
|
||||
var screenStart = world.GetScreenPosition(start);
|
||||
|
|
|
|||
|
|
@ -32,10 +32,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.Platform;
|
||||
using MatterHackers.MatterControl.VersionManagement;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MatterHackers.MatterControl.Library
|
||||
|
|
@ -106,6 +108,8 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
var childContainers = new List<ILibraryContainerLink>();
|
||||
|
||||
this.Items.Clear();
|
||||
|
||||
// read in data
|
||||
foreach (FileInfo file in dirContents)
|
||||
{
|
||||
|
|
@ -299,12 +303,20 @@ namespace MatterHackers.MatterControl.Library
|
|||
|
||||
public static void AddCromeHeaders(HttpRequestMessage request)
|
||||
{
|
||||
#if true
|
||||
// request.Headers.Add("User-Agent", "MatterControl");
|
||||
request.Headers.UserAgent.Add(new ProductInfoHeaderValue("MatterControl", LatestVersionRequest.VersionKey.CurrentBuildNumber));
|
||||
var token = UserSettings.Instance.get("GitHubPat");
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
request.Headers.Authorization = new AuthenticationHeaderValue("Token", token);
|
||||
}
|
||||
#else
|
||||
request.Headers.Add("Connection", "keep-alive");
|
||||
request.Headers.Add("Upgrade-Insecure-Requests", "1");
|
||||
request.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36");
|
||||
request.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
|
||||
var token = UserSettings.Instance.get("GitHubPat");
|
||||
if (string.IsNullOrEmpty(token))
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
request.Headers.Add("Authorization", $"token {token}");
|
||||
}
|
||||
|
|
@ -313,6 +325,7 @@ namespace MatterHackers.MatterControl.Library
|
|||
request.Headers.Add("Sec-Fetch-User", "?1");
|
||||
request.Headers.Add("Sec-Fetch-Dest", "document");
|
||||
request.Headers.Add("Accept-Language", "en-US,en;q=0.9");
|
||||
#endif
|
||||
}
|
||||
|
||||
private class StaticDataItem : ILibraryAssetStream
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2018, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.PrintLibrary;
|
||||
using MatterHackers.VectorMath;
|
||||
|
||||
namespace MatterHackers.MatterControl.CustomWidgets
|
||||
{
|
||||
public class SearchableSectionWidget : SectionWidget
|
||||
{
|
||||
public event EventHandler<StringEventArgs> SearchInvoked;
|
||||
|
||||
private TextEditWithInlineCancel searchPanel;
|
||||
|
||||
public SearchableSectionWidget(string sectionTitle, GuiWidget sectionContent, ThemeConfig theme, int headingPointSize = -1, bool expandingContent = true, bool expanded = true, string serializationKey = null, bool defaultExpansion = false, bool setContentVAnchor = true, string emptyText = null)
|
||||
: base(sectionTitle, sectionContent, theme, theme.CreateSearchButton(), headingPointSize, expandingContent, expanded, serializationKey, defaultExpansion, setContentVAnchor)
|
||||
{
|
||||
var headerRow = this.Children.First();
|
||||
|
||||
searchPanel = new TextEditWithInlineCancel(theme, emptyText)
|
||||
{
|
||||
Visible = false,
|
||||
BackgroundColor = theme.TabBarBackground,
|
||||
MinimumSize = new Vector2(0, headerRow.Height)
|
||||
};
|
||||
|
||||
searchPanel.TextEditWidget.Margin = new BorderDouble(3, 0);
|
||||
|
||||
searchPanel.TextEditWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
|
||||
{
|
||||
var filter = searchPanel.TextEditWidget.Text.Trim();
|
||||
|
||||
this.SearchInvoked?.Invoke(this, new StringEventArgs(filter));
|
||||
|
||||
searchPanel.Visible = false;
|
||||
headerRow.Visible = true;
|
||||
searchPanel.TextEditWidget.Text = "";
|
||||
};
|
||||
|
||||
searchPanel.ResetButton.Click += (s, e) =>
|
||||
{
|
||||
searchPanel.Visible = false;
|
||||
headerRow.Visible = true;
|
||||
searchPanel.TextEditWidget.Text = "";
|
||||
};
|
||||
|
||||
var searchButton = this.rightAlignedContent as GuiWidget;
|
||||
searchButton.Click += (s, e) =>
|
||||
{
|
||||
searchPanel.Visible = true;
|
||||
headerRow.Visible = false;
|
||||
};
|
||||
|
||||
this.AddChild(searchPanel, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ using MatterHackers.MatterControl.PartPreviewWindow;
|
|||
namespace MatterHackers.MatterControl.DesignTools
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using CustomWidgets;
|
||||
using DataConverters3D;
|
||||
using MatterHackers.Agg.Platform;
|
||||
|
|
@ -61,8 +62,29 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
|
||||
var activeImage = imageObject.Image;
|
||||
|
||||
var imageSection = new SearchableSectionWidget("Image".Localize(), new FlowLayoutWidget(FlowDirection.TopToBottom), theme, emptyText: "Search Google".Localize());
|
||||
imageSection.SearchInvoked += (s, e) =>
|
||||
var imageSection = new SectionWidget("Image".Localize(), new FlowLayoutWidget(FlowDirection.TopToBottom), theme);
|
||||
|
||||
var emptyText = "Search Google".Localize();
|
||||
|
||||
var searchRow = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
Margin = new BorderDouble(5, 0)
|
||||
};
|
||||
|
||||
var searchField = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: "Search Google for images")
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
VAnchor = VAnchor.Center
|
||||
};
|
||||
searchRow.AddChild(searchField);
|
||||
var searchButton = new IconButton(StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16, theme.InvertIcons), theme)
|
||||
{
|
||||
ToolTipText = "Search".Localize(),
|
||||
};
|
||||
searchRow.AddChild(searchButton);
|
||||
|
||||
void DoSearch(object s, EventArgs e)
|
||||
{
|
||||
string imageType = " silhouette";
|
||||
|
||||
|
|
@ -71,9 +93,16 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
imageType = "";
|
||||
}
|
||||
|
||||
ApplicationController.LaunchBrowser($"http://www.google.com/search?q={e.Data}{imageType}&tbm=isch");
|
||||
var search = HttpUtility.UrlEncode(searchField.Text);
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
{
|
||||
ApplicationController.LaunchBrowser($"http://www.google.com/search?q={search}{imageType}&tbm=isch");
|
||||
}
|
||||
};
|
||||
|
||||
searchField.ActualTextEditWidget.EditComplete += DoSearch;
|
||||
searchButton.Click += DoSearch;
|
||||
|
||||
theme.ApplyBoxStyle(imageSection, margin: 0);
|
||||
|
||||
column.AddChild(imageSection);
|
||||
|
|
@ -175,7 +204,7 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
var invertCheckbox = new CheckBox(new CheckBoxViewText("Invert".Localize(), textColor: theme.TextColor))
|
||||
{
|
||||
Checked = imageObject.Invert,
|
||||
Margin = new BorderDouble(0),
|
||||
Margin = new BorderDouble(5, 0),
|
||||
VAnchor = VAnchor.Center,
|
||||
};
|
||||
invertCheckbox.CheckedStateChanged += (s, e) =>
|
||||
|
|
@ -184,6 +213,8 @@ namespace MatterHackers.MatterControl.DesignTools
|
|||
};
|
||||
row.AddChild(invertCheckbox);
|
||||
|
||||
imageSection.ContentPanel.AddChild(searchRow);
|
||||
|
||||
row.AddChild(new HorizontalSpacer());
|
||||
|
||||
row.AddChild(changeButton);
|
||||
|
|
|
|||
|
|
@ -452,9 +452,9 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
gitHubPat = "";
|
||||
}
|
||||
var accessToken = new MHTextEditWidget(gitHubPat, theme, pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter a GitHub Person Access Token".Localize())
|
||||
var accessToken = new MHTextEditWidget(gitHubPat, theme, pixelWidth: 350, messageWhenEmptyAndNotSelected: "Enter Person Access Token".Localize())
|
||||
{
|
||||
HAnchor = HAnchor.Stretch,
|
||||
HAnchor = HAnchor.Absolute,
|
||||
Margin = new BorderDouble(5),
|
||||
Name = "GitHubPat Edit Field"
|
||||
};
|
||||
|
|
@ -462,11 +462,18 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
|
||||
};
|
||||
accessToken.Closed += (s, e) =>
|
||||
{
|
||||
UserSettings.Instance.set("GitHubPat", accessToken.ActualTextEditWidget.Text);
|
||||
};
|
||||
this.AddSettingsRow(
|
||||
new SettingsItem(
|
||||
"GitHub Personal Access Token".Localize(),
|
||||
accessToken,
|
||||
theme),
|
||||
theme)
|
||||
{
|
||||
ToolTipText = "This is used to increase the number of downloads allowed when browsing GitHub repositories".Localize(),
|
||||
},
|
||||
advancedPanel);
|
||||
|
||||
advancedPanel.Children<SettingsItem>().First().Border = new BorderDouble(0, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue