Skip to content

Commit

Permalink
HT-475: Fixed ProjectsListBase to make it possible to select a projec…
Browse files Browse the repository at this point in the history
…t after double-clicking a column header.

Included a little bit of minor code cleanup.
  • Loading branch information
tombogle committed May 22, 2024
1 parent 69d5653 commit f85cea7
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 69 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [14.1.1] - 2024-05-23

### Fixed

- [SIL.Windows.Forms.DblBundle] Fixed bug in ProjectsListBase that made it impossible to select a project after double-clicking a column header. (See HT-475)

## [14.1.0] - 2024-05-13

### Added
Expand Down Expand Up @@ -391,7 +397,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [SIL.NUnit3Compatibility] new project/package that allows to use NUnit3 syntax with NUnit2
projects

[Unreleased]: https://github.com/sillsdev/libpalaso/compare/v14.1.0...master
[Unreleased]: https://github.com/sillsdev/libpalaso/compare/v14.1.1...master
[14.1.1]: https://github.com/sillsdev/libpalaso/compare/v14.1.0...v14.1.1
[14.1.0]: https://github.com/sillsdev/libpalaso/compare/v14.0.0...v14.1.0
[14.0.0]: https://github.com/sillsdev/libpalaso/compare/v13.0.1...v14.0.0
[13.0.1]: https://github.com/sillsdev/libpalaso/compare/v13.0.0...v13.0.1
Expand Down
1 change: 1 addition & 0 deletions Palaso.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Annotatable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Arbil/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Argb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=autosize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bbbcccvvv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BBCCCVVV/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bidi/@EntryIndexedValue">True</s:Boolean>
Expand Down
76 changes: 40 additions & 36 deletions SIL.Windows.Forms.DblBundle/ProjectsListBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using JetBrains.Annotations;
using L10NSharp;
using SIL.DblBundle;
using SIL.DblBundle.Text;
Expand Down Expand Up @@ -36,15 +37,15 @@ public abstract partial class ProjectsListBase<TM, TL> : UserControl
private bool m_projectSelected; // The value of this boolean is only reliable if m_sorting is true.
private bool m_sorting;

public ProjectsListBase()
protected ProjectsListBase()
{
InitializeComponent();
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string SelectedProject
{
get { return m_selectedProject; }
get => m_selectedProject;
set
{
m_selectedProject = value;
Expand All @@ -61,38 +62,39 @@ public string SelectedProject
}
}

[PublicAPI]
public void AddReadOnlyProject(string projectFilePath)
{
m_readOnlyProjects.Add(projectFilePath);
}

public virtual bool IncludeHiddenProjects
{
get { return m_includeHiddenProjects; }
get => m_includeHiddenProjects;
set
{
m_includeHiddenProjects = value;
ReloadExistingProjects();
}
}

protected virtual DataGridViewColumn InactiveColumn { get { return null; } }
protected virtual DataGridViewColumn InactiveColumn => null;

[PublicAPI]
protected void OverrideColumnHeaderText(int columnIndex, string displayName)
{
m_list.Columns[columnIndex].HeaderText = displayName;
}

[PublicAPI]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool HiddenProjectsExist
{
get { return m_hiddenProjectsExist; }
}
public bool HiddenProjectsExist => m_hiddenProjectsExist;

[PublicAPI]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GridSettings GridSettings
{
get { return GridSettings.Create(m_list); }
get => GridSettings.Create(m_list);
set
{
if (value == null)
Expand Down Expand Up @@ -134,15 +136,18 @@ protected override void OnLoad(EventArgs e)
// don't change the AutoSizeMode of the fill column
if (m_list.Columns[i] == FillColumn)
continue;
int colw = m_list.Columns[i].Width;
int colWidth = m_list.Columns[i].Width;
m_list.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
m_list.Columns[i].Width = colw;
m_list.Columns[i].Width = colWidth;
}
}
}

protected virtual DataGridViewColumn FillColumn { get { return colRecordingProjectName; } }
protected virtual DataGridViewColumn FillColumn => colRecordingProjectName;

/// <summary>
/// Enumeration of folders where existing project files are stored
/// </summary>
protected abstract IEnumerable<string> AllProjectFolders { get; }

protected abstract string ProjectFileExtension { get; }
Expand All @@ -167,8 +172,7 @@ protected virtual IEnumerable<Tuple<string, IProjectInfo>> Projects

