Skip to content

Commit

Permalink
Bugfix project path not automatically generated and history not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
fahminlb33 committed Jan 29, 2022
1 parent 7d6ba51 commit 6241617
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
11 changes: 7 additions & 4 deletions src/KFlearning.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ static void Main()
Log.Debug("Enabling TLS support");
NetworkHelpers.EnableTls();

// app exit handler
Application.ApplicationExit += Application_ApplicationExit;

// bootstrapper
Log.Debug("Bootstrapping application");
ApplicationConfiguration.Initialize();
Expand All @@ -85,6 +82,10 @@ static void Main()
MessageBox.Show(MessagesText.FatalShutdown, MessagesText.AppName,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
AppExitHandler();
}
}

private static void RegisterLogger()
Expand Down Expand Up @@ -128,6 +129,8 @@ private static void RegisterServices()
services.AddTransient<ITemplateProvider, PythonProvider>();
services.AddTransient<ITemplateProvider, WebProvider>();

services.AddTransient<IUsesPersistence, HistoryService>();

// register clients
services.AddTransient<WebClient>();

Expand All @@ -140,7 +143,7 @@ private static void RegisterServices()
Container = services.BuildServiceProvider();
}

private static void Application_ApplicationExit(object? sender, EventArgs e)
private static void AppExitHandler()
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/KFlearning.App/Services/HistoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IHistoryService : IUsesPersistence
public class HistoryService : IHistoryService
{
private const int HistorySize = 20;
private const string HistorySettingsName = "History.Settings";
private const string HistorySettingsName = "history";

private readonly List<Project> _projects = new List<Project>();
private readonly IPersistanceStorage _storage;
Expand Down
9 changes: 3 additions & 6 deletions src/KFlearning.App/Views/CreateProjectView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public void BindData()
cboTemplate.DataSource = _presenter.CboTemplateDataSource;
cboTemplate.DisplayMember = _presenter.CboTemplateDisplayMember;

txtProjectName.DataBindings.Add(nameof(txtProjectName.Text), _presenter,
nameof(_presenter.TxtProjectNameText));

txtLocation.DataBindings.Add(nameof(txtLocation.Text), _presenter,
nameof(_presenter.TxtLocationText));
}
Expand All @@ -38,7 +35,7 @@ protected override void OnLoad(EventArgs e)

private void cmdCreate_Click(object sender, EventArgs e)
{
if (!_presenter.CmdCreateClickHandler(cboTemplate.SelectedItem))
if (!_presenter.CmdCreateClickHandler(txtProjectName.Text, cboTemplate.SelectedItem))
{
return;
}
Expand All @@ -55,12 +52,12 @@ private void cmdBrowse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
}

_presenter.BasePath = fbd.SelectedPath;
_presenter.UpdateProjectPath();
_presenter.UpdateProjectPath(txtProjectName.Text);
}

private void txtProjectName_TextChanged(object sender, EventArgs e)
{
_presenter.UpdateProjectPath();
_presenter.UpdateProjectPath(txtProjectName.Text);
}
}
}
32 changes: 12 additions & 20 deletions src/KFlearning.App/Views/CreateProjectViewPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using KFlearning.Annotations;
using KFlearning.App.Resources;
using KFlearning.App.Services;
using KFlearning.Core.Services;
using KFlearning.TemplateProvider;
using Microsoft.Extensions.Logging;

Expand All @@ -16,19 +17,20 @@ public class CreateProjectViewPresenter : INotifyPropertyChanged
private readonly ILogger<CreateProjectViewPresenter> _logger;
private readonly IProjectService _projectService;
private readonly ITemplateService _templateService;
private readonly IPathManager _pathManager;

private string _basePath = string.Empty;
private Project? _project;
private object? _cboTemplateDataSource;
private string? _cboTemplateDisplayMember;
private string? _txtLocationText;
private string? _txtProjectNameText;

public CreateProjectViewPresenter(ILogger<CreateProjectViewPresenter> logger, IProjectService projectService, ITemplateService templateService)
public CreateProjectViewPresenter(ILogger<CreateProjectViewPresenter> logger, IProjectService projectService, ITemplateService templateService, IPathManager pathManager)
{
_logger = logger;
_projectService = projectService;
_templateService = templateService;
_pathManager = pathManager;
}

#region Properties
Expand Down Expand Up @@ -77,17 +79,6 @@ public string BasePath
}
}

public string? TxtProjectNameText
{
get => _txtProjectNameText;
set
{
if (value == _txtProjectNameText) return;
_txtProjectNameText = value;
OnPropertyChanged();
}
}

public string? TxtLocationText
{
get => _txtLocationText;
Expand All @@ -103,13 +94,14 @@ public string BasePath

public void OnLoadHandler()
{
BasePath = _pathManager.GetPath(PathKind.ProjectRoot);
CboTemplateDataSource = _templateService.GetTemplates();
CboTemplateDisplayMember = nameof(ITemplateProvider.Title);
}

public bool CmdCreateClickHandler(object selectedItem)
public bool CmdCreateClickHandler(string projectName, object selectedItem)
{
if (string.IsNullOrWhiteSpace(TxtProjectNameText))
if (string.IsNullOrWhiteSpace(projectName))
{
MessageBox.Show(MessagesText.CreateProjectDuplicateError, MessagesText.AppName,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Expand All @@ -132,23 +124,23 @@ public bool CmdCreateClickHandler(object selectedItem)

Project = new Project
{
Name = TxtProjectNameText,
Path = _projectService.GetPathForProject(TxtProjectNameText, BasePath),
Name = projectName,
Path = _projectService.GetPathForProject(projectName, BasePath),
Template = (ITemplateProvider)selectedItem,
CreatedAt = DateTime.Now
};

return true;
}

public void UpdateProjectPath()
public void UpdateProjectPath(string projectName)
{
if (string.IsNullOrWhiteSpace(TxtProjectNameText))
if (string.IsNullOrWhiteSpace(projectName))
{
return;
}

TxtLocationText = _projectService.GetPathForProject(TxtProjectNameText, BasePath);
TxtLocationText = _projectService.GetPathForProject(projectName, BasePath);
}

#region INotifyPropertyChanged Implementation
Expand Down

0 comments on commit 6241617

Please sign in to comment.