Skip to content

Commit

Permalink
代码清理
Browse files Browse the repository at this point in the history
  • Loading branch information
wtcpython committed Feb 12, 2025
1 parent 6dfa7be commit 5ec70c6
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 148 deletions.
6 changes: 0 additions & 6 deletions Controls/BrowserMenuItems.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<MenuFlyoutItem Text="截图" Click="ScreenClip">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="S" Modifiers="Control,Shift"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>

<MenuFlyoutItem Text="在页面上查找">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="F" Modifiers="Control"/>
Expand Down
46 changes: 0 additions & 46 deletions Controls/BrowserMenuItems.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Web.WebView2.Core;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Windows.Win32;
using Windows.Win32.UI.Input.KeyboardAndMouse;

namespace Edge
{
Expand All @@ -19,7 +15,6 @@ public BrowserMenuItems()
private void TryCreateNewTab(object sender, RoutedEventArgs e)
{
MainWindow mainWindow = App.GetWindowForElement(this);

mainWindow.AddHomePage();
}

Expand Down Expand Up @@ -57,47 +52,6 @@ private void CloseApp(object sender, RoutedEventArgs e)
App.mainWindows.ForEach(x => x.Close());
}

private void ScreenClip(object sender, RoutedEventArgs e)
{
WebView2 webView2 = App.GetWebView2(this);
webView2.Focus(FocusState.Programmatic);

List<INPUT> inputs =
[
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_CONTROL } }
},
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_SHIFT } }
},
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_S } }
},
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_S, dwFlags = KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP } }
},
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_SHIFT, dwFlags = KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP } }
},
new()
{
type = INPUT_TYPE.INPUT_KEYBOARD,
Anonymous = { ki = { wVk = VIRTUAL_KEY.VK_CONTROL, dwFlags = KEYBD_EVENT_FLAGS.KEYEVENTF_KEYUP } }
}
];
PInvoke.SendInput(inputs.ToArray(), Marshal.SizeOf<INPUT>());
}

private void MenuFlyout_Opening(object sender, object e)
{
var items = (sender as MenuFlyout).Items.ToList()[2..^3];
Expand Down
2 changes: 1 addition & 1 deletion Controls/WebSearch.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTex
string lastWord = text.Split(' ')[^1].ToLower();
if (!string.IsNullOrEmpty(lastWord))
{
sender.ItemsSource = App.searchEngine.SearchWords(lastWord);
sender.ItemsSource = App.searchEngine.SearchWords(lastWord).Take(10).ToList();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Edge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.2.250129-preview2" />
<PackageReference Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.2.250129-preview2" />
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.2.250129-preview2" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3079-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3116-prerelease" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250127003-experimental3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.7.250208002-preview1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.2" />
<PackageReference Include="WinUIEdit" Version="0.0.3-prerelease" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
46 changes: 0 additions & 46 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,6 @@
HorizontalAlignment="Stretch"
AddTabButtonClick="TabViewAddTabButtonClick"
PointerPressed="TabViewPointerPressed">
<TabView.TabStripHeader>
<Button
Style="{StaticResource AlternateCloseButtonStyle}"
ToolTipService.ToolTip="工作区">
<FontIcon Glyph="&#xe8b7;"/>
<Button.Flyout>
<Flyout>
<StackPanel Width="300" Spacing="10">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<TextBlock Text="Edge 工作区" VerticalAlignment="Center" FontWeight="Bold"/>

<local:IconButton
TipText="创建新工作区"
IconGlyph="&#xecc8;"
HorizontalAlignment="Right"
Grid.Column="1" />
<local:IconButton
TipText="更多选项"
IconGlyph="&#xe712;"
Grid.Column="2" />
</Grid>

<TextBlock TextWrapping="WrapWholeWords">
使用工作区组织浏览活动,并与他人共享,以实现无缝的协作浏览。
</TextBlock>

<Grid ColumnSpacing="5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Button Content="新建" Click="CreateNewWorkspaces" HorizontalAlignment="Stretch" Style="{ThemeResource AccentButtonStyle}"/>
<Button Content="了解更多信息" Click="LearnAboutWorkspaces" HorizontalAlignment="Stretch" Grid.Column="1"/>
</Grid>
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
</TabView.TabStripHeader>

<TabView.TabStripFooter>
<Grid Background="Transparent" Name="AppTitleBar" Padding="0,0,200,0"/>
Expand Down
14 changes: 2 additions & 12 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ private void OnRestoreClicked(object sender, RoutedEventArgs args)
/// </summary>
private void OnMoveClicked(object sender, RoutedEventArgs args)
{
PInvoke.SendMessage((HWND)this.GetWindowHandle(), PInvoke.WM_SYSCOMMAND, 0xF010, 0);
PInvoke.SendMessage(new(this.GetWindowHandle()), PInvoke.WM_SYSCOMMAND, 0xF010, 0);
}

/// <summary>
/// 窗口大小
/// </summary>
private void OnSizeClicked(object sender, RoutedEventArgs args)
{
PInvoke.SendMessage((HWND)this.GetWindowHandle(), PInvoke.WM_SYSCOMMAND, 0xF000, 0);
PInvoke.SendMessage(new(this.GetWindowHandle()), PInvoke.WM_SYSCOMMAND, 0xF000, 0);
}

/// <summary>
Expand Down Expand Up @@ -300,16 +300,6 @@ private void TabViewAddTabButtonClick(TabView sender, object args)
AddHomePage();
}

private async void LearnAboutWorkspaces(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("https://aka.ms/edgeworkspaces/learn-more-msa"));
}

private void CreateNewWorkspaces(object sender, RoutedEventArgs e)
{

}

