bool App::QuickImportProject(DPath folder) { // Quickly makes a project in a folder by importing all resource files and C++ sources. if (!BEntry(folder.GetFullPath()).Exists()) return false; BMessage settings; settings.AddString("name", folder.GetFileName()); settings.AddString("target", folder.GetFileName()); // skipping templatename field on purpose settings.AddInt32("type", PROJECT_GUI); settings.AddString("path", folder.GetFullPath()); settings.AddInt32("scmtype", gDefaultSCM); settings.AddBool("createfolder", false); DPath path(folder); BEntry entry(path.GetFullPath()); Project *proj = CreateNewProject(settings); if (!proj) return false; entry.SetTo(folder.GetFullPath()); entry_ref addref; entry.GetRef(&addref); BMessage addmsg(M_ADD_FILES); addmsg.AddRef("refs",&addref); PostToProjectWindow(&addmsg,NULL); return true; }
void KICAD_MANAGER_FRAME::OnNewProject( wxCommandEvent& aEvent ) { wxString default_dir = GetMruPath(); wxFileDialog dlg( this, _( "Create New Project" ), default_dir, wxEmptyString, ProjectFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); // Add a "Create a new directory" checkbox dlg.SetExtraControlCreator( &DIR_CHECKBOX::Create ); if( dlg.ShowModal() == wxID_CANCEL ) return; wxFileName pro( dlg.GetPath() ); // wxFileName automatically extracts an extension. But if it isn't // a .pro extension, we should keep it as part of the filename if( !pro.GetExt().IsEmpty() && pro.GetExt().ToStdString() != ProjectFileExtension ) pro.SetName( pro.GetName() + wxT( "." ) + pro.GetExt() ); pro.SetExt( ProjectFileExtension ); // enforce extension if( !pro.IsAbsolute() ) pro.MakeAbsolute(); // Append a new directory with the same name of the project file. if( static_cast<DIR_CHECKBOX*>( dlg.GetExtraControl() )->CreateNewDir() ) pro.AppendDir( pro.GetName() ); // Check if the project directory is empty if it already exists. wxDir directory( pro.GetPath() ); if( !pro.DirExists() ) { if( !pro.Mkdir() ) { wxString msg; msg.Printf( _( "Directory \"%s\" could not be created.\n\n" "Please make sure you have write permissions and try again." ), pro.GetPath() ); DisplayErrorMessage( this, msg ); return; } } else if( directory.HasFiles() ) { wxString msg = _( "The selected directory is not empty. It is recommended that you " "create projects in their own empty directory.\n\nDo you " "want to continue?" ); if( !IsOK( this, msg ) ) return; } CreateNewProject( pro ); LoadProject( pro ); }
//----------------------------------------------------------------------------- void EdProjectManager::ConnectSigSlots() { connect(&m_newProjectAct, SIGNAL(triggered()), this, SLOT(CreateNewProject())); connect(&m_openProjectAct, SIGNAL(triggered()), this, SLOT(OpenExistingProject())); connect(&m_saveProjectAct, SIGNAL(triggered()), this, SLOT(SaveCurrentProject())); connect(&m_closeProjectAct, SIGNAL(triggered()), this, SLOT(CloseCurrentProject())); connect(&m_buildProjectAct, SIGNAL(triggered()), this, SLOT(slot_BuildProject())); connect(&m_publishProjectAct, SIGNAL(triggered()), this, SLOT(slot_PublishProject())); EditorApp::ValidOnlyWhenProjectIsLoaded(&m_closeProjectAct); EditorApp::ValidOnlyWhenProjectIsLoaded(&m_saveProjectAct); EditorApp::ValidOnlyWhenProjectIsLoaded(&m_buildProjectAct); }
// CreateExistingProject -- Saves only the necessary bits - asks if you to recreate void NewProjectWindow::CreateExistingProject(void) { char tmp[256]; //char cmd[256]; BAlert *alert; long result; sprintf(tmp,"Would you like to Recreate your Project \"%s\".\n\nPlease note this means all the existing files will be overwritten.\n\nIf you are unsure, click No.",ProjectName.String()); alert = new BAlert("", tmp, " Yes ", " No ", NULL, B_WIDTH_FROM_WIDEST, B_WARNING_ALERT); alert->SetShortcut(0, B_ESCAPE); result = alert->Go(); if (result == B_OK) { // right - do the lot CreateNewProject(); } else { // Only save necessary bits like project ptrFileWindow->SaveProject(); } }
/* Creates a new project folder, copy a template into this new folder. * and open this new project as working project */ void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) { wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep(); wxString title = _("New Project Folder"); wxDirDialog dlg( this, title, default_dir ); if( dlg.ShowModal() == wxID_CANCEL ) return; // Builds the project .pro filename, from the new project folder name wxFileName fn; fn.AssignDir( dlg.GetPath() ); fn.SetName( dlg.GetPath().AfterLast( SEP() ) ); fn.SetExt( wxT( "pro" ) ); // Launch the template selector dialog, and copy files CreateNewProject( fn.GetFullPath(), true ); // Initialize the project event.SetId( wxID_ANY ); OnLoadProject( event ); }
void CXMLDlg::OnCreateOutput() { CWaitCursor Wait; SCENG_Init(); // Get the <#document> item HTREEITEM pItem = m_treeOutput.GetRootItem(); if (!pItem) return; // Get the <?xml version="1.0" encoding="iso-8859-1" ?> item pItem = m_treeOutput.GetChildItem(pItem); if (!pItem) return; // Get the <xml> item pItem = m_treeOutput.GetNextItem(pItem, TVGN_NEXT); if (!pItem) return; // Get the first <project> item pItem = m_treeOutput.GetChildItem(pItem); if (!pItem) return; // Process all <project> items while (pItem) { if (!m_treeOutput.GetItemText(pItem).CompareNoCase(_T("project"))) CreateNewProject(pItem); pItem = m_treeOutput.GetNextItem(pItem, TVGN_NEXT); } SCENG_Fini(); }
// NewProjectWindow::MessageReceived -- receives messages void NewProjectWindow::MessageReceived (BMessage *message) { switch(message->what) { case BTN_ADD: // aka Create or Save { //printf ("txtNewProject->Text() - %s\n\n",txtNewProject->Text()); BString tmp = "Untitled"; if (tmp.Compare(txtNewProject->Text()) != 0) { if (PanelType == 1) { CreateExistingProject(); } else { CreateNewProject(); } Lock(); Quit(); } else { // Tip 2 - New Project Name - something other than untitled ;) TipNumber = 2; new HelpTipWindow(BRect(0.0, 0.0, 350.0, 120.0)); } } break; case BTN_CANCEL: { // This Window is no longer needed. Lock(); Quit(); } break; default: BWindow::MessageReceived(message); break; } }
void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) { // Any open KIFACE's must be closed if they are not part of the new project. // (We never want a KIWAY_PLAYER open on a KIWAY that isn't in the same project.) // User is prompted here to close those KIWAY_PLAYERs: if( !Kiway.PlayersClose( false ) ) return; // evt_id can be one of: // ID_NEW_PROJECT, ID_NEW_PROJECT_FROM_TEMPLATE, ID_LOAD_PROJECT, and // wxID_ANY from 3 different places. int evt_id = event.GetId(); wxString title; ClearMsg(); bool newProject = ( evt_id == ID_NEW_PROJECT ) || ( evt_id == ID_NEW_PROJECT_FROM_TEMPLATE ); if( evt_id != wxID_ANY ) { int style; if( newProject ) { title = _( "Create New Project" ); style = wxFD_SAVE | wxFD_OVERWRITE_PROMPT; } else { title = _( "Open Existing Project" ); style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; } wxString default_dir = GetMruPath(); wxFileDialog dlg( this, title, default_dir, wxEmptyString, ProjectFileWildcard, style ); if( dlg.ShowModal() == wxID_CANCEL ) return; //DBG( printf( "%s: wxFileDialog::GetPath=%s\n", __func__, TO_UTF8( dlg.GetPath() ) );) wxFileName pro( dlg.GetPath() ); pro.SetExt( ProjectFileExtension ); // enforce extension if( !pro.IsAbsolute() ) pro.MakeAbsolute(); if( newProject ) { // Check if the project directory is empty wxDir directory( pro.GetPath() ); if( directory.HasFiles() ) { wxString msg = _( "The selected directory is not empty. We recommend you " "create projects in their own clean directory.\n\nDo you " "want to create a new empty directory for the project?" ); if( IsOK( this, msg ) ) { // Append a new directory with the same name of the project file // and try to create it pro.AppendDir( pro.GetName() ); if( !wxMkdir( pro.GetPath() ) ) // There was a problem, undo pro.RemoveLastDir(); } } if( evt_id == ID_NEW_PROJECT ) { CreateNewProject( pro.GetFullPath() ); } else if( evt_id == ID_NEW_PROJECT_FROM_TEMPLATE ) { // Launch the template selector dialog CreateNewProject( pro.GetFullPath(), true ); } } SetProjectFileName( pro.GetFullPath() ); } wxString prj_filename = GetProjectFileName(); wxString nameless_prj = NAMELESS_PROJECT wxT( ".pro" ); wxLogDebug( wxT( "%s: %s" ), GetChars( wxFileName( prj_filename ).GetFullName() ), GetChars( nameless_prj ) ); // Check if project file exists and if it is not noname.pro if( !wxFileExists( prj_filename ) && !wxFileName( prj_filename ).GetFullName().IsSameAs( nameless_prj ) ) { wxString msg = wxString::Format( _( "KiCad project file '%s' not found" ), GetChars( prj_filename ) ); DisplayError( this, msg ); return; } // Either this is the first time kicad has been run or one of the projects in the // history list is no longer valid. This prevents kicad from automatically creating // a noname.pro file in the same folder as the kicad binary. if( wxFileName( prj_filename ).GetFullName().IsSameAs( nameless_prj ) && !newProject ) { m_active_project = false; m_MessagesBox->SetValue( _( "To proceed, you can use the File menu to start a new project." ) ); return; } else { m_active_project = true; m_MessagesBox->Clear(); } Prj().ConfigLoad( Pgm().SysSearch(), GeneralGroupName, s_KicadManagerParams ); title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + prj_filename; if( !wxFileName( prj_filename ).IsDirWritable() ) title += _( " [Read Only]" ); else SetMruPath( Prj().GetProjectPath() ); // Only set MRU path if we have write access. SetTitle( title ); if( !prj_filename.IsSameAs( nameless_prj ) ) UpdateFileHistory( prj_filename, &Pgm().GetFileHistory() ); m_LeftWin->ReCreateTreePrj(); // Rebuild the list of watched paths. // however this is possible only when the main loop event handler is running, // so we use it to run the rebuild function. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS ); wxPostEvent( this, cmd ); PrintPrjInfo(); }
void App::MessageReceived(BMessage *msg) { switch (msg->what) { case M_MAKE_PROJECT: case M_RUN_PROJECT: case M_RUN_IN_TERMINAL: case M_RUN_IN_DEBUGGER: case M_RUN_WITH_ARGS: case M_FORCE_REBUILD: case M_SHOW_ADD_NEW_PANEL: case M_SHOW_FIND_AND_OPEN_PANEL: case M_SHOW_FIND_IN_PROJECT_FILES: case M_SHOW_ERROR_WINDOW: case M_TOGGLE_ERROR_WINDOW: { entry_ref ref; if (msg->FindRef("refs",&ref) == B_OK) PostToProjectWindow(msg,&ref); else PostToProjectWindow(msg,NULL); break; } case M_OPEN_PARTNER: { entry_ref ref; if (msg->FindRef("refs",&ref) == B_OK) OpenPartner(ref); break; } case M_NEW_PROJECT: { TemplateWindow *win = new TemplateWindow(BRect(100, 100, 400, 300)); win->Show(); break; } case M_SHOW_OPEN_PROJECT: { CheckCreateOpenPanel(); fOpenPanel->Show(); break; } case M_CREATE_PROJECT: { CreateNewProject(*msg); break; } case M_QUICK_IMPORT: { entry_ref ref; if (msg->FindRef("refs",&ref) != B_OK || !QuickImportProject(DPath(ref))) { StartWindow *startwin = new StartWindow(); startwin->Show(); break; } break; } // These are for quit determination. We have to use our own counter variable // (sWindowCount) because BFilePanels throw the count off. Using a variable // is much preferable to subclassing just for this reason. case M_REGISTER_WINDOW: { sWindowCount++; break; } case M_DEREGISTER_WINDOW: { sWindowCount--; if (sWindowCount <= 1) PostMessage(B_QUIT_REQUESTED); break; } case EDIT_OPEN_FILE: { int32 index = 0; entry_ref ref; while (msg->FindRef("refs",index,&ref) == B_OK) { int32 line; if (msg->FindInt32("line",index,&line) != B_OK) line = -1; int32 column; if (msg->FindInt32("column",index,&column) != B_OK) column = -1; OpenFile(ref,line,column); index++; } CheckCreateOpenPanel(); fOpenPanel->GetPanelDirectory(&ref); gLastProjectPath.SetTo(ref); BWindow* openWindow = fOpenPanel->Window(); break; } case M_FIND_AND_OPEN_FILE: { FindAndOpenFile(msg); break; } case M_BUILDING_FILE: { SourceFile *file; if (msg->FindPointer("sourcefile",(void**)&file) == B_OK) printf(B_TRANSLATE("Building %s\n"),file->GetPath().GetFileName()); else printf(B_TRANSLATE("NULL pointer in M_BUILDING_FILE\n")); break; } case M_LINKING_PROJECT: { printf(B_TRANSLATE("Linking\n")); break; } case M_UPDATING_RESOURCES: { printf(B_TRANSLATE("Updating resources\n")); break; } case M_BUILD_FAILURE: { BString errstr; if (msg->FindString("errstr",&errstr) == B_OK) printf("%s\n",errstr.String()); else { ErrorList errors; errors.Unflatten(*msg); printf(B_TRANSLATE("Build failure\n%s"), errors.AsString().String()); } sReturnCode = -1; PostMessage(B_QUIT_REQUESTED); break; } case M_BUILD_WARNINGS: { BString errstr; if (msg->FindString("errstr",&errstr) == B_OK) printf("%s\n",errstr.String()); break; } case M_BUILD_SUCCESS: { printf(B_TRANSLATE("Success\n")); PostMessage(B_QUIT_REQUESTED); break; } default: BApplication::MessageReceived(msg); } }
long ProjNewGUI::HandleButtonClick(NativeControl Handle, NativeGUIWin NW, int ButtonID) { SECURITY_INLINE_CHECK(073, 73); switch(ButtonID) { case ID_SAVE: { if(AppScope->GUIWins->CVG) AppScope->GUIWins->CVG->CloseViewsForIO(); if (CreateNewProject()) { // can't have two delayed notifications in queue at once so only way to open Import Wizard and close // New project is to do it ourselves. if (UserMessageYN("Import Data", "Your new Project has been created and saved.\nWould you like to import some data now?")) { Close(); if(!AppScope->GUIWins->IWG) { AppScope->GUIWins->IWG = new ImportWizGUI(AppScope->AppDB, AppScope->MainProj, AppScope->AppEffects, AppScope->StatusLog, true); if(AppScope->GUIWins->IWG->ConstructError) { delete AppScope->GUIWins->IWG; AppScope->GUIWins->IWG = NULL; } // if } // if if(AppScope->GUIWins->IWG) { AppScope->GUIWins->IWG->Open(AppScope->MainProj); } } // if AppScope->MCP->SetParam(1, WCS_TOOLBARCLASS_MODULES, WCS_TOOLBAR_CLOSE_MOD, WCS_TOOLBAR_ITEM_PNG, 0); } // if saved break; } // case IDCANCEL: { AppScope->MCP->SetParam(1, WCS_TOOLBARCLASS_MODULES, WCS_TOOLBAR_CLOSE_MOD, WCS_TOOLBAR_ITEM_PNG, 0); break; } // case IDC_ADDTEMPLATE: { AddTemplate(); break; } // IDC_ADDTEMPLATE case IDC_REMOVETEMPLATE: { RemoveTemplate(); break; } // IDC_REMOVETEMPLATE case IDC_MOVETEMPUP: { ChangeTemplateListPosition(1); break; } // IDC_MOVETEMPLATEUP case IDC_MOVETEMPDOWN: { ChangeTemplateListPosition(0); break; } // IDC_MOVETEMPLATEDOWN case IDC_ENABLETEMPLATE: { EnableTemplate(1); break; } // IDC_ENABLETEMPLATE case IDC_DISABLETEMPLATE: { EnableTemplate(0); break; } // IDC_DISABLETEMPLATE default: break; } // ButtonID return(0); } // ProjNewGUI::HandleButtonClick
void KICAD_MANAGER_FRAME::OnCreateProjectFromTemplate( wxCommandEvent& event ) { DIALOG_TEMPLATE_SELECTOR* ps = new DIALOG_TEMPLATE_SELECTOR( this ); wxFileName templatePath; wxString envStr; // KiCad system template path. ENV_VAR_MAP_CITER it = Pgm().GetLocalEnvVariables().find( "KICAD_TEMPLATE_DIR" ); if( it != Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString ) { templatePath.AssignDir( it->second.GetValue() ); ps->AddTemplatesPage( _( "System Templates" ), templatePath ); } // User template path. it = Pgm().GetLocalEnvVariables().find( "KICAD_USER_TEMPLATE_DIR" ); if( it != Pgm().GetLocalEnvVariables().end() && it->second.GetValue() != wxEmptyString ) { templatePath.AssignDir( it->second.GetValue() ); ps->AddTemplatesPage( _( "User Templates" ), templatePath ); } // Show the project template selector dialog if( ps->ShowModal() != wxID_OK ) return; if( ps->GetSelectedTemplate() == NULL ) { wxMessageBox( _( "No project template was selected. Cannot generate new project." ), _( "Error" ), wxOK | wxICON_ERROR, this ); return; } // Get project destination folder and project file name. wxString default_dir = wxFileName( Prj().GetProjectFullName() ).GetPathWithSep(); wxString title = _( "New Project Folder" ); wxFileDialog dlg( this, title, default_dir, wxEmptyString, ProjectFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); // Add a "Create a new directory" checkbox dlg.SetExtraControlCreator( &DIR_CHECKBOX::Create ); if( dlg.ShowModal() == wxID_CANCEL ) return; wxFileName fn( dlg.GetPath() ); // wxFileName automatically extracts an extension. But if it isn't // a .pro extension, we should keep it as part of the filename if( !fn.GetExt().IsEmpty() && fn.GetExt().ToStdString() != ProjectFileExtension ) fn.SetName( fn.GetName() + wxT( "." ) + fn.GetExt() ); fn.SetExt( ProjectFileExtension ); // enforce extension if( !fn.IsAbsolute() ) fn.MakeAbsolute(); // Append a new directory with the same name of the project file. if( static_cast<DIR_CHECKBOX*>( dlg.GetExtraControl() )->CreateNewDir() ) fn.AppendDir( fn.GetName() ); // Check if the project directory is empty if it already exists. wxDir directory( fn.GetPath() ); if( !fn.DirExists() ) { if( !fn.Mkdir() ) { wxString msg; msg.Printf( _( "Directory \"%s\" could not be created.\n\n" "Please make sure you have write permissions and try again." ), fn.GetPath() ); DisplayErrorMessage( this, msg ); return; } } if( !fn.IsDirWritable() ) { wxString msg; msg.Printf( _( "Cannot write to folder \"%s\"." ), fn.GetPath() ); wxMessageDialog msgDlg( this, msg, _( "Error!" ), wxICON_ERROR | wxOK | wxCENTER ); msgDlg.SetExtendedMessage( _( "Please check your access permissions to this folder " "and try again." ) ); msgDlg.ShowModal(); return; } ClearMsg(); // Make sure we are not overwriting anything in the destination folder. std::vector< wxFileName > destFiles; if( ps->GetSelectedTemplate()->GetDestinationFiles( fn, destFiles ) ) { std::vector< wxFileName > overwrittenFiles; for( const auto& file : destFiles ) { if( file.FileExists() ) overwrittenFiles.push_back( file ); } if( !overwrittenFiles.empty() ) { wxString extendedMsg = _( "Overwriting files:" ) + "\n"; for( const auto& file : overwrittenFiles ) extendedMsg += "\n" + file.GetFullName(); KIDIALOG msgDlg( this, _( "Similar files already exist in the destination folder." ), _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING ); msgDlg.SetExtendedMessage( extendedMsg ); msgDlg.SetOKLabel( _( "Overwrite" ) ); msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ ); if( msgDlg.ShowModal() == wxID_CANCEL ) return; } } wxString errorMsg; // The selected template widget contains the template we're attempting to use to // create a project if( !ps->GetSelectedTemplate()->CreateProject( fn, &errorMsg ) ) { wxMessageDialog createDlg( this, _( "A problem occurred creating new project from template!" ), _( "Template Error" ), wxOK | wxICON_ERROR ); if( !errorMsg.empty() ) createDlg.SetExtendedMessage( errorMsg ); createDlg.ShowModal(); return; } CreateNewProject( fn.GetFullPath() ); LoadProject( fn ); }