Skip to content

Commit

Permalink
Added capability of saving column sizes in Settings/Organs (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 authored Mar 25, 2024
1 parent 4b358fe commit b92ab3e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/grandorgue/dialogs/settings/GOSettingsDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -63,8 +63,9 @@ GOSettingsDialog::GOSettingsDialog(
AddTab(m_MidiDevicePage, PAGE_MIDI_DEVICES, _("MIDI Devices"));
m_MidiMessagePage = new GOSettingsMidiMessage(config, midi, notebook);
AddTab(m_MidiMessagePage, PAGE_INITIAL_MIDI, _("Initial MIDI"));
m_OrgansPage = new GOSettingsOrgans(config, midi, notebook);
AddTab(m_OrgansPage, PAGE_ORGANS, _("Organs"));
m_OrgansPage
= new GOSettingsOrgans(config, midi, this, PAGE_ORGANS, _("Organs"));
AddTab(m_OrgansPage);
m_ReverbPage = new GOSettingsReverb(config, notebook);
AddTab(m_ReverbPage, PAGE_REVERB, _("Reverb"));
m_TemperamentsPage = new GOSettingsTemperaments(config, notebook);
Expand Down
26 changes: 24 additions & 2 deletions src/grandorgue/dialogs/settings/GOSettingsOrgans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "config/GOConfig.h"
#include "dialogs/midi-event/GOMidiEventDialog.h"
#include "files/GOStdFileName.h"
#include "size/GOAdditionalSizeKeeperProxy.h"
#include "wxcontrols/GOGrid.h"

#include "GOOrgan.h"
Expand All @@ -54,8 +55,12 @@ END_EVENT_TABLE()
enum { GRID_COL_NAME = 0, GRID_COL_MIDI, GRID_COL_PATH, GRID_N_COLS };

GOSettingsOrgans::GOSettingsOrgans(
GOConfig &settings, GOMidi &midi, wxWindow *parent)
: wxPanel(parent, wxID_ANY),
GOConfig &settings,
GOMidi &midi,
GOTabbedDialog *pDlg,
const wxString &name,
const wxString &label)
: GODialogTab(pDlg, name, label),
m_config(settings),
m_midi(midi),
m_OrigOrganList(settings.GetOrganList()),
Expand Down Expand Up @@ -660,6 +665,23 @@ void GOSettingsOrgans::ReplaceOrganPath(
}
}

const wxString WX_GRID_ORGANS = wxT("GridOrgans");

void GOSettingsOrgans::ApplyAdditionalSizes(
const GOAdditionalSizeKeeper &sizeKeeper) {
GOAdditionalSizeKeeperProxy proxyGridOrgans(
const_cast<GOAdditionalSizeKeeper &>(sizeKeeper), WX_GRID_ORGANS);

m_GridOrgans->ApplyColumnSizes(proxyGridOrgans);
}

void GOSettingsOrgans::CaptureAdditionalSizes(
GOAdditionalSizeKeeper &sizeKeeper) const {
GOAdditionalSizeKeeperProxy proxyGridOrgans(sizeKeeper, WX_GRID_ORGANS);

m_GridOrgans->CaptureColumnSizes(proxyGridOrgans);
}

