mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-05 02:00:34 +08:00
Share and window status button, Configuration system, check update every week
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="QuickLook.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<legacyCorruptedStateExceptionsPolicy enabled="true" />
|
||||
</runtime>
|
||||
<userSettings>
|
||||
<QuickLook.Properties.Settings>
|
||||
<setting name="Upgraded" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
<setting name="LastUpdate" serializeAs="String">
|
||||
<value>2017-01-01</value>
|
||||
</setting>
|
||||
</QuickLook.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
@@ -20,9 +20,11 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using QuickLook.Helpers;
|
||||
using QuickLook.Properties;
|
||||
|
||||
namespace QuickLook
|
||||
{
|
||||
@@ -68,6 +70,8 @@ namespace QuickLook
|
||||
return;
|
||||
}
|
||||
|
||||
UpgradeSettings();
|
||||
CheckUpdate();
|
||||
RunListener(e);
|
||||
|
||||
// first instance: run and preview this file
|
||||
@@ -75,6 +79,26 @@ namespace QuickLook
|
||||
RemoteCallShowPreview(e);
|
||||
}
|
||||
|
||||
private void CheckUpdate()
|
||||
{
|
||||
if (DateTime.Now - Settings.Default.LastUpdate < TimeSpan.FromDays(7))
|
||||
return;
|
||||
|
||||
Task.Delay(120 * 1000).ContinueWith(_ => Updater.CheckForUpdates(true));
|
||||
Settings.Default.LastUpdate = DateTime.Now;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void UpgradeSettings()
|
||||
{
|
||||
if (!Settings.Default.Upgraded)
|
||||
return;
|
||||
|
||||
Settings.Default.Upgrade();
|
||||
Settings.Default.Upgraded = false;
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void RemoteCallShowPreview(StartupEventArgs e)
|
||||
{
|
||||
PipeServerManager.SendMessage(e.Args.First());
|
||||
|
||||
+3
-3
@@ -22,16 +22,16 @@ using System.Windows.Data;
|
||||
|
||||
namespace QuickLook.Converters
|
||||
{
|
||||
public sealed class BooleanTrueToVisibilityCollapsedConverter : DependencyObject, IValueConverter
|
||||
public sealed class BooleanToVisibilityConverter : DependencyObject, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return Visibility.Collapsed;
|
||||
return Visibility.Visible;
|
||||
|
||||
var v = (bool) value;
|
||||
|
||||
return v ? Visibility.Collapsed : Visibility.Visible;
|
||||
return v ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
@@ -18,6 +18,7 @@
|
||||
<Window.Resources>
|
||||
<converters:BooleanToResizeModeConverter x:Key="BooleanToResizeModeConverter" />
|
||||
<converters:BooleanToResizeBorderThicknessConverter x:Key="BooleanToResizeBorderThicknessConverter" />
|
||||
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
</Window.Resources>
|
||||
<Window.ResizeMode>
|
||||
<Binding Converter="{StaticResource BooleanToResizeModeConverter}" ElementName="mainWindow"
|
||||
@@ -59,7 +60,32 @@
|
||||
<DockPanel x:Name="titlebar" Height="28" Dock="Top">
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonCloseWindow" Icon="TimesCircle"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True"
|
||||
Width="15" Height="15" Margin="10,0" Foreground="Gray"
|
||||
Width="15" Height="15" Margin="5,0,10,0" Foreground="Gray"
|
||||
Cursor="Hand" />
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonWindowStatus"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True"
|
||||
Width="14" Height="14" Margin="5,0,5,0" Foreground="Gray"
|
||||
Visibility="{Binding ContextObject.CanResize,ElementName=mainWindow,Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
Cursor="Hand">
|
||||
<fa:ImageAwesome.Style>
|
||||
<Style TargetType="{x:Type fa:ImageAwesome}">
|
||||
<Setter Property="Icon" Value="WindowMaximize" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding WindowState, ElementName=mainWindow}"
|
||||
Value="Maximized">
|
||||
<Setter Property="Icon" Value="WindowRestore" />
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding WindowState, ElementName=mainWindow}"
|
||||
Value="Normal">
|
||||
<Setter Property="Icon" Value="WindowMaximize" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</fa:ImageAwesome.Style>
|
||||
</fa:ImageAwesome>
|
||||
<fa:ImageAwesome DockPanel.Dock="Right" x:Name="buttonShare" Icon="ShareAlt"
|
||||
WindowChrome.IsHitTestVisibleInChrome="True"
|
||||
Width="14" Height="14" Margin="10,0,5,0" Foreground="Gray"
|
||||
Cursor="Hand" />
|
||||
<Button x:Name="buttonOpenWith" DockPanel.Dock="Right" Content="Open with..." Height="20"
|
||||
Margin="10,0,0,0" Padding="5,0"
|
||||
@@ -101,7 +127,7 @@
|
||||
<Grid x:Name="titleArea" Background="Transparent">
|
||||
<TextBlock Text="{Binding ContextObject.Title, ElementName=mainWindow}" FontSize="14"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
VerticalAlignment="Center" Margin="5,0" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
<Grid>
|
||||
|
||||
@@ -76,6 +76,12 @@ namespace QuickLook
|
||||
else
|
||||
ViewWindowManager.GetInstance().RunAndClosePreview();
|
||||
};
|
||||
|
||||
buttonWindowStatus.MouseLeftButtonUp += (sender, e) =>
|
||||
WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
|
||||
|
||||
buttonShare.MouseLeftButtonUp +=
|
||||
(sender, e) => RunWith("rundll32.exe", $"shell32.dll,OpenAs_RunDLL {Path}");
|
||||
}
|
||||
|
||||
public bool Pinned
|
||||
@@ -88,23 +94,42 @@ namespace QuickLook
|
||||
}
|
||||
}
|
||||
|
||||
public string PreviewPath { get; private set; }
|
||||
public string Path { get; private set; }
|
||||
public IViewer Plugin { get; private set; }
|
||||
|
||||
public ContextObject ContextObject { get; private set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
internal void Run()
|
||||
internal void RunWith(string with, string arg)
|
||||
{
|
||||
if (string.IsNullOrEmpty(PreviewPath))
|
||||
if (string.IsNullOrEmpty(Path))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(PreviewPath)
|
||||
Process.Start(new ProcessStartInfo(with)
|
||||
{
|
||||
WorkingDirectory = Path.GetDirectoryName(PreviewPath)
|
||||
Arguments = arg,
|
||||
WorkingDirectory = System.IO.Path.GetDirectoryName(Path)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Run()
|
||||
{
|
||||
if (string.IsNullOrEmpty(Path))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(Path)
|
||||
{
|
||||
WorkingDirectory = System.IO.Path.GetDirectoryName(Path)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -177,7 +202,7 @@ namespace QuickLook
|
||||
|
||||
internal void BeginShow(IViewer matchedPlugin, string path, Action<ExceptionDispatchInfo> exceptionHandler)
|
||||
{
|
||||
PreviewPath = path;
|
||||
Path = path;
|
||||
Plugin = matchedPlugin;
|
||||
|
||||
ContextObject.ViewerWindow = this;
|
||||
@@ -221,12 +246,12 @@ namespace QuickLook
|
||||
|
||||
private void SetOpenWithButtonAndPath()
|
||||
{
|
||||
var isExe = FileHelper.GetAssocApplication(PreviewPath, out string appFriendlyName);
|
||||
var isExe = FileHelper.GetAssocApplication(Path, out string appFriendlyName);
|
||||
|
||||
buttonOpenWith.Content = isExe == null
|
||||
? Directory.Exists(PreviewPath)
|
||||
? string.Format(TranslationHelper.GetString("MW_BrowseFolder"), Path.GetFileName(PreviewPath))
|
||||
: string.Format(TranslationHelper.GetString("MW_Open"), Path.GetFileName(PreviewPath))
|
||||
? Directory.Exists(Path)
|
||||
? string.Format(TranslationHelper.GetString("MW_BrowseFolder"), System.IO.Path.GetFileName(Path))
|
||||
: string.Format(TranslationHelper.GetString("MW_Open"), System.IO.Path.GetFileName(Path))
|
||||
: isExe == true
|
||||
? string.Format(TranslationHelper.GetString("MW_Run"), appFriendlyName)
|
||||
: string.Format(TranslationHelper.GetString("MW_OpenWith"), appFriendlyName);
|
||||
|
||||
+24
@@ -22,5 +22,29 @@ namespace QuickLook.Properties {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool Upgraded {
|
||||
get {
|
||||
return ((bool)(this["Upgraded"]));
|
||||
}
|
||||
set {
|
||||
this["Upgraded"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("2017-01-01")]
|
||||
public global::System.DateTime LastUpdate {
|
||||
get {
|
||||
return ((global::System.DateTime)(this["LastUpdate"]));
|
||||
}
|
||||
set {
|
||||
this["LastUpdate"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="QuickLook.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="Upgraded" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
<Setting Name="LastUpdate" Type="System.DateTime" Scope="User">
|
||||
<Value Profile="(Default)">2017-01-01</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -107,7 +107,7 @@
|
||||
<Link>Properties\GitVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Converters\BooleanToResizeModeConverter.cs" />
|
||||
<Compile Include="Converters\BooleanTrueToVisibilityCollapsedConverter.cs" />
|
||||
<Compile Include="Converters\BooleanToVisibilityConverter.cs" />
|
||||
<Compile Include="Converters\BooleanToResizeBorderThicknessConverter.cs" />
|
||||
<Compile Include="FocusMonitor.cs" />
|
||||
<Compile Include="Helpers\AutoStartupHelper.cs" />
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<Icon_CheckUpdate>Check for &Updates...</Icon_CheckUpdate>
|
||||
<Icon_Quit>&Quit</Icon_Quit>
|
||||
<Update_NoUpdate>You are now on the latest version.</Update_NoUpdate>
|
||||
<Update_Found>New version {0} is released. Click here to open the download page.</Update_Found>
|
||||
<Update_Found>QuickLook {0} is released. Click here to open the download page.</Update_Found>
|
||||
<Update_Error>Error occured when checking for updates: {0}</Update_Error>
|
||||
<InfoPanel_LastModified>Last modified at {0}</InfoPanel_LastModified>
|
||||
<InfoPanel_DriveSize>Capacity {0}, {1} available</InfoPanel_DriveSize>
|
||||
@@ -35,7 +35,7 @@
|
||||
<Icon_CheckUpdate>检查更新... (&U)</Icon_CheckUpdate>
|
||||
<Icon_Quit>退出 (&Q)</Icon_Quit>
|
||||
<Update_NoUpdate>您已使用了最新版本。</Update_NoUpdate>
|
||||
<Update_Found>发现新版本 {0}。点击这里打开下载页面。</Update_Found>
|
||||
<Update_Found>QuickLook {0} 已发布。点击这里打开下载页面。</Update_Found>
|
||||
<Update_Error>检查更新时发生错误:{0}</Update_Error>
|
||||
<InfoPanel_LastModified>最后修改于 {0}</InfoPanel_LastModified>
|
||||
<InfoPanel_DriveSize>总容量 {0},可用 {1}</InfoPanel_DriveSize>
|
||||
|
||||
Reference in New Issue
Block a user