|
From: Emilien K. <cur...@us...> - 2005-03-03 16:20:39
|
Update of /cvsroot/wxdevcenter/wxDevCenter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28018/src Modified Files: Application.cpp Project.cpp Log Message: Ajout des mécanismes primaires de gestion des projets. Index: Project.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Project.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Project.cpp 3 Dec 2004 16:47:46 -0000 1.1 --- Project.cpp 3 Mar 2005 16:20:28 -0000 1.2 *************** *** 3,7 **** * @author Cursor * ! * @brief Implémentation de la classe de gestion du projet. */ // --- 3,7 ---- * @author Cursor * ! * @brief Implémentation des classes de gestion des projets. */ // *************** *** 26,35 **** #include <wxDevCenter/Project.h> using namespace wxDevCenter; ! ////////////////////////////////////////////////////////////////////// ! // Construction/Destruction Project::Project(): ! m_bIsActive(false), m_strName(""), m_strPath(""), --- 26,40 ---- #include <wxDevCenter/Project.h> + #include <wx/tokenzr.h> + using namespace wxDevCenter; ! IMPLEMENT_DYNAMIC_CLASS(wxDevCenter::Project, wxObject); ! ! /** ! * Implémentation de la classe wxDevCenter::Project ! */ Project::Project(): ! wxObject(), m_strName(""), m_strPath(""), *************** *** 45,73 **** ! ////////////////////////////////////////////////////////////////////// ! // Création/Ouverture/Fermeture ! bool Project::OpenFromFile(wxString WXUNUSED(strFile)) { ! m_bIsActive = true; ! return true; } ! bool Project::Create(wxString WXUNUSED(strFile), wxString WXUNUSED(strName)) { ! m_bIsActive = true; ! return true; } ! void Project::Close() { ! m_strName = ""; ! m_strPath = ""; ! m_strDescription = ""; ! m_bIsActive = false; } --- 50,322 ---- ! // Méthode de création d'un nouveau projet. ! bool Project::OnCreateProject() { ! return true; } ! // Méthode d'ouverture de projet. ! bool Project::OnOpenProject(Archive& WXUNUSED(ar)) { ! return true; } ! // Méthode de sauvegarde de projet. ! bool Project::OnSaveProject(Archive& WXUNUSED(ar)) { ! return true; ! } ! ! // Méthode testant la possibilité de fermer un projet. ! bool Project::CanCloseProject() ! { ! /** @todo Fermer les documents attachés.*/ ! return true; ! } ! ! // Méthode de fermeture de projet. ! bool Project::OnCloseProject() ! { ! return true; ! } ! ! ! /** ! * Implémentation de la classe wxDevCenter::ProjectTemplate ! */ ! ProjectTemplate::ProjectTemplate(wxClassInfo* pProjectClassInfo, wxString strName, wxString strDescript, wxString strIcon, wxString strExt): ! wxObject(), ! m_strName(strName), ! m_strDescript(strDescript), ! m_strIcon(strIcon), ! m_pProjectClassInfo(pProjectClassInfo) ! { ! if(!strExt.IsEmpty()) ! AddFileProjectExtension(strExt); ! } ! ! ! // Ajoute des extensions de fichiers de projets. ! void ProjectTemplate::AddFileProjectExtension(wxString strExt) ! { ! wxStringTokenizer ST(strExt, wxT(";")); ! while(ST.HasMoreTokens()) ! m_strExtArray.Add(ST.GetNextToken()); ! } ! ! // Retourne le wildcard associé au fichier du projet. ! wxString ProjectTemplate::GetDocWildcard(bool bShowStarDotStar)const ! { ! wxString strWildcard, str; ! unsigned int n; ! str.Empty(); ! for(n=0; n<m_strExtArray.GetCount(); n++) ! str += "*." + m_strExtArray[n] + ";"; ! str.RemoveLast(); ! strWildcard = m_strName + " (" + str + ")|" + str; ! if(bShowStarDotStar) ! strWildcard += "|" + wxString(WXDC_FILE_WILDCARD_ALLFILE) + "|*.*"; ! strWildcard += "|"; ! return strWildcard; } + // Crée un objet projet. + Project* ProjectTemplate::CreateProject() + { + return (Project*)m_pProjectClassInfo->CreateObject(); + } + /** + * Implémentation de la classe wxDevCenter::ProjectManager + */ + // Constructeur par défaut. + ProjectManager::ProjectManager(): + ProjectTemplateArray(), + m_pCurrentProject(NULL) + { + } + // Destructeur. + ProjectManager::~ProjectManager() + { + CloseProject(true); + } + + // Initialisation du gestionnaire. + void ProjectManager::Initialize() + { + } + + // Finalisation du gestionnaire. + void ProjectManager::Finalize() + { + } + + + // Ferme le projet en cours. + bool ProjectManager::CloseProject(bool bForce) + { + if(HasProject()) + { + // Préfermeture. + if(!m_pCurrentProject->CanCloseProject() && !bForce) + return false; + // Fermeture. + if(!m_pCurrentProject->OnCloseProject() && !bForce) + return false; + // Destruction. + delete m_pCurrentProject; + m_pCurrentProject = NULL; + } + return true; + } + + // Ouvre un projet depuis un fichier spécifié. + bool ProjectManager::OpenProject(FilePath strFile, int iTemplateIndex) + { + // Fermeture de l'ancien projet. + if(!CloseProject()) + return false; + + // Validation du type de projet. + if(iTemplateIndex==-1) + iTemplateIndex = ChooseProjectTemplateFromExtension(strFile); + if(iTemplateIndex==-1) + return false; + + m_pCurrentProject = GetProjectTemplate(iTemplateIndex)->CreateProject(); + + if(m_pCurrentProject) + { + // Appelle de le chargement du projet. + Archive* pAr = wxGetApp().CreateDocumentArchive(strFile, Archive::read); + if(pAr!=NULL) + { + if(m_pCurrentProject->OnOpenProject(*pAr)) + { + delete pAr; + return true; + } + } + delete m_pCurrentProject; + } + return false; + } + + // Sauvegarde les données du projet. + bool ProjectManager::SaveProject() + { + if(HasProject()) + { + // Appelle de le chargement du projet. + FilePath path = m_pCurrentProject->GetPath(); + Archive* pAr = wxGetApp().CreateDocumentArchive(path, Archive::write); + if(pAr!=NULL) + { + if(m_pCurrentProject->OnSaveProject(*pAr)) + { + delete pAr; + return true; + } + } + } + return false; + } + + // Crée un nouveau projet. + bool ProjectManager::CreateProject(int iTemplateIndex) + { + // Fermeture de l'ancien projet. + if(!CloseProject()) + return false; + + // Test du type de projet + if(iTemplateIndex==-1) + iTemplateIndex = ChooseProjectTemplate(); + if(iTemplateIndex==-1) + return false; + + m_pCurrentProject = GetProjectTemplate(iTemplateIndex)->CreateProject(); + + // Appelle de l'initialisation du projet. + if(!m_pCurrentProject->OnCreateProject()) + { + delete m_pCurrentProject; + return false; + } + + return true; + } + + // Accès à l'index d'un type de projet. + int ProjectManager::GetProjectTemplateIndex(const ProjectTemplate* pTemplate) + { + for(unsigned int n=0; n<GetCount(); n++) + if(Item(n)==pTemplate) + return n; + return -1; + } + + // Enregistre un type de projet. + bool ProjectManager::RegisterProjectType(ProjectTemplate* pTemplate) + { + if(GetProjectTemplateIndex(pTemplate)==-1) + { + Add(pTemplate); + return true; + } + else + return false; + } + + // Retourne le wildcard de tous les types de projets. + wxString ProjectManager::GetAllWildcard(bool bShowStarDotStar, bool bShowAllRegisteredExt)const + { + unsigned int m, n; + wxString strWild; + strWild.Empty(); + + if(bShowAllRegisteredExt) + { + strWild = wxString(WXDC_FILE_WILDCARD_ALLREGISTERED) + wxT("|"); + for(m=0; m<GetCount(); m++) + { + for(n=0; n<GetProjectTemplate(m)->GetExtensionCount(); n++) + { + strWild << wxT("*.") << GetProjectTemplate(m)->GetExtension(n) << wxT(";"); + } + } + strWild.RemoveLast(); + strWild << wxT("|"); + } + + for(n=0; n<GetCount(); n++) + strWild << GetProjectTemplate(n)->GetDocWildcard(false); + + if(bShowStarDotStar) + strWild << wxString(WXDC_FILE_WILDCARD_ALLFILE) << wxT("|*.*|"); + return strWild; + } + + // Fait choisir un patron de projet à l'utilisateur. + int ProjectManager::ChooseProjectTemplate()const + { + wxArrayString ar; + for(unsigned int n=0; n<GetProjectTemplateCount(); n++) + ar.Add(GetProjectTemplate(n)->GetName() + wxT(" - ") + GetProjectTemplate(n)->GetDescript()); + return wxGetSingleChoiceIndex(WXDC_PROJECT_QUERY_TYPE, WXDC_NAME, ar); + } + + // Choisit un type de projet en fonction de l'extensions d'un fichier. + int ProjectManager::ChooseProjectTemplateFromExtension(const FilePath& strFile)const + { + wxString strExt = strFile.GetFileExt(); + for(unsigned int n=0; n<GetProjectTemplateCount(); n++) + for(unsigned int m=0; m<GetProjectTemplate(n)->GetExtensionCount(); m++) + if(strExt==GetProjectTemplate(n)->GetExtension(m)) + return (int)n; + return -1; + } Index: Application.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Application.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Application.cpp 28 Feb 2005 15:26:23 -0000 1.13 --- Application.cpp 3 Mar 2005 16:20:28 -0000 1.14 *************** *** 61,67 **** m_ConfigManager.CreateUserProfile(); ! // Initialise le DocManager m_DocManager.InitDocManager(); // Charge les plugins. LoadPlugins(); --- 61,70 ---- m_ConfigManager.CreateUserProfile(); ! // Initialise le DocManager m_DocManager.InitDocManager(); + // Initialise le ProjectManager + m_ProjectManager.Initialize(); + // Charge les plugins. LoadPlugins(); *************** *** 93,96 **** --- 96,101 ---- int Application::OnExit(void) { + // Finalisation du gestionnaire de projets. + m_ProjectManager.Finalize(); // Enregistrement de la config m_ConfigManager.Finalize(); *************** *** 103,116 **** Application::Application(void): wxApp(), - m_pProject(NULL), m_pStandardFileSystem(NULL), m_IconBundleCache(40) { - m_pProject = new Project; } Application::~Application(void) { - delete m_pProject; } --- 108,118 ---- *************** *** 123,127 **** void Application::CreateProject() { ! CloseProject(); } --- 125,129 ---- void Application::CreateProject() { ! m_ProjectManager.CreateProject(); } *************** *** 130,150 **** void Application::LoadProject() { ! CloseProject(); ! wxFileDialog FileDialog(NULL, WXDC_PROJECT_QUERY_OPEN, "", "", WXDC_PROJECT_WILDCARD, wxOPEN); ! if(FileDialog.ShowModal()==wxID_OK) ! { ! m_pProject->OpenFromFile(FileDialog.GetPath()); ! } } // Ferme le projet en cours void Application::CloseProject() { ! if(m_pProject->IsActive()) ! { ! m_pProject->Close(); ! } } --- 132,166 ---- void Application::LoadProject() { ! if(!m_ProjectManager.CloseProject()) ! return; ! FileSystemDialog FD(NULL, -1, WXDC_PROJECT_QUERY_OPEN, WXDC_SYSTEM_DEFAULT_PATH); ! FD.AttachFileSystems(&m_FileSystemManager); ! FD.SetWildcard(m_ProjectManager.GetAllWildcard()); ! if(FD.ShowModal()==wxID_OK) ! { ! int iProjectType = FD.GetFilterIndex(); ! if(iProjectType==wxNOT_FOUND // Pas de sélection de type ! || iProjectType==0 // "Tous les types enregistrés" ! || iProjectType==(int)m_ProjectManager.GetProjectTemplateCount()) // "*.*" ! iProjectType = -1; ! ! wxArrayString files; ! FD.GetSelectedFileList(files); ! if(files.GetCount()>0) ! m_ProjectManager.OpenProject(files[0], iProjectType); ! } } + // Sauvegarde le projet. + void Application::SaveProject() + { + m_ProjectManager.SaveProject(); + } // Ferme le projet en cours void Application::CloseProject() { ! m_ProjectManager.CloseProject(); } *************** *** 152,156 **** bool Application::IsProjectActive(void) { ! return (m_pProject!=NULL)?m_pProject->IsActive():false; } --- 168,172 ---- bool Application::IsProjectActive(void) { ! return m_ProjectManager.HasProject(); } |