void GOSettingsOrgans::OnOrganUp(wxCommandEvent &event) {
VisibleOrganRecs recs(GetCurrentOrganRecs());
const int l = recs.size();
Expand Down
17 changes: 14 additions & 3 deletions src/grandorgue/dialogs/settings/GOSettingsOrgans.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <unordered_set>

#include <wx/hashset.h>
#include <wx/panel.h>

#include "dialogs/common/GODialogTab.h"

#include "ptrvector.h"

Expand All @@ -22,12 +23,13 @@ class wxGridEvent;
class wxGridRangeSelectEvent;
class wxTextCtrl;

class GOAdditionalSizeKeeper;
class GOArchiveFile;
class GOConfig;
class GOGrid;
class GOOrgan;

class GOSettingsOrgans : public wxPanel {
class GOSettingsOrgans : public GODialogTab {
public:
enum {
ID_ORGANS = 200,
Expand Down Expand Up @@ -116,6 +118,10 @@ class GOSettingsOrgans : public wxPanel {
void DelSelectedOrgans();
void ReplaceOrganPath(const unsigned index, const wxString &newPath);

void ApplyAdditionalSizes(const GOAdditionalSizeKeeper &sizeKeeper) override;
void CaptureAdditionalSizes(
GOAdditionalSizeKeeper &sizeKeeper) const override;

void OnCharHook(wxKeyEvent &ev);

void OnOrganSelectCell(wxGridEvent &event);
Expand All @@ -130,7 +136,12 @@ class GOSettingsOrgans : public wxPanel {
void OnDelPreset(wxCommandEvent &event);

public:
GOSettingsOrgans(GOConfig &settings, GOMidi &midi, wxWindow *parent);
GOSettingsOrgans(
GOConfig &settings,
GOMidi &midi,
GOTabbedDialog *pDlg,
const wxString &name,
const wxString &label);

virtual bool TransferDataToWindow() override;
virtual bool TransferDataFromWindow() override;
Expand Down
2 changes: 2 additions & 0 deletions src/grandorgue/size/GOSizeKeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void GOSizeKeeper::Load(GOConfigReader &cfg, const wxString &group) {
CMBSetting,
m_group,
wxString::Format(WX_ADDITIONAL_SIZE_VALUE_FMT, i),
0,
32000,
false,
-1);
}
Expand Down
20 changes: 20 additions & 0 deletions src/grandorgue/wxcontrols/GOGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <wx/dc.h>

#include "size/GOAdditionalSizeKeeper.h"

class RightVisibleCellRenderer : public wxGridCellStringRenderer {
virtual void Draw(
wxGrid &grid,
Expand Down Expand Up @@ -201,6 +203,24 @@ void GOGrid::SetColumnRightVisible(unsigned colN, bool isRightVisible) {
m_AreColumnsRightVisible[colN] = isRightVisible;
}

const wxString WX_COL_SIZE_KEY_FMT = wxT("Column%03dSize");

void GOGrid::ApplyColumnSizes(const GOAdditionalSizeKeeper &sizeKeeper) {
for (int l = GetNumberCols(), i = 0; i < l; i++) {
int newSize
= sizeKeeper.GetAdditionalSize(wxString::Format(WX_COL_SIZE_KEY_FMT, i));

if (newSize > 0)
SetColSize(i, newSize);
}
}

void GOGrid::CaptureColumnSizes(GOAdditionalSizeKeeper &sizeKeeper) const {
for (int l = GetNumberCols(), i = 0; i < l; i++)
sizeKeeper.SetAdditionalSize(
wxString::Format(WX_COL_SIZE_KEY_FMT, i), GetColSize(i));
}

wxGridCellRenderer *GOGrid::GetDefaultRendererForCell(int row, int col) const {
wxGridCellRenderer *pRenderer;

Expand Down
5 changes: 5 additions & 0 deletions src/grandorgue/wxcontrols/GOGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <wx/grid.h>

class GOAdditionalSizeKeeper;

class GOGrid : public wxGrid {
private:
wxGridCellStringRenderer *p_RightVisibleRenderer;
Expand All @@ -30,6 +32,9 @@ class GOGrid : public wxGrid {
bool IsColumnRightVisible(unsigned colN) const;
void SetColumnRightVisible(unsigned colN, bool isRightVisible);

void ApplyColumnSizes(const GOAdditionalSizeKeeper &sizeKeeper);
void CaptureColumnSizes(GOAdditionalSizeKeeper &sizeKeeper) const;

virtual wxGridCellRenderer *GetDefaultRendererForCell(
int row, int col) const override;
};
Expand Down

0 comments on commit b92ab3e

Please sign in to comment.