Skip to content

Commit 56cb31f

Browse files
committed
finish auto-hide
1 parent 5b97e7e commit 56cb31f

16 files changed

Lines changed: 241 additions & 71 deletions

File tree

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
x:Name="imagePanel"
1010
d:DesignHeight="300" d:DesignWidth="300">
1111
<Grid>
12-
<Rectangle>
12+
<Rectangle Visibility="{Binding BackgroundVisibility, ElementName=imagePanel}">
1313
<Rectangle.Fill>
1414
<ImageBrush x:Name="backgroundBrush" ImageSource="Resources/background.png" AlignmentY="Top" Viewport="0,0,32,32"
1515
ViewportUnits="Absolute" Stretch="UniformToFill" TileMode="Tile" />

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public partial class ImagePanel : UserControl, INotifyPropertyChanged, IDisposab
4545
private BitmapScalingMode _renderMode = BitmapScalingMode.HighQuality;
4646
private BitmapSource _source;
4747
private double _zoomFactor = 1d;
48+
private Visibility _backgroundVisibility = Visibility.Visible;
4849

4950
private bool _zoomToFit = true;
5051

@@ -88,6 +89,16 @@ public bool ZoomToFit
8889
}
8990
}
9091

92+
public Visibility BackgroundVisibility
93+
{
94+
get => _backgroundVisibility;
95+
set
96+
{
97+
_backgroundVisibility = value;
98+
OnPropertyChanged();
99+
}
100+
}
101+
91102
public double MinZoomFactor
92103
{
93104
get => _minZoomFactor;

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ public void Prepare(string path, ContextObject context)
6464
context.PreferredSize = new Size(1024, 768);
6565

6666
Directory.SetCurrentDirectory(App.AppPath);
67-
68-
context.AutoHideTitlebar = true;
67+
6968
context.TitlebarOverlap = true;
7069
}
7170

QuickLook.Plugin/QuickLook.Plugin.PDFViewer/PdfViewerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</ListBox.ItemTemplate>
7171
</ListBox>
7272
<Grid Grid.Column="1" Background="#00EFEFEF">
73-
<imageViewer:ImagePanel x:Name="pagePanel" RenderMode="NearestNeighbor" />
73+
<imageViewer:ImagePanel x:Name="pagePanel" RenderMode="NearestNeighbor" BackgroundVisibility="Collapsed" />
7474
</Grid>
7575
</Grid>
7676
</UserControl>

QuickLook.Plugin/QuickLook.Plugin.TextViewer/Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Prepare(string path, ContextObject context)
6464