protected virtual IProjectInfo GetProjectInfo(string path)
{
Exception exception;
var metadata = DblMetadataBase<TL>.Load<TM>(path, out exception);
var metadata = DblMetadataBase<TL>.Load<TM>(path, out var exception);
return exception == null ? metadata : null;
}

Expand Down Expand Up @@ -215,10 +219,12 @@ private void LoadExistingProjects()
(m_filterBundleId != null && m_filterBundleId != project.Item2.Id))
continue;

List<object> rowData = new List<object>();
rowData.Add(project.Item1);
rowData.Add(project.Item2.Language);
rowData.Add(GetRecordingProjectName(project));
List<object> rowData = new List<object>
{
project.Item1,
project.Item2.Language,
GetRecordingProjectName(project)
};
rowData.AddRange(GetAdditionalRowData(project.Item2));
int iRow = m_list.Rows.Add(rowData.ToArray());

Expand All @@ -240,8 +246,7 @@ private void LoadExistingProjects()
if (SelectedProject != null)
{
SelectedProject = null;
if (SelectedProjectChanged != null)
SelectedProjectChanged(this, new EventArgs());
SelectedProjectChanged?.Invoke(this, EventArgs.Empty);
}
}
else
Expand All @@ -251,8 +256,7 @@ private void LoadExistingProjects()
m_list.CellValueChanged += HandleCellValueChanged;
m_list.CellValidating += HandleCellValidating;

if (ListLoaded != null)
ListLoaded(this, new EventArgs());
ListLoaded?.Invoke(this, EventArgs.Empty);
}

public void SetFilter(string icuLocale, string bundleId)
Expand All @@ -274,16 +278,15 @@ private void HandleSelectionChanged(object sender, EventArgs e)
if (DesignMode || m_list.SelectedRows.Count < 1 || m_list.SelectedRows[0].Index < 0)
SelectedProject = null;
else
SelectedProject = m_list.SelectedRows[0].Cells[colProjectPathOrId.Index].Value as String;
SelectedProject = m_list.SelectedRows[0].Cells[colProjectPathOrId.Index].Value as string;

if (SelectedProjectChanged != null)
SelectedProjectChanged(this, new EventArgs());
SelectedProjectChanged?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// See https://stackoverflow.com/questions/1407195/prevent-datagridview-selecting-a-row-when-sorted-if-none-was-previously-selected/1407261#1407261
/// </summary>
void HandleProjectListSorted(object sender, EventArgs e)
private void HandleProjectListSorted(object sender, EventArgs e)
{
if (m_sorting)
{
Expand All @@ -301,18 +304,21 @@ void HandleProjectListSorted(object sender, EventArgs e)
private void HandleCellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
// ignore double-click of header cells
if (e.RowIndex < 0) return;
OnDoubleClick(new EventArgs());
if (e.RowIndex < 0)
{
m_sorting = false;
return;
}

OnDoubleClick(EventArgs.Empty);
}

private void HandleListCellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
// clicking on the header row
// also make sure we're not already set for sorting -- can happen if header is double-clicked
if ((e.Button == MouseButtons.Left) && (e.RowIndex == -1) && !m_sorting)
{
if (e.Button == MouseButtons.Left && e.RowIndex == -1 && !m_sorting)
PrepareToSort();
}
}

protected virtual void SetHiddenFlag(bool inactive)
Expand Down Expand Up @@ -348,14 +354,12 @@ private void HandleCellValidating(object sender, DataGridViewCellValidatingEvent

private void HandleColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
if (ColumnWidthChanged != null)
ColumnWidthChanged(this, e);
ColumnWidthChanged?.Invoke(this, e);
}

private void HandleColumnDisplayIndexChanged(object sender, DataGridViewColumnEventArgs e)
{
if (ColumnDisplayIndexChanged != null)
ColumnDisplayIndexChanged(this, e);
ColumnDisplayIndexChanged?.Invoke(this, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1" PrivateAssets="all" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="L10NSharp" Version="7.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="SIL.ReleaseTasks" Version="2.5.0" PrivateAssets="All" />
Expand Down
117 changes: 117 additions & 0 deletions TestApps/SIL.Windows.Forms.TestApp/ChooseProject.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f85cea7

Please sign in to comment.