KiCad PCB EDA Suite
basicframe.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-2017 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 
32 #include <wx/stdpaths.h>
33 #include <wx/string.h>
34 
35 #include <dialog_shim.h>
36 #include <eda_doc.h>
37 #include <id.h>
38 #include <kiface_i.h>
39 #include <pgm_base.h>
40 #include <wxstruct.h>
41 #include <menus_helpers.h>
42 #include <bitmaps.h>
43 
44 #include <wx/display.h>
45 #include <wx/utils.h>
46 
47 
49 #define DEFAULT_AUTO_SAVE_INTERVAL 600
50 
51 #define URL_GET_INVOLVED "http://kicad-pcb.org/contribute/"
52 
53 const wxChar traceAutoSave[] = wxT( "KICAD_TRACE_AUTOSAVE" );
54 
57 
59 static const wxString entryAutoSaveInterval = "AutoSaveInterval";
60 
62 static const wxString entryPerspective = "Perspective";
63 
65 static const wxString entryMruPath = "MostRecentlyUsedPath";
66 
67 static const wxString entryPosY = "Pos_y";
68 static const wxString entryPosX = "Pos_x";
69 static const wxString entrySizeY = "Size_y";
70 static const wxString entrySizeX = "Size_x";
71 static const wxString entryMaximized = "Maximized";
72 
74 EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType,
75  const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
76  long aStyle, const wxString& aFrameName ) :
77  wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName )
78 {
79  wxSize minsize;
80 
81  m_Ident = aFrameType;
82  m_mainToolBar = NULL;
83  m_hasAutoSave = false;
84  m_autoSaveState = false;
85  m_autoSaveInterval = -1;
86  m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
87  m_mruPath = wxStandardPaths::Get().GetDocumentsDir();
88  minsize.x = 470;
89  minsize.y = 350;
90 
91  SetSizeHints( minsize.x, minsize.y, -1, -1, -1, -1 );
92 
93  if( ( aSize.x < minsize.x ) || ( aSize.y < minsize.y ) )
94  SetSize( 0, 0, minsize.x, minsize.y );
95 
96  // Create child subwindows.
97 
98  // Dimensions of the user area of the main window.
99  GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
100 
101  m_FramePos.x = m_FramePos.y = 0;
102 
103  Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
104  wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
105 
106  // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
107  // to be called before any other hook for wxCloseEvent, which is necessary.
108  Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
109 
110  // remove border from wxAui panes for all derived classes
111  Connect( wxEVT_SHOW, wxShowEventHandler( EDA_BASE_FRAME::removePaneBorder ) );
112 }
113 
114 
115 void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
116 {
117  DIALOG_SHIM* dlg = NULL;
118  wxWindowList list = GetChildren();
119 
120  // Quasi modal dialogs create issues (crashes) when closing Kicad.
121  // I am guessing they are delete too late, when deleting main frames.
122  // AFAIK, only these DIALOG_SHIM dialogs create such issues.
123  // The policy is do not allow closing Kicad if a Quasi modal dialog is open.
124  // (Anyway, closing without prompting the user is certainly bad,
125  // because an edit is in preogress)
126  // Therefore, iterate through the child list to find at least
127  // a DIALOG_SHIM opened in quasi modal mode
128  for( wxWindowList::iterator iter = list.begin(); iter != list.end(); ++iter )
129  {
130  if( (dlg = dynamic_cast<DIALOG_SHIM*> (*iter) ) != NULL )
131  {
132  if( dlg->IsQuasiModal() )
133  break;
134  else
135  dlg = NULL;
136  }
137  }
138 
139  if( dlg )
140  {
141  // Happens when a quasi modal dialog is currently open.
142  // For example: if the Kicad manager try to close Kicad.
143  wxMessageBox( _(
144  "The program cannot be closed\n"
145  "A quasi-modal dialog window is currently open, please close it first." ) );
146  event.Veto();
147  return;
148  }
149 
150  wxConfigBase* cfg = config();
151 
152  if( cfg )
153  SaveSettings( cfg ); // virtual, wxFrame specific
154 
155  event.Skip(); // we did not "handle" the event, only eavesdropped on it.
156 }
157 
158 
159 void EDA_BASE_FRAME::removePaneBorder( wxShowEvent& event )
160 {
161  // nothing to be set
162  if( !m_auimgr.GetManagedWindow() )
163  return;
164 
165  // remove the ugly 1-pixel white border on AUI panes
166  wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
167 
168  for( size_t i = 0; i < panes.GetCount(); i++ )
169  m_auimgr.GetPane( panes.Item( i ).name ).PaneBorder( false );
170 
171  m_auimgr.Update();
172 }
173 
174 
176 {
177  delete m_autoSaveTimer;
178 
179  // This is needed for OSX: avoids further OnDraw processing after this
180  // destructor and before the native window is destroyed
181  this->Freeze();
182 }
183 
184 
185 bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
186 {
187  if( !wxFrame::ProcessEvent( aEvent ) )
188  return false;
189 
190  if( IsShown() && m_hasAutoSave && IsActive() &&
192  {
193  if( !m_autoSaveState )
194  {
195  wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
196  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
197  m_autoSaveState = true;
198  }
199  else if( m_autoSaveTimer->IsRunning() )
200  {
201  wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
202  m_autoSaveTimer->Stop();
203  m_autoSaveState = false;
204  }
205  }
206 
207  return true;
208 }
209 
210 
211 bool EDA_BASE_FRAME::Enable( bool enable )
212 {
213  // so we can do logging of this state change:
214 
215 #if defined(DEBUG)
216  const char* type_id = typeid( *this ).name();
217  printf( "wxFrame %-28s: %s\n", type_id, enable ? "enabled" : "disabled" );
218 #endif
219 
220  return wxFrame::Enable( enable );
221 }
222 
223 
225 {
226  m_autoSaveInterval = aInterval;
227 
228  if( m_autoSaveTimer->IsRunning() )
229  {
230  if( m_autoSaveInterval > 0 )
231  {
232  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
233  }
234  else
235  {
236  m_autoSaveTimer->Stop();
237  m_autoSaveState = false;
238  }
239  }
240 }
241 
242 
243 void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
244 {
245  if( !doAutoSave() )
246  m_autoSaveTimer->Start( m_autoSaveInterval * 1000, wxTIMER_ONE_SHOT );
247 }
248 
249 
251 {
252  wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
253 }
254 
255 
257 {
258 }
259 
260 
262 {
263  ReCreateMenuBar();
264  GetMenuBar()->Refresh();
265 }
266 
267 
269 {
270  ReCreateMenuBar();
271  GetMenuBar()->Refresh();
272 }
273 
274 
275 void EDA_BASE_FRAME::LoadSettings( wxConfigBase* aCfg )
276 {
277  int maximized = 0;
278 
279  wxString baseCfgName = ConfigBaseName();
280 
281  wxString text = baseCfgName + entryPosX;
282  aCfg->Read( text, &m_FramePos.x );
283 
284  text = baseCfgName + entryPosY;
285  aCfg->Read( text, &m_FramePos.y );
286 
287  text = baseCfgName + entrySizeX;
288  aCfg->Read( text, &m_FrameSize.x, 600 );
289 
290  text = baseCfgName + entrySizeY;
291  aCfg->Read( text, &m_FrameSize.y, 400 );
292 
293  text = baseCfgName + entryMaximized;
294  aCfg->Read( text, &maximized, 0 );
295 
296  if( m_hasAutoSave )
297  {
298  text = baseCfgName + entryAutoSaveInterval;
299  aCfg->Read( text, &m_autoSaveInterval, DEFAULT_AUTO_SAVE_INTERVAL );
300  }
301 
302  // Ensure the window is on a connected display, and is visible.
303  // (at least a corner of the frame must be visible on screen)
304  // Sometimes, if a window was moved on an auxiliary display, and when this
305  // display is no more available, it is not the case.
306  wxRect rect( m_FramePos, m_FrameSize );
307 
308  if( wxDisplay::GetFromPoint( rect.GetTopLeft() ) == wxNOT_FOUND &&
309  wxDisplay::GetFromPoint( rect.GetTopRight() ) == wxNOT_FOUND &&
310  wxDisplay::GetFromPoint( rect.GetBottomLeft() ) == wxNOT_FOUND &&
311  wxDisplay::GetFromPoint( rect.GetBottomRight() ) == wxNOT_FOUND )
312  {
313  m_FramePos = wxDefaultPosition;
314  }
315 
316  // Ensure Window title bar is visible
317 #if defined( __WXMAC__ )
318  // for macOSX, the window must be below system (macOSX) toolbar
319  // Ypos_min = GetMBarHeight(); seems no more exist in new API (subject to change)
320  int Ypos_min = 20;
321 #else
322  int Ypos_min = 0;
323 #endif
324  if( m_FramePos.y < Ypos_min )
325  m_FramePos.y = Ypos_min;
326 
327  if( maximized )
328  Maximize();
329 
330  aCfg->Read( baseCfgName + entryPerspective, &m_perspective );
331  aCfg->Read( baseCfgName + entryMruPath, &m_mruPath );
332 }
333 
334 
335 void EDA_BASE_FRAME::SaveSettings( wxConfigBase* aCfg )
336 {
337  wxString text;
338 
339  if( IsIconized() )
340  return;
341 
342  wxString baseCfgName = ConfigBaseName();
343 
344  m_FrameSize = GetSize();
345  m_FramePos = GetPosition();
346 
347  text = baseCfgName + wxT( "Pos_x" );
348  aCfg->Write( text, (long) m_FramePos.x );
349 
350  text = baseCfgName + wxT( "Pos_y" );
351  aCfg->Write( text, (long) m_FramePos.y );
352 
353  text = baseCfgName + wxT( "Size_x" );
354  aCfg->Write( text, (long) m_FrameSize.x );
355 
356  text = baseCfgName + wxT( "Size_y" );
357  aCfg->Write( text, (long) m_FrameSize.y );
358 
359  text = baseCfgName + wxT( "Maximized" );
360  aCfg->Write( text, IsMaximized() );
361 
362  if( m_hasAutoSave )
363  {
364  text = baseCfgName + entryAutoSaveInterval;
365  aCfg->Write( text, m_autoSaveInterval );
366  }
367 
368  // Once this is fully implemented, wxAuiManager will be used to maintain
369  // the persistance of the main frame and all it's managed windows and
370  // all of the legacy frame persistence position code can be removed.
371  wxString perspective = m_auimgr.SavePerspective();
372 
373  // printf( "perspective(%s): %s\n",
374  // TO_UTF8( m_FrameName + entryPerspective ), TO_UTF8( perspective ) );
375  aCfg->Write( baseCfgName + entryPerspective, perspective );
376  aCfg->Write( baseCfgName + entryMruPath, m_mruPath );
377 }
378 
379 
380 wxConfigBase* EDA_BASE_FRAME::config()
381 {
382  // KICAD_MANAGER_FRAME overrides this
383  wxConfigBase* ret = Kiface().KifaceSettings();
384  //wxASSERT( ret );
385  return ret;
386 }
387 
388 
390 {
391  return Kiface().KifaceSearch();
392 }
393 
394 
396 {
397  return Kiface().GetHelpFileName();
398 }
399 
400 
401 void EDA_BASE_FRAME::PrintMsg( const wxString& text )
402 {
403  SetStatusText( text );
404 }
405 
406 
407 void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName,
408  wxFileHistory* aFileHistory )
409 {
410  wxFileHistory* fileHistory = aFileHistory;
411 
412  if( !fileHistory )
413  fileHistory = &Kiface().GetFileHistory();
414 
415  fileHistory->AddFileToHistory( FullFileName );
416 }
417 
418 
419 wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
420  wxFileHistory* aFileHistory )
421 {
422  wxFileHistory* fileHistory = aFileHistory;
423 
424  if( !fileHistory )
425  fileHistory = &Kiface().GetFileHistory();
426 
427  int baseId = fileHistory->GetBaseId();
428 
429  wxASSERT( cmdId >= baseId && cmdId < baseId + (int) fileHistory->GetCount() );
430 
431  unsigned i = cmdId - baseId;
432 
433  if( i < fileHistory->GetCount() )
434  {
435  wxString fn = fileHistory->GetHistoryFile( i );
436 
437  if( wxFileName::FileExists( fn ) )
438  return fn;
439  else
440  {
441  wxString msg = wxString::Format(
442  wxT( "file '%s' was not found." ),
443  GetChars( fn ) );
444 
445  wxMessageBox( msg );
446 
447  fileHistory->RemoveFileFromHistory( i );
448  }
449  }
450 
451  return wxEmptyString;
452 }
453 
454 
455 void EDA_BASE_FRAME::GetKicadHelp( wxCommandEvent& event )
456 {
457  const SEARCH_STACK& search = sys_search();
458 
459  /* We have to get document for beginners,
460  * or the full specific doc
461  * if event id is wxID_INDEX, we want the document for beginners.
462  * else the specific doc file (its name is in Kiface().GetHelpFileName())
463  * The document for beginners is the same for all KiCad utilities
464  */
465  if( event.GetId() == wxID_INDEX )
466  {
467  // List of possible names for Getting Started in KiCad
468  const wxChar* names[2] = {
469  wxT( "getting_started_in_kicad" ),
470  wxT( "Getting_Started_in_KiCad" )
471  };
472 
473  wxString helpFile;
474  // Search for "getting_started_in_kicad.html" or "getting_started_in_kicad.pdf"
475  // or "Getting_Started_in_KiCad.html" or "Getting_Started_in_KiCad.pdf"
476  for( unsigned ii = 0; ii < DIM( names ); ii++ )
477  {
478  helpFile = SearchHelpFileFullPath( search, names[ii] );
479 
480  if( !helpFile.IsEmpty() )
481  break;
482  }
483 
484  if( !helpFile )
485  {
486  wxString msg = wxString::Format( _(
487  "Html or pdf help file \n'%s'\n or\n'%s' could not be found." ), names[0], names[1] );
488  wxMessageBox( msg );
489  }
490  else
491  {
492  GetAssociatedDocument( this, helpFile );
493  }
494 
495  return;
496  }
497 
498  wxString base_name = help_name();
499  wxString helpFile = SearchHelpFileFullPath( search, base_name );
500 
501  if( !helpFile )
502  {
503  wxString msg = wxString::Format( _(
504  "Help file '%s' could not be found." ),
505  GetChars( base_name )
506  );
507  wxMessageBox( msg );
508  }
509  else
510  {
511  GetAssociatedDocument( this, helpFile );
512  }
513 }
514 
515 
516 void EDA_BASE_FRAME::OnSelectPreferredEditor( wxCommandEvent& event )
517 {
518  // Ask for the current editor and instruct GetEditorName() to not show
519  // unless we pass false as argument.
520  wxString editorname = Pgm().GetEditorName( false );
521 
522  // Ask the user to select a new editor, but suggest the current one as the default.
523  editorname = Pgm().AskUserForPreferredEditor( editorname );
524 
525  // If we have a new editor name request it to be copied to m_editor_name and saved
526  // to the preferences file. If the user cancelled the dialog then the previous
527  // value will be retained.
528  if( !editorname.IsEmpty() )
529  Pgm().SetEditorName( editorname );
530 }
531 
532 
533 void EDA_BASE_FRAME::GetKicadContribute( wxCommandEvent& event )
534 {
535  if( !wxLaunchDefaultBrowser( URL_GET_INVOLVED ) )
536  {
537  wxString msg;
538  msg.Printf( _( "Could not launch the default browser.\n"
539  "For information on how to help the KiCad project, visit %s" ),
541  wxMessageBox( msg, _( "Get involved with KiCad" ), wxOK, this );
542  }
543 }
544 
545 
546 void EDA_BASE_FRAME::GetKicadAbout( wxCommandEvent& event )
547 {
548  void ShowAboutDialog(EDA_BASE_FRAME * aParent); // See AboutDialog_main.cpp
549  ShowAboutDialog( this );
550 }
551 
552 
553 bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
554 {
555  wxString msg;
556  wxFileName fn = aFileName;
557 
558  // Check for absence of a file path with a file name. Unfortunately KiCad
559  // uses paths relative to the current project path without the ./ part which
560  // confuses wxFileName. Making the file name path absolute may be less than
561  // elegant but it solves the problem.
562  if( fn.GetPath().IsEmpty() && fn.HasName() )
563  fn.MakeAbsolute();
564 
565  wxCHECK_MSG( fn.IsOk(), false,
566  wxT( "File name object is invalid. Bad programmer!" ) );
567  wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
568  wxT( "File name object path <" ) + fn.GetFullPath() +
569  wxT( "> is not set. Bad programmer!" ) );
570 
571  if( fn.IsDir() && !fn.IsDirWritable() )
572  {
573  msg.Printf( _( "You do not have write permissions to folder <%s>." ),
574  GetChars( fn.GetPath() ) );
575  }
576  else if( !fn.FileExists() && !fn.IsDirWritable() )
577  {
578  msg.Printf( _( "You do not have write permissions to save file <%s> to folder <%s>." ),
579  GetChars( fn.GetFullName() ), GetChars( fn.GetPath() ) );
580  }
581  else if( fn.FileExists() && !fn.IsFileWritable() )
582  {
583  msg.Printf( _( "You do not have write permissions to save file <%s>." ),
584  GetChars( fn.GetFullPath() ) );
585  }
586 
587  if( !msg.IsEmpty() )
588  {
589  wxMessageBox( msg );
590  return false;
591  }
592 
593  return true;
594 }
595 
596 
597 void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName,
598  const wxString& aBackupFileExtension )
599 {
600  wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
601  wxCHECK_RET( !aBackupFileExtension.IsEmpty(), wxT( "Invalid backup file extension!" ) );
602 
603  wxFileName autoSaveFileName = aFileName;
604 
605  // Check for auto save file.
606  autoSaveFileName.SetName( AUTOSAVE_PREFIX_FILENAME + aFileName.GetName() );
607 
608  wxLogTrace( traceAutoSave,
609  wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
610 
611  if( !autoSaveFileName.FileExists() )
612  return;
613 
614  wxString msg = wxString::Format( _(
615  "Well this is potentially embarrassing!\n"
616  "It appears that the last time you were editing the file\n"
617  "'%s'\n"
618  "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
619  GetChars( aFileName.GetFullName() )
620  );
621 
622  int response = wxMessageBox( msg, Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION, this );
623 
624  // Make a backup of the current file, delete the file, and rename the auto save file to
625  // the file name.
626  if( response == wxYES )
627  {
628  // Get the backup file name.
629  wxFileName backupFileName = aFileName;
630  backupFileName.SetExt( aBackupFileExtension );
631 
632  // If an old backup file exists, delete it. If an old copy of the file exists, rename
633  // it to the backup file name
634  if( aFileName.FileExists() )
635  {
636  // Remove the old file backup file.
637  if( backupFileName.FileExists() )
638  wxRemoveFile( backupFileName.GetFullPath() );
639 
640  // Rename the old file to the backup file name.
641  if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath() ) )
642  {
643  msg.Printf( _( "Could not create backup file <%s>" ),
644  GetChars( backupFileName.GetFullPath() ) );
645  wxMessageBox( msg );
646  }
647  }
648 
649  if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
650  {
651  wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
652  Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION, this );
653  }
654  }
655  else
656  {
657  wxLogTrace( traceAutoSave,
658  wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
659 
660  // Remove the auto save file when using the previous file as is.
661  wxRemoveFile( autoSaveFileName.GetFullPath() );
662  }
663 }
664 
665 
667 {
668  if( evt_type != 0 )
669  {
670  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
671  evt.SetEventObject( this );
672  evt.SetId( evt_type );
673  wxPostEvent( this, evt );
674  return true;
675  }
676 
677  return false;
678 }
679 
680 
681 void EDA_BASE_FRAME::OnChangeIconsOptions( wxCommandEvent& event )
682 {
683  if( event.GetId() == ID_KICAD_SELECT_ICONS_IN_MENUS )
684  {
685  Pgm().SetUseIconsInMenus( event.IsChecked() );
686  }
687 
688  ReCreateMenuBar();
689 }
690 
691 
692 void EDA_BASE_FRAME::AddMenuIconsOptions( wxMenu* MasterMenu )
693 {
694  wxMenu* menu = NULL;
695  wxMenuItem* item = MasterMenu->FindItem( ID_KICAD_SELECT_ICONS_OPTIONS );
696 
697  if( item ) // This menu exists, do nothing
698  return;
699 
700  menu = new wxMenu;
701 
702  menu->Append( new wxMenuItem( menu, ID_KICAD_SELECT_ICONS_IN_MENUS,
703  _( "Icons in Menus" ), wxEmptyString,
704  wxITEM_CHECK ) );
705  menu->Check( ID_KICAD_SELECT_ICONS_IN_MENUS, Pgm().GetUseIconsInMenus() );
706 
707  AddMenuItem( MasterMenu, menu,
709  _( "Icons Options" ),
710  _( "Select show icons in menus and icons sizes" ),
711  KiBitmap( icon_xpm ) );
712 }
void CheckForAutoSaveFile(const wxFileName &aFileName, const wxString &aBackupFileExtension)
Function CheckForAutoSaveFile checks if an auto save file exists for aFileName and takes the appropri...
Definition: basicframe.cpp:597
#define DIM(x)
of elements in an array
Definition: macros.h:98
bool m_autoSaveState
Flag to indicate the last auto save state.
Definition: wxstruct.h:155
void PrintMsg(const wxString &text)
Definition: basicframe.cpp:401
void SetUseIconsInMenus(bool aUseIcons)
True to use menu icons.
Definition: pgm_base.h:327
VTBL_ENTRY void SetEditorName(const wxString &aFileName)
Definition: pgm_base.cpp:330
wxString m_mruPath
Most recently used path.
Definition: wxstruct.h:165
virtual bool doAutoSave()
Function doAutoSave should be overridden by the derived class to handle the auto save feature...
Definition: basicframe.cpp:250
virtual void ShowChangedIcons()
Function ShowChangedIcons redraws items menus after a icon was changed option.
Definition: basicframe.cpp:268
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:55
This file is part of the common library.
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
void windowClosing(wxCloseEvent &event)
Function windowClosing (with its unexpected name so it does not collide with the real OnWindowClose()...
Definition: basicframe.cpp:115
virtual void SaveSettings(wxConfigBase *aCfg)
Function SaveSettings saves common frame parameters to a configuration data file. ...
Definition: basicframe.cpp:335
#define URL_GET_INVOLVED
Definition: basicframe.cpp:51
void onAutoSaveTimer(wxTimerEvent &aEvent)
Function onAutoSaveTimer handles the auto save timer event.
Definition: basicframe.cpp:243
wxString ConfigBaseName()
Function ConfigBaseName.
Definition: wxstruct.h:268
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:86
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
Definition: basicframe.cpp:380
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
virtual void OnChangeIconsOptions(wxCommandEvent &event)
Function OnChangeIconsOptions Selects the current icons options in menus (or toolbars) in Kicad (the ...
Definition: basicframe.cpp:681
Class SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
Definition: dialog_shim.h:60
wxAuiManager m_auimgr
Definition: wxstruct.h:149
bool IsWritable(const wxFileName &aFileName)
Function IsWritable checks if aFileName can be written.
Definition: basicframe.cpp:553
VTBL_ENTRY const wxString AskUserForPreferredEditor(const wxString &aDefaultEditor=wxEmptyString)
Shows a dialog that instructs the user to select a new preferred editor.
Definition: pgm_base.cpp:375
wxTimer * m_autoSaveTimer
The timer used to implement the auto save feature;.
Definition: wxstruct.h:161
void UpdateFileHistory(const wxString &FullFileName, wxFileHistory *aFileHistory=NULL)
Function UpdateFileHistory Updates the list of recently opened files.
Definition: basicframe.cpp:407
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
static const wxString entryPosX
X position of frame, in pixels (suffix)
Definition: basicframe.cpp:68
wxString m_perspective
wxAuiManager perspective.
Definition: wxstruct.h:163
void GetKicadHelp(wxCommandEvent &event)
Definition: basicframe.cpp:455
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
Definition: kiface_i.h:127
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
void removePaneBorder(wxShowEvent &event)
Removes border from wxAui panes.
Definition: basicframe.cpp:159
virtual const SEARCH_STACK & sys_search()
Function sys_search returns a SEARCH_STACK pertaining to entire program, and is overloaded in KICAD_M...
Definition: basicframe.cpp:389
Base window classes and related definitions.
bool Enable(bool enable) override
Definition: basicframe.cpp:211
FRAME_T m_Ident
Id Type (pcb, schematic, library..)
Definition: wxstruct.h:138
virtual void LoadSettings(wxConfigBase *aCfg)
Function LoadSettings loads common frame parameters from a configuration file.
Definition: basicframe.cpp:275
virtual void OnSelectPreferredEditor(wxCommandEvent &event)
Function OnSelectPreferredEditor Open a dialog to select the editor that will used in KiCad to edit o...
Definition: basicframe.cpp:516
wxFileHistory & GetFileHistory()
Definition: kiface_i.h:123
wxString SearchHelpFileFullPath(const SEARCH_STACK &aSStack, const wxString &aBaseName)
Function SearchHelpFileFullPath returns the help file's full path.
void GetKicadAbout(wxCommandEvent &event)
Definition: basicframe.cpp:546
static const wxString entryPerspective
Configuration file entry for wxAuiManger perspective.
Definition: basicframe.cpp:62
bool IsQuasiModal()
Definition: dialog_shim.h:93
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
wxPoint m_FramePos
Definition: wxstruct.h:139
bool PostCommandMenuEvent(int evt_type)
Function PostCommandMenuEvent.
Definition: basicframe.cpp:666
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:145
const wxString & GetHelpFileName() const
Function GetHelpFileName returns just the basename portion of the current help file.
Definition: kiface_i.h:121
void SetAutoSaveInterval(int aInterval)
Definition: basicframe.cpp:224
void AddMenuIconsOptions(wxMenu *MasterMenu)
Function AddMenuIconsOptions creates a menu list for icons in menu and icon sizes choice...
Definition: basicframe.cpp:692
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
static const wxString entrySizeX
Width of frame, in pixels (suffix)
Definition: basicframe.cpp:70
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void GetKicadContribute(wxCommandEvent &event)
Definition: basicframe.cpp:533
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:117
static const wxString entrySizeY
Height of frame, in pixels (suffix)
Definition: basicframe.cpp:69
wxString GetFileFromHistory(int cmdId, const wxString &type, wxFileHistory *aFileHistory=NULL)
Function GetFileFromHistory fetches the file name from the file history list.
Definition: basicframe.cpp:419
static const wxString entryPosY
Y position of frame, in pixels (suffix)
Definition: basicframe.cpp:67
virtual wxString help_name()
Definition: basicframe.cpp:395
static const wxString entryAutoSaveInterval
Configuration file entry name for auto save interval.
Definition: basicframe.cpp:59
VTBL_ENTRY const wxString & GetEditorName(bool aCanShowFileChooser=true)
Return the preferred editor name.
Definition: pgm_base.cpp:338
static const wxString entryMaximized
Nonzero iff frame is maximized (suffix)
Definition: basicframe.cpp:71
virtual bool isAutoSaveRequired() const
Function autoSaveRequired returns the auto save status of the application.
Definition: wxstruct.h:181
bool m_hasAutoSave
Flag to indicate if this frame supports auto save.
Definition: wxstruct.h:152
wxSize m_FrameSize
Definition: wxstruct.h:140
#define AUTOSAVE_PREFIX_FILENAME
Prefix to create filenames for schematic files or other difile when auto-saved to retrieve a crash...
Definition: wxstruct.h:71
static const wxString entryMruPath
Configuration file entry for most recently used path.
Definition: basicframe.cpp:65
int m_autoSaveInterval
The auto save interval time in seconds.
Definition: wxstruct.h:158
virtual void ShowChangedLanguage()
Function ShowChangedLanguage redraws the menus and what not in current language.
Definition: basicframe.cpp:261
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
Definition: basicframe.cpp:185
#define DEFAULT_AUTO_SAVE_INTERVAL
The default auto save interval is 10 minutes.
Definition: basicframe.cpp:49
virtual void ReCreateMenuBar()
Function ReCreateMenuBar Creates recreates the menu bar.
Definition: basicframe.cpp:256
const wxChar traceAutoSave[]
Flag to enable auto save feature debug tracing.
Definition: basicframe.cpp:53
EDA_BASE_FRAME(wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
Definition: basicframe.cpp:74