Beispiel #1
0
wxTreeItemId
PHPWorkspaceView::EnsureFolderExists(const wxTreeItemId& projectItem, const wxString& path, const wxString& project)
{
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project);
    wxASSERT_MSG(pProject, wxString::Format("Could not locate project %s", project));

    int imgId = m_mgr->GetStdIcons()->GetMimeImageId(FileExtManager::TypeFolder);
    wxString curpath;
    wxTreeItemId parent = projectItem;
    wxArrayString parts = ::wxStringTokenize(path, "/", wxTOKEN_STRTOK);
    for(size_t i = 0; i < parts.GetCount(); ++i) {
        if(!curpath.IsEmpty()) {
            curpath << "/";
        }
        curpath << parts.Item(i);

        if(!HasFolderWithName(parent, parts.Item(i), parent)) {
            ItemData* itemData = new ItemData(ItemData::Kind_Folder);
            itemData->SetFolderPath(curpath);
            itemData->SetProjectName(project);
            itemData->SetFolderName(parts.Item(i));
            parent =
                m_treeCtrlView->AppendItem(parent,
                                           parts.Item(i) == "." ? pProject->GetFilename().GetPath() : parts.Item(i),
                                           imgId,
                                           imgId,
                                           itemData);
        }
    }
    m_treeCtrlView->SortChildren(projectItem);
    return parent;
}
Beispiel #2
0
void PHPWorkspaceView::DoAddFolderFiles(const wxString& project,
                                        const wxString& folder,
                                        const wxTreeItemId& folderTreeItemId,
                                        wxStringSet_t* filesAdded)
{
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project);
    CHECK_PTR_RET(pProject);

    PHPFolder::Ptr_t pFolder = pProject->Folder(folder);
    CHECK_PTR_RET(pFolder);

    wxArrayString files;
    pFolder->GetFiles(files, pProject->GetFilename().GetPath());
    files.Sort();

    for(size_t i = 0; i < files.GetCount(); ++i) {
        wxFileName fn(files.Item(i));
        // create the user data
        ItemData* itemData = new ItemData(ItemData::Kind_File);
        itemData->SetFile(fn.GetFullPath());
        itemData->SetFolderPath(folder);
        itemData->SetProjectName(project);

        int imgId = DoGetItemImgIdx(fn.GetFullName());
        m_treeCtrlView->AppendItem(folderTreeItemId, fn.GetFullName(), imgId, imgId, itemData);

        if(filesAdded) {
            filesAdded->insert(fn.GetFullPath());
        }
    }
}
Beispiel #3
0
void PHPWorkspaceView::OnNewFolder(wxCommandEvent& e)
{
    wxUnusedVar(e);

    wxString name = wxGetTextFromUser(_("New Folder Name:"), _("New Folder"));
    if(name.IsEmpty()) return;

    wxString project = DoGetSelectedProject();
    if(project.IsEmpty()) return;

    wxTreeItemId parent = m_treeCtrlView->GetSelection();
    CHECK_ITEM_RET(parent);

    ItemData* itemData = DoGetItemData(parent);
    CHECK_PTR_RET(itemData);

    if(!itemData->IsFolder() && !itemData->IsProject()) return;

    PHPProject::Ptr_t proj = PHPWorkspace::Get()->GetProject(project);
    CHECK_PTR_RET(proj);

    wxString folder;
    if(itemData->IsFolder()) {
        folder << itemData->GetFolderPath() << "/" << name;
    } else {
        folder << name;
    }
    PHPFolder::Ptr_t pFolder = proj->AddFolder(folder);
    proj->Save();

    // Update the UI
    DoAddFolder(parent, pFolder, proj);
}
Beispiel #4
0
void PHPWorkspace::GetProjectFiles(const wxString& projectName, wxArrayString& files) const
{
    PHPProject::Ptr_t p = GetProject(projectName.IsEmpty() ? GetActiveProjectName() : projectName);
    CHECK_PTR_RET(p);

    p->GetFilesArray(files);
}
Beispiel #5
0
void PHPWorkspaceView::DoAddFilesToFolder(const wxArrayString& paths, PHPProject::Ptr_t pProject, bool notify)
{
    if(paths.IsEmpty()) return;

    CHECK_PTR_RET(pProject);

    wxString folder_path = PHPFolder::GetFolderPathFromFileFullPath(paths.Item(0), pProject->GetFilename().GetPath());
    wxTreeItemId folderItem =
        EnsureFolderExists(DoGetProjectItem(pProject->GetName()), folder_path, pProject->GetName());
    PHPFolder::Ptr_t pFolder = pProject->AddFolder(folder_path);
    CHECK_PTR_RET(pFolder);

    wxArrayString newPaths;
    for(size_t i = 0; i < paths.GetCount(); i++) {
        if(pFolder->AddFile(paths.Item(i))) {
            newPaths.Add(paths.Item(i));
        }
    }
    if(newPaths.IsEmpty()) return;

    if(notify) {
        DoAddFilesToTreeView(folderItem, pProject, pFolder, newPaths);
        // Notify the plugins
        clCommandEvent evtFilesAdded(wxEVT_PROJ_FILE_ADDED);
        evtFilesAdded.SetStrings(newPaths);
        EventNotifier::Get()->AddPendingEvent(evtFilesAdded);
    }
}
Beispiel #6
0
void PHPWorkspace::OnProjectSyncEnd(clCommandEvent& event)
{
    const wxString& name = event.GetString();
    if(m_inSyncProjects.count(name) == 0) {
        clWARNING() << "PHPWorkspace::OnProjectSyncEnd: unable to find project '" << name << "' in the workspace..."
                    << clEndl;
        return;
    }

    clDEBUG() << "PHPWorkspace::OnProjectSyncEnd: project" << name << "completed sync" << clEndl;
    m_inSyncProjects.erase(name);

    // Load the project
    PHPProject::Ptr_t pProj = GetProject(name);
    CHECK_PTR_RET(pProj);

    // Update the project files
    pProj->SetFiles(event.GetStrings());

    if(m_inSyncProjects.empty()) {
        clDEBUG() << "PHPWorkspace::OnProjectSyncEnd: all projects completed sync" << clEndl;
        if(m_projectSyncOwner) {
            clCommandEvent endEvent(wxEVT_PHP_WORKSPACE_FILES_SYNC_END);
            m_projectSyncOwner->AddPendingEvent(endEvent);
        }
    }
}
Beispiel #7
0
void PHPWorkspace::FromJSON(const JSONElement& e)
{
    m_projects.clear();
    if(e.hasNamedObject("projects")) {
        PHPProject::Ptr_t firstProject;
        JSONElement projects = e.namedObject("projects");
        int count = projects.arraySize();
        for(int i = 0; i < count; ++i) {
            PHPProject::Ptr_t p(new PHPProject());
            wxString project_file = projects.arrayItem(i).toString();
            wxFileName fnProject(project_file);
            fnProject.MakeAbsolute(m_workspaceFile.GetPath());
            p->Load(fnProject);
            m_projects.insert(std::make_pair(p->GetName(), p));
            if(!firstProject) {
                firstProject = p;
            }
        }

        PHPProject::Ptr_t activeProject = GetActiveProject();
        if(!activeProject && firstProject) {
            // No active project found, mark the first project as active
            activeProject = firstProject;
            SetProjectActive(firstProject->GetName());
        }

        if(activeProject) {
            // Notify about active project been set
            clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED);
            evt.SetProjectName(activeProject->GetName());
            evt.SetFileName(activeProject->GetFilename().GetFullPath());
            EventNotifier::Get()->AddPendingEvent(evt);
        }
    }
}
wxString PHPCodeCompletion::ExpandRequire(const wxFileName& curfile, const wxString& require)
{
    PHPScanner_t scanner = ::phpLexerNew("<?php " + require);
    if(!scanner) return "";

    wxString outFile;
    phpLexerToken token;
    while(::phpLexerNext(scanner, token)) {
        if(token.IsAnyComment()) continue;
        switch(token.type) {
        case kPHP_T_REQUIRE:
        case kPHP_T_REQUIRE_ONCE:
            break;
        case kPHP_T_CONSTANT_ENCAPSED_STRING: {
            wxString str = token.text;
            str.Trim().Trim(false);
            // strip the " or ' from the string
            str.Remove(0, 1).RemoveLast();
            outFile << str;
            break;
        }
        case kPHP_T_FILE:
            outFile << curfile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
            break;
        case kPHP_T_DIR:
            outFile << curfile.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
            break;
        }
    }

    wxFileName fileName(outFile);
    if(fileName.IsOk() && fileName.IsRelative()) {
        wxArrayString paths;
        paths.Add(curfile.GetPath());
        // Relative path, we try to resolve it by looking at the include path give to us
        PHPProject::Ptr_t proj = PHPWorkspace::Get()->GetActiveProject();
        if(proj) {
            wxArrayString incpaths = proj->GetSettings().GetIncludePathAsArray();
            paths.insert(paths.end(), incpaths.begin(), incpaths.end());
        }

        for(size_t i = 0; i < paths.GetCount(); ++i) {
            wxFileName tmpFile = fileName;
            if(tmpFile.MakeAbsolute(paths.Item(i))) {
                wxString fullpath = tmpFile.GetFullPath();
                if(wxFileName::Exists(fullpath)) {
                    fileName = tmpFile;
                    break;
                }
            }
        }
    }

    if(fileName.IsOk()) {
        fileName.Normalize();
        outFile = fileName.GetFullPath();
    }
    ::phpLexerDestroy(&scanner);
    return outFile;
}
Beispiel #9
0
void PHPWorkspaceView::DoAddFolder(const wxTreeItemId& parent, PHPFolder::Ptr_t folder, PHPProject::Ptr_t project)
{
    // add the folder itself
    ItemData* itemData = new ItemData(ItemData::Kind_Folder);
    itemData->SetFolderPath(folder->GetPathRelativeToProject());
    itemData->SetProjectName(project->GetName());
    itemData->SetFolderName(folder->GetName()); // display name

    wxTreeItemId folderItem = EnsureFolderExists(
        DoGetProjectItem(project->GetName()), folder->GetPathRelativeToProject(), project->GetName());

    // Get list of folders
    const PHPFolder::List_t& children = folder->GetChildren();
    PHPFolder::List_t::const_iterator iter = children.begin();
    for(; iter != children.end(); ++iter) {
        DoAddFolder(folderItem, *iter, project);
    }

    wxArrayString folderFiles;
    folder->GetFiles(folderFiles, project->GetFilename().GetPath(), 0);

    // Add the files
    for(size_t i = 0; i < folderFiles.GetCount(); ++i) {
        ItemData* itemData = new ItemData(ItemData::Kind_File);
        itemData->SetFile(folderFiles.Item(i));
        itemData->SetProjectName(project->GetName());
        itemData->SetFolderPath(folder->GetPathRelativeToProject());
        int imgId = DoGetItemImgIdx(folderFiles.Item(i));
        m_treeCtrlView->AppendItem(folderItem, wxFileName(folderFiles.Item(i)).GetFullName(), imgId, imgId, itemData);
    }
}
Beispiel #10
0
wxFileName PHPWorkspace::GetProjectFileName(const wxString& projectName) const
{
    PHPProject::Ptr_t p = GetProject(projectName);
    if(!p) {
        return wxFileName();
    }
    return p->GetFilename();
}
Beispiel #11
0
void PHPWorkspace::DelFile(const wxString& project, const wxString& filename)
{
    PHPProject::Ptr_t proj = GetProject(project);
    CHECK_PTR_RET(proj);

    wxArrayString files;
    files.Add(filename);
    proj->FilesDeleted(files, true);
}
Beispiel #12
0
void PHPWorkspaceView::OnImportFiles(wxCommandEvent& e)
{
    ImportFilesDlg dlg(wxTheApp->GetTopWindow());
    if(dlg.ShowModal() == wxID_OK) {
        PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(DoGetSelectedProject());
        CHECK_PTR_RET(pProject);

        pProject->ImportDirectory(dlg.GetPath(), dlg.GetFileSpec(), dlg.GetIsRecursive());
        LoadWorkspace();
    }
}
Beispiel #13
0
void PHPWorkspace::DeleteProject(const wxString& project)
{
    PHPProject::Ptr_t p = GetProject(project);
    CHECK_PTR_RET(p);
    m_projects.erase(project);
    if(p->IsActive() && !m_projects.empty()) {
        // we are removing the active project, select a new project to be the active
        PHPProject::Ptr_t newActiveProject = m_projects.begin()->second;
        newActiveProject->SetIsActive(true);
        newActiveProject->Save();
    }
    Save(); // save the workspace
}
Beispiel #14
0
void PhpPlugin::OnGetActiveProjectFiles(wxCommandEvent& e)
{
    if(PHPWorkspace::Get()->IsOpen()) {
        wxArrayString* pfiles = (wxArrayString*)e.GetClientData();
        if(pfiles) {
            wxString activeProjectName = PHPWorkspace::Get()->GetActiveProjectName();
            PHPProject::Ptr_t proj = PHPWorkspace::Get()->GetProject(activeProjectName);
            CHECK_PTR_RET(proj);
            proj->GetFiles(*pfiles);
        }
    } else {
        e.Skip();
    }
}
Beispiel #15
0
wxString MapRemoteFileToLocalFile(const wxString& remoteFile)
{
    // Check that a workspace is opened
    if(!PHPWorkspace::Get()->IsOpen()) return remoteFile;

    // Sanity
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetActiveProject();
    if(!pProject) return remoteFile;

    // Map filename file attribute returned by xdebug to local filename
    wxString filename = remoteFile;

    // Remote the "file://" from the file path
    filename.StartsWith(FILE_SCHEME, &filename);
    CL_DEBUG("filename => %s", filename);

    // On Windows, the file is returned like (after removing the file://)
    // /C:/Http/htdocs/file.php - remote the leading "/"
    wxRegEx reMSWPrefix("/[a-zA-Z]{1}:/");
    if(reMSWPrefix.IsValid() && reMSWPrefix.Matches(filename)) {
        // Windows file
        CL_DEBUG("filename => %s", filename);
        filename.Remove(0, 1);
    }

    // Remove URI encoding ("%20"=>" " etc)
    DecodeFileName(filename);
    CL_DEBUG("filename => %s", filename);

    // First check if the remote file exists locally
    if(wxFileName(filename).Exists()) {
        return wxFileName(filename).GetFullPath();
    }

    // Use the active project file mapping
    const PHPProjectSettingsData& settings = pProject->GetSettings();
    const JSONElement::wxStringMap_t& mapping = settings.GetFileMapping();
    JSONElement::wxStringMap_t::const_iterator iter = mapping.begin();
    for(; iter != mapping.end(); ++iter) {
        const wxString& localFolder = iter->first;
        const wxString& remoteFolder = iter->second;
        if(filename.StartsWith(remoteFolder)) {
            filename.Replace(remoteFolder, localFolder);
            return wxFileName(filename).GetFullPath();
        }
    }

    // No matching was found
    return remoteFile;
}
void PHPProjectSettingsDlg::Save()
{
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(m_projectName);
    CHECK_PTR_RET(pProject);

    PHPProjectSettingsData& data = pProject->GetSettings();

    // General settings
    data.SetRunAs(m_choicebook1->GetSelection() == 0 ? PHPProjectSettingsData::kRunAsCLI :
                  PHPProjectSettingsData::kRunAsWebsite);
    data.SetPhpExe(m_filePickerPHPExe->GetPath());
    data.SetIndexFile(m_filePickerIndex->GetPath());
    data.SetArgs(m_textCtrlProgramArgs->GetValue());
    data.SetWorkingDirectory(m_dirPickerWorkingDirectory->GetPath());
    data.SetIncludePath(m_textCtrlPHPIncludePath->GetValue());
    data.SetPauseWhenExeTerminates(m_checkBoxPauseWhenExecutionEnds->IsChecked());
    data.SetPhpIniFile(m_filePickerPhpIni->GetPath());
    data.SetProjectURL(m_textCtrlWebSiteURL->GetValue());
    data.SetUseSystemBrowser(m_checkBoxSystemBrowser->IsChecked());

    // Code Completion settings
    data.SetCcIncludePath(m_textCtrlCCIncludePath->GetValue());

    // Save the file mapping
    JSONElement::wxStringMap_t mapping;
    int itemCount = m_dvListCtrlFileMapping->GetItemCount();
    for(int i = 0; i < itemCount; ++i) {
        wxVariant source, target;
        m_dvListCtrlFileMapping->GetValue(source, i, 0);
        m_dvListCtrlFileMapping->GetValue(target, i, 1);
        mapping.insert(std::make_pair(source.GetString(), target.GetString()));
    }
    data.SetFileMapping(mapping);

    wxString fileExts = m_pgPropFileTypes->GetValue().GetString();
    fileExts.Replace(",", ";");
    pProject->SetImportFileSpec(fileExts);

    wxString excludeDirs = m_pgPropExcludeFolders->GetValue().GetString();
    excludeDirs.Replace(",", ";");
    pProject->SetExcludeFolders(excludeDirs);

    // Save the project content
    pProject->Save();
    SetDirty(false);
}
Beispiel #17
0
void PHPWorkspaceView::DoBuildProjectNode(const wxTreeItemId& projectItem, PHPProject::Ptr_t project)
{
    // Get the top level folders and add them
    const PHPFolder::Map_t& folders = project->GetFolders();
    PHPFolder::Map_t::const_iterator iter = folders.begin();
    for(; iter != folders.end(); ++iter) {
        DoAddFolder(projectItem, iter->second, project);
    }
}
Beispiel #18
0
void PHPWorkspaceView::OnRenameFile(wxCommandEvent& e)
{
    wxTreeItemId item = DoGetSingleSelection();
    CHECK_ITEM_RET(item);

    ItemData *data = DoGetItemData(item);
    CHECK_PTR_RET(data);
    CHECK_ID_FILE(data);

    wxFileName old_file_name = data->GetFile();
    wxString new_name = ::wxGetTextFromUser(_("New file name:"), _("Rename file"), old_file_name.GetFullName() );
    if ( new_name.IsEmpty() )
        return;

    if ( new_name == old_file_name.GetFullName() )
        return;

    // Check to see if we got a file with the old path opened
    bool reopenFile = false;
    IEditor *editor = m_mgr->FindEditor(old_file_name.GetFullPath());
    if ( editor ) {
        m_mgr->ClosePage( editor->GetFileName().GetFullName() );
        reopenFile = true;
        editor = NULL;
    }

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(DoGetSelectedProject());
    CHECK_PTR_RET(pProject);

    if ( pProject->RenameFile(old_file_name.GetFullPath(), new_name) ) {
        // Locate the folder
        pProject->Save();
        m_treeCtrlView->SetItemText(item, new_name);
        // Update the item data
        old_file_name.SetFullName(new_name);
        data->SetFile( old_file_name.GetFullPath() );
        
        // Open the file if it was opened earlier
        // old_file_name now contains the new full path to the new file
        if ( reopenFile ) {
            m_mgr->OpenFile( old_file_name.GetFullPath() );
        }
    }
}
Beispiel #19
0
void PHPWorkspaceView::OnMakeIndexPHP(wxCommandEvent& e)
{
    e.Skip();
    wxTreeItemId item = DoGetSingleSelection();
    CHECK_ITEM_RET(item);

    ItemData* itemData = DoGetItemData(item);
    CHECK_PTR_RET(itemData);
    CHECK_ID_FILE(itemData);

    wxString projectName = itemData->GetProjectName();
    if(projectName.IsEmpty()) return;
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(projectName);
    CHECK_PTR_RET(pProject);

    PHPProjectSettingsData& settings = pProject->GetSettings();
    settings.SetIndexFile(itemData->GetFile());
    pProject->Save();
}
Beispiel #20
0
void PHPWorkspaceView::OnAddFile(wxCommandEvent& e)
{
    wxTreeItemId folderItem = DoGetSingleSelection();
    CHECK_ITEM_RET(folderItem);

    ItemData* data = DoGetItemData(folderItem);
    CHECK_PTR_RET(data);

    if(!data->IsFolder()) return;

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(data->GetProjectName());
    CHECK_PTR_RET(pProject);

    PHPFolder::Ptr_t pFolder = pProject->Folder(data->GetFolderPath());
    CHECK_PTR_RET(pFolder);

    wxFileDialog dlg(wxTheApp->GetTopWindow(),
                     _("Add file"),
                     pFolder->GetFullPath(pProject->GetFilename().GetPath()),
                     wxT(""),
                     wxT("PHP Files (*.php)|*.php|PHP include files (*.inc)|*.inc|All files (*)|*"),
                     wxFD_FILE_MUST_EXIST | wxFD_OPEN | wxFD_MULTIPLE);
    if(dlg.ShowModal() == wxID_OK) {

        wxArrayString paths;
        dlg.GetPaths(paths);

        if(paths.IsEmpty()) return;

        // if the file is not under the project's tree - do not add it
        // Use the folder taken from the file's full path and the pFolder as the base folder for adding the file
        if(!paths.Item(0).StartsWith(pProject->GetFilename().GetPath())) {
            ::wxMessageBox(_("Can not add file to project. File must be under the project directory tree"),
                           "CodeLite",
                           wxOK | wxCENTER | wxICON_WARNING);
            return;
        }

        DoAddFilesToFolder(paths, pProject, true);
        pProject->Save();
    }
}
Beispiel #21
0
void PHPWorkspaceView::OnNewClass(wxCommandEvent& e)
{
    wxTreeItemId folderId = DoGetSingleSelection();
    ItemData* data = DoGetItemData(folderId);
    if(!data || !data->IsFolder()) {
        return;
    }

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(data->GetProjectName());
    CHECK_PTR_RET(pProject);

    PHPFolder::Ptr_t pFolder = pProject->Folder(data->GetFolderPath());
    CHECK_PTR_RET(pFolder);

    NewPHPClass dlg(wxTheApp->GetTopWindow(), pFolder->GetFullPath(pProject->GetFilename().GetPath(), false));
    if(dlg.ShowModal() == wxID_OK) {
        PHPClassDetails pcd = dlg.GetDetails();
        pFolder = pProject->AddFolder(PHPFolder::GetFolderPathFromFileFullPath(pcd.GetFilepath().GetFullPath(),
                                                                               pProject->GetFilename().GetPath()));
        CHECK_PTR_RET(pFolder);

        folderId = EnsureFolderExists(
            DoGetProjectItem(pProject->GetName()), pFolder->GetPathRelativeToProject(), pProject->GetName());
        DoAddFileWithContent(
            folderId, pcd.GetFilepath(), pcd.ToString(EditorConfigST::Get()->GetOptions()->GetEOLAsString(), "    "));
    }
}
Beispiel #22
0
void PHPWorkspaceView::OnDeleteFolder(wxCommandEvent& e)
{
    wxTreeItemId folderItem = DoGetSingleSelection();
    if(!IsFolderItem(folderItem)) return;

    ItemData* data = DoGetItemData(folderItem);
    wxString folder = data->GetFolderPath();
    wxString project = DoGetSelectedProject();
    if(folder.IsEmpty() || project.IsEmpty()) return;

    wxString msg = wxString() << _("Are you sure you want to delete folder '") << folder
                              << ("'?\nNote: selecting 'Yes' will NOT remove any file from the file system");
    if(wxMessageBox(msg, wxT("CodeLite"), wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTER) != wxYES) return;

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project);
    CHECK_PTR_RET(pProject);
    pProject->DeleteFolder(folder);
    pProject->Save();

    // Update the UI
    m_treeCtrlView->Delete(folderItem);
}
Beispiel #23
0
void PHPWorkspaceView::DoAddFilesToTreeView(const wxTreeItemId& folderId, PHPProject::Ptr_t pProject, PHPFolder::Ptr_t pFolder, const wxArrayString& files)
{
    for(size_t i=0; i<files.GetCount(); ++i) {
        ItemData *itemData = new ItemData(ItemData::Kind_File);
        itemData->SetFile( files.Item(i) );
        itemData->SetProjectName( pProject->GetName() );
        itemData->SetFolderPath( pFolder->GetPathRelativeToProject() );
        
        int imgId = DoGetItemImgIdx(files.Item(i));
        m_treeCtrlView->AppendItem(folderId, wxFileName(files.Item(i)).GetFullName(), imgId, imgId, itemData);
    }
    m_treeCtrlView->SortChildren( folderId );
}
Beispiel #24
0
void XDebugManager::DoApplyBreakpoints()
{
    CL_DEBUG("CodeLite >>> Applying breakpoints");
    CHECK_PTR_RET(m_readerThread);
    
    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetActiveProject();
    CHECK_PTR_RET(pProject);
    
    const PHPProjectSettingsData& settings = pProject->GetSettings();
    bool bRunAsWebserver = ( pProject->GetSettings().GetRunAs() == PHPProjectSettingsData::kRunAsWebsite);
    
    XDebugBreakpoint::List_t& breakpoints = m_breakpointsMgr.GetBreakpoints();
    XDebugBreakpoint::List_t::iterator iter = breakpoints.begin();
    for( ; iter != breakpoints.end(); ++iter ) {

        // apply only breakpoints without xdebug-id attached to them
        if ( iter->IsApplied() ) { 
            continue;
        }
    
        wxStringMap_t sftpMapping;
        SSHWorkspaceSettings sftpSettings;
        sftpSettings.Load();
        if ( !sftpSettings.GetRemoteFolder().IsEmpty() && sftpSettings.IsRemoteUploadEnabled() ) {
            sftpMapping.insert( std::make_pair(PHPWorkspace::Get()->GetFilename().GetPath(), sftpSettings.GetRemoteFolder()) );
        }
        
        wxString command;
        XDebugCommandHandler::Ptr_t handler( new XDebugBreakpointCmdHandler(this, ++TranscationId, *iter) );
        wxString filepath = bRunAsWebserver ? settings.GetMappdPath( iter->GetFileName(), true , sftpMapping) : iter->GetFileName();
        command << "breakpoint_set -i " 
                << handler->GetTransactionId() 
                << " -t line"
                << " -f " << filepath
                << " -n " << iter->GetLine();
        DoSocketWrite( command );
        AddHandler( handler );
    }
}
Beispiel #25
0
void PHPWorkspace::ParseWorkspace(bool full)
{
    // Request for parsing
    if(full) {
        // a full parsing is needed, stop the paser thread
        // close the database, delete it and recreate it
        // then, restart the parser thread
        PHPParserThread::Clear();
        PHPParserThread::Release(); // Stop and wait the thread terminates

        // Close the CC manager
        PHPCodeCompletion::Instance()->Close();

        // Delete the file
        wxFileName fnDatabaseFile(m_workspaceFile.GetPath(), "phpsymbols.db");
        fnDatabaseFile.AppendDir(".codelite");

        wxLogNull noLog;
        bool bRemoved = ::wxRemoveFile(fnDatabaseFile.GetFullPath());
        wxUnusedVar(bRemoved);

        // Start the managers again
        PHPParserThread::Instance()->Start();
        PHPCodeCompletion::Instance()->Open(m_workspaceFile);
    }

    PHPParserThreadRequest* req = new PHPParserThreadRequest(PHPParserThreadRequest::kParseWorkspaceFilesQuick);
    req->workspaceFile = GetFilename().GetFullPath();
    GetWorkspaceFiles(req->files);

    // Append the current project CC include paths
    PHPProject::Ptr_t pProject = GetActiveProject();
    if(pProject) {
        PHPProjectSettingsData& settings = pProject->GetSettings();
        req->frameworksPaths = settings.GetCCIncludePathAsArray();
    }
    PHPParserThread::Instance()->Add(req);
}
Beispiel #26
0
void PHPWorkspaceView::OnNewFile(wxCommandEvent& e)
{
    wxTreeItemId folderId = DoGetSingleSelection();
    ItemData *data = DoGetItemData( folderId );
    if( data->IsFolder() ) {
        PHPProject::Ptr_t pProj = PHPWorkspace::Get()->GetProject(data->GetProjectName());
        CHECK_PTR_RET(pProj);

        PHPFolder::Ptr_t pFolder = pProj->Folder(data->GetFolderPath());
        CHECK_PTR_RET(pFolder);

        NewFileDlg dlg(wxTheApp->GetTopWindow(), pFolder->GetFullPath( pProj->GetFilename().GetPath() ) );
        if(dlg.ShowModal() == wxID_OK) {
            wxFileName filename = dlg.GetPath();
            if( filename.FileExists() ) {
                // A file with this name already exists
                wxMessageBox(_("A file with same name already exists!"), wxT("CodeLite"), wxOK|wxCENTER|wxICON_WARNING);
                return;
            }
            DoAddFileWithContent(folderId, filename, "");
        }
    }
}
Beispiel #27
0
wxStringMap_t XDebugManager::GetFileMapping(PHPProject::Ptr_t pProject) const
{
    wxASSERT(pProject);
    wxStringMap_t mappings;
    const PHPProjectSettingsData& settings = pProject->GetSettings();
    mappings = settings.GetFileMapping();
    
    // Add the SFTP mappings
    SSHWorkspaceSettings sftpSettings;
    sftpSettings.Load();
    if ( !sftpSettings.GetRemoteFolder().IsEmpty() && sftpSettings.IsRemoteUploadEnabled() ) {
        mappings.insert( std::make_pair(PHPWorkspace::Get()->GetFilename().GetPath(), sftpSettings.GetRemoteFolder()) );
    }
    return mappings;
}
Beispiel #28
0
void PHPWorkspace::SetProjectActive(const wxString& project)
{
    PHPProject::Map_t::iterator iter = m_projects.begin();
    PHPProject::Ptr_t activeProject;
    for(; iter != m_projects.end(); ++iter) {
        if(iter->first == project) {
            activeProject = iter->second;
        }
        bool newState = (iter->first == project);
        if(iter->second->IsActive() != newState) {
            iter->second->SetIsActive(newState);
            // Save the change to the file system
            iter->second->Save();
        }
    }

    // notify about this change
    if(activeProject) {
        clProjectSettingsEvent evt(wxEVT_ACTIVE_PROJECT_CHANGED);
        evt.SetProjectName(project);
        evt.SetFileName(activeProject->GetFilename().GetFullPath());
        EventNotifier::Get()->AddPendingEvent(evt);
    }
}
Beispiel #29
0
void PHPWorkspaceView::DoAddFileWithContent(const wxTreeItemId& folderId,
                                            const wxFileName& filename,
                                            const wxString& content)
{
    // file can only be added to a folder
    ItemData* data = DoGetItemData(folderId);
    if(!data || !data->IsFolder()) {
        return;
    }

    if(filename.FileExists()) {
        // a file with this name already exists
        wxMessageBox(_("A file with same name already exists!"), wxT("CodeLite"), wxOK | wxCENTER | wxICON_WARNING);
        return;
    }

    FileExtManager::FileType type = FileExtManager::GetType(filename.GetFullName());

    // Create the file
    const wxString __EOL__ = EditorConfigST::Get()->GetOptions()->GetEOLAsString();

    // Make sure that the path exists
    filename.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);

    wxFFile fp;
    if(fp.Open(filename.GetFullPath(), wxT("w+"))) {

        // if its is a PHP file, write the php tag at to the top of the file
        if(type == FileExtManager::TypePhp) {
            fp.Write(wxString() << "<?php " << __EOL__ << __EOL__ << content);
        }
        fp.Close();
    }

    // add the new file
    wxString project_name = DoGetSelectedProject();
    wxString folder_name = data->GetFolderPath();

    PHPProject::Ptr_t pProject = PHPWorkspace::Get()->GetProject(project_name);
    CHECK_PTR_RET(pProject);

    PHPFolder::Ptr_t pFolder = pProject->Folder(folder_name);
    CHECK_PTR_RET(pFolder);

    if(PHPWorkspace::Get()->AddFile(project_name, folder_name, filename.GetFullPath())) {
        wxArrayString filesToAdd;
        filesToAdd.Add(filename.GetFullPath());
        DoAddFilesToTreeView(folderId, pProject, pFolder, filesToAdd);
    }

    // Open the newly added file
    m_mgr->OpenFile(filename.GetFullPath());

    IEditor* editor = m_mgr->GetActiveEditor();
    if(editor) {
        editor->SetCaretAt(editor->GetLength());
    }

    // Notify plugins about new files was added to workspace
    wxArrayString files;
    files.Add(filename.GetFullPath());

    // Notify the plugins
    clCommandEvent evtFilesAdded(wxEVT_PROJ_FILE_ADDED);
    evtFilesAdded.SetStrings(files);
    EventNotifier::Get()->AddPendingEvent(evtFilesAdded);
}