Add user write permission tests to Kicad and other minor fixes.

* Check user write permissions before saving project file.
* Append read only to file name and path in title bar when the user
  does not have write privileges.
* Remove displaying file dialog every time the project file is saved.
* Doxygen comment and coding style policy fixes.
This commit is contained in:
Wayne Stambaugh 2011-08-19 11:08:41 -04:00
parent 1e2b145a2f
commit 09d5e6937c
4 changed files with 117 additions and 87 deletions

View File

@ -1,10 +1,7 @@
/*****************************************************************************/
/**
* @file kicad.cpp
* @brief Main kicad library manager file
*/
/*****************************************************************************/
#include "fctsys.h"
#include "appl_wxstruct.h"
@ -24,7 +21,7 @@
#include "build_version.h"
const wxString g_KicadPrjFilenameExtension(wxT(".pro") );
const wxString g_KicadPrjFilenameExtension( wxT( ".pro" ) );
/* Import functions */
char* GetFileName( char* FullPathName );
@ -42,17 +39,21 @@ IMPLEMENT_APP( WinEDA_App )
/* MacOSX: Needed for file association
* http://wiki.wxwidgets.org/WxMac-specific_topics
*/
void WinEDA_App::MacOpenFile(const wxString &fileName) {
KICAD_MANAGER_FRAME * frame = ((KICAD_MANAGER_FRAME*)GetTopWindow());
wxFileName fn = fileName;
void WinEDA_App::MacOpenFile( const wxString &fileName )
{
KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) GetTopWindow();
wxFileName fn = fileName;
frame->m_ProjectFileName = fn;
if( m_fileHistory.GetCount() )
{
frame->m_ProjectFileName = m_fileHistory.GetHistoryFile( 0 );
if( !frame->m_ProjectFileName.FileExists() )
{
m_fileHistory.RemoveFileFromHistory( 0 );
}
else
{
wxCommandEvent cmd( 0, wxID_FILE1 );
@ -60,20 +61,23 @@ void WinEDA_App::MacOpenFile(const wxString &fileName) {
}
}
frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath() );
wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath();
if( !fn.IsDirWritable() )
title += _( " [Read Only]" );
frame->SetTitle( title );
frame->m_LeftWin->ReCreateTreePrj();
frame->PrintMsg( _( "Working dir: " ) + frame->m_ProjectFileName.GetPath() +
_( "\nProject: " ) + frame->m_ProjectFileName.GetFullName() +
wxT( "\n" ) );
_( "\nProject: " ) + frame->m_ProjectFileName.GetFullName() +
wxT( "\n" ) );
}
/*****************************************************************************/
bool WinEDA_App::OnInit()
/*****************************************************************************/
{
KICAD_MANAGER_FRAME* frame;
@ -81,21 +85,26 @@ bool WinEDA_App::OnInit()
// read current setup and reopen last directory if no filename to open in command line
bool reopenLastUsedDirectory = argc == 1;
GetSettings(reopenLastUsedDirectory);
GetSettings( reopenLastUsedDirectory );
/* Make nameless project translatable */
wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT, ProjectFileExtension );
frame = new KICAD_MANAGER_FRAME( NULL, wxT( "KiCad" ),
wxPoint( 30, 20 ), wxSize( 600, 400 ) );
wxPoint( 30, 20 ), wxSize( 600, 400 ) );
if( argc > 1 )
{
frame->m_ProjectFileName = argv[1];
}
else if( m_fileHistory.GetCount() )
{
frame->m_ProjectFileName = m_fileHistory.GetHistoryFile( 0 );
if( !frame->m_ProjectFileName.FileExists() )
{
m_fileHistory.RemoveFileFromHistory( 0 );
}
else
{
wxCommandEvent cmd( 0, wxID_FILE1 );
@ -110,8 +119,13 @@ bool WinEDA_App::OnInit()
frame->OnLoadProject( cmd );
}
frame->SetTitle( GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath() );
wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath();
if( !namelessProject.IsDirWritable() )
title += _( " [Read Only]" );
frame->SetTitle( title );
frame->ReCreateMenuBar();
frame->RecreateBaseHToolbar();
@ -137,8 +151,8 @@ bool WinEDA_App::OnInit()
}
#endif /* USE_SPLASH_IMAGE */
frame->Show( TRUE );
frame->Show( true );
frame->Raise();
return TRUE;
return true;
}

View File

