Skip to content

Commit c56148f

Browse files
committed
feat(popup): Remember popup width and height, add option to keep on top
1 parent 0a686c6 commit c56148f

File tree

5 files changed

+76
-9
lines changed

5 files changed

+76
-9
lines changed

src/SyncTrayzor/Pages/Settings/SettingsView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<CheckBox DockPanel.Dock="Top" IsChecked="{Binding ShowDeviceOrFolderRejectedBalloons.Value}" Content="{l:Loc SettingsView_ShowDeviceOrFolderRejectedBalloons}"/>
7676
<CheckBox DockPanel.Dock="Top" IsChecked="{Binding ShowTrayIconOnlyOnClose.Value}" Content="{l:Loc SettingsView_OnlyShowTrayIconOnClose}"/>
7777
<CheckBox DockPanel.Dock="Top" IsChecked="{Binding KeepActivityPopupOpen.Value}" Content="{l:Loc SettingsView_KeepActivityPopupOpen}"/>
78+
<CheckBox DockPanel.Dock="Top" IsChecked="{Binding KeepActivityPopupOnTop.Value}" Content="{l:Loc SettingsView_KeepActivityPopupOnTop}"/>
7879
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,5,0,0">
7980
<Label Padding="0,0,5,0" Target="{Binding ElementName=IconAnimationModeSelect}" VerticalAlignment="Center" Content="{l:Loc SettingsView_AnimateTrayIcon}"/>
8081
<ComboBox x:Name="IconAnimationModeSelect" ItemsSource="{Binding IconAnimationModes}" SelectedValuePath="Value" SelectedValue="{Binding IconAnimationMode.Value}"/>

src/SyncTrayzor/Pages/Settings/SettingsViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public class SettingsViewModel : Screen
7171
public SettingItem<bool> ShowDeviceConnectivityBalloons { get; }
7272
public SettingItem<bool> ShowDeviceOrFolderRejectedBalloons { get; }
7373
public SettingItem<bool> KeepActivityPopupOpen { get; }
74+
public SettingItem<bool> KeepActivityPopupOnTop { get; }
75+
public SettingItem<int> ActivityPopupWidth { get; }
76+
public SettingItem<int> ActivityPopupHeight { get; }
7477

