KISTATUSBAR: code refinement and add comments

This commit is contained in:
jean-pierre charras 2024-01-07 09:47:40 +01:00
parent 84d161a4b7
commit 3f70387a17
5 changed files with 53 additions and 19 deletions

View File

@ -33,6 +33,7 @@
#include <background_jobs_monitor.h> #include <background_jobs_monitor.h>
#include <notifications_manager.h> #include <notifications_manager.h>
#include <bitmaps.h> #include <bitmaps.h>
#include <wx/dcclient.h>
#define FIELD_OFFSET_BGJOB_TEXT 0 #define FIELD_OFFSET_BGJOB_TEXT 0
#define FIELD_OFFSET_BGJOB_GAUGE 1 #define FIELD_OFFSET_BGJOB_GAUGE 1
@ -211,3 +212,26 @@ void KISTATUSBAR::SetNotificationCount(int aCount)
// force a repaint or it wont until it gets activity // force a repaint or it wont until it gets activity
Refresh(); Refresh();
} }
#include <widgets/ui_common.h>
void KISTATUSBAR::SetEllipsedTextField( const wxString& aText, int aFieldId )
{
wxRect fieldRect;
int width = -1;
wxString etext = aText;
// Only GetFieldRect() returns the current size for variable size fields
// Other methods return -1 for the width of these fields.
if( GetFieldRect( aFieldId, fieldRect ) )
width = fieldRect.GetWidth();
if( width > 20 )
{
wxClientDC dc( this );
// Gives a margin to the text to be sure it is not clamped at its end
int margin = KIUI::GetTextSize( wxT( "XX" ), this ).x;
etext = wxControl::Ellipsize( etext, dc, wxELLIPSIZE_MIDDLE, width - margin );
}
SetStatusText( etext, aFieldId );
}

View File

@ -45,6 +45,13 @@ public:
KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id ); KISTATUSBAR( int aNumberFields, wxWindow* parent, wxWindowID id );
public: public:
/**
* Set the text in a field using wxELLIPSIZE_MIDDLE option to adjust the text size
* to the field size (unfortunately, setting the wxStatusBar style to wxELLIPSIZE_MIDDLE
* does not work fine
*/
void SetEllipsedTextField( const wxString& aText, int aFieldId );
/** /**
* Shows the background progress bar * Shows the background progress bar
*/ */

View File

@ -63,7 +63,6 @@
#include <widgets/kistatusbar.h> #include <widgets/kistatusbar.h>
#include <wx/ffile.h> #include <wx/ffile.h>
#include <wx/filedlg.h> #include <wx/filedlg.h>
#include <wx/dcclient.h>
#include <wx/dnd.h> #include <wx/dnd.h>
#include <wx/process.h> #include <wx/process.h>
#include <atomic> #include <atomic>
@ -456,6 +455,11 @@ void KICAD_MANAGER_FRAME::OnSize( wxSizeEvent& event )
PrintPrjInfo(); PrintPrjInfo();
#if defined( _WIN32 )
KISTATUSBAR* statusBar = static_cast<KISTATUSBAR*>( GetStatusBar() );
statusBar->SetEllipsedTextField( m_FileWatcherInfo, 1 );
#endif
event.Skip(); event.Skip();
} }
@ -868,22 +872,8 @@ void KICAD_MANAGER_FRAME::PrintPrjInfo()
// wxStatusBar's wxELLIPSIZE_MIDDLE flag doesn't work (at least on Mac). // wxStatusBar's wxELLIPSIZE_MIDDLE flag doesn't work (at least on Mac).
wxString status = wxString::Format( _( "Project: %s" ), Prj().GetProjectFullName() ); wxString status = wxString::Format( _( "Project: %s" ), Prj().GetProjectFullName() );
wxStatusBar* statusBar = GetStatusBar(); KISTATUSBAR* statusBar = static_cast<KISTATUSBAR*>( GetStatusBar() );
wxRect fieldRect; statusBar->SetEllipsedTextField( status, 0 );
int width = -1;
// Only GetFieldRect() returns the current size for variable size fields
// Other methods return -1 for the width of these fields.
if( statusBar->GetFieldRect( 0, fieldRect ) )
width = fieldRect.GetWidth();
if( width > 20 )
{
wxClientDC dc( this );
status = wxControl::Ellipsize( status, dc, wxELLIPSIZE_MIDDLE, width );
}
SetStatusText( status );
} }

View File

@ -63,6 +63,11 @@ public:
void OnFileHistory( wxCommandEvent& event ); void OnFileHistory( wxCommandEvent& event );
void OnClearFileHistory( wxCommandEvent& aEvent ); void OnClearFileHistory( wxCommandEvent& aEvent );
void OnExit( wxCommandEvent& event ); void OnExit( wxCommandEvent& event );
/** Create the status line (like a wxStatusBar). This is actually a KISTATUSBAR status bar.
* the specified number of fields is the extra number of fields, not the full field count.
* @return a KISTATUSBAR (derived from wxStatusBar)
*/
wxStatusBar* OnCreateStatusBar( int number, long style, wxWindowID id, wxStatusBar* OnCreateStatusBar( int number, long style, wxWindowID id,
const wxString& name ) override; const wxString& name ) override;
@ -168,6 +173,9 @@ public:
void CreatePCM(); // creates the PLUGIN_CONTENT_MANAGER void CreatePCM(); // creates the PLUGIN_CONTENT_MANAGER
// Used only on Windows: stores the info message about file watcher
wxString m_FileWatcherInfo;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
protected: protected:

View File

@ -76,6 +76,7 @@
#include "kicad_manager_frame.h" #include "kicad_manager_frame.h"
#include "project_tree_pane.h" #include "project_tree_pane.h"
#include <widgets/kistatusbar.h>
/* Note about the project tree build process: /* Note about the project tree build process:
@ -1368,18 +1369,22 @@ void PROJECT_TREE_PANE::FileWatcherReset()
wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() ); wxString prj_dir = wxPathOnly( m_Parent->GetProjectFileName() );
#if defined( _WIN32 ) #if defined( _WIN32 )
KISTATUSBAR* statusBar = static_cast<KISTATUSBAR*>( m_Parent->GetStatusBar() );
if( KIPLATFORM::ENV::IsNetworkPath( prj_dir ) ) if( KIPLATFORM::ENV::IsNetworkPath( prj_dir ) )
{ {
// Due to a combination of a bug in SAMBA sending bad change event IDs and wxWidgets // Due to a combination of a bug in SAMBA sending bad change event IDs and wxWidgets
// choosing to fault on an invalid event ID instead of sanely ignoring them we need to // choosing to fault on an invalid event ID instead of sanely ignoring them we need to
// avoid spawning a filewatcher. Unfortunately this punishes corporate environments with // avoid spawning a filewatcher. Unfortunately this punishes corporate environments with
// Windows Server shares :/ // Windows Server shares :/
m_Parent->SetStatusText( _( "Network path: not monitoring folder changes" ), 1 ); m_Parent->m_FileWatcherInfo = _( "Network path: not monitoring folder changes" );
statusBar->SetEllipsedTextField( m_Parent->m_FileWatcherInfo, 1 );
return; return;
} }
else else
{ {
m_Parent->SetStatusText( _( "Local path: monitoring folder changes" ), 1 ); m_Parent->m_FileWatcherInfo = _( "Local path: monitoring folder changes" );
statusBar->SetEllipsedTextField( m_Parent->m_FileWatcherInfo, 1 );
} }
#endif #endif