Skip to content

Commit

Permalink
fix height/width of columns
Browse files Browse the repository at this point in the history
Add height/width of window saving
  • Loading branch information
xantari committed Feb 4, 2021
1 parent 2de7d3b commit d1ac66b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
67 changes: 47 additions & 20 deletions PinCab.Configurator/DatabaseBrowserForm.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using DuoVia.FuzzyStrings;
using FluentDateTime;
using Newtonsoft.Json;
using PinCab.Configurator.Models;
using PinCab.Configurator.Utils;
using PinCab.Utils;
using PinCab.Utils.Extensions;
using PinCab.Utils.Models;
using PinCab.Utils.Utils;
Expand All @@ -14,12 +12,8 @@
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PinCab.Configurator
Expand All @@ -30,11 +24,19 @@ public partial class DatabaseBrowserForm : Form
private readonly DatabaseBrowserSettingsManager _settingManager = new DatabaseBrowserSettingsManager();
//private BackgroundQueue _queue = new BackgroundQueue();
private bool _loading = true;
private DatabaseBrowserSettings _settings { get; set; }

public DatabaseBrowserForm()
{
InitializeComponent();

_settings = _settingManager.LoadSettings();
if (_settings == null) //Load the defaults and save to the filesystem
{
_settings = new DatabaseBrowserSettings();
_settingManager.SaveSettings(_settings);
}

_dbManager = new DatabaseManager(backgroundWorkerProgressBar.ReportProgress);

if (!SystemInformation.TerminalServerSession)
Expand All @@ -50,40 +52,58 @@ public DatabaseBrowserForm()

private void ConfigureFilters()
{
//TODO: Load from the last state (create a database form manager that persists filter selections to .json setting file)
var settings = _settingManager.LoadSettings();
if (settings == null) //Load the defaults and save to the filesystem
{
settings = new DatabaseBrowserSettings();
_settingManager.SaveSettings(settings);
}
dateTimePickerBegin.Value = settings.BeginDate.BeginningOfDay();
dateTimePickerEnd.Value = settings.EndDate.EndOfDay();
//Load from the last state (create a database form manager that persists filter selections to .json setting file)
dateTimePickerBegin.Value = _settings.BeginDate.BeginningOfDay();
dateTimePickerEnd.Value = _settings.EndDate.EndOfDay();
var databaseTypeList = EnumExtensions.GetEnumDescriptionList<DatabaseEntryType>();
databaseTypeList.Insert(0, "All");
cmbType.DataSource = databaseTypeList;
txtSearch.Text = settings.SearchTerm;
txtSearch.Text = _settings.SearchTerm;

foreach (string type in cmbType.Items)
{
if (type == settings.TypeFilter)
if (type == _settings.TypeFilter)
cmbType.SelectedItem = type;
}

foreach (string type in cmbDatabase.Items)
{
if (type == settings.DatabaseFilter)
if (type == _settings.DatabaseFilter)
cmbDatabase.SelectedItem = type;
}

foreach (var tag in settings.TagFilter)
foreach (var tag in _settings.TagFilter)
{
TagObject tagwinforms = new TagObject(tag, RebindGridUsingFilter);
tagwinforms.Init();
flowLayoutPanelTags.Controls.Add(tagwinforms);
}

flowLayoutPanelTags.Padding = new Padding(3, 3, 3, 3);

if (_settings.WindowHeight > 0 && _settings.WindowWidth > 0)
{
Height = _settings.WindowHeight;
Width = _settings.WindowWidth;
}
}

private void SetDatabaseGridWidths()
{
int count = 1;
foreach (var setting in _settings.DatabaseGridColumnWidths)
{
if (count <= dataGridViewEntryList.Columns.Count)
dataGridViewEntryList.Columns[count - 1].Width = setting;
count++;
}
count = 1;
foreach (var setting in _settings.RelatedGridColumnWidths)
{
if (count <= dataGridViewChildEntries.Columns.Count)
dataGridViewChildEntries.Columns[count - 1].Width = setting;
count++;
}
}

private void LoadDatabaseGrid()
Expand Down Expand Up @@ -126,6 +146,8 @@ private void ConfigureGrid()
column.Resizable = DataGridViewTriState.True;
}
dataGridViewChildEntries.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;

SetDatabaseGridWidths();
//Speed tweak testing
//dataGridViewEntryList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
//dataGridViewEntryList.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
Expand Down Expand Up @@ -463,7 +485,9 @@ private void refreshDatabaseToolStripMenuItem_Click(object sender, EventArgs e)

private void dataGridViewEntryList_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
if (e.ListChangedType != ListChangedType.Reset)
//Autosize the columns only if the user hasn't customized the grid settings or it saved the last
//grid column sizes after first run of the program
if (e.ListChangedType != ListChangedType.Reset && _settings.DatabaseGridColumnWidths.Count == 0)
{
dataGridViewEntryList.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
Expand Down Expand Up @@ -649,6 +673,9 @@ private void DatabaseBrowserForm_FormClosing(object sender, FormClosingEventArgs
settings.RelatedGridColumnWidths.Add(column.Width);
}

settings.WindowHeight = Height;
settings.WindowWidth = Width;

_settingManager.SaveSettings(settings);
}

Expand Down
2 changes: 2 additions & 0 deletions PinCab.Utils/Models/DatabaseBrowserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public DatabaseBrowserSettings()
public DateTime BeginDate { get; set; }
public DateTime EndDate { get; set; }
public string TypeFilter { get; set; }
public int WindowHeight { get; set; }
public int WindowWidth { get; set; }
public List<string> TagFilter { get; set; }
public string DatabaseFilter { get; set; }
public List<int> DatabaseGridColumnWidths { get; set; }
Expand Down

0 comments on commit d1ac66b

Please sign in to comment.