@ -74,19 +74,27 @@ private:
public:
KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
const wxPoint& pos, const wxSize& size );
const wxPoint& pos, const wxSize& size );
~KICAD_MANAGER_FRAME();
/**
* Function CreateCommandToolbar
* Create the main buttons (fast launch buttons)
*/
void OnCloseWindow( wxCloseEvent& Event );
void OnSize( wxSizeEvent& event );
void OnSashDrag( wxSashEvent& event );
/**
* Function OnLoadProject
* loads an exiting or creates a new project (.pro) file.
*/
void OnLoadProject( wxCommandEvent& event );
/**
* Function OnSaveProject
* is the command event hendler to Save the project (.pro) file containing the top level
* configuration parameters.
*/
void OnSaveProject( wxCommandEvent& event );
void OnArchiveFiles( wxCommandEvent& event );
void OnUnarchiveFiles( wxCommandEvent& event );
void OnRunPcbNew( wxCommandEvent& event );
@ -105,7 +113,15 @@ public:
void Process_Preferences( wxCommandEvent& event );
void ReCreateMenuBar();
void RecreateBaseHToolbar();
void PrintMsg( const wxString& text );
/**
* Function PrintMsg
* displays \a aText in the text panel.
*
* @param aText The text to display.
*/
void PrintMsg( const wxString& aText );
void ClearMsg();
void SetLanguage( wxCommandEvent& event );
void OnRefresh( wxCommandEvent& event );
@ -117,7 +133,22 @@ public:
void CreateNewProject( const wxString PrjFullFileName );
/**
* Function LoadSettings
* loads the Kicad main frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void LoadSettings();
/**
* Function SaveSettings
* saves the Kicad main frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void SaveSettings();
DECLARE_EVENT_TABLE()
@ -160,7 +191,12 @@ public:
void OnSize( wxSizeEvent& event );
private:
/**
* Function CreateCommandToolbar
* creates the main tool bar buttons (fast launch buttons)
*/
void CreateCommandToolbar( void );
wxBitmapButton* AddBitmapButton( wxWindowID aId, const wxBitmap & aBitmap );
DECLARE_EVENT_TABLE()

View File