private void TabViewPointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
var properties = e.GetCurrentPoint(null).Properties;
Expand Down
1 change: 0 additions & 1 deletion NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SetWindowSubclass
SendMessage
DefSubclassProc
SendInput
ScreenToClient
GetDpiForWindow

Expand Down
8 changes: 1 addition & 7 deletions Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Name="homeGrid">
<Grid>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand Down Expand Up @@ -43,12 +43,6 @@
<TextBlock Text="{x:Bind Name}" HorizontalAlignment="Center"/>
<StackPanel.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="打开" Click="OpenWebSite">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xe8a7;"/>
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>

<MenuFlyoutItem Text="隐藏" Click="HideItem">
<MenuFlyoutItem.Icon>
<FontIcon Glyph="&#xed1a;"/>
Expand Down
9 changes: 1 addition & 8 deletions Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HomePage()

if (App.settings.ShowBackground)
{
homeGrid.Background = new ImageBrush()
Background = new ImageBrush()
{
ImageSource = new BitmapImage()
{
Expand Down Expand Up @@ -78,13 +78,6 @@ private void OpenSuggestWebsite(object sender, ItemClickEventArgs e)
mainWindow.AddNewTab(new WebViewPage((e.ClickedItem as WebsiteInfo).Uri));
}

private void OpenWebSite(object sender, RoutedEventArgs e)
{
MainWindow mainWindow = App.GetWindowForElement(this);
Uri uri = ((sender as MenuFlyoutItem).DataContext as WebsiteInfo).Uri;
mainWindow.AddNewTab(new WebViewPage(uri));
}

private void HideItem(object sender, RoutedEventArgs e)
{
Info.SuggestWebsiteList.Remove((sender as MenuFlyoutItem).DataContext as WebsiteInfo);
Expand Down
9 changes: 4 additions & 5 deletions Pages/WebViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@

<StackPanel Orientation="Horizontal">
<local:IconButton
x:Name="uriGoBackButton"
TipText="返回 (Alt+向左键)"
Key="Left" Modifiers="Menu"
IconGlyph="&#xe72b;"
ButtonClicked="UriGoBackRequest" />
ButtonClicked="UriGoBackRequest"
IsEnabled="{Binding ElementName=EdgeWebViewEngine, Path=CanGoBack, Mode=TwoWay}"/>
<local:IconButton
x:Name="uriGoForwardButton"
TipText="继续 (Alt+向右键)"
Key="Right" Modifiers="Menu"
IconGlyph="&#xe72a;"
ButtonClicked="UriGoForwardRequest" />
ButtonClicked="UriGoForwardRequest"
Visibility="{Binding ElementName=EdgeWebViewEngine, Path=CanGoForward, Mode=TwoWay}"/>
<local:IconButton
x:Name="uriRefreshButton"
TipText="刷新 (Ctrl+R)"
Key="R" Modifiers="Control"
IconGlyph="&#xe72c;"
Expand Down
11 changes: 0 additions & 11 deletions Pages/WebViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public WebViewPage(Uri WebUri)
{
InitializeComponent();
InitializeToolbarVisibility();
SetNavigationButtonStatus();
EdgeWebViewEngine.Source = WebUri;
}

Expand All @@ -27,13 +26,6 @@ private void InitializeToolbarVisibility()
homeButton.Visibility = App.settings.ToolBar!["HomeButton"] ? Visibility.Visible : Visibility.Collapsed;
}

private void SetNavigationButtonStatus()
{
uriGoBackButton.IsEnabled = EdgeWebViewEngine.CanGoBack;
uriGoForwardButton.Visibility = App.settings.ToolBar!["ForwardButton"] && EdgeWebViewEngine.CanGoForward
? Visibility.Visible : Visibility.Collapsed;
}

private void WebView2Initialized(WebView2 sender, CoreWebView2InitializedEventArgs args)
{
sender.CoreWebView2.ContextMenuRequested += CoreWebView2_ContextMenuRequested;
Expand All @@ -60,7 +52,6 @@ private void CoreWebView2_DOMContentLoaded(CoreWebView2 sender, CoreWebView2DOMC
FaviconUri = new Uri(sender.FaviconUri),
Time = DateTime.Now.ToString()
});
SetNavigationButtonStatus();

if (App.settings.Favorites.Where(x => x.Uri.Equals(sender.Source)).Any())
{
Expand Down Expand Up @@ -296,13 +287,11 @@ private void CoreWebView2_NewWindowRequested(CoreWebView2 sender, CoreWebView2Ne
private void UriGoBackRequest(object sender, RoutedEventArgs e)
{
if (EdgeWebViewEngine.CanGoBack) EdgeWebViewEngine.GoBack();
SetNavigationButtonStatus();
}

private void UriGoForwardRequest(object sender, RoutedEventArgs e)
{
if (EdgeWebViewEngine.CanGoForward) EdgeWebViewEngine.GoForward();
SetNavigationButtonStatus();
}

private void UriRefreshRequest(object sender, RoutedEventArgs e) => EdgeWebViewEngine.Reload();
Expand Down
2 changes: 0 additions & 2 deletions Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.UI;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using System;
Expand Down Expand Up @@ -48,7 +47,6 @@ public static void SetBackdrop(this Window window)
public static void SetThemeColor(this Window window)
{
string appearance = App.settings.Appearance;
window.AppWindow.TitleBar.PreferredTheme = Enum.Parse<TitleBarTheme>(appearance);
if (window.Content is FrameworkElement rootElement)
{
rootElement.RequestedTheme = Enum.Parse<ElementTheme>(appearance);
Expand Down

0 comments on commit 5ec70c6

Please sign in to comment.