KiCad PCB EDA Suite
eda_base_frame.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <bitmaps.h>
27 #include <bitmap_store.h>
28 #include <dialog_shim.h>
31 #include <eda_dde.h>
32 #include <filehistory.h>
33 #include <id.h>
34 #include <kiface_base.h>
35 #include <menus_helpers.h>
36 #include <panel_hotkeys_editor.h>
37 #include <paths.h>
38 #include <confirm.h>
39 #include <pgm_base.h>
40 #include <settings/app_settings.h>
44 #include <tool/action_manager.h>
45 #include <tool/action_menu.h>
46 #include <tool/action_toolbar.h>
47 #include <tool/actions.h>
48 #include <tool/common_control.h>
49 #include <tool/tool_manager.h>
50 #include <tool/tool_dispatcher.h>
51 #include <trace_helpers.h>
52 #include <widgets/paged_dialog.h>
53 #include <widgets/infobar.h>
55 #include <wx/app.h>
56 #include <wx/config.h>
57 #include <wx/display.h>
58 #include <wx/stdpaths.h>
59 #include <wx/string.h>
60 #include <wx/treebook.h>
61 #include <kiplatform/app.h>
62 #include <kiplatform/ui.h>
63 
64 #include <functional>
65 
66 wxDEFINE_EVENT( UNITS_CHANGED, wxCommandEvent );
67 
68 
69 // Minimum window size
70 static const wxSize minSize( FRAME_T aFrameType )
71 {
72  switch( aFrameType )
73  {
74  case KICAD_MAIN_FRAME_T:
75  return wxSize( 406, 354 );
76 
77  default:
78  return wxSize( 500, 400 );
79  }
80 }
81 
82 
83 static const wxSize defaultSize( FRAME_T aFrameType )
84 {
85  switch( aFrameType )
86  {
87  case KICAD_MAIN_FRAME_T:
88  return wxSize( 850, 540 );
89 
90  default:
91  return wxSize( 1280, 720 );
92  }
93 }
94 
95 
96 BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
97  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
98  EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
99 
100  EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
101  EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
102  EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
103  EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
104  EVT_MOVE( EDA_BASE_FRAME::OnMove )
105  EVT_SIZE( EDA_BASE_FRAME::OnSize )
106  EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
107 
108  EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
109 END_EVENT_TABLE()
110 
111 
112 void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
113 {
114  m_ident = aFrameType;
115  m_maximizeByDefault = false;
116  m_infoBar = nullptr;
117  m_settingsManager = nullptr;
118  m_fileHistory = nullptr;
119  m_hasAutoSave = false;
120  m_autoSaveState = false;
121  m_autoSaveInterval = -1;
122  m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
123  m_userUnits = EDA_UNITS::MILLIMETRES;
124  m_isClosing = false;
125  m_isNonUserClose = false;
126  m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
127  m_mruPath = PATHS::GetDefaultUserProjectsPath();
128  m_frameSize = defaultSize( aFrameType );
129  m_displayIndex = -1;
130 
131  m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
132 
133  m_settingsManager = &Pgm().GetSettingsManager();
134 
135  // Set a reasonable minimal size for the frame
136  SetSizeHints( minSize( aFrameType ).x, minSize( aFrameType ).y, -1, -1, -1, -1 );
137 
138  // Store dimensions of the user area of the main window.
139  GetClientSize( &m_frameSize.x, &m_frameSize.y );
140 
141  Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
142  wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
143 
144  // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
145  // to be called before any other hook for wxCloseEvent, which is necessary.
146  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
147 
148  initExitKey();
149 }
150 
151 
153  wxFrame(),
154  TOOLS_HOLDER(),
155  KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME )
156 {
157  commonInit( aFrameType );
158 }
159 
160 
161 EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
162  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
163  long aStyle, const wxString& aFrameName, KIWAY* aKiway ) :
164  wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
165  TOOLS_HOLDER(),
166  KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME )
167 {
168  commonInit( aFrameType );
169 }
170 
171 
173 {
174  for( wxWindow* iter : GetChildren() )
175  {
176  DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
177 
178  if( dlg && dlg->IsQuasiModal() )
179  return dlg;
180  }
181 
182  // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
183  // so we have to look for it separately.
184  if( m_ident == FRAME_SCH )
185  {
186  wxWindow* cvpcb = wxWindow::FindWindowByName( "CvpcbFrame" );
187 
188  if( cvpcb )
189  return cvpcb;
190  }
191 
192  return nullptr;
193 }
194 
195 
196 void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
197 {
198  // Don't allow closing when a quasi-modal is open.
199  wxWindow* quasiModal = findQuasiModalDialog();
200 
201  if( quasiModal )
202  {
203  // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
204  // when they have no idea what those are.
205  quasiModal->Raise();
206  wxBell();
207 
208  if( event.CanVeto() )
209  event.Veto();
210 
211  return;
212  }
213 
214 
215  if( event.GetId() == wxEVT_QUERY_END_SESSION
216  || event.GetId() == wxEVT_END_SESSION )
217  {
218  // End session means the OS is going to terminate us
219  m_isNonUserClose = true;
220  }
221 
222  if( canCloseWindow( event ) )
223  {
224  m_isClosing = true;
225  APP_SETTINGS_BASE* cfg = config();
226 
227  if( cfg )
228  SaveSettings( cfg ); // virtual, wxFrame specific
229 
230  doCloseWindow();
231 
232  // Destroy (safe delete frame) this frame only in non modal mode.
233  // In modal mode, the caller will call Destroy().
234  if( !IsModal() )
235  Destroy();
236  }
237  else
238  {
239  if( event.CanVeto() )
240  event.Veto();
241  }
242 }
243 
244 
246 {
247  delete m_autoSaveTimer;
248  delete m_fileHistory;
249 
251 
252  SocketCleanup();
253 
255 }
256 
257 
258 bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
259 {
260 #ifdef __WXMAC__
261  // Apple in its infinite wisdom will raise a disabled window before even passing
262  // us the event, so we have no way to stop it. Instead, we have to catch an
263  // improperly ordered disabled window and quasi-modal dialog here and reorder
264  // them.
265  if( !IsEnabled() && IsActive() )
266  {
267  wxWindow* dlg = findQuasiModalDialog();
268  if( dlg )
269  dlg->Raise();
270  }
271 #endif
272 
273  if( !wxFrame::ProcessEvent( aEvent ) )
274  return false;
275 
276  if( !m_isClosing && m_hasAutoSave && IsShown() && IsActive()
278  && m_autoSaveInterval > 0 )
279  {
280  if( !m_autoSaveState )
281  {
282  wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
283  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
284  m_autoSaveState = true;
285  }
286  else if( m_autoSaveTimer->IsRunning() )
287  {
288  wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
289  m_autoSaveTimer->Stop();
290  m_autoSaveState = false;
291  }
292  }
293 
294  return true;
295 }
296 
297 
299 {
300  m_autoSaveInterval = aInterval;
301 
302  if( m_autoSaveTimer->IsRunning() )
303  {
304  if( m_autoSaveInterval > 0 )
305  {
306  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
307  }
308  else
309  {
310  m_autoSaveTimer->Stop();
311  m_autoSaveState = false;
312  }
313  }
314 }
315 
316 
317 void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
318 {
319  if( !doAutoSave() )
320  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
321 }
322 
323 
325 {
326  wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
327 }
328 
329 
330 void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
331 {
332  wxLogTrace( kicadTraceKeyEvent, "EDA_BASE_FRAME::OnCharHook %s", dump( aKeyEvent ) );
333 
334  // Key events can be filtered here.
335  // Currently no filtering is made.
336  aKeyEvent.Skip();
337 }
338 
339 
340 void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
341 {
342  if( !m_toolDispatcher )
343  aEvent.Skip();
344  else
346 }
347 
348 
350 {
352  std::placeholders::_1,
353  this,
354  aConditions );
355 
356  m_uiUpdateMap[aID] = evtFunc;
357 
358  Bind( wxEVT_UPDATE_UI, evtFunc, aID );
359 }
360 
361 
363 {
364  const auto it = m_uiUpdateMap.find( aID );
365 
366  if( it == m_uiUpdateMap.end() )
367  return;
368 
369  Unbind( wxEVT_UPDATE_UI, it->second, aID );
370 }
371 
372 
373 void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
374  ACTION_CONDITIONS aCond )
375 {
376  bool checkRes = false;
377  bool enableRes = true;
378  bool showRes = true;
379  SELECTION& selection = aFrame->GetCurrentSelection();
380 
381  try
382  {
383  checkRes = aCond.checkCondition( selection );
384  enableRes = aCond.enableCondition( selection );
385  showRes = aCond.showCondition( selection );
386  }
387  catch( std::exception& )
388  {
389  // Something broke with the conditions, just skip the event.
390  aEvent.Skip();
391  return;
392  }
393 
394  aEvent.Enable( enableRes );
395  aEvent.Show( showRes );
396 
397  // wxWidgets 3.1.5+ includes a field in the event that says if the event supports being
398  // checked, since wxMenuItems don't want to be checked unless they actually are checkable
399 #if wxCHECK_VERSION( 3, 1, 5 )
400  if( aEvent.IsCheckable() )
401  aEvent.Check( checkRes );
402 #else
403  bool canCheck = true;
404 
405  // wxMenuItems don't want to be checked unless they actually are checkable, so we have to
406  // check to see if they can be and can't just universally apply a check in this event.
407  if( auto menu = dynamic_cast<wxMenu*>( aEvent.GetEventObject() ) )
408  canCheck = menu->FindItem( aEvent.GetId() )->IsCheckable();
409 
410  if( canCheck )
411  aEvent.Check( checkRes );
412 #endif
413 }
414 
415 
417 {
418  // Setup the conditions to check a language menu item
419  auto isCurrentLang =
420  [] ( const SELECTION& aSel, int aLangIdentifier )
421  {
422  return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
423  };
424 
425  for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
426  {
427  ACTION_CONDITIONS cond;
428  cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
429  LanguagesList[ii].m_WX_Lang_Identifier ) );
430 
431  RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
432  }
433 }
434 
435 
437 {
438 }
439 
440 
441 void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
442 {
443  COMMON_CONTROL* commonControl = m_toolManager->GetTool<COMMON_CONTROL>();
444  ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
445 
446  helpMenu->Add( ACTIONS::help );
447  helpMenu->Add( ACTIONS::gettingStarted );
448  helpMenu->Add( ACTIONS::listHotKeys );
449  helpMenu->Add( ACTIONS::getInvolved );
450  helpMenu->Add( ACTIONS::donate );
451  helpMenu->Add( ACTIONS::reportBug );
452 
453  helpMenu->AppendSeparator();
454  helpMenu->Add( _( "&About KiCad" ), "", wxID_ABOUT, BITMAPS::about );
455 
456  // Trailing space keeps OSX from hijacking our menu (and disabling everything in it).
457  aMenuBar->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
458 }
459 
460 
462 {
464 
465  if( GetMenuBar() )
466  {
467  ReCreateMenuBar();
468  GetMenuBar()->Refresh();
469  }
470 }
471 
472 
473 void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
474 {
475  TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
476 
477  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
478 
479  if( m_fileHistory )
480  {
481  int historySize = settings->m_System.file_history_size;
482  m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
483  }
484 
486  ThemeChanged();
487 
488  if( GetMenuBar() )
489  {
490  // For icons in menus, icon scaling & hotkeys
491  ReCreateMenuBar();
492  GetMenuBar()->Refresh();
493  }
494 }
495 
496 
498 {
500 
501  // Update all the toolbars to have new icons
502  wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
503 
504  for( size_t i = 0; i < panes.GetCount(); ++i )
505  {
506  if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
507  toolbar->RefreshBitmaps();
508  }
509 }
510 
511 
512 void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
513 {
514 #ifdef __WXMAC__
515  int currentDisplay = wxDisplay::GetFromWindow( this );
516 
517  if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
518  {
519  wxLogTrace( traceDisplayLocation, "OnSize: current display changed %d to %d",
520  m_displayIndex, currentDisplay );
521  m_displayIndex = currentDisplay;
523  }
524 #endif
525 
526  aEvent.Skip();
527 }
528 
529 
530 void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
531 {
532  if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
533  return;
534 
535  const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
536 
537  if( state != nullptr )
538  {
539  LoadWindowState( state->window );
540  }
541 }
542 
543 
545 {
546  bool wasDefault = false;
547 
548  m_framePos.x = aState.pos_x;
549  m_framePos.y = aState.pos_y;
550  m_frameSize.x = aState.size_x;
551  m_frameSize.y = aState.size_y;
552 
553  wxLogTrace( traceDisplayLocation, "Config position (%d, %d) with size (%d, %d)",
555 
556  // Ensure minimum size is set if the stored config was zero-initialized
557  if( m_frameSize.x < minSize( m_ident ).x || m_frameSize.y < minSize( m_ident ).y )
558  {
560  wasDefault = true;
561 
562  wxLogTrace( traceDisplayLocation, "Using minimum size (%d, %d)",
563  m_frameSize.x, m_frameSize.y );
564  }
565 
566  wxLogTrace( traceDisplayLocation, "Number of displays: %d", wxDisplay::GetCount() );
567 
568  if( aState.display >= wxDisplay::GetCount() )
569  {
570  wxLogTrace( traceDisplayLocation, "Previous display not found" );
571 
572  // If it isn't attached, use the first display
573  // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
574  const unsigned int index = 0;
575  wxDisplay display( index );
576  wxRect clientSize = display.GetGeometry();
577 
578  m_framePos = wxDefaultPosition;
579 
580  // Ensure the window fits on the display, since the other one could have been larger
581  if( m_frameSize.x > clientSize.width )
582  m_frameSize.x = clientSize.width;
583 
584  if( m_frameSize.y > clientSize.height )
585  m_frameSize.y = clientSize.height;
586  }
587  else
588  {
589  wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
590  wxPoint upperLeft( m_framePos.x, m_framePos.y );
591 
592  wxDisplay display( aState.display );
593  wxRect clientSize = display.GetClientArea();
594 
595  int yLimTop = clientSize.y;
596  int yLimBottom = clientSize.y + clientSize.height;
597  int xLimLeft = clientSize.x;
598  int xLimRight = clientSize.x + clientSize.width;
599 
600  if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
601  upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
602  upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
603  upperLeft.y > yLimBottom )
604  {
605  m_framePos = wxDefaultPosition;
606  wxLogTrace( traceDisplayLocation, "Resetting to default position" );
607  }
608  }
609 
610  wxLogTrace( traceDisplayLocation, "Final window position (%d, %d) with size (%d, %d)",
612 
613  SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
614 
615  // Center the window if we reset to default
616  if( m_framePos.x == -1 )
617  {
618  wxLogTrace( traceDisplayLocation, "Centering window" );
619  Center();
620  m_framePos = GetPosition();
621  }
622 
623  // Record the frame sizes in an un-maximized state
626 
627  // Maximize if we were maximized before
628  if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
629  {
630  wxLogTrace( traceDisplayLocation, "Maximizing window" );
631  Maximize();
632  }
633 
634  m_displayIndex = wxDisplay::GetFromWindow( this );
635 }
636 
637 
639 {
640  wxDisplay display( wxDisplay::GetFromWindow( this ) );
641  wxRect clientSize = display.GetClientArea();
642  wxPoint pos = GetPosition();
643  wxSize size = GetWindowSize();
644 
645  wxLogTrace( traceDisplayLocation,
646  "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d", clientSize.x, clientSize.y,
647  clientSize.width, clientSize.height );
648 
649  if( pos.y < clientSize.y )
650  {
651  wxLogTrace( traceDisplayLocation,
652  "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d", pos.y,
653  clientSize.y );
654  pos.y = clientSize.y;
655  }
656 
657  if( pos.x < clientSize.x )
658  {
659  wxLogTrace( traceDisplayLocation,
660  "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d", pos.x,
661  clientSize.x );
662  pos.x = clientSize.x;
663  }
664 
665  if( pos.x + size.x - clientSize.x > clientSize.width )
666  {
667  int newWidth = clientSize.width - ( pos.x - clientSize.x );
668  wxLogTrace( traceDisplayLocation,
669  "ensureWindowIsOnScreen: effective width %d above available %d, setting to %d",
670  pos.x + size.x, clientSize.width, newWidth );
671  size.x = newWidth;
672  }
673 
674  if( pos.y + size.y - clientSize.y > clientSize.height )
675  {
676  int newHeight = clientSize.height - ( pos.y - clientSize.y );
677  wxLogTrace( traceDisplayLocation,
678  "ensureWindowIsOnScreen: effective height %d above available %d, setting to %d",
679  pos.y + size.y, clientSize.height, newHeight );
680  size.y = newHeight;
681  }
682 
683  wxLogTrace( traceDisplayLocation, "Updating window position (%d, %d) with size (%d, %d)",
684  pos.x, pos.y, size.x, size.y );
685 
686  SetSize( pos.x, pos.y, size.x, size.y );
687 }
688 
689 
691 {
692  LoadWindowState( aCfg->state );
693 
694  if( m_hasAutoSave )
695  m_autoSaveInterval = Pgm().GetCommonSettings()->m_System.autosave_interval;
696 
697  m_perspective = aCfg->perspective;
698  m_mruPath = aCfg->mru_path;
699 
700  TOOLS_HOLDER::CommonSettingsChanged( false, false );
701 }
702 
703 
705 {
706  wxString text;
707 
708  if( IsIconized() )
709  return;
710 
711  wxString baseCfgName = ConfigBaseName();
712 
713  // If the window is maximized, we use the saved window size from before it was maximized
714  if( IsMaximized() )
715  {
718  }
719  else
720  {
722  m_framePos = GetPosition();
723  }
724 
725  aCfg->state.pos_x = m_framePos.x;
726  aCfg->state.pos_y = m_framePos.y;
727  aCfg->state.size_x = m_frameSize.x;
728  aCfg->state.size_y = m_frameSize.y;
729  aCfg->state.maximized = IsMaximized();
730  aCfg->state.display = wxDisplay::GetFromWindow( this );
731 
732  wxLogTrace( traceDisplayLocation, "Saving window maximized: %s",
733  IsMaximized() ? "true" : "false" );
734  wxLogTrace( traceDisplayLocation, "Saving config position (%d, %d) with size (%d, %d)",
736 
737  // TODO(JE) should auto-save in common settings be overwritten by every app?
738  if( m_hasAutoSave )
739  Pgm().GetCommonSettings()->m_System.autosave_interval = m_autoSaveInterval;
740 
741  // Once this is fully implemented, wxAuiManager will be used to maintain
742  // the persistence of the main frame and all it's managed windows and
743  // all of the legacy frame persistence position code can be removed.
744  aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
745 
746  aCfg->mru_path = m_mruPath;
747 }
748 
749 
751 {
753 
754  // Get file history size from common settings
755  int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
756 
757  // Load the recently used files into the history menu
758  m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ),
760  m_fileHistory->Load( *aCfg );
761 }
762 
763 
765 {
767 
768  bool fileOpen = m_isClosing && m_isNonUserClose;
769 
770  wxString currentlyOpenedFile = GetCurrentFileName();
771 
772  if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
773  {
774  wxFileName rfn( currentlyOpenedFile );
775  rfn.MakeRelativeTo( Prj().GetProjectPath() );
776  Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
777  }
778 
779  // Save the recently used files list
780  if( m_fileHistory )
781  {
782  // Save the currently opened file in the file history
783  if( !currentlyOpenedFile.IsEmpty() )
784  UpdateFileHistory( currentlyOpenedFile );
785 
786  m_fileHistory->Save( *aCfg );
787  }
788 }
789 
790 
792 {
793  return &aCfg->m_Window;
794 }
795 
796 
798 {
799  // KICAD_MANAGER_FRAME overrides this
800  return Kiface().KifaceSettings();
801 }
802 
803 
805 {
806  return Kiface().KifaceSearch();
807 }
808 
809 
811 {
812  return Kiface().GetHelpFileName();
813 }
814 
815 
816 void EDA_BASE_FRAME::PrintMsg( const wxString& text )
817 {
818  SetStatusText( text );
819 }
820 
821 
823 {
824 #if defined( __WXOSX_MAC__ )
826 #else
827  m_infoBar = new WX_INFOBAR( this, &m_auimgr );
828 
829  m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
830 #endif
831 }
832 
833 
835 {
836 #if defined( __WXOSX_MAC__ )
837  m_auimgr.Update();
838 #else
839  // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
840  // hiding it.
841  m_auimgr.Update();
842 
843  // We don't want the infobar displayed right away
844  m_auimgr.GetPane( "InfoBar" ).Hide();
845  m_auimgr.Update();
846 #endif
847 }
848 
849 
850 void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
852 {
854 
855  if( aShowCloseButton )
857 
858  GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
859 }
860 
861 
862 void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
863  std::function<void(void)> aCallback )
864 {
866 
867  if( aShowCloseButton )
869 
870  if( aCallback )
871  m_infoBar->SetCallback( aCallback );
872 
873  GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
874 }
875 
876 
877 void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
878 {
880 
881  if( aShowCloseButton )
883 
884  GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
885 }
886 
887 
888 void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
889 {
891 
892  if( aShowCloseButton )
894 
895  GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
896 }
897 
898 
899 void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
900 {
901  if( !aFileHistory )
902  aFileHistory = m_fileHistory;
903 
904  wxASSERT( aFileHistory );
905 
906  aFileHistory->AddFileToHistory( FullFileName );
907 
908  // Update the menubar to update the file history menu
909  if( !m_isClosing && GetMenuBar() )
910  {
911  ReCreateMenuBar();
912  GetMenuBar()->Refresh();
913  }
914 }
915 
916 
917 wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
918  FILE_HISTORY* aFileHistory )
919 {
920  if( !aFileHistory )
921  aFileHistory = m_fileHistory;
922 
923  wxASSERT( aFileHistory );
924 
925  int baseId = aFileHistory->GetBaseId();
926 
927  wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
928 
929  unsigned i = cmdId - baseId;
930 
931  if( i < aFileHistory->GetCount() )
932  {
933  wxString fn = aFileHistory->GetHistoryFile( i );
934 
935  if( wxFileName::FileExists( fn ) )
936  {
937  return fn;
938  }
939  else
940  {
941  DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
942  aFileHistory->RemoveFileFromHistory( i );
943  }
944  }
945 
946  // Update the menubar to update the file history menu
947  if( GetMenuBar() )
948  {
949  ReCreateMenuBar();
950  GetMenuBar()->Refresh();
951  }
952 
953  return wxEmptyString;
954 }
955 
956 
958 {
959  if( !aFileHistory )
960  aFileHistory = m_fileHistory;
961 
962  wxASSERT( aFileHistory );
963 
964  aFileHistory->ClearFileHistory();
965 
966  // Update the menubar to update the file history menu
967  if( GetMenuBar() )
968  {
969  ReCreateMenuBar();
970  GetMenuBar()->Refresh();
971  }
972 }
973 
974 
975 void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
976 {
977  void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
978  ShowAboutDialog( this );
979 }
980 
981 
982 void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
983 {
984  PAGED_DIALOG dlg( this, _( "Preferences" ), true );
985  wxTreebook* book = dlg.GetTreebook();
986 
987  book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) );
988 
989  book->AddPage( new PANEL_MOUSE_SETTINGS( &dlg, book ), _( "Mouse and Touchpad" ) );
990 
991  PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
992  book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
993 
994  wxWindow* viewer3D = nullptr;
995 
996  for( unsigned i = 0; i < KIWAY_PLAYER_COUNT; ++i )
997  {
998  KIWAY_PLAYER* frame = dlg.Kiway().Player( (FRAME_T) i, false );
999 
1000  if( frame )
1001  {
1002  frame->InstallPreferences( &dlg, hotkeysPanel );
1003 
1004  if( !viewer3D )
1005  viewer3D = wxFindWindowByName( QUALIFIED_VIEWER3D_FRAMENAME( frame ) );
1006  }
1007  }
1008 
1009  if( viewer3D )
1010  static_cast<EDA_BASE_FRAME*>( viewer3D )->InstallPreferences( &dlg, hotkeysPanel );
1011 
1012  // The Kicad manager frame is not a player so we have to add it by hand
1013  wxWindow* manager = wxFindWindowByName( KICAD_MANAGER_FRAME_NAME );
1014 
1015  if( manager )
1016  static_cast<EDA_BASE_FRAME*>( manager )->InstallPreferences( &dlg, hotkeysPanel );
1017 
1018  for( size_t i = 0; i < book->GetPageCount(); ++i )
1019  book->GetPage( i )->Layout();
1020 
1021  if( dlg.ShowModal() == wxID_OK )
1022  dlg.Kiway().CommonSettingsChanged( false, false );
1023 }
1024 
1025 
1026 bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
1027 {
1028  wxString msg;
1029  wxFileName fn = aFileName;
1030 
1031  // Check for absence of a file path with a file name. Unfortunately KiCad
1032  // uses paths relative to the current project path without the ./ part which
1033  // confuses wxFileName. Making the file name path absolute may be less than
1034  // elegant but it solves the problem.
1035  if( fn.GetPath().IsEmpty() && fn.HasName() )
1036  fn.MakeAbsolute();
1037 
1038  wxCHECK_MSG( fn.IsOk(), false,
1039  wxT( "File name object is invalid. Bad programmer!" ) );
1040  wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
1041  wxT( "File name object path <" ) + fn.GetFullPath() +
1042  wxT( "> is not set. Bad programmer!" ) );
1043 
1044  if( fn.IsDir() && !fn.IsDirWritable() )
1045  {
1046  msg.Printf( _( "Insufficient permissions to folder '%s'." ),
1047  fn.GetPath() );
1048  }
1049  else if( !fn.FileExists() && !fn.IsDirWritable() )
1050  {
1051  msg.Printf( _( "Insufficient permissions to save file '%s'." ),
1052  fn.GetFullName(), fn.GetPath() );
1053  }
1054  else if( fn.FileExists() && !fn.IsFileWritable() )
1055  {
1056  msg.Printf( _( "Insufficient permissions to save file '%s'." ),
1057  fn.GetFullPath() );
1058  }
1059 
1060  if( !msg.IsEmpty() )
1061  {
1062  wxMessageBox( msg );
1063  return false;
1064  }
1065 
1066  return true;
1067 }
1068 
1069 
1070 void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
1071 {
1072  wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
1073 
1074  wxFileName autoSaveFileName = aFileName;
1075 
1076  // Check for auto save file.
1077  autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() );
1078 
1079  wxLogTrace( traceAutoSave,
1080  wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
1081 
1082  if( !autoSaveFileName.FileExists() )
1083  return;
1084 
1085  wxString msg = wxString::Format( _(
1086  "Well this is potentially embarrassing!\n"
1087  "It appears that the last time you were editing the file\n"
1088  "\"%s\"\n"
1089  "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
1090  aFileName.GetFullName()
1091  );
1092 
1093  int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1094  this );
1095 
1096  // Make a backup of the current file, delete the file, and rename the auto save file to
1097  // the file name.
1098  if( response == wxYES )
1099  {
1100  if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
1101  {
1102  wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
1103  Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
1104  }
1105  }
1106  else
1107  {
1108  wxLogTrace( traceAutoSave,
1109  wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
1110 
1111  // Remove the auto save file when using the previous file as is.
1112  wxRemoveFile( autoSaveFileName.GetFullPath() );
1113  }
1114 }
1115 
1116 
1118 {
1119  // This function should be overridden in child classes
1120  return false;
1121 }
1122 
1123 
1125 {
1126  wxAcceleratorEntry entries[1];
1127  entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
1128  wxAcceleratorTable accel( 1, entries );
1129  SetAcceleratorTable( accel );
1130 }
1131 
1132 
1134 {
1137 }
1138 
1139 
1141 {
1142  m_undoList.PushCommand( aNewitem );
1143 
1144  // Delete the extra items, if count max reached
1145  if( m_undoRedoCountMax > 0 )
1146  {
1147  int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
1148 
1149  if( extraitems > 0 )
1150  ClearUndoORRedoList( UNDO_LIST, extraitems );
1151  }
1152 }
1153 
1154 
1156 {
1157  m_redoList.PushCommand( aNewitem );
1158 
1159  // Delete the extra items, if count max reached
1160  if( m_undoRedoCountMax > 0 )
1161  {
1162  int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
1163 
1164  if( extraitems > 0 )
1165  ClearUndoORRedoList( REDO_LIST, extraitems );
1166  }
1167 }
1168 
1169 
1171 {
1172  return m_undoList.PopCommand();
1173 }
1174 
1175 
1177 {
1178  return m_redoList.PopCommand();
1179 }
1180 
1181 
1183 {
1184  SetUserUnits( aUnits );
1186 
1187  wxCommandEvent e( UNITS_CHANGED );
1188  ProcessEventLocally( e );
1189 }
1190 
1191 
1192 void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
1193 {
1194  // When we maximize the window, we want to save the old information
1195  // so that we can add it to the settings on next window load.
1196  // Contrary to the documentation, this event seems to be generated
1197  // when the window is also being unmaximized on OSX, so we only
1198  // capture the size information when we maximize the window when on OSX.
1199 #ifdef __WXOSX__
1200  if( !IsMaximized() )
1201 #endif
1202  {
1204  m_normalFramePos = GetPosition();
1205  wxLogTrace( traceDisplayLocation,
1206  "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
1209  }
1210 
1211  // Skip event to actually maximize the window
1212  aEvent.Skip();
1213 }
1214 
1215 
1217 {
1218 #ifdef __WXGTK__
1219  wxSize winSize = GetSize();
1220 
1221  // GTK includes the window decorations in the normal GetSize call,
1222  // so we have to use a GTK-specific sizing call that returns the
1223  // non-decorated window size.
1224  if( m_ident == KICAD_MAIN_FRAME_T )
1225  {
1226  int width = 0;
1227  int height = 0;
1228  GTKDoGetSize( &width, &height );
1229 
1230  winSize.Set( width, height );
1231  }
1232 #else
1233  wxSize winSize = GetSize();
1234 #endif
1235 
1236  return winSize;
1237 }
1238 
1239 
1241 {
1242  // Update the icon theme when the system theme changes and update the toolbars
1244  ThemeChanged();
1245 
1246  // This isn't handled by ThemeChanged()
1247  if( GetMenuBar() )
1248  {
1249  // For icons in menus, icon scaling & hotkeys
1250  ReCreateMenuBar();
1251  GetMenuBar()->Refresh();
1252  }
1253 }
1254 
1255 
1256 void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
1257 {
1258  // Call the handler to update the colors used in the frame
1260 
1261  // Skip the change event to ensure the rest of the window controls get it
1262  aEvent.Skip();
1263 }
1264 
1265 
1266 #ifdef _WIN32
1267 WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
1268 {
1269  // This will help avoid the menu keeping focus when the alt key is released
1270  // You can still trigger accelerators as long as you hold down alt
1271  if( message == WM_SYSCOMMAND )
1272  if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
1273  return 0;
1274 
1275  return wxFrame::MSWWindowProc( message, wParam, lParam );
1276 }
1277 #endif
SELECTION_CONDITION showCondition
Returns true if the UI control should be shown.
wxString mru_path
Definition: app_settings.h:84
virtual void HandleSystemColorChange()
Update the UI in response to a change in the system colors.
static TOOL_ACTION listHotKeys
Definition: actions.h:178
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
Definition: pgm_base.cpp:70
void PrintMsg(const wxString &text)
A mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:36
Define the structure of a toolbar with buttons that invoke ACTIONs.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
MESSAGE_TYPE
Sets the type of message for special handling if needed.
Definition: infobar.h:91
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
DDE server & client.
void SaveFileState(const wxString &aFileName, const WINDOW_SETTINGS *aWindowCfg, bool aOpen)
wxString m_mruPath
virtual void OnCharHook(wxKeyEvent &aKeyEvent)
Capture the key event before it is sent to the GUI.
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
This file is part of the common library.
void SaveWindowSettings(WINDOW_SETTINGS *aCfg)
Save window settings to the given settings object.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
UNDO_REDO_CONTAINER m_undoList
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:32
void onSystemColorChange(wxSysColourChangedEvent &aEvent)
SELECTION_CONDITION enableCondition
Returns true if the UI control should be enabled.
void windowClosing(wxCloseEvent &event)
(with its unexpected name so it does not collide with the real OnWindowClose() function provided in d...
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
SELECTION_CONDITION checkCondition
Returns true if the UI control should be checked.
static void HandleUpdateUIEvent(wxUpdateUIEvent &aEvent, EDA_BASE_FRAME *aFrame, ACTION_CONDITIONS aCond)
Handle events generated when the UI is trying to figure out the current state of the UI controls rela...
int m_KI_Lang_Identifier
KiCad identifier used in menu selection (See id.h)
Definition: pgm_base.h:65
virtual bool isAutoSaveRequired() const
Return the auto save status of the application.
void Save(APP_SETTINGS_BASE &aSettings)
Saves history into a JSON settings object.
Definition: filehistory.cpp:67
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void onAutoSaveTimer(wxTimerEvent &aEvent)
Handle the auto save timer event.
static TOOL_ACTION reportBug
Cursor control event types.
Definition: actions.h:181
virtual void doCloseWindow()
bool IsQuasiModal() const
Definition: dialog_shim.h:106
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
const wxChar *const traceDisplayLocation
Flag to enable debug output of display positioning logic.
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual bool IsModal() const
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
void ClearScaledBitmapCache()
Wipes out the scaled bitmap cache so that the icon theme can be changed.
Definition: bitmap.cpp:173
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
Definition: filehistory.cpp:45
virtual void ShowChangedLanguage()
virtual int GetRedoCommandCount() const
wxPoint m_normalFramePos
void ChangeUserUnits(EDA_UNITS aUnits)
Look for files in a number of paths.
Definition: search_stack.h:41
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:82
static TOOL_ACTION donate
Definition: actions.h:179
wxAuiManager m_auimgr
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
Definition: infobar.cpp:128
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: filehistory.h:42
#define DEFAULT_MAX_UNDO_ITEMS
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
wxTimer * m_autoSaveTimer
void LoadWindowState(const wxString &aFileName)
PICKED_ITEMS_LIST * PopCommand()
void ShowInfoBarWarning(const wxString &aWarningMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and a warning icon on the left ...
void ClearFileHistory()
Clear all entries from the file history.
std::function< void(wxUpdateUIEvent &) > UIUpdateHandler
This is the handler functor for the update UI events.
virtual void ClearUndoORRedoList(UNDO_REDO_LIST aList, int aItemCount=-1)
Remove the aItemCount of old commands from aList and delete commands, pickers and picked items if nee...
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxString m_perspective
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:151
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_base.h:113
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
void PushCommand(PICKED_ITEMS_LIST *aCommand)
void initExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
Definition: filehistory.cpp:96
wxWindow * findQuasiModalDialog()
void SocketCleanup()
Definition: eda_dde.cpp:313
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
wxString perspective
Definition: app_settings.h:85
void ensureWindowIsOnScreen()
wxSize m_normalFrameSize
virtual void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
virtual int GetUndoCommandCount() const
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
static const wxSize defaultSize(FRAME_T aFrameType)
virtual void unitsChangeRefresh()
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
virtual void OnSize(wxSizeEvent &aEvent)
std::map< int, UIUpdateHandler > m_uiUpdateMap
Set by the close window event handler after frames are asked if they can close.
virtual void UnregisterUIUpdateHandler(int aID) override
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, KIWAY *aKiway)
void FinishAUIInitialization()
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
struct WINDOW_STATE window
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
void SetCallback(std::function< void(void)> aCallback)
Provide a callback to be called when the infobar is dismissed (either by user action or timer).
Definition: infobar.h:156
const wxString & GetHelpFileName() const
Return just the basename portion of the current help file.
Definition: kiface_base.h:109
virtual WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg)
Return a pointer to the window settings for this frame.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
#define _(s)
wxLogTrace helper definitions.
void OnKicadAbout(wxCommandEvent &event)
A holder to handle information on schematic or board items.
void ThemeChanged()
Notifies the store that the icon theme has been changed by the user, so caches must be invalidated.
Handle actions that are shared between different applications.
Specialization of the wxAuiPaneInfo class for KiCad panels.
Stores the window positioning/state.
Definition: app_settings.h:68
UNDO_REDO_CONTAINER m_redoList
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
virtual bool canCloseWindow(wxCloseEvent &aCloseEvent)
wxDEFINE_EVENT(UNITS_CHANGED, wxCommandEvent)
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:160
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
const PROJECT_FILE_STATE * GetFileState(const wxString &aFileName)
virtual void OnMove(wxMoveEvent &aEvent)
EDA_UNITS
Definition: eda_units.h:38
static wxString GetAutoSaveFilePrefix()
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:139
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
Definition: filehistory.cpp:85
void OnMaximize(wxMaximizeEvent &aEvent)
void SetAutoSaveInterval(int aInterval)
virtual void ThemeChanged()
Process light/dark theme change.
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:101
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
wxSize GetWindowSize()
Get the undecorated window size that can be used for restoring the window size.
see class PGM_BASE
wxString ConfigBaseName() override
Get the configuration base name.
WX_INFOBAR * m_infoBar
#define KICAD_MANAGER_FRAME_NAME
WINDOW_STATE state
Definition: app_settings.h:83
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
The base frame for deriving all KiCad main window classes.
void LoadWindowSettings(const WINDOW_SETTINGS *aCfg)
Load window settings from the given settings object.
void commonInit(FRAME_T aFrameType)
Collect common initialization functions used in all CTORs.
static TOOL_ACTION help
Definition: actions.h:177
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
virtual wxString help_name()
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:92
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
void OnPreferences(wxCommandEvent &event)
Displays the preferences and settings of all opened editors paged dialog.
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:554
static const wxSize minSize(FRAME_T aFrameType)
WX_INFOBAR * GetInfoBar()
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
void SetUserUnits(EDA_UNITS aUnits)
Definition: id.h:86
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
virtual void InstallPreferences(PAGED_DIALOG *, PANEL_HOTKEYS_EDITOR *)
Allow a frame to load its preference panels (if any) into the preferences dialog.
unsigned int display
Definition: app_settings.h:75
static TOOL_ACTION getInvolved
Definition: actions.h:180
static TOOL_ACTION gettingStarted
Definition: actions.h:176
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
virtual wxString GetCurrentFileName() const
Get the full filename + path of the currently opened file in the frame.
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
void RemoveShutdownBlockReason(wxWindow *aWindow)
Removes any shutdown block reason set.
Definition: gtk/app.cpp:78
FILE_HISTORY * m_fileHistory
void OnMenuEvent(wxMenuEvent &event)
The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu events aren't ...
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:276
virtual void ReCreateMenuBar()
Recreates the menu bar.
BITMAP_STORE * GetBitmapStore()
Definition: bitmap.cpp:93