26 #include <wx/stdpaths.h> 27 #include <wx/string.h> 28 #include <wx/display.h> 48 #define DEFAULT_AUTO_SAVE_INTERVAL 600 81 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
82 long aStyle, const wxString& aFrameName,
KIWAY* aKiway ) :
83 wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
87 m_hasAutoSave =
false;
88 m_autoSaveState =
false;
89 m_autoSaveInterval = -1;
91 m_mruPath = wxStandardPaths::Get().GetDocumentsDir();
92 m_toolManager =
nullptr;
95 const int minsize_x = 500;
96 const int minsize_y = 400;
97 SetSizeHints( minsize_x, minsize_y, -1, -1, -1, -1 );
100 GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
113 for(
auto& iter : GetChildren() )
115 DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
124 wxWindow* cvpcb = wxWindow::FindWindowByName(
"CvpcbFrame" );
149 wxConfigBase* cfg =
config();
245 if( !IsEnabled() && IsActive() )
253 if( !wxFrame::ProcessEvent( aEvent ) )
261 wxLogTrace(
traceAutoSave, wxT(
"Starting auto save timer." ) );
267 wxLogTrace(
traceAutoSave, wxT(
"Stopping auto save timer." ) );
305 wxCHECK_MSG(
false,
true, wxT(
"Auto save timer function not overridden. Bad programmer!" ) );
336 if( event.GetEventType() == wxEVT_MENU_OPEN )
338 currentMenu = dynamic_cast<ACTION_MENU*>( event.GetMenu() );
343 else if( event.GetEventType() == wxEVT_MENU_HIGHLIGHT )
348 else if( event.GetEventType() == wxEVT_MENU_CLOSE )
353 currentMenu =
nullptr;
370 helpMenu->SetTool( commonControl );
377 helpMenu->AppendSeparator();
378 helpMenu->Add(
_(
"&About KiCad" ),
"", wxID_ABOUT, about_xpm );
380 aMenuBar->Append( helpMenu,
_(
"&Help" ) );
389 GetMenuBar()->Refresh();
403 GetMenuBar()->Refresh();
433 aCfg->Read( text, &maximized, 0 );
447 if( wxDisplay::GetFromPoint( rect.GetTopLeft() ) == wxNOT_FOUND &&
448 wxDisplay::GetFromPoint( rect.GetTopRight() ) == wxNOT_FOUND &&
449 wxDisplay::GetFromPoint( rect.GetBottomLeft() ) == wxNOT_FOUND &&
450 wxDisplay::GetFromPoint( rect.GetBottomRight() ) == wxNOT_FOUND )
456 #if defined( __WXMAC__ ) 477 std::unique_ptr<wxConfigBase> pcbSettings =
GetNewConfig( wxT(
"eeschema" ) );
484 std::unique_ptr<wxConfigBase> pcbSettings =
GetNewConfig( wxT(
"pcbnew" ) );
504 text = baseCfgName + wxT(
"Pos_x" );
507 text = baseCfgName + wxT(
"Pos_y" );
510 text = baseCfgName + wxT(
"Size_x" );
513 text = baseCfgName + wxT(
"Size_y" );
516 text = baseCfgName + wxT(
"Maximized" );
517 aCfg->Write( text, IsMaximized() );
528 wxString perspective =
m_auimgr.SavePerspective();
560 SetStatusText( text );
565 wxFileHistory* aFileHistory )
567 wxFileHistory* fileHistory = aFileHistory;
572 fileHistory->AddFileToHistory( FullFileName );
577 wxFileHistory* aFileHistory )
579 wxFileHistory* fileHistory = aFileHistory;
584 int baseId = fileHistory->GetBaseId();
586 wxASSERT( cmdId >= baseId && cmdId < baseId + (
int) fileHistory->GetCount() );
588 unsigned i = cmdId - baseId;
590 if( i < fileHistory->GetCount() )
592 wxString fn = fileHistory->GetHistoryFile(
i );
594 if( wxFileName::FileExists( fn ) )
601 fileHistory->RemoveFileFromHistory(
i );
605 return wxEmptyString;
624 book->AddPage( hotkeysPanel,
_(
"Hotkeys" ) );
638 static_cast<EDA_BASE_FRAME*>( manager )->InstallPreferences( &dlg, hotkeysPanel );
640 if( dlg.ShowModal() == wxID_OK )
648 wxFileName fn = aFileName;
654 if( fn.GetPath().IsEmpty() && fn.HasName() )
657 wxCHECK_MSG( fn.IsOk(),
false,
658 wxT(
"File name object is invalid. Bad programmer!" ) );
659 wxCHECK_MSG( !fn.GetPath().IsEmpty(),
false,
660 wxT(
"File name object path <" ) + fn.GetFullPath() +
661 wxT(
"> is not set. Bad programmer!" ) );
663 if( fn.IsDir() && !fn.IsDirWritable() )
665 msg.Printf(
_(
"You do not have write permissions to folder \"%s\"." ),
668 else if( !fn.FileExists() && !fn.IsDirWritable() )
670 msg.Printf(
_(
"You do not have write permissions to save file \"%s\" to folder \"%s\"." ),
673 else if( fn.FileExists() && !fn.IsFileWritable() )
675 msg.Printf(
_(
"You do not have write permissions to save file \"%s\"." ),
691 wxCHECK_RET( aFileName.IsOk(), wxT(
"Invalid file name!" ) );
693 wxFileName autoSaveFileName = aFileName;
699 wxT(
"Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
701 if( !autoSaveFileName.FileExists() )
705 "Well this is potentially embarrassing!\n" 706 "It appears that the last time you were editing the file\n" 708 "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
712 int response = wxMessageBox( msg,
Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION,
this );
716 if( response == wxYES )
719 wxFileName backupFileName = aFileName;
724 if( aFileName.FileExists() )
727 if( !wxRenameFile( aFileName.GetFullPath(), backupFileName.GetFullPath(), true ) )
729 msg.Printf(
_(
"Could not create backup file \"%s\"" ),
730 GetChars( backupFileName.GetFullPath() ) );
735 if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
737 wxMessageBox(
_(
"The auto save file could not be renamed to the board file name." ),
738 Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION,
this );
744 wxT(
"Removing auto save file " ) + autoSaveFileName.GetFullPath() );
747 wxRemoveFile( autoSaveFileName.GetFullPath() );
#define IMMEDIATE_ACTIONS_KEY
static TOOL_ACTION listHotKeys
void PrintMsg(const wxString &text)
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
#define PREFER_SELECT_TO_DRAG_KEY
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
std::unique_ptr< wxConfigBase > GetNewConfig(const wxString &aProgName)
Create a new wxConfig so we can put configuration files in a more proper place for each platform.
VTBL_ENTRY void CommonSettingsChanged(bool aEnvVarsChanged)
Function CommonSettingsChanged Calls CommonSettingsChanged() on all KIWAY_PLAYERs.
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.
void windowClosing(wxCloseEvent &event)
(with its unexpected name so it does not collide with the real OnWindowClose() function provided in d...
virtual void SaveSettings(wxConfigBase *aCfg)
Saves common frame parameters to a configuration data file.
virtual bool isAutoSaveRequired() const
Return the auto save status of the application.
wxConfigBase * KifaceSettings() const
void onAutoSaveTimer(wxTimerEvent &aEvent)
Handle the auto save timer event.
wxString ConfigBaseName()
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void UpdateHotKeys(bool aFullUpdate)
Function UpdateHotKeys() Optionally reads the hotkey config files and then rebuilds the internal hotk...
PGM_BASE & Pgm()
The global Program "get" accessor.
Class SEARCH_STACK looks for files in a number of places.
Class DIALOG_SHIM may sit in the inheritance tree between wxDialog and any class written by wxFormBui...
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
wxTimer * m_autoSaveTimer
void UpdateFileHistory(const wxString &FullFileName, wxFileHistory *aFileHistory=NULL)
Update the list of recently opened files.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
static const wxString entryPosX
X position of frame, in pixels (suffix)
TOOL_ACTION * FindAction(const std::string &aActionName) const
Function FindAction() Finds an action with a given name (if there is one available).
wxTreebook * GetTreebook()
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
wxWindow * findQuasiModalDialog()
const wxString & GetHelpFileName() const
Function GetHelpFileName returns just the basename portion of the current help file.
void ShowAboutDialog(EDA_BASE_FRAME *aParent)
virtual void OnCharHook(wxKeyEvent &event)
Capture the key event before it is sent to the GUI.
void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
static wxString GetBackupSuffix()
virtual const SEARCH_STACK & sys_search()
Return a SEARCH_STACK pertaining to entire program.
virtual void DisplayToolMsg(const wxString &msg)
virtual void LoadSettings(wxConfigBase *aCfg)
Load common frame parameters from a configuration file.
void AddStandardHelpMenu(wxMenuBar *aMenuBar)
Adds the standard KiCad help menu to the menubar.
static const wxString entryPerspective
Configuration file entry for wxAuiManger perspective.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
wxLogTrace helper definitions.
#define DEFAULT_AUTO_SAVE_INTERVAL
The default auto save interval is 10 minutes.
void OnKicadAbout(wxCommandEvent &event)
void OnMenuOpen(wxMenuEvent &event)
Workaround some issues in wxWidgets where the menu events aren't captured by the menus themselves.
VTBL_ENTRY wxConfigBase * CommonSettings() const
virtual void CommonSettingsChanged(bool aEnvVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
static wxString GetAutoSaveFilePrefix()
void SetAutoSaveInterval(int aInterval)
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
std::vector< std::string > m_toolStack
static const wxString entrySizeX
Width of frame, in pixels (suffix)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define KICAD_MANAGER_FRAME_NAME
FILE_HISTORY & GetFileHistory()
The base frame for deriving all KiCad main window classes.
static const wxString entrySizeY
Height of frame, in pixels (suffix)
wxString GetFileFromHistory(int cmdId, const wxString &type, wxFileHistory *aFileHistory=NULL)
Fetches the file name from the file history list.
static const wxString entryPosY
Y position of frame, in pixels (suffix)
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
virtual wxString help_name()
static const wxString entryAutoSaveInterval
Configuration file entry name for auto save interval.
virtual void PopTool(const std::string &actionName)
void OnPreferences(wxCommandEvent &event)
static const wxString entryMaximized
Nonzero iff frame is maximized (suffix)
virtual void InstallPreferences(PAGED_DIALOG *, PANEL_HOTKEYS_EDITOR *)
Function InstallPreferences Allow a frame to load its preference panels (if any) into the preferences...
TOOL_MANAGER * m_toolManager
std::string CurrentToolName() const
static const wxString entryMruPath
Configuration file entry for most recently used path.
static TOOL_ACTION getInvolved
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
static TOOL_ACTION gettingStarted
bool ProcessEvent(wxEvent &aEvent) override
Override the default process event handler to implement the auto save feature.
static TOOL_ACTION selectionTool
#define WARP_MOUSE_ON_MOVE_KEY
virtual void ReCreateMenuBar()
Recreates the menu bar.