Skip to content

Commit

Permalink
Initial code for latest paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
anovik committed Mar 24, 2024
1 parent b1f5912 commit 734dd00
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/SmartCommander/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.IO;
using System.Threading.Tasks;
using Avalonia.Threading;
using System.Linq;

namespace SmartCommander
{
Expand Down Expand Up @@ -114,6 +115,8 @@ private void App_ShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
{
OptionsModel.Instance.LeftPanePath = viewModel.LeftFileViewModel.CurrentDirectory;
OptionsModel.Instance.RightPanePath = viewModel.RightFileViewModel.CurrentDirectory;
OptionsModel.Instance.LeftPaneLatestPaths = viewModel.LeftFileViewModel.LatestDirectories.ToList();
OptionsModel.Instance.RightPaneLatestPaths = viewModel.RightFileViewModel.LatestDirectories.ToList();
}
}
if (OptionsModel.Instance.SaveWindowPositionSize)
Expand Down
21 changes: 15 additions & 6 deletions src/SmartCommander/Models/OptionsModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using static System.Environment;

Expand All @@ -11,15 +12,19 @@ public class OptionsModel
static string _settingsPath = Path.Combine(_settingsDir, "settings.json");
static OptionsModel()
{
Directory.CreateDirectory(_settingsDir);
if (File.Exists(_settingsPath))
{
var options = JsonConvert.DeserializeObject<OptionsModel>(File.ReadAllText(_settingsPath));
if (options != null)
try
{
Directory.CreateDirectory(_settingsDir);
if (File.Exists(_settingsPath))
{
Instance = options;
var options = JsonConvert.DeserializeObject<OptionsModel>(File.ReadAllText(_settingsPath));
if (options != null)
{
Instance = options;
}
}
}
catch { }
}
public void Save() => File.WriteAllText(_settingsPath, JsonConvert.SerializeObject(this));

Expand Down Expand Up @@ -54,5 +59,9 @@ static OptionsModel()

public bool IsDarkThemeEnabled { get; set; }

public List<string> LeftPaneLatestPaths = new List<string>();

public List<string> RightPaneLatestPaths = new List<string>();

}
}
4 changes: 4 additions & 0 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public enum SortingBy
SortingByDate,
}

// TODO: switch directories text box to editable combo box

public class FilesPaneViewModel : ViewModelBase
{
private string _currentDirectory = "";
Expand All @@ -44,11 +46,13 @@ public string CurrentDirectory
{
_currentDirectory = value;
GetFilesFolders(CurrentDirectory, FoldersFilesList);
// TODO: add to LatestDirectories
this.RaisePropertyChanged("CurrentDirectory");
this.RaisePropertyChanged("CurrentDirectoryInfo");
}
}

public ObservableCollection<string> LatestDirectories { get; set; } = new ObservableCollection<string>();

private MainWindowViewModel _mainVM;

Expand Down
5 changes: 5 additions & 0 deletions src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using SmartCommander.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Compression;
using System.Reactive;
Expand Down Expand Up @@ -45,10 +46,14 @@ public MainWindowViewModel()
if (!string.IsNullOrEmpty(OptionsModel.Instance.LeftPanePath))
{
LeftFileViewModel.CurrentDirectory = OptionsModel.Instance.LeftPanePath;
LeftFileViewModel.LatestDirectories = new ObservableCollection<string>(
OptionsModel.Instance.LeftPaneLatestPaths);
}
if (!string.IsNullOrEmpty(OptionsModel.Instance.RightPanePath))
{
RightFileViewModel.CurrentDirectory = OptionsModel.Instance.RightPanePath;
RightFileViewModel.LatestDirectories = new ObservableCollection<string>(
OptionsModel.Instance.RightPaneLatestPaths);
}
SetTheme();
_progress = new Progress<int>(v => Progress_Show(v));
Expand Down

0 comments on commit 734dd00

Please sign in to comment.