Пример #1
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(), "    "));
    }
}
Пример #2
0
void PHPWorkspaceView::DoDeleteSelectedFileItem()
{
    wxTreeItemId item = DoGetSingleSelection();
    CHECK_ITEM_RET(item);

    ItemData* itemData = DoGetItemData(item);
    if(!itemData || !itemData->IsFile()) return;

    wxString msg, caption;
    caption << _("Removing file '") << wxFileName(itemData->GetFile()).GetFullName() << "'";
    msg << _("Removing file '") << wxFileName(itemData->GetFile()).GetFullName() << "' from project '"
        << itemData->GetProjectName() << "'\n"
        << _("You can select to remove the file from the project and optionally from the file system\n")
        << _("From where should codelite remove the file?");

    wxMessageDialog dlg(EventNotifier::Get()->TopFrame(), msg, caption, wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT);
    dlg.SetYesNoCancelLabels("File system && project", "Project only", "Cancel");

    int answer = dlg.ShowModal();
    if(answer == wxID_YES || answer == wxID_NO) {
        wxString fileName = itemData->GetFile();
        // Remove from from project
        if(PHPWorkspace::Get()->DelFile(itemData->GetProjectName(), itemData->GetFolderPath(), fileName)) {
            m_treeCtrlView->Delete(item);

        } else {
            return;
        }
        if(answer == wxID_YES) {
            ::wxRemoveFile(fileName);
        }
    }
}
Пример #3
0
void PHPWorkspaceView::OnOpenFile(wxCommandEvent& e)
{
    wxTreeItemId item = DoGetSingleSelection();
    if(item.IsOk() == false)
        return;
    DoOpenFile(item);
}
Пример #4
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() );
        }
    }
}
Пример #5
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();
}
Пример #6
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();
    }
}
Пример #7
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);
}
Пример #8
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, "");
        }
    }
}