From 2dabf50dda645103cb7f34ee866c3014c6041e15 Mon Sep 17 00:00:00 2001 From: Oleg Samarin Date: Sat, 2 Mar 2024 21:07:50 +0300 Subject: [PATCH] Fixed displaying long file paths in the Paths and Reverb tabs of the settings dialog https://github.com/GrandOrgue/grandorgue/issues/1663 --- src/grandorgue/CMakeLists.txt | 1 + .../dialogs/settings/GOSettingsPaths.cpp | 30 +++++-------- .../dialogs/settings/GOSettingsReverb.cpp | 4 +- src/grandorgue/wxcontrols/GODirPickerCtrl.h | 30 +++++++++++++ src/grandorgue/wxcontrols/GOFilePickerCtrl.h | 32 ++++++++++++++ .../wxcontrols/GORightVisiblePicker.cpp | 19 +++++++++ .../wxcontrols/GORightVisiblePicker.h | 42 +++++++++++++++++++ 7 files changed, 137 insertions(+), 21 deletions(-) create mode 100644 src/grandorgue/wxcontrols/GODirPickerCtrl.h create mode 100644 src/grandorgue/wxcontrols/GOFilePickerCtrl.h create mode 100644 src/grandorgue/wxcontrols/GORightVisiblePicker.cpp create mode 100644 src/grandorgue/wxcontrols/GORightVisiblePicker.h diff --git a/src/grandorgue/CMakeLists.txt b/src/grandorgue/CMakeLists.txt index 80443daea..6768baee7 100644 --- a/src/grandorgue/CMakeLists.txt +++ b/src/grandorgue/CMakeLists.txt @@ -202,6 +202,7 @@ sound/GOSoundStateHandler.cpp sound/GOSound.cpp yaml/GOSaveableToYaml.cpp yaml/go-wx-yaml.cpp +wxcontrols/GORightVisiblePicker.cpp GOAudioGauge.cpp GOAudioRecorder.cpp GOBitmapCache.cpp diff --git a/src/grandorgue/dialogs/settings/GOSettingsPaths.cpp b/src/grandorgue/dialogs/settings/GOSettingsPaths.cpp index 79a23cc12..f2960c095 100644 --- a/src/grandorgue/dialogs/settings/GOSettingsPaths.cpp +++ b/src/grandorgue/dialogs/settings/GOSettingsPaths.cpp @@ -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). */ @@ -14,6 +14,7 @@ #include #include "config/GOConfig.h" +#include "wxcontrols/GODirPickerCtrl.h" GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) : wxPanel(parent, wxID_ANY), m_config(settings) { @@ -27,10 +28,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_Samplesets = new wxDirPickerCtrl( + m_Samplesets = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for open new organs at"), wxDefaultPosition, wxDefaultSize, @@ -43,10 +43,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_OrganPackages = new wxDirPickerCtrl( + m_OrganPackages = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for load new organ packages from"), wxDefaultPosition, wxDefaultSize, @@ -59,10 +58,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_OrganCache = new wxDirPickerCtrl( + m_OrganCache = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for storing organ cache"), wxDefaultPosition, wxDefaultSize, @@ -74,10 +72,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_OrganSettings = new wxDirPickerCtrl( + m_OrganSettings = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for storing organ settings"), wxDefaultPosition, wxDefaultSize, @@ -90,10 +87,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_OrganCombinations = new wxDirPickerCtrl( + m_OrganCombinations = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for export/import organ combinations"), wxDefaultPosition, wxDefaultSize, @@ -106,10 +102,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_ExportImport = new wxDirPickerCtrl( + m_ExportImport = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for export/import organ settings"), wxDefaultPosition, wxDefaultSize, @@ -122,10 +117,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_AudioRecorder = new wxDirPickerCtrl( + m_AudioRecorder = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for your audio recordings"), wxDefaultPosition, wxDefaultSize, @@ -138,10 +132,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_MidiRecorder = new wxDirPickerCtrl( + m_MidiRecorder = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for your MIDI recording"), wxDefaultPosition, wxDefaultSize, @@ -154,10 +147,9 @@ GOSettingsPaths::GOSettingsPaths(GOConfig &settings, wxWindow *parent) 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); grid->Add( - m_MidiPlayer = new wxDirPickerCtrl( + m_MidiPlayer = new GODirPickerCtrl( this, wxID_ANY, - wxEmptyString, _("Select directory for the MIDI player"), wxDefaultPosition, wxDefaultSize, diff --git a/src/grandorgue/dialogs/settings/GOSettingsReverb.cpp b/src/grandorgue/dialogs/settings/GOSettingsReverb.cpp index 95a96bc29..a13491d16 100644 --- a/src/grandorgue/dialogs/settings/GOSettingsReverb.cpp +++ b/src/grandorgue/dialogs/settings/GOSettingsReverb.cpp @@ -19,6 +19,7 @@ #include "config/GOConfig.h" #include "files/GOStandardFile.h" +#include "wxcontrols/GOFilePickerCtrl.h" #include "GOWave.h" @@ -53,10 +54,9 @@ GOSettingsReverb::GOSettingsReverb(GOConfig &settings, wxWindow *parent) new wxStaticText(this, wxID_ANY, _("Impulse response:")), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT); - m_File = new wxFilePickerCtrl( + m_File = new GOFilePickerCtrl( this, ID_FILE, - wxEmptyString, _("Select an impulse file"), _("*.wav"), wxDefaultPosition, diff --git a/src/grandorgue/wxcontrols/GODirPickerCtrl.h b/src/grandorgue/wxcontrols/GODirPickerCtrl.h new file mode 100644 index 000000000..ee2ce57bd --- /dev/null +++ b/src/grandorgue/wxcontrols/GODirPickerCtrl.h @@ -0,0 +1,30 @@ +/* + * Copyright 2006 Milan Digital Audio LLC + * Copyright 2009-2024 GrandOrgue contributors (see AUTHORS) + * License GPL-2.0 or later + * (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). + */ + +#ifndef GODIRPICKERCTRL_H +#define GODIRPICKERCTRL_H + +#include + +#include "GORightVisiblePicker.h" + +class GODirPickerCtrl : public wxDirPickerCtrl, private GORightVisiblePicker { +public: + GODirPickerCtrl( + wxWindow *parent, + wxWindowID id, + const wxString &title, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = 0) + : wxDirPickerCtrl(parent, id, wxEmptyString, title, pos, size, style), + GORightVisiblePicker(this) {} + + OVERRIDE_UPDATE_TEXTCTRL(wxDirPickerCtrl) +}; + +#endif /* GODIRPICKERCTRL_H */ diff --git a/src/grandorgue/wxcontrols/GOFilePickerCtrl.h b/src/grandorgue/wxcontrols/GOFilePickerCtrl.h new file mode 100644 index 000000000..96a1f7b5b --- /dev/null +++ b/src/grandorgue/wxcontrols/GOFilePickerCtrl.h @@ -0,0 +1,32 @@ +/* + * Copyright 2006 Milan Digital Audio LLC + * Copyright 2009-2024 GrandOrgue contributors (see AUTHORS) + * License GPL-2.0 or later + * (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). + */ + +#ifndef GOFILEPICKERCTRL_H +#define GOFILEPICKERCTRL_H + +#include + +#include "GORightVisiblePicker.h" + +class GOFilePickerCtrl : public wxFilePickerCtrl, private GORightVisiblePicker { +public: + GOFilePickerCtrl( + wxWindow *parent, + wxWindowID id, + const wxString &title, + const wxString &wildcard, + const wxPoint &pos = wxDefaultPosition, + const wxSize &size = wxDefaultSize, + long style = 0) + : wxFilePickerCtrl( + parent, id, wxEmptyString, title, wildcard, pos, size, style), + GORightVisiblePicker(this) {} + + OVERRIDE_UPDATE_TEXTCTRL(wxFilePickerCtrl) +}; + +#endif /* GOFILEPICKERCTRL_H */ diff --git a/src/grandorgue/wxcontrols/GORightVisiblePicker.cpp b/src/grandorgue/wxcontrols/GORightVisiblePicker.cpp new file mode 100644 index 000000000..3bf5506ae --- /dev/null +++ b/src/grandorgue/wxcontrols/GORightVisiblePicker.cpp @@ -0,0 +1,19 @@ +/* + * Copyright 2006 Milan Digital Audio LLC + * Copyright 2009-2024 GrandOrgue contributors (see AUTHORS) + * License GPL-2.0 or later + * (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). + */ + +#include "GORightVisiblePicker.h" + +#include +#include + +void GORightVisiblePicker::EnsureRigtIsVisible() { + wxTextCtrl *pTxt = p_picker->GetTextCtrl(); + + if (pTxt) { + pTxt->ShowPosition(pTxt->GetValue().length()); + } +} diff --git a/src/grandorgue/wxcontrols/GORightVisiblePicker.h b/src/grandorgue/wxcontrols/GORightVisiblePicker.h new file mode 100644 index 000000000..8c639441c --- /dev/null +++ b/src/grandorgue/wxcontrols/GORightVisiblePicker.h @@ -0,0 +1,42 @@ +/* + * Copyright 2006 Milan Digital Audio LLC + * Copyright 2009-2024 GrandOrgue contributors (see AUTHORS) + * License GPL-2.0 or later + * (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). + */ + +#ifndef GORIGHTVISIBLEPICKER_H +#define GORIGHTVISIBLEPICKER_H + +class wxPickerBase; + +/** + * This class is designed for enchancing the standard wx*PickerCtrl classes + * If the file name is too long to fit in the text control, it makes visible + * the rightmost part of the filename + * + * Usage: + * 1. make a subclass of wx*PickerCtrl and GORightVisiblePicker + * 2. use the OVERRIDE_UPDATE_TEXTCTRL macro + */ + +class GORightVisiblePicker { +private: + wxPickerBase *p_picker; + +protected: + GORightVisiblePicker(wxPickerBase *pPicker) : p_picker(pPicker) {} + + // Scrolls the text in the text control of the p_picker to right + void EnsureRigtIsVisible(); +}; + +// This macro must be used in the class declaration for overriding the standard +// UpdatePickerFromTextCtrl() method +#define OVERRIDE_UPDATE_TEXTCTRL(baseClass) \ + void UpdateTextCtrlFromPicker() override { \ + baseClass::UpdateTextCtrlFromPicker(); \ + EnsureRigtIsVisible(); \ + } + +#endif /* GORIGHTVISIBLEPICKER_H */