Skip to content

Commit

Permalink
chore: update assembly name; more fine tune fixes for drag position.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir Dahal committed Mar 24, 2024
1 parent 6504887 commit 5e39ec0
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 20 deletions.
24 changes: 19 additions & 5 deletions SambatWidget.Core/BaseCalendarRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,22 @@ public string GetConsecutiveEnglishMonthsPair()
return remainingDays;
}
}
public string GetWeekDayName() => _carouselNepDate.EnglishDate.DayOfWeek.ToString();
public string GetShortWeekDayName() => _carouselNepDate.EnglishDate.ToString("ddd");
public string GetWeekDayName()
{
if (!IsToday())
{
return GetThisMonthNepaliStartDate().DayOfWeek.ToString();
}
return DateTime.Now.DayOfWeek.ToString();
}
public string GetShortWeekDayName()
{
if (!IsToday())
{
return GetThisMonthNepaliStartDate().EnglishDate.ToString("ddd");
}
return DateTime.Now.ToString("ddd");
}
public bool IsToday() => NepaliDate.Now == _carouselNepDate;
public string GetFormattedEnglishDate() => _carouselNepDate.EnglishDate.ToString("dd MMM, yyyy");
public string GetFormattedNepaliDate()
Expand Down Expand Up @@ -97,15 +111,15 @@ private IEnumerable<WidgetCalendarCellModel> Render()
{
return PrepareCalendarDataGrid(Populate());
}
private int GetThisMonthStartDateIndex()
private NepaliDate GetThisMonthNepaliStartDate()
{
return (int)new NepaliDate(_carouselNepDate.Year, _carouselNepDate.Month, 1).DayOfWeek;
return new NepaliDate(_carouselNepDate.Year, _carouselNepDate.Month, 1);
}
private IEnumerable<WidgetCalendarCellModel> PrepareCalendarDataGrid(List<WidgetCalendarCellModel> cells)
{
int currRow = 0;
int currCol = 0;
int monthStartDateIndex = GetThisMonthStartDateIndex();
int monthStartDateIndex = (int)GetThisMonthNepaliStartDate().DayOfWeek;
for (int i = 0; i < cells.Count(); i++)
{
if (currRow == 4 && currCol == 6)
Expand Down
53 changes: 38 additions & 15 deletions SambatWidget.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,41 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
if (!_settings.Loaded) return;
if (!_settings.DefaultPositionSet)
else if (!_settings.DefaultPositionSet)
{
_settings.SetDefaultPosition(InitPosition);
CalculateAndSaveWindowMoveOffset();
return;
}
base.OnRenderSizeChanged(sizeInfo);
try
else
{
if (!_vm.IsExpanded)
{
this.Top = (App.Setting.Position.Y + _settings.WindowHeight) - this.WidgetHeader.ActualHeight;
}
else
{
this.Top = (App.Setting.Position.Y + this.WidgetHeader.ActualHeight) - this.ActualHeight;
}
base.OnRenderSizeChanged(sizeInfo);
}
finally
if (_settings.IsRenderedAfterMouseAction)
{
CalculateAndSaveWindowMoveOffset();
CalculateWidgetPositionState();
_settings.SetMouseActionRender(false);
}
CalculateAndSaveWindowMoveOffset();
}

private void CalculateWidgetPositionState()
{
if (!_vm.IsExpanded)
{
this.Top = (App.Setting.Position.Y + _settings.WindowHeight) - this.WidgetHeader.ActualHeight;
}
else
{
this.Top = (App.Setting.Position.Y + this.WidgetHeader.ActualHeight) - this.ActualHeight;
}
}

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
try
{
IsMouseDown = false;
_settings.SetMouseActionRender(true);
if (_settings.Position.X == this.Left && _settings.Position.Y == this.Top)
{
_vm.ToggleExpandCommand.Execute(null);
Expand Down Expand Up @@ -114,6 +120,23 @@ protected override void OnKeyUp(KeyEventArgs e)
break;
}
}
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
try
{
_settings.SetWindowHeight(this.ActualHeight);
_settings.SetMouseActionRender(true);
if (App.Setting.MinimizeOnLostFocus && !App.IsShuttingDown)
{
_vm.MinimizeWidgetCommand.Execute(null);
}
}
finally
{
CalculateAndSaveWindowMoveOffset();
}
}
private void CalculateAndSaveWindowMoveOffset()
{
this.CalculateWindowMoveOffset();
Expand Down
1 change: 1 addition & 0 deletions SambatWidget.UI/Models/SettingModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class SettingModel
public bool LockPosition { get; set; }
public bool AllowTransparency { get; set; }
public string TimeZone { get; set; }
public bool MinimizeOnLostFocus { get; set; }
public bool ShowTimeZoneOffset { get; set; }
public bool AutoRunAtStartup { get; set; }
public bool AllowGlobalPosition { get; set; } = true;
Expand Down
5 changes: 5 additions & 0 deletions SambatWidget.UI/Models/WidgetWindowSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class WidgetWindowSetting
{
public bool Loaded { get; private set; }
public bool DefaultPositionSet { get; private set; }
public bool IsRenderedAfterMouseAction { get; private set; }
public Point Position { get; private set; }
public double WindowHeight { get; private set; }
public WidgetWindowSetting()
Expand All @@ -36,5 +37,9 @@ public void SetDefaultPosition(Action action)
action();
DefaultPositionSet = true;
}
public void SetMouseActionRender(bool isMouseAction)
{
IsRenderedAfterMouseAction = isMouseAction;
}
}
}
5 changes: 5 additions & 0 deletions SambatWidget.UI/Resources/WidgetContextMenus.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
Header="Show Timezone"
IsCheckable="True"
IsChecked="{Binding ShowTimeZone}" />
<MenuItem
Command="{Binding WidgetContextMenuViewModel.ToggleMinimizeOnLostFocusCommand}"
Header="Minimize On Lost Focus"
IsCheckable="True"
IsChecked="{Binding WidgetContextMenuViewModel.MinimizeOnLostFocus}" />
<MenuItem
Command="{Binding WidgetContextMenuViewModel.ToggleAutoRunAtStartupCommand}"
Header="Autorun at startup"
Expand Down
1 change: 1 addition & 0 deletions SambatWidget.UI/SambatWidget.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<AssemblyName>SambatWidget</AssemblyName>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions SambatWidget.UI/ViewModels/WidgetContextMenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public partial class WidgetContextMenuViewModel : ObservableObject
[ObservableProperty]
bool isLocked = App.Setting.LockPosition;

[ObservableProperty]
bool minimizeOnLostFocus = App.Setting.MinimizeOnLostFocus;

[ObservableProperty]
bool globalPosition = App.Setting.AllowGlobalPosition;

Expand Down Expand Up @@ -47,6 +50,11 @@ private void LockPosition()
App.Setting.LockPosition = IsLocked;
}
[RelayCommand]
private void ToggleMinimizeOnLostFocus()
{
App.Setting.MinimizeOnLostFocus = MinimizeOnLostFocus;
}
[RelayCommand]
private void ShowSetting()
{
new SettingWindow().ShowDialog();
Expand Down
10 changes: 10 additions & 0 deletions SambatWidget.UI/ViewModels/WidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ private void ShowToday()
});
}
[RelayCommand]
private void MinimizeWidget()
{
Render(() =>
{
IsExpanded = false;
App.Setting.IsExpanded = false;
DecideWhenToTransparent();
});
}
[RelayCommand]
private void ToggleExpand()
{
Render(() =>
Expand Down

0 comments on commit 5e39ec0

Please sign in to comment.