Skip to content

Commit d5c7326

Browse files
committed
feat(settings, database): redesign settings UI and add database operations with backup
- Redesigned settings UI for improved clarity and user experience - Added main SQLite operations: integrity check, vacuum, reindex with badge status indicators - Implemented database backup feature with automatic date-based naming - Included error handling with user dialogs for feedback
1 parent db2f2c6 commit d5c7326

File tree

8 files changed

+333
-101
lines changed

8 files changed

+333
-101
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
using System.Windows.Media;
4+
5+
namespace CodeSnip.Helpers
6+
{
7+
public class ResultToBrushConverter : IValueConverter
8+
{
9+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10+
{
11+
string? result = value as string;
12+
if (string.IsNullOrEmpty(result))
13+
return Brushes.Gray;
14+
15+
if (result == "✓")
16+
return Brushes.Green;
17+
else if (result == "✗")
18+
return Brushes.Red;
19+
20+
return Brushes.Gray;
21+
}
22+
23+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
throw new NotImplementedException();
26+
}
27+
}
28+
29+
}

src/CodeSnip/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private void OpenSettings()
327327
// Store current values before opening the flyout to check for changes later
328328
bool oldShowEmptyLanguages = ShowEmptyLanguages;
329329
bool oldShowEmptyCategories = ShowEmptyCategories;
330-
var vm = new SettingsViewModel(settingsService);
330+
var vm = new SettingsViewModel(settingsService, _databaseService);
331331
_flyoutService.ShowFlyout("flySettings", vm, "Settings", () =>
332332
{
333333
settingsService.HighlightLine = vm.HighlightLine;

src/CodeSnip/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<helpers:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
3232

3333
<DataTemplate DataType="{x:Type settingsView:SettingsViewModel}">
34-
<settingsView:SetingsView />
34+
<settingsView:SettingsView />
3535
</DataTemplate>
3636
<DataTemplate DataType="{x:Type codeRunnerView:CodeRunnerViewModel}">
3737
<codeRunnerView:CodeRunnerView />

src/CodeSnip/Services/DatabaseService.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,50 @@ public void DeleteCategory(int id)
341341
conn.Execute("DELETE FROM Categories WHERE ID = @Id", new { Id = id });
342342
}
343343

344+
public async Task<bool> RunIntegrityCheckAsync()
345+
{
346+
try
347+
{
348+
using var conn = CreateConnection();
349+
var result = await conn.QueryAsync<string>("PRAGMA integrity_check;");
350+
return result.Count() == 1 && result.First() == "ok";
351+
}
352+
catch (Exception ex)
353+
{
354+
await DialogService.Instance.ShowMessageAsync("Integrity Check Failed", ex.Message);
355+
return false;
356+
}
357+
}
344358

359+
public async Task<bool> RunVacuumAsync()
360+
{
361+
try
362+
{
363+
using var conn = CreateConnection();
364+
await conn.ExecuteAsync("VACUUM;");
365+
return true;
366+
}
367+
catch (Exception ex)
368+
{
369+
await DialogService.Instance.ShowMessageAsync("Vacuum Failed", ex.Message);
370+
return false;
371+
}
372+
}
373+
374+
public async Task<bool> RunReindexAsync()
375+
{
376+
try
377+
{
378+
using var conn = CreateConnection();
379+
await conn.ExecuteAsync("REINDEX;");
380+
return true;
381+
}
382+
catch (Exception ex)
383+
{
384+
await DialogService.Instance.ShowMessageAsync("Reindex Failed", ex.Message);
385+
return false;
386+
}
387+
}
345388

346389
private const string ddl = @"
347390
CREATE TABLE IF NOT EXISTS Languages (

src/CodeSnip/Views/SettingsView/SetingsView.xaml

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)