6565
public void View(string path, ContextObject context)
6666
{
67-
_tvp = new TextViewerPanel(path);
67+
_tvp = new TextViewerPanel(path, context);
6868

6969
context.ViewerContent = _tvp;
7070
context.Title = $"{Path.GetFileName(path)}";

QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System.Windows.Input;
2222
using System.Windows.Media;
2323
using ICSharpCode.AvalonEdit.Highlighting;
24-
using QuickLook.Helpers;
2524
using UtfUnknown;
2625

2726
namespace QuickLook.Plugin.TextViewer
@@ -31,7 +30,7 @@ namespace QuickLook.Plugin.TextViewer
3130
/// </summary>
3231
public partial class TextViewerPanel : UserControl
3332
{
34-
public TextViewerPanel(string path)
33+
public TextViewerPanel(string path, ContextObject context)
3534
{
3635
InitializeComponent();
3736

@@ -42,7 +41,7 @@ public TextViewerPanel(string path)
4241
viewer.PreviewMouseWheel += Viewer_MouseWheel;
4342

4443
viewer.FontFamily =
45-
new FontFamily(TranslationHelper.GetString("Editor_FontFamily"));
44+
new FontFamily(context.GetString("Editor_FontFamily"));
4645

4746
LoadFile(path);
4847
}

QuickLook.Plugin/QuickLook.Plugin.VideoViewer/ViewerPanel.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private void TogglePlayPause(object sender, MouseButtonEventArgs e)
266266
[DebuggerNonUserCode]
267267
private void ShowErrorNotification(object sender, EventArgs e)
268268
{
269-
TrayIconManager.GetInstance().ShowNotification("", "An error occurred while loading the video.");
269+
_context.ShowNotification("", "An error occurred while loading the video.");
270270
mediaElement?.Stop();
271271

272272
Dispose();
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright © 2017 Paddy Xu
2+
//
3+
// This file is part of QuickLook program.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Windows;
21+
using System.Windows.Markup;
22+
23+
namespace QuickLook.Actions
24+
{
25+
[ContentProperty("Actions")]
26+
public class ConditionalEventTrigger : FrameworkContentElement
27+
{
28+
public static readonly DependencyProperty ConditionProperty =
29+
DependencyProperty.Register("Condition", typeof(bool), typeof(ConditionalEventTrigger));
30+
31+
public static readonly DependencyProperty TriggersProperty = DependencyProperty.RegisterAttached("Triggers",
32+
typeof(ConditionalEventTriggerCollection), typeof(ConditionalEventTrigger), new PropertyMetadata
33+
{
34+
PropertyChangedCallback = (obj, e) =>
35+
{
36+
// When "Triggers" is set, register handlers for each trigger in the list
37+
var element = (FrameworkElement) obj;
38+
var triggers = (List<ConditionalEventTrigger>) e.NewValue;
39+
foreach (var trigger in triggers)
40+
element.AddHandler(trigger.RoutedEvent, new RoutedEventHandler((obj2, e2) =>
41+
trigger.OnRoutedEvent(element)));
42+
}
43+
});
44+
45+
private static readonly RoutedEvent TriggerActionsEvent = EventManager.RegisterRoutedEvent("",
46+
RoutingStrategy.Direct,
47+
typeof(EventHandler), typeof(ConditionalEventTrigger));
48+
49+
public ConditionalEventTrigger()
50+
{
51+
Actions = new List<TriggerAction>();
52+
}
53+
54+
public RoutedEvent RoutedEvent { get; set; }
55+
public List<TriggerAction> Actions { get; set; }
56+
57+
// Condition
58+
public bool Condition
59+
{
60+
get => (bool) GetValue(ConditionProperty);
61+
set => SetValue(ConditionProperty, value);
62+
}
63+
64+
// "Triggers" attached property
65+
public static ConditionalEventTriggerCollection GetTriggers(DependencyObject obj)
66+
{
67+
return (ConditionalEventTriggerCollection) obj.GetValue(TriggersProperty);
68+
}
69+
70+
public static void SetTriggers(DependencyObject obj, ConditionalEventTriggerCollection value)
71+
{
72+
obj.SetValue(TriggersProperty, value);
73+
}
74+
75+
// When an event fires, check the condition and if it is true fire the actions
76+
private void OnRoutedEvent(FrameworkElement element)
77+
{
78+
DataContext = element.DataContext; // Allow data binding to access element properties
79+
if (Condition)
80+
{
81+
// Construct an EventTrigger containing the actions, then trigger it
82+
var dummyTrigger = new EventTrigger {RoutedEvent = TriggerActionsEvent};
83+
foreach (var action in Actions)
84+
dummyTrigger.Actions.Add(action);
85+
86+
element.Triggers.Add(dummyTrigger);
87+
try
88+
{
89+
element.RaiseEvent(new RoutedEventArgs(TriggerActionsEvent));
90+
}
91+
finally
92+
{
93+
element.Triggers.Remove(dummyTrigger);
94+
}
95+
}
96+
}
97+
}
98+
99+
// Create collection type visible to XAML - since it is attached we cannot construct it in code
100+
public class ConditionalEventTriggerCollection : List<ConditionalEventTrigger>
101+
{
102+
}
103+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright © 2017 Paddy Xu
2+
//
3+
// This file is part of QuickLook program.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
using System.Globalization;
20+
using System.Windows;
21+
using System.Windows.Data;
22+
using System.Windows.Media.Animation;
23+
24+
namespace QuickLook.Converters
25+
{
26+
public sealed class BooleanToKeyTimeConverter : DependencyObject, IValueConverter
27+
{
28+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
29+
{
30+
if (value == null)
31+
return KeyTime.FromTimeSpan(TimeSpan.MaxValue);
32+
33+
var v = (bool) value;
34+
35+
return v
36+
? KeyTime.FromTimeSpan(parameter as TimeSpan? ?? TimeSpan.MaxValue)
37+
: KeyTime.FromTimeSpan(TimeSpan.MaxValue);
38+
}
39+
40+
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
41+
{
42+
throw new NotImplementedException();
43+
}
44+
}
45+
}

QuickLook/Helpers/TranslationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace QuickLook.Helpers
2626
{
27-
public class TranslationHelper
27+
internal class TranslationHelper
2828
{
2929
private static readonly CultureInfo CurrentCultureInfo = CultureInfo.CurrentUICulture;
3030
//private static readonly CultureInfo CurrentCultureInfo = CultureInfo.GetCultureInfo("zh-CN");

0 commit comments

Comments
 (0)