Skip to content

Commit

Permalink
Code Quality: Changed default settings for Network locations widget (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored May 22, 2024
1 parent dac6a20 commit 4b77a5a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Files.App/Services/Settings/GeneralSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public bool ShowDrivesWidget

public bool ShowNetworkLocationsWidget
{
get => Get(false);
get => Get(true);
set => Set(value);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ public bool DrivesWidgetExpanded

public bool NetworkLocationsWidgetExpanded
{
get => Get(true);
get => Get(false);
set => Set(value);
}

Expand Down
37 changes: 19 additions & 18 deletions src/Files.App/ViewModels/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,78 @@ public HomeViewModel()

// Methods

public void ReloadWidgets()
private void ReloadWidgets()
{
var reloadQuickAccessWidget = WidgetsHelpers.TryGetWidget<QuickAccessWidgetViewModel>(this);
var reloadDrivesWidget = WidgetsHelpers.TryGetWidget<DrivesWidgetViewModel>(this);
var reloadNetworkLocationsWidget = WidgetsHelpers.TryGetWidget<NetworkLocationsWidgetViewModel>(this);
var reloadFileTagsWidget = WidgetsHelpers.TryGetWidget<FileTagsWidgetViewModel>(this);
var reloadRecentFilesWidget = WidgetsHelpers.TryGetWidget<RecentFilesWidgetViewModel>(this);
var insertIndex = 0;

if (reloadQuickAccessWidget)
{
var quickAccessWidget = new QuickAccessWidget();

AddWidget(
InsertWidget(
new(
quickAccessWidget,
quickAccessWidget.ViewModel,
(value) => UserSettingsService.GeneralSettingsService.FoldersWidgetExpanded = value,
() => UserSettingsService.GeneralSettingsService.FoldersWidgetExpanded));
() => UserSettingsService.GeneralSettingsService.FoldersWidgetExpanded),
insertIndex++);
}

if (reloadDrivesWidget)
{
var drivesWidget = new DrivesWidget();

AddWidget(
InsertWidget(
new(
drivesWidget,
drivesWidget.ViewModel,
(value) => UserSettingsService.GeneralSettingsService.DrivesWidgetExpanded = value,
() => UserSettingsService.GeneralSettingsService.DrivesWidgetExpanded));
() => UserSettingsService.GeneralSettingsService.DrivesWidgetExpanded),
insertIndex++);
}

if (reloadNetworkLocationsWidget)
{
var networkLocationsWidget = new NetworkLocationsWidget();

AddWidget(
InsertWidget(
new(
networkLocationsWidget,
networkLocationsWidget.ViewModel,
(value) => UserSettingsService.GeneralSettingsService.NetworkLocationsWidgetExpanded = value,
() => UserSettingsService.GeneralSettingsService.NetworkLocationsWidgetExpanded));
() => UserSettingsService.GeneralSettingsService.NetworkLocationsWidgetExpanded),
insertIndex++);
}

if (reloadFileTagsWidget)
{
var fileTagsWidget = new FileTagsWidget();

AddWidget(
InsertWidget(
new(
fileTagsWidget,
fileTagsWidget.ViewModel,
(value) => UserSettingsService.GeneralSettingsService.FileTagsWidgetExpanded = value,
() => UserSettingsService.GeneralSettingsService.FileTagsWidgetExpanded));
() => UserSettingsService.GeneralSettingsService.FileTagsWidgetExpanded),
insertIndex++);
}

if (reloadRecentFilesWidget)
{
var recentFilesWidget = new RecentFilesWidget();

AddWidget(
InsertWidget(
new(
recentFilesWidget,
recentFilesWidget.ViewModel,
(value) => UserSettingsService.GeneralSettingsService.RecentFilesWidgetExpanded = value,
() => UserSettingsService.GeneralSettingsService.RecentFilesWidgetExpanded));
() => UserSettingsService.GeneralSettingsService.RecentFilesWidgetExpanded),
insertIndex++);
}
}

Expand All @@ -109,12 +115,7 @@ public void RefreshWidgetList()
ReloadWidgets();
}

public bool AddWidget(WidgetContainerItem widgetModel)
{
return InsertWidget(widgetModel, WidgetItems.Count + 1);
}

public bool InsertWidget(WidgetContainerItem widgetModel, int atIndex)
private bool InsertWidget(WidgetContainerItem widgetModel, int atIndex)
{
// The widget must not be null and must implement IWidgetItemModel
if (widgetModel.WidgetItemModel is not IWidgetViewModel widgetItemModel)
Expand Down Expand Up @@ -145,7 +146,7 @@ public bool CanAddWidget(string widgetName)
return !(WidgetItems.Any((item) => item.WidgetItemModel.WidgetName == widgetName));
}

public void RemoveWidgetAt(int index)
private void RemoveWidgetAt(int index)
{
if (index < 0)
{
Expand Down

0 comments on commit 4b77a5a

Please sign in to comment.