Пример #1
0
void SFTPTreeView::OnMenuNewFile(wxCommandEvent& event)
{
    wxArrayTreeItemIds items;
    m_treeCtrl->GetSelections(items);
    if(items.size() != 1) return;

    MyClientData* cd = GetItemData(items.Item(0));
    CHECK_PTR_RET(cd);

    if(!cd->IsFolder()) { return; }

    wxString defaultValue;
    static size_t s_untitledCounter = 0;
    defaultValue << "Untitled" << ++s_untitledCounter;

    wxString new_name = ::wxGetTextFromUser(_("Enter the new file name:"), _("New File"), defaultValue);
    if(!new_name.IsEmpty()) {
        wxString fullpath = cd->GetFullPath();
        fullpath << "/" << new_name;
        wxTreeItemId fileItem = DoAddFile(items.Item(0), fullpath);
        if(fileItem.IsOk()) { DoOpenFile(fileItem); }
    }
}
Пример #2
0
void wxCodeCompletionBox::DoShowCompletionBox()
{
    CHECK_PTR_RET(m_stc);

    // guesstimate a line height
    wxMemoryDC dc;
    wxBitmap bmp(1, 1);
    dc.SelectObject(bmp);
    wxFont font = m_stc->StyleGetFont(0);
    dc.SetFont(font);
    wxSize textSize = dc.GetTextExtent("Tp");

    int lineHeight = textSize.y + 3; // 3 pixels margins
    wxRect rect = GetRect();
    wxSize screenSize = ::wxGetDisplaySize();

    // determine the box x position
    int wordStart = m_startPos;
    wxPoint pt = m_stc->PointFromPosition(wordStart);
    pt = m_stc->ClientToScreen(pt);
    pt.y += lineHeight;

    // Check Y axis
    if((pt.y + rect.GetHeight()) > screenSize.GetHeight()) {
        // the completion box goes out of the Y axis, move it up
        pt.y -= lineHeight;
        pt.y -= rect.GetHeight();
    }

    // Check X axis
    if((pt.x + rect.GetWidth()) > screenSize.GetWidth()) {
        // the completion box goes out of the X axis. Move it to the left
        pt.x -= ((pt.x + rect.GetWidth()) - screenSize.GetWidth());
    }
    Move(pt);
    Show();
}
Пример #3
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);
}
Пример #4
0
void clTreeCtrlPanel::OnDeleteFolder(wxCommandEvent& event)
{
    wxTreeItemId item = GetTreeCtrl()->GetFocusedItem();
    clTreeCtrlData* cd = GetItemData(item);
    CHECK_PTR_RET(cd);
    CHECK_COND_RET(cd->IsFolder());

    wxString message;
    message << _("Are you sure you want to delete folder:\n'") << cd->GetPath() << _("'");

    wxRichMessageDialog dialog(EventNotifier::Get()->TopFrame(),
                               message,
                               _("Confirm"),
                               wxYES_NO | wxCANCEL | wxNO_DEFAULT | wxCENTER | wxICON_WARNING);
    dialog.SetYesNoLabels(_("Delete Folder"), _("Don't Delete"));
    if(dialog.ShowModal() == wxID_YES) {
        if(wxFileName::Rmdir(cd->GetPath(), wxPATH_RMDIR_RECURSIVE)) {
            // Remove this item from its parent cache
            UpdateItemDeleted(item);
            // Remove the item from the UI
            GetTreeCtrl()->Delete(item);
        }
    }
}
Пример #5
0
void PSGeneralPage::OnCustomEditorClicked(wxCommandEvent& event)
{
    wxPGProperty* prop = m_pgMgr136->GetSelectedProperty();
    CHECK_PTR_RET(prop);
    m_dlg->SetIsDirty(true);
    
    if ( prop == m_pgPropProgram ) {
        wxFileName curvalue = prop->GetValueAsString();
        wxString program = ::wxFileSelector(_("Choose a file"), curvalue.GetPath());
        if ( !program.IsEmpty() ) {
            program.Replace("\\", "/");
            prop->SetValue( program );
        }
        
    } else if ( prop == m_pgPropWorkingDirectory ) {
        wxString curpath = prop->GetValueAsString();
        wxFileName fp(curpath, "");
        wxString newPath = ::wxDirSelector(_("Choose a directory"), fp.GetPath());
        if ( !newPath.IsEmpty() ) {
            newPath.Replace("\\", "/");
            prop->SetValue( newPath );
        }
    }
}
Пример #6
0
void PHPCodeCompletion::OnInsertDoxyBlock(clCodeCompletionEvent& e)
{
    e.Skip();

    // Do we have a workspace open?
    CHECK_COND_RET(PHPWorkspace::Get()->IsOpen());

    // Sanity
    IEditor* editor = dynamic_cast<IEditor*>(e.GetEditor());
    CHECK_PTR_RET(editor);

    // Is this a PHP editor?
    CHECK_COND_RET(IsPHPFile(editor));

    // Get the text from the caret current position
    // until the end of file
    wxString unsavedBuffer = editor->GetTextRange(editor->GetCurrentPosition(), editor->GetLength());
    unsavedBuffer.Trim().Trim(false);
    PHPSourceFile source("<?php " + unsavedBuffer);
    source.SetParseFunctionBody(false);
    source.Parse();

    PHPEntityBase::Ptr_t ns = source.Namespace();
    if(ns) {
        const PHPEntityBase::List_t& children = ns->GetChildren();
        for(PHPEntityBase::List_t::const_iterator iter = children.begin(); iter != children.end(); ++iter) {
            PHPEntityBase::Ptr_t match = *iter;
            if(match->GetLine() == 0 && match->Is(kEntityTypeFunction)) {
                e.Skip(false); // notify codelite to stop processing this event
                wxString phpdoc = match->FormatPhpDoc();
                phpdoc.Trim();
                e.SetTooltip(phpdoc);
            }
        }
    }
}
Пример #7
0
void XDebugManager::DoHandleResponse(wxXmlNode* xml)
{
    CHECK_PTR_RET(xml);
    
    wxString txId = xml->GetAttribute("transaction_id");
    long nTxId (0);
    txId.ToCLong(&nTxId);
    XDebugCommandHandler::Ptr_t handler = PopHandler(nTxId);
    if ( handler ) {
        handler->Process(xml);
        
    } else {
        
        // Just log the reply
        wxXmlDocument doc;
        doc.SetRoot( xml );
        
        wxStringOutputStream sos;
        if ( doc.Save( sos ) ) {
            CL_DEBUG( sos.GetString() );
        }
        doc.DetachRoot();
    }
}
Пример #8
0
void ColoursAndFontsManager::SetTheme(const wxString& themeName)
{
    LexerConf::Ptr_t lexer = GetLexer("c++", themeName);
    CHECK_PTR_RET(lexer);

    bool isDark = lexer->IsDark();
    wxString fallbackTheme;
    if(isDark) {
        fallbackTheme = "Zmrok-like";
    } else {
        fallbackTheme = "Default";
    }

    const wxArrayString& lexers = GetAllLexersNames();
    for(size_t i = 0; i < lexers.size(); ++i) {
        wxArrayString themesForLexer = GetAvailableThemesForLexer(lexers.Item(i));
        if(themesForLexer.Index(themeName) == wxNOT_FOUND) {
            SetActiveTheme(lexers.Item(i), fallbackTheme);
        } else {
            SetActiveTheme(lexers.Item(i), themeName);
        }
    }
    SetGlobalTheme(themeName);
}
Пример #9
0
void WordCompletionPlugin::OnWordComplete(clCodeCompletionEvent& event)
{
    event.Skip(); // Always skip this

    IEditor* activeEditor = dynamic_cast<IEditor*>(event.GetEditor());
    CHECK_PTR_RET(activeEditor);

    WordCompletionSettings settings;
    settings.Load();

    // Enabled?
    if(!settings.IsEnabled()) {
        return;
    }

    // Build the suggetsion list
    static wxBitmap sBmp = wxNullBitmap;
    if(!sBmp.IsOk()) {
        sBmp = m_mgr->GetStdIcons()->LoadBitmap("word");
    }

    // Filter (what the user has typed so far)
    // wxStyledTextCtrl* stc = activeEditor->GetCtrl();
    // int curPos = stc->GetCurrentPos();
    // int start = stc->WordStartPosition(stc->GetCurrentPos(), true);
    // if(curPos < start) return;

    wxString filter = event.GetWord().Lower(); // stc->GetTextRange(start, curPos);

    wxStringSet_t words = m_dictionary->GetWords();
    // Parse the current bufer (if modified), to include non saved words
    if(activeEditor->IsModified()) {
        // For performance (this parsing is done in the main thread)
        // only parse the visible area of the document
        wxStringSet_t unsavedBufferWords;
        wxStyledTextCtrl* stc = activeEditor->GetCtrl();
        int startPos = stc->PositionFromLine(stc->GetFirstVisibleLine());
        int endPos = stc->GetCurrentPos();

        wxString buffer = stc->GetTextRange(startPos, endPos);
        WordCompletionThread::ParseBuffer(buffer, unsavedBufferWords);

        // Merge the results
        words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end());
    }

    // Get the editor keywords and add them
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName());
    if(lexer) {
        wxString keywords;
        for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) {
            keywords << lexer->GetKeyWords(i) << " ";
        }
        wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK);
        words.insert(langWords.begin(), langWords.end());
    }

    wxStringSet_t filterdSet;
    if(filter.IsEmpty()) {
        filterdSet.swap(words);
    } else {
        for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) {
            wxString word = *iter;
            wxString lcWord = word.Lower();
            if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) {
                if(lcWord.StartsWith(filter) && filter != word) {
                    filterdSet.insert(word);
                }
            } else {
                if(lcWord.Contains(filter) && filter != word) {
                    filterdSet.insert(word);
                }
            }
        }
    }
    wxCodeCompletionBoxEntry::Vec_t entries;
    for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) {
        entries.push_back(wxCodeCompletionBoxEntry::New(*iter, sBmp));
    }
    event.GetEntries().insert(event.GetEntries().end(), entries.begin(), entries.end());
}
Пример #10
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);
}
Пример #11
0
void WordCompletionPlugin::OnWordComplete(wxCommandEvent& event)
{
    event.Skip();
    IEditor* activeEditor = m_mgr->GetActiveEditor();
    CHECK_PTR_RET(activeEditor);

    WordCompletionSettings settings;
    settings.Load();

    // Enabled?
    if(!settings.IsEnabled()) return;

    // Build the suggetsion list
    wxString suggestString;
    wxCodeCompletionBoxEntry::Vec_t entries;
    wxCodeCompletionBox::BmpVec_t bitmaps;
    bitmaps.push_back(m_images.Bitmap("m_bmpWord"));

    // Filter (what the user has typed so far)
    wxStyledTextCtrl* stc = activeEditor->GetCtrl();
    int curPos = stc->GetCurrentPos();
    int start = stc->WordStartPosition(stc->GetCurrentPos(), true);
    if(curPos < start) return;

    wxString filter = stc->GetTextRange(start, curPos);
    wxString lcFilter = filter.Lower();

    wxStringSet_t words = m_dictionary->GetWords();
    // Parse the current bufer (if modified), to include non saved words
    if(activeEditor->IsModified()) {
        wxStringSet_t unsavedBufferWords;
        WordCompletionThread::ParseBuffer(stc->GetText(), unsavedBufferWords);

        // Merge the results
        words.insert(unsavedBufferWords.begin(), unsavedBufferWords.end());
    }

    // Get the editor keywords and add them
    LexerConf::Ptr_t lexer = ColoursAndFontsManager::Get().GetLexerForFile(activeEditor->GetFileName().GetFullName());
    if(lexer) {
        wxString keywords;
        for(size_t i = 0; i < wxSTC_KEYWORDSET_MAX; ++i) {
            keywords << lexer->GetKeyWords(i) << " ";
        }
        wxArrayString langWords = ::wxStringTokenize(keywords, "\n\t \r", wxTOKEN_STRTOK);
        words.insert(langWords.begin(), langWords.end());
    }

    wxStringSet_t filterdSet;
    if(lcFilter.IsEmpty()) {
        filterdSet.swap(words);
    } else {
        for(wxStringSet_t::iterator iter = words.begin(); iter != words.end(); ++iter) {
            wxString word = *iter;
            wxString lcWord = word.Lower();
            if(settings.GetComparisonMethod() == WordCompletionSettings::kComparisonStartsWith) {
                if(lcWord.StartsWith(lcFilter) && filter != word) {
                    filterdSet.insert(word);
                }
            } else {
                if(lcWord.Contains(lcFilter) && filter != word) {
                    filterdSet.insert(word);
                }
            }
        }
    }
    for(wxStringSet_t::iterator iter = filterdSet.begin(); iter != filterdSet.end(); ++iter) {
        entries.push_back(wxCodeCompletionBoxEntry::New(*iter, 0));
    }

    wxCodeCompletionBoxManager::Get().ShowCompletionBox(activeEditor->GetCtrl(),
                                                        entries,
                                                        bitmaps,
                                                        event.GetId() == XRCID("text_word_complete") ?
                                                            wxCodeCompletionBox::kInsertSingleMatch :
                                                            wxCodeCompletionBox::kNone,
                                                        wxNOT_FOUND);
}
Пример #12
0
void XDebugManager::DoSocketWrite(const wxString &command )
{
    CHECK_PTR_RET(m_readerThread);
    m_readerThread->SendMsg( command );
}
Пример #13
0
void SyntaxHighlightDlg::OnOutputViewColourChanged(wxColourPickerEvent& event)
{
    CHECK_PTR_RET(m_lexer);
    event.Skip();
    m_isModified = true;
}
Пример #14
0
void CodeFormatter::OnFormatString(clSourceFormatEvent& e)
{
    wxString str = e.GetInputString();
    if(str.IsEmpty()) {
        e.SetFormattedString(str);
        return;
    }

    // execute the formatter
    FormatOptions fmtroptions;
    m_mgr->GetConfigTool()->ReadObject(wxT("FormatterOptions"), &fmtroptions);

    wxString output;
    if(FileExtManager::IsPHPFile(e.GetFileName())) {

        if(fmtroptions.GetPhpEngine() == kPhpFormatEngineBuiltin) {
            // use the built-in PHP formatter
            // Construct the formatting options
            PHPFormatterOptions phpOptions;
            phpOptions.flags = fmtroptions.GetPHPFormatterOptions();
            if(m_mgr->GetEditorSettings()->GetIndentUsesTabs()) {
                phpOptions.flags |= kPFF_UseTabs;
            }
            phpOptions.indentSize = m_mgr->GetEditorSettings()->GetTabWidth();
            phpOptions.eol = m_mgr->GetEditorSettings()->GetEOLAsString();
            // Create the formatter buffer
            PHPFormatterBuffer buffer(e.GetInputString(), phpOptions);

            // Format the source
            buffer.format();

            // set the output
            output = buffer.GetBuffer();
        } else {
            wxFileName php(fmtroptions.GetPhpExecutable());
            if(!php.Exists()) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHP executable path"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }
            wxFileName phar(fmtroptions.GetPHPCSFixerPhar());
            if(!phar.Exists()) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHAR file"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }

            // Run the command, PHP-CS-Fixer works directly on the file
            //
            output.Clear();
            IProcess::Ptr_t phpFixer(::CreateSyncProcess(fmtroptions.GetPhpFixerCommand(),
                                                         IProcessCreateDefault | IProcessCreateWithHiddenConsole));
            CHECK_PTR_RET(phpFixer);
            phpFixer->WaitForTerminate(output);
        }
    } else if(fmtroptions.GetEngine() == kFormatEngineAStyle) {
        wxString options = fmtroptions.AstyleOptionsAsString();

        // determine indentation method and amount
        bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs();
        int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth();
        int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth();
        options << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth;

        AstyleFormat(str, options, output);
        output << DoGetGlobalEOLString();

    } else if(fmtroptions.GetEngine() == kFormatEngineClangFormat) {
        ClangPreviewFormat(str, output, fmtroptions);

    } else {
        // ??
    }
    e.SetFormattedString(output);
}
Пример #15
0
void CodeFormatter::DoFormatFile(IEditor* editor)
{
    int curpos = editor->GetCurrentPosition();

    // execute the formatter
    FormatOptions fmtroptions;
    m_mgr->GetConfigTool()->ReadObject(wxT("FormatterOptions"), &fmtroptions);
    if(FileExtManager::IsPHPFile(editor->GetFileName())) {

        if(fmtroptions.GetPhpEngine() == kPhpFormatEngineBuiltin) {

            // use the built-in PHP formatter

            // Construct the formatting options
            PHPFormatterOptions phpOptions;
            phpOptions.flags = fmtroptions.GetPHPFormatterOptions();
            if(m_mgr->GetEditorSettings()->GetIndentUsesTabs()) {
                phpOptions.flags |= kPFF_UseTabs;
            }
            phpOptions.indentSize = m_mgr->GetEditorSettings()->GetTabWidth();
            phpOptions.eol = m_mgr->GetEditorSettings()->GetEOLAsString();
            // Create the formatter buffer
            PHPFormatterBuffer buffer(editor->GetCtrl()->GetText(), phpOptions);

            // Format the source
            buffer.format();

            // Restore line
            if(!buffer.GetBuffer().IsEmpty()) {
                clSTCLineKeeper lk(editor);
                editor->GetCtrl()->BeginUndoAction();
                // Replace the text with the new formatted buffer
                editor->SetEditorText(buffer.GetBuffer());
                editor->GetCtrl()->EndUndoAction();
            }
        } else {
            wxFileName php(fmtroptions.GetPhpExecutable());
            if(!php.Exists()) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHP executable path"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }
            wxFileName phar(fmtroptions.GetPHPCSFixerPhar());
            if(!phar.Exists()) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer: Missing PHAR file"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }

            // Run the command, PHP-CS-Fixer works directly on the file
            // so create a copy of the file and format it, then replace the buffers
            // we do this like this so we won't lose our ability to undo the action
            wxString output;
            wxString command, filename, tmpfile;
            filename = editor->GetFileName().GetFullPath();
            tmpfile << filename << ".php-cs-fixer";
            if(!FileUtils::WriteFileContent(tmpfile, editor->GetEditorText())) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer:\nFailed to write temporary file"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }

            // Ensure that the temporary file is deleted once we are done with it
            FileUtils::Deleter fd(tmpfile);

            ::WrapWithQuotes(tmpfile);
            command << fmtroptions.GetPhpFixerCommand() << " " << tmpfile;
            ::WrapInShell(command);
            IProcess::Ptr_t phpFixer(
                ::CreateSyncProcess(command, IProcessCreateDefault | IProcessCreateWithHiddenConsole));
            CHECK_PTR_RET(phpFixer);
            phpFixer->WaitForTerminate(output);

            output.clear();
            if(!FileUtils::ReadFileContent(tmpfile, output)) {
                ::wxMessageBox(_("Can not format file using PHP-CS-Fixer:\nfailed to read temporary file content"),
                               "Code Formatter",
                               wxICON_ERROR | wxOK | wxCENTER);
                return;
            }

            // Update the editor
            clEditorStateLocker lk(editor->GetCtrl());
            editor->GetCtrl()->BeginUndoAction();
            editor->SetEditorText(output);
            editor->GetCtrl()->EndUndoAction();
        }

    } else {
        // We allow ClangFormat to work only when the source file is known to be
        // a C/C++ source file or JavaScript (these are the types of files that clang-format can handle properly)
        if(fmtroptions.GetEngine() == kFormatEngineClangFormat &&
           (FileExtManager::IsCxxFile(editor->GetFileName()) ||
            FileExtManager::IsJavascriptFile(editor->GetFileName()))) {

            int from = wxNOT_FOUND, length = wxNOT_FOUND;
            wxString formattedOutput;
            if(editor->GetSelectionStart() != wxNOT_FOUND) {
                // we got a selection, only format it
                from = editor->GetSelectionStart();
                length = editor->GetSelectionEnd() - from;
                if(length <= 0) {
                    from = wxNOT_FOUND;
                    length = wxNOT_FOUND;
                }
            }

            // Make sure we format the editor string and _not_ the file (there might be some newly added lines
            // that could be missing ...)
            if(!ClangFormatBuffer(
                   editor->GetCtrl()->GetText(), editor->GetFileName(), formattedOutput, curpos, from, length)) {
                ::wxMessageBox(_("Source code formatting error!"), "CodeLite", wxICON_ERROR | wxOK | wxCENTER);
                return;
            }

            clEditorStateLocker lk(editor->GetCtrl());
            editor->GetCtrl()->BeginUndoAction();
            editor->SetEditorText(formattedOutput);
            editor->SetCaretAt(curpos);
            editor->GetCtrl()->EndUndoAction();

        } else {
            // AStyle
            wxString options = fmtroptions.AstyleOptionsAsString();

            // determine indentation method and amount
            bool useTabs = m_mgr->GetEditorSettings()->GetIndentUsesTabs();
            int tabWidth = m_mgr->GetEditorSettings()->GetTabWidth();
            int indentWidth = m_mgr->GetEditorSettings()->GetIndentWidth();
            options << (useTabs && tabWidth == indentWidth ? wxT(" -t") : wxT(" -s")) << indentWidth;

            wxString output;
            wxString inputString;
            bool formatSelectionOnly(editor->GetSelection().IsEmpty() == false);

            if(formatSelectionOnly) {
                // get the lines contained in the selection
                int selStart = editor->GetSelectionStart();
                int selEnd = editor->GetSelectionEnd();
                int lineNumber = editor->LineFromPos(selStart);

                selStart = editor->PosFromLine(lineNumber);
                selEnd = editor->LineEnd(editor->LineFromPos(selEnd));

                editor->SelectText(selStart, selEnd - selStart);
                inputString = editor->GetSelection();

            } else {
                inputString = editor->GetEditorText();
            }

            AstyleFormat(inputString, options, output);
            if(!output.IsEmpty()) {

                // append new-line
                wxString eol;
                if(editor->GetEOL() == 0) { // CRLF
                    eol = wxT("\r\n");
                } else if(editor->GetEOL() == 1) { // CR
                    eol = wxT("\r");
                } else {
                    eol = wxT("\n");
                }

                if(!formatSelectionOnly) output << eol;

                if(formatSelectionOnly) {
                    clEditorStateLocker lk(editor->GetCtrl());
                    // format the text (add the indentation)
                    output = editor->FormatTextKeepIndent(output,
                                                          editor->GetSelectionStart(),
                                                          Format_Text_Indent_Prev_Line | Format_Text_Save_Empty_Lines);
                    editor->ReplaceSelection(output);

                } else {
                    clEditorStateLocker lk(editor->GetCtrl());
                    editor->SetEditorText(output);
                }
            }
        }
    }
    // Notify that a file was indented
    wxCommandEvent evt(wxEVT_CODEFORMATTER_INDENT_COMPLETED);
    evt.SetString(editor->GetFileName().GetFullPath());
    EventNotifier::Get()->AddPendingEvent(evt);
}
void PHPEditorContextMenu::DoGotoDefinition()
{
    CHECK_PTR_RET(m_manager->GetActiveEditor());
    PHPCodeCompletion::Instance()->GotoDefinition(m_manager->GetActiveEditor(),
                                                  m_manager->GetActiveEditor()->GetCtrl()->GetCurrentPos());
}
Пример #17
0
void SyntaxHighlightDlg::CreateLexerPage()
{
    CHECK_PTR_RET(m_lexer);

    const StyleProperty::List_t& m_propertyList = m_lexer->GetLexerProperties();
    std::list<StyleProperty>::const_iterator it = m_propertyList.begin();
    StyleProperty selTextProperties;

    for(; it != m_propertyList.end(); it++) {
        if(it->GetId() != SEL_TEXT_ATTR_ID) {
            m_properties->Append((*it).GetName());
        } else {
            selTextProperties = *it;
        }
    }

    if(m_properties->GetCount()) m_properties->SetSelection(0);

    wxString initialColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT).GetAsString();
    wxString bgInitialColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).GetAsString();
    wxFont initialFont = wxNullFont;
    // bool     initialEolFilled (false);
    bool initialStyleWithinPreProcessor(true);

    if(m_propertyList.empty() == false) {
        StyleProperty p;
        p = (*m_propertyList.begin());
        initialColor = p.GetFgColour();
        bgInitialColor = p.GetBgColour();

        int size = p.GetFontSize();
        wxString face = p.GetFaceName();
        bool bold = p.IsBold();
        initialFont = wxFont(size,
                             wxFONTFAMILY_TELETYPE,
                             wxFONTSTYLE_NORMAL,
                             bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL,
                             false,
                             face);
    }
    initialStyleWithinPreProcessor = m_lexer->GetStyleWithinPreProcessor();

    m_fontPicker->SetSelectedFont(initialFont);
    m_colourPicker->SetColour(wxColour(initialColor));
    m_bgColourPicker->SetColour(wxColour(bgInitialColor));
    m_globalFontPicker->SetSelectedFont(initialFont);
    m_globalBgColourPicker->SetColour(wxColour(bgInitialColor));
    m_fileSpec->ChangeValue(m_lexer->GetFileSpec());
    m_styleWithinPreProcessor->SetValue(initialStyleWithinPreProcessor);

    // Update selected text properties
    m_colourPickerSelTextBgColour->SetColour(selTextProperties.GetBgColour());
    m_colourPickerSelTextFgColour->SetColour(selTextProperties.GetFgColour());
    m_checkBoxCustomSelectionFgColour->SetValue(m_lexer->IsUseCustomTextSelectionFgColour());

    if(m_propertyList.empty()) {
        m_fontPicker->Enable(false);
        m_colourPicker->Enable(false);
    }

    // Fill the themes for this lexer
    m_choiceLexerThemes->Clear();
    wxArrayString themes = ColoursAndFontsManager::Get().GetAvailableThemesForLexer(m_lexer->GetName());
    int sel = themes.Index(m_lexer->GetThemeName());
    if(sel == -1) {
        sel = 0;
    }
    m_choiceLexerThemes->Append(themes);
    if(!m_choiceLexerThemes->IsEmpty()) {
        m_choiceLexerThemes->SetSelection(sel);
    }
}
Пример #18
0
void SyntaxHighlightDlg::OnStyleWithinPreprocessor(wxCommandEvent& event)
{
    CHECK_PTR_RET(m_lexer);
    m_isModified = true;
    m_lexer->SetStyleWithinPreProcessor(event.IsChecked());
}
Пример #19
0
void ColoursAndFontsManager::AddLexer(LexerConf::Ptr_t lexer)
{
    CHECK_PTR_RET(lexer);
    DoAddLexer(lexer->ToJSON());
}
Пример #20
0
void XDebugManager::DoContinue()
{
    CHECK_PTR_RET(m_readerThread);
    SendRunCommand();
}