@ -1,6 +1,6 @@
/***********************************************************/
/* mdiframe.cpp - KICAD_MANAGER_FRAME is the kicad main frame */
/***********************************************************/
/***************************************************************/
/* mainframe.cpp - KICAD_MANAGER_FRAME is the kicad main frame */
/***************************************************************/
#ifdef __GNUG__
#pragma implementation
@ -22,9 +22,9 @@ static const wxString TreeFrameWidthEntry( wxT( "LeftWinWidth" ) );
KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent,
const wxString& title,
const wxPoint& pos,
const wxSize& size ) :
const wxString& title,
const wxPoint& pos,
const wxSize& size ) :
EDA_BASE_FRAME( parent, KICAD_MAIN_FRAME, title, pos, size )
{
wxString msg;
@ -105,17 +105,12 @@ KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME()
}
/*
* Put text in the dialog frame
*/
void KICAD_MANAGER_FRAME::PrintMsg( const wxString& text )
void KICAD_MANAGER_FRAME::PrintMsg( const wxString& aText )
{
m_RightWin->m_DialogWin->AppendText( text );
m_RightWin->m_DialogWin->AppendText( aText );
}
/* Resize windows when dragging window borders
*/
void KICAD_MANAGER_FRAME::OnSashDrag( wxSashEvent& event )
{
event.Skip();
@ -148,7 +143,7 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
m_FrameSize.y = py;
}
Event.SetCanVeto( TRUE );
Event.SetCanVeto( true );
SaveSettings();
@ -156,7 +151,8 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
if( wxGetApp().m_HtmlCtrl )
{
if( wxGetApp().m_HtmlCtrl->GetFrame() ) // returns NULL if no help frame active
wxGetApp().m_HtmlCtrl->GetFrame()->Close( TRUE );
wxGetApp().m_HtmlCtrl->GetFrame()->Close( true );
wxGetApp().m_HtmlCtrl = NULL;
}
@ -171,16 +167,19 @@ void KICAD_MANAGER_FRAME::OnExit( wxCommandEvent& event )
Close( true );
}
void KICAD_MANAGER_FRAME::OnRunBitmapConverter( wxCommandEvent& event )
{
ExecuteFile( this, BITMAPCONVERTER_EXE, wxEmptyString );
}
void KICAD_MANAGER_FRAME::OnRunPcbCalculator( wxCommandEvent& event )
{
ExecuteFile( this, PCB_CALCULATOR_EXE, wxEmptyString );
}
void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
@ -211,8 +210,8 @@ void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
wxString path = wxT("\"");
path += fn.GetPath( wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME ) + wxT("\"");
wxString path = wxT( "\"" );
path += fn.GetPath( wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME ) + wxT( "\"" );
ExecuteFile( this, GERBVIEW_EXE, path );
}
@ -243,8 +242,9 @@ void KICAD_MANAGER_FRAME::OnOpenFileInTextEditor( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_CANCEL )
return;
wxString filename = wxT("\"");
filename += dlg.GetPath() + wxT("\"");
wxString filename = wxT( "\"" );
filename += dlg.GetPath() + wxT( "\"" );
if( !dlg.GetPath().IsEmpty() && !wxGetApp().GetEditorName().IsEmpty() )
ExecuteFile( this, wxGetApp().GetEditorName(), filename );
}
@ -262,12 +262,6 @@ void KICAD_MANAGER_FRAME::ClearMsg()
}
/**
* Load Kicad main frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void KICAD_MANAGER_FRAME::LoadSettings()
{
wxASSERT( wxGetApp().m_EDA_Config != NULL );
@ -279,12 +273,6 @@ void KICAD_MANAGER_FRAME::LoadSettings()
}
/**
* Save Kicad main frame specific configuration settings.
*
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void KICAD_MANAGER_FRAME::SaveSettings()
{
wxASSERT( wxGetApp().m_EDA_Config != NULL );

View File

@ -27,18 +27,19 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString PrjFullFileName )
wxFileName newProjectName = PrjFullFileName;
ClearMsg();
/* Init default config filename */
filename = wxGetApp().FindLibraryPath( wxT( "kicad" ) + g_KicadPrjFilenameExtension);
filename = wxGetApp().FindLibraryPath( wxT( "kicad" ) + g_KicadPrjFilenameExtension );
/* Check if file kicad.pro exist in template directory */
if( wxFileName::FileExists( filename ) )
{
wxCopyFile( filename, PrjFullFileName );
wxCopyFile( filename, PrjFullFileName );
}
else
{
DisplayInfoMessage( NULL, _( "Project template file <kicad.pro> not found " ) );
return;
DisplayInfoMessage( NULL, _( "Project template file <kicad.pro> not found. " ) );
return;
}
/* Init schematic filename */
@ -46,8 +47,7 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString PrjFullFileName )
SchematicFileExtension ).GetFullName();
/* Init pcb board filename */
m_BoardFileName = wxFileName( newProjectName.GetName(),
PcbFileExtension ).GetFullName();
m_BoardFileName = wxFileName( newProjectName.GetName(), PcbFileExtension ).GetFullName();
/* Init project filename */
m_ProjectFileName = newProjectName;
@ -56,15 +56,14 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString PrjFullFileName )
wxGetApp().WriteProjectConfig( PrjFullFileName, GeneralGroupName, NULL );
}
/**
* Loading a new project
*/
void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
{
int style;
wxString title;
ClearMsg();
if( event.GetId() != wxID_ANY )
{
if( event.GetId() == ID_NEW_PROJECT )
@ -78,8 +77,7 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
}
wxFileDialog dlg( this, title, wxGetCwd(), wxEmptyString,
ProjectFileWildcard, style );
wxFileDialog dlg( this, title, wxGetCwd(), wxEmptyString, ProjectFileWildcard, style );
if( dlg.ShowModal() == wxID_CANCEL )
return;
@ -90,24 +88,26 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
{
// Ensure project filename extension is .pro
wxString fullname = m_ProjectFileName.GetFullPath();
if ( !fullname.EndsWith( g_KicadPrjFilenameExtension ) )
{
fullname += g_KicadPrjFilenameExtension;
m_ProjectFileName.SetFullName( fullname );
}
CreateNewProject( m_ProjectFileName.GetFullPath() );
}
}
wxLogDebug( wxT( "Loading Kicad project file: " ) +
m_ProjectFileName.GetFullPath() );
wxLogDebug( wxT( "Loading Kicad project file: " ) + m_ProjectFileName.GetFullPath() );
/* Check if project file exists and if it is not noname.pro */
wxString filename = m_ProjectFileName.GetFullName();
wxString nameless_prj = NAMELESS_PROJECT;
nameless_prj += g_KicadPrjFilenameExtension;
if( !m_ProjectFileName.FileExists() && !filename.IsSameAs(nameless_prj))
if( !m_ProjectFileName.FileExists() && !filename.IsSameAs( nameless_prj ) )
{
DisplayError( this, _( "Kicad project file <" ) +
m_ProjectFileName.GetFullPath() + _( "> not found" ) );
@ -118,8 +118,13 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
wxGetApp().ReadProjectConfig( m_ProjectFileName.GetFullPath(),
GeneralGroupName, NULL, false );
SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + m_ProjectFileName.GetFullPath() );
title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + m_ProjectFileName.GetFullPath();
if( !m_ProjectFileName.IsDirWritable() )
title += _( " [Read Only]" );
SetTitle( title );
UpdateFileHistory( m_ProjectFileName.GetFullPath() );
m_LeftWin->ReCreateTreePrj();
@ -130,23 +135,10 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
}
/**
* Save the project top level configuration parameters.
*/
void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
{
wxString fn;
wxFileDialog dlg( this, _( "Save Project File" ), wxGetCwd(),
m_ProjectFileName.GetFullName(), ProjectFileWildcard,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL )
if( !IsWritable( m_ProjectFileName ) )
return;
m_ProjectFileName = dlg.GetPath();
wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(),
GeneralGroupName, NULL );
wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(), GeneralGroupName, NULL );
}