7578
public BindableCollection<LabelledValue<IconAnimationMode>> IconAnimationModes { get; }
7679
public SettingItem<IconAnimationMode> IconAnimationMode { get; }
@@ -143,6 +146,9 @@ public SettingsViewModel(
143146
ShowDeviceConnectivityBalloons = CreateBasicSettingItem(x => x.ShowDeviceConnectivityBalloons);
144147
ShowDeviceOrFolderRejectedBalloons = CreateBasicSettingItem(x => x.ShowDeviceOrFolderRejectedBalloons);
145148
KeepActivityPopupOpen = CreateBasicSettingItem(x => x.KeepActivityPopupOpen);
149+
KeepActivityPopupOnTop = CreateBasicSettingItem(x => x.KeepActivityPopupOnTop);
150+
ActivityPopupWidth = CreateBasicSettingItem(x => x.ActivityPopupWidth);
151+
ActivityPopupHeight = CreateBasicSettingItem(x => x.ActivityPopupHeight );
146152

147153
IconAnimationModes = new BindableCollection<LabelledValue<IconAnimationMode>>()
148154
{

src/SyncTrayzor/Pages/Tray/PopupViewModel.cs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public class PopupViewModel : Screen, IDisposable
1212
{
1313
private const int PopupOffsetX = -80;
1414
private readonly IConfigurationProvider configurationProvider;
15-
private bool keepOpen;
1615
private bool isClosing;
1716
private Point initialPopupPosition;
17+
private Configuration configuration;
1818

1919
public FileTransfersTrayViewModel FileTransfersViewModel { get; private set; }
2020

@@ -26,8 +26,7 @@ Func<FileTransfersTrayViewModel> fileTransfersViewModelFactory
2626
initialPopupPosition = WpfScreenHelper.MouseHelper.MousePosition; // Get initial mouse position as early as possible
2727

2828
this.configurationProvider = configurationProvider;
29-
var configuration = configurationProvider.Load();
30-
keepOpen = configuration.KeepActivityPopupOpen;
29+
configuration = configurationProvider.Load();
3130

3231
FileTransfersViewModel = fileTransfersViewModelFactory();
3332
FileTransfersViewModel.ConductWith(this);
@@ -45,7 +44,8 @@ public void SetPopupPosition(Point popupPosition)
4544

4645
protected override void OnActivate()
4746
{
48-
SetViewStartPosition();
47+
LoadViewSettings();
48+
SetViewBounds();
4949
base.OnActivate();
5050
}
5151

@@ -80,7 +80,8 @@ private void View_Closing(object sender, CancelEventArgs e)
8080

8181
private void View_Deactivated(object sender, System.EventArgs e)
8282
{
83-
if (keepOpen)
83+
SaveViewSettings();
84+
if (configuration.KeepActivityPopupOpen)
8485
{
8586
return;
8687
}
@@ -91,16 +92,59 @@ private void View_Deactivated(object sender, System.EventArgs e)
9192
RequestClose();
9293
}
9394

95+
private void LoadViewSettings()
96+
{
97+
if (View is not Window w)
98+
{
99+
return;
100+
}
101+
w.ShowInTaskbar = configuration.KeepActivityPopupOpen;
102+
w.Topmost = configuration.KeepActivityPopupOnTop;
103+
w.Width = configuration.ActivityPopupWidth;
104+
w.Height = configuration.ActivityPopupHeight;
105+
}
106+
107+
private void SaveViewSettings()
108+
{
109+
if (View is not Window w)
110+
{
111+
return;
112+
}
113+
114+
var viewWidth = (int)w.Width;
115+
var viewHeight = (int)w.Height;
116+
if (
117+
viewWidth == configuration.ActivityPopupWidth
118+
&& viewHeight == configuration.ActivityPopupHeight
119+
)
120+
{
121+
return;
122+
}
123+
124+
// save view settings to config
125+
configurationProvider.AtomicLoadAndSave( config =>
126+
{
127+
config.ActivityPopupWidth = viewWidth;
128+
config.ActivityPopupHeight = viewHeight;
129+
} );
130+
}
131+
94132
private void ConfigurationChanged(object sender, ConfigurationChangedEventArgs e)
95133
{
96-
keepOpen = e.NewConfiguration.KeepActivityPopupOpen;
97-
if (!keepOpen && IsActive)
134+
configuration = e.NewConfiguration;
135+
if (!configuration.KeepActivityPopupOpen && IsActive)
98136
{
99137
RequestClose();
138+
return;
139+
}
140+
if (View is not Window w)
141+
{
142+
return;
100143
}
144+
w.Topmost = configuration.KeepActivityPopupOnTop;
101145
}
102146

103-
private void SetViewStartPosition()
147+
private void SetViewBounds()
104148
{
105149
if (View is not Window w)
106150
{

src/SyncTrayzor/Properties/Resources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,10 @@ Please donate to the syncthing project.</value>
10061006
<value>Keep activity popup open</value>
10071007
<comment>Description for checkbox in settings menu</comment>
10081008
</data>
1009+
<data name="SettingsView_KeepActivityPopupOnTop" xml:space="preserve">
1010+
<value>Keep activity popup on top</value>
1011+
<comment>Description for checkbox in settings menu</comment>
1012+
</data>
10091013
<data name="ConflictResolutionView_FileName_FileDeleted" xml:space="preserve">
10101014
<value>[File Deleted]</value>
10111015
<comment>When the base file for a conflict is not found, this placeholder is shown instead of the actual file name</comment>

src/SyncTrayzor/Services/Config/Configuration.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public int Version
2929
public bool ShowDeviceOrFolderRejectedBalloons { get; set; }
3030
public bool ShowSynchronizedBalloonEvenIfNothingDownloaded { get; set; }
3131
public bool KeepActivityPopupOpen { get; set; }
32+
public bool KeepActivityPopupOnTop { get; set; }
33+
public int ActivityPopupWidth { get; set; }
34+
public int ActivityPopupHeight { get; set; }
3235
public string SyncthingAddress { get; set; }
3336
public bool StartSyncthingAutomatically { get; set; }
3437

@@ -112,6 +115,9 @@ public Configuration()
112115
ShowFileInFolderCommand = "explorer.exe /select, \"{0}\"";
113116
LogLevel = LogLevel.Info;
114117
KeepActivityPopupOpen = false;
118+
KeepActivityPopupOnTop = true;
119+
ActivityPopupWidth = 300;
120+
ActivityPopupHeight = 350;
115121
}
116122

117123
public Configuration(Configuration other)
@@ -151,6 +157,9 @@ public Configuration(Configuration other)
151157
ShowFileInFolderCommand = other.ShowFileInFolderCommand;
152158
LogLevel = other.LogLevel;
153159
KeepActivityPopupOpen = other.KeepActivityPopupOpen;
160+
KeepActivityPopupOnTop = other.KeepActivityPopupOnTop;
161+
ActivityPopupWidth = other.ActivityPopupWidth;
162+
ActivityPopupHeight = other.ActivityPopupHeight;
154163
}
155164

156165
public override string ToString()
@@ -170,7 +179,10 @@ public override string ToString()
170179
$"ConflictResolverDeletesToRecycleBin={ConflictResolverDeletesToRecycleBin} PauseDevicesOnMeteredNetworks={PauseDevicesOnMeteredNetworks} " +
171180
$"HaveDonated={HaveDonated} IconAnimationMode={IconAnimationMode} OpenFolderCommand={OpenFolderCommand} ShowFileInFolderCommand={ShowFileInFolderCommand}" +
172181
$"LogLevel={LogLevel}" +
173-
$"KeepActivityPopupOpen={KeepActivityPopupOpen}>";
182+
$"KeepActivityPopupOpen={KeepActivityPopupOpen}>" +
183+
$"KeepActivityPopupOnTop={KeepActivityPopupOnTop}>" +
184+
$"ActivityPopupWindowWidth={ActivityPopupWidth}>"+
185+
$"ActivityPopupWindowHeight={ActivityPopupHeight}>";
174186
}
175187
}
176188
}

0 commit comments

Comments
 (0)