52 #include <wx/display.h> 53 #include <wx/stdpaths.h> 54 #include <wx/string.h> 68 return wxSize( 406, 354 );
71 return wxSize( 500, 400 );
80 return wxSize( 850, 540 );
83 return wxSize( 1280, 720 );
101 const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
102 long aStyle, const wxString& aFrameName,
KIWAY* aKiway ) :
103 wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
106 m_ident( aFrameType ),
107 m_maximizeByDefault( false ),
108 m_infoBar(
nullptr ),
109 m_settingsManager(
nullptr ),
110 m_fileHistory(
nullptr ),
111 m_hasAutoSave( false ),
112 m_autoSaveState( false ),
113 m_autoSaveInterval(-1 ),
116 m_isClosing( false ),
117 m_isNonUserClose( false )
125 m_settingsManager = &
Pgm().GetSettingsManager();
128 SetSizeHints(
minSize( aFrameType ).x,
minSize( aFrameType ).y, -1, -1, -1, -1 );
131 GetClientSize( &m_frameSize.x, &m_frameSize.y );
146 for( wxWindow* iter : GetChildren() )
148 DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
158 wxWindow* cvpcb = wxWindow::FindWindowByName(
"CvpcbFrame" );
180 if( event.CanVeto() )
187 if( event.GetId() == wxEVT_QUERY_END_SESSION
188 ||
event.GetId() == wxEVT_END_SESSION )
211 if( event.CanVeto() )
235 if( !IsEnabled() && IsActive() )
243 if( !wxFrame::ProcessEvent( aEvent ) )
251 wxLogTrace(
traceAutoSave, wxT(
"Starting auto save timer." ) );
257 wxLogTrace(
traceAutoSave, wxT(
"Stopping auto save timer." ) );
295 wxCHECK_MSG(
false,
true, wxT(
"Auto save timer function not overridden. Bad programmer!" ) );
320 std::placeholders::_1,
326 Bind( wxEVT_UPDATE_UI, evtFunc, aID );
337 Unbind( wxEVT_UPDATE_UI, it->second, aID );
344 bool checkRes =
false;
345 bool enableRes =
true;
355 catch( std::exception& )
362 aEvent.Enable( enableRes );
363 aEvent.Show( showRes );
367 #if wxCHECK_VERSION( 3, 1, 5 ) 368 if( aEvent.IsCheckable() )
369 aEvent.Check( checkRes );
371 bool canCheck =
true;
375 if(
auto menu = dynamic_cast<wxMenu*>( aEvent.GetEventObject() ) )
376 canCheck = menu->FindItem( aEvent.GetId() )->IsCheckable();
379 aEvent.Check( checkRes );
388 [] (
const SELECTION& aSel,
int aLangIdentifier )
390 return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
396 cond.
Check( std::bind( isCurrentLang, std::placeholders::_1,
420 helpMenu->AppendSeparator();
421 helpMenu->Add(
_(
"&About KiCad" ),
"", wxID_ABOUT,
about_xpm );
423 aMenuBar->Append( helpMenu,
_(
"&Help" ) );
432 GetMenuBar()->Refresh();
453 GetMenuBar()->Refresh();
460 if( !
Pgm().GetCommonSettings()->m_Session.remember_open_files )
465 if( state !=
nullptr )
474 bool wasDefault =
false;
495 if( aState.
display >= wxDisplay::GetCount() )
501 const unsigned int index = 0;
502 wxDisplay display( index );
503 wxRect clientSize = display.GetGeometry();
519 wxDisplay display( aState.
display );
520 wxRect clientSize = display.GetClientArea();
524 #define SCREEN_BORDER_REGION 0.10 530 if( upperLeft.x > xLimRight ||
531 upperRight.x < xLimLeft ||
532 upperRight.y > yLim )
540 #if defined( __WXOSX__ ) 617 wxLogTrace(
traceDisplayLocation,
"Saving window maximized: %s", IsMaximized() ?
"true" :
"false" );
639 int fileHistorySize =
Pgm().GetCommonSettings()->m_System.file_history_size;
656 if(
Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
658 wxFileName rfn( currentlyOpenedFile );
659 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
667 if( !currentlyOpenedFile.IsEmpty() )
702 SetStatusText( text );
708 #if defined( __WXOSX_MAC__ ) 720 #if defined( __WXOSX_MAC__ ) 728 m_auimgr.GetPane(
"InfoBar" ).Hide();
738 if( aShowCloseButton )
746 std::function<
void(
void)> aCallback )
750 if( aShowCloseButton )
764 if( aShowCloseButton )
775 if( aShowCloseButton )
787 wxASSERT( aFileHistory );
795 GetMenuBar()->Refresh();
806 wxASSERT( aFileHistory );
808 int baseId = aFileHistory->GetBaseId();
810 wxASSERT( cmdId >= baseId && cmdId < baseId + (
int) aFileHistory->GetCount() );
812 unsigned i = cmdId - baseId;
814 if( i < aFileHistory->GetCount() )
816 wxString fn = aFileHistory->GetHistoryFile( i );
818 if( wxFileName::FileExists( fn ) )
825 aFileHistory->RemoveFileFromHistory( i );
833 GetMenuBar()->Refresh();
836 return wxEmptyString;
845 wxASSERT( aFileHistory );
853 GetMenuBar()->Refresh();
875 book->AddPage( hotkeysPanel,
_(
"Hotkeys" ) );
889 static_cast<EDA_BASE_FRAME*>( manager )->InstallPreferences( &dlg, hotkeysPanel );
891 for(
size_t i = 0; i < book->GetPageCount(); ++i )
892 book->GetPage( i )->Layout();
894 if( dlg.ShowModal() == wxID_OK )
902 wxFileName fn = aFileName;
908 if( fn.GetPath().IsEmpty() && fn.HasName() )
911 wxCHECK_MSG( fn.IsOk(),
false,
912 wxT(
"File name object is invalid. Bad programmer!" ) );
913 wxCHECK_MSG( !fn.GetPath().IsEmpty(),
false,
914 wxT(
"File name object path <" ) + fn.GetFullPath() +
915 wxT(
"> is not set. Bad programmer!" ) );
917 if( fn.IsDir() && !fn.IsDirWritable() )
919 msg.Printf(
_(
"You do not have write permissions to folder \"%s\"." ),
922 else if( !fn.FileExists() && !fn.IsDirWritable() )
924 msg.Printf(
_(
"You do not have write permissions to save file \"%s\" to folder \"%s\"." ),
925 fn.GetFullName(), fn.GetPath() );
927 else if( fn.FileExists() && !fn.IsFileWritable() )
929 msg.Printf(
_(
"You do not have write permissions to save file \"%s\"." ),
945 wxCHECK_RET( aFileName.IsOk(), wxT(
"Invalid file name!" ) );
947 wxFileName autoSaveFileName = aFileName;
953 wxT(
"Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
955 if( !autoSaveFileName.FileExists() )
959 "Well this is potentially embarrassing!\n" 960 "It appears that the last time you were editing the file\n" 962 "it was not saved properly. Do you wish to restore the last saved edits you made?" ),
963 aFileName.GetFullName()
966 int response = wxMessageBox( msg,
Pgm().App().GetAppName(), wxYES_NO | wxICON_QUESTION,
this );
970 if( response == wxYES )
972 if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
974 wxMessageBox(
_(
"The auto save file could not be renamed to the board file name." ),
975 Pgm().App().GetAppName(), wxOK | wxICON_EXCLAMATION,
this );
981 wxT(
"Removing auto save file " ) + autoSaveFileName.GetFullPath() );
984 wxRemoveFile( autoSaveFileName.GetFullPath() );
998 wxAcceleratorEntry entries[1];
999 entries[0].Set( wxACCEL_CTRL,
int(
'Q' ), wxID_EXIT );
1000 wxAcceleratorTable accel( 1, entries );
1001 SetAcceleratorTable( accel );
1021 if( extraitems > 0 )
1036 if( extraitems > 0 )
1059 wxCommandEvent e( UNITS_CHANGED );
1060 ProcessEventLocally( e );
1072 if( !IsMaximized() )
1077 wxLogTrace(
traceDisplayLocation,
"Maximizing window - Saving position (%d, %d) with size (%d, %d)",
1094 GTKDoGetSize( &width, &height );
1096 wxSize winSize( width, height );
1098 wxSize winSize = GetSize();
SELECTION_CONDITION showCondition
Returns true if the UI control should be shown.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION)
Show the infobar with the provided message and icon for a specific period of time.
static TOOL_ACTION listHotKeys
LANGUAGE_DESCR LanguagesList[]
An array containing all the languages that KiCad supports.
void PrintMsg(const wxString &text)
A mix in class which holds the location of a wxWindow's KIWAY.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
void SaveFileState(const wxString &aFileName, const WINDOW_SETTINGS *aWindowCfg, bool aOpen)
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
bool m_isClosing
Set by NonUserClose() to indicate that the user did not request the current close.
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.
void SaveWindowSettings(WINDOW_SETTINGS *aCfg)
Save window settings to the given settings object.
UNDO_REDO_CONTAINER m_undoList
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
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)
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.
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
virtual void doCloseWindow()
bool IsQuasiModal() const
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
APP_SETTINGS_BASE * KifaceSettings() const
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...
virtual bool IsContentModified()
Get if the contents of the frame have been modified since the last save.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
virtual int GetRedoCommandCount() const
void ChangeUserUnits(EDA_UNITS aUnits)
Look for files in a number of paths.
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...
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...
#define DEFAULT_MAX_UNDO_ITEMS
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
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)
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
#define SCREEN_BORDER_REGION
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()
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.
SEARCH_STACK & KifaceSearch()
Only for DSO specific 'non-library' files.
wxWindow * findQuasiModalDialog()
Stores the common settings that are saved and loaded for each window / frame.
const wxString & GetHelpFileName() const
Return 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.
const BITMAP_OPAQUE about_xpm[1]
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.
virtual int GetUndoCommandCount() const
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.
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 ...
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.
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.
struct WINDOW_STATE window
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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).
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...
wxLogTrace helper definitions.
void OnKicadAbout(wxCommandEvent &event)
A holder to handle information on schematic or board items.
Handle actions that are shared between different applications.
Specialization of the wxAuiPaneInfo class for KiCad panels.
Stores the window positioning/state.
UNDO_REDO_CONTAINER m_redoList
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
virtual bool canCloseWindow(wxCloseEvent &aCloseEvent)
wxDEFINE_EVENT(UNITS_CHANGED, wxCommandEvent)
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.
const PROJECT_FILE_STATE * GetFileState(const wxString &aFileName)
virtual void OnMove(wxMoveEvent &aEvent)
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.
A modified version of the wxInfoBar class that allows us to:
void SetMaxFiles(size_t aMaxFiles)
Update the number of files that will be contained inside the file history.
void OnMaximize(wxMaximizeEvent &aEvent)
void SetAutoSaveInterval(int aInterval)
wxSize GetWindowSize()
Get the undecorated window size that can be used for restoring the window size.
wxString ConfigBaseName() override
Get the configuration base name.
#define KICAD_MANAGER_FRAME_NAME
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.
const wxChar *const kicadTraceKeyEvent
Flag to enable wxKeyEvent debug tracing.
virtual wxString help_name()
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
void OnPreferences(wxCommandEvent &event)
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
static const wxSize minSize(FRAME_T aFrameType)
WX_INFOBAR * GetInfoBar()
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
void SetUserUnits(EDA_UNITS aUnits)
virtual void InstallPreferences(PAGED_DIALOG *, PANEL_HOTKEYS_EDITOR *)
Allow a frame to load its preference panels (if any) into the preferences dialog.
static TOOL_ACTION getInvolved
virtual void ShowChangedLanguage()
Redraw the menus and what not in current language.
static TOOL_ACTION gettingStarted
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.
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.
virtual void ReCreateMenuBar()
Recreates the menu bar.