예제 #1
0
void cbDebuggerPlugin::OnEditorHook(cb_unused cbEditor* editor, wxScintillaEvent& event)
{
    if (event.GetEventType() == wxEVT_SCI_START_DRAG)
        m_DragInProgress = true;
    else if (event.GetEventType() == wxEVT_SCI_FINISHED_DRAG)
        m_DragInProgress = false;
}
void SmartIndentPascal::OnEditorHook(cbEditor* ed, wxScintillaEvent& event) const
{
    if (!ed) return;

    // check the event type and the currently set language
    // if it is not a CharAdded event or the language is not Pascal return
    wxEventType type = event.GetEventType();
    if ( type != wxEVT_SCI_CHARADDED ) return;

    cbStyledTextCtrl* stc = ed->GetControl();
    if ( !stc ) return;

    // check if smart indent is enabled
    const bool smartIndent = Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/smart_indent"), true);
    if ( !smartIndent ) return;

    wxString langname = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ed->GetLanguage());
    if ( langname != wxT("Pascal") ) return;

    ed->AutoIndentDone(); // we are responsible.

    wxChar ch = event.GetKey();
    if ( (ch == wxT('\n')) || ( (stc->GetEOLMode() == wxSCI_EOL_CR) && (ch == wxT('\r')) ) )
        DoIndent(ed, langname);   // indent because \n added
    else if ( ch != wxT(' ') )
        DoUnIndent(ed, langname); // un-indent because not a newline added

    bool braceCompleted = false;
    if ( SelectionBraceCompletionEnabled() || stc->IsBraceShortcutActive() )
        braceCompleted = stc->DoSelectionBraceCompletion(ch);
    if (!braceCompleted && BraceCompletionEnabled())
        stc->DoBraceCompletion(ch);
}
예제 #3
0
	/// Indent if newline was added.
	void OnCharAdded(wxScintillaEvent &event) {
		// Change this if support for mac files with \r is needed
		if (event.GetKey() == '\n' || event.GetKey() == '\r') {
			int currentLine = GetCurrentLine();
			if (currentLine <= 0) {
				return;
			}

			// width of one indent character
			int indentWidth = (GetUseTabs() ? GetTabWidth() : 1);
			if (indentWidth == 0) {
				return;
			}

			// indent as prev line level
			int indentSize = GetLineIndentation(currentLine - 1);
			SetLineIndentation(currentLine, indentSize);

			// position = (line start pos) + (tabs count) + (space count)
			GotoPos(PositionFromLine(currentLine)
				+ (indentSize / indentWidth)
				+ (indentSize % indentWidth));

			// notify that the text was changed
			ChangeModified(true);
		}
	}
예제 #4
0
void ClangPlugin::OnEditorHook(cbEditor* ed, wxScintillaEvent& event)
{
    event.Skip();

    if (!IsProviderFor(ed))
        return;
    cbStyledTextCtrl* stc = ed->GetControl();
    if (event.GetEventType() == wxEVT_SCI_MODIFIED)
    {
        if (event.GetModificationType() & (wxSCI_MOD_INSERTTEXT | wxSCI_MOD_DELETETEXT))
        {
            const int pos = stc->GetCurrentPos();
            const int line = stc->LineFromPosition(pos);
            if ( (m_LastModifyLine != -1)&&(line != m_LastModifyLine) )
            {
                RequestReparse();
            }
            m_LastModifyLine = line;
        }
    }
    else if (event.GetEventType() == wxEVT_SCI_CHANGE)
    {
        //fprintf(stdout,"wxEVT_SCI_CHANGE\n");
    }
}
예제 #5
0
void CCTestFrame::OnMarginClick(wxScintillaEvent& event)
{
    if (event.GetMargin()==C_FOLDING_MARGIN)
    {
        int lineYpix = event.GetPosition();
        int line     = m_Control->LineFromPosition(lineYpix);

        m_Control->ToggleFold(line);
    }
}
예제 #6
0
void CodeEditor::OnMarginClick(wxScintillaEvent &event)
{
	if (event.GetMargin() == 1)
	{
		int lineClick = LineFromPosition(event.GetPosition());
		int levelClick = GetFoldLevel(lineClick);
		if ((levelClick & wxSCI_FOLDLEVELHEADERFLAG) > 0)
		{
			ToggleFold (lineClick);
		}
	}
}
예제 #7
0
void ClangPlugin::OnEditorHook(cbEditor* ed, wxScintillaEvent& event)
{
    event.Skip();
    if (!IsProviderFor(ed))
        return;
    if (event.GetEventType() == wxEVT_SCI_MODIFIED)
    {
        if (event.GetModificationType() & (wxSCI_MOD_INSERTTEXT | wxSCI_MOD_DELETETEXT))
        {
            m_ReparseTimer.Start(REPARSE_DELAY, wxTIMER_ONE_SHOT);
            m_DiagnosticTimer.Start(DIAGNOSTIC_DELAY, wxTIMER_ONE_SHOT);
        }
    }
}
예제 #8
0
	void OnHotSpotClick(wxScintillaEvent &event) {
		AutoCompCancel();
		CallTipCancel();

		wxPoint clientPos = PointFromPosition(event.GetPosition());
		wxPoint screenPos = ClientToScreen(clientPos);
		int lineHeight = TextHeight(LineFromPosition(event.GetPosition()));

		CloseWatch();
		m_watch = new OneVariableWatchView(
			this, event.GetText(),
			wxPoint(screenPos.x - 50, screenPos.y + lineHeight), 
			wxSize(100, 400));
		m_watch->Show();
	}
void MaterialScriptEditor::OnCharAdded(wxScintillaEvent &event)
{
    ScintillaEditor::OnCharAdded(event);

    char ch = event.GetKey();
    if(getCallTipManager().isTrigger(ch))
    {
        int lineNum = GetCurrentLine();
        if(lineNum != -1)
        {
            wxString line = GetLine(lineNum);
            int pos = GetCurrentPos() - 1;

            wxString word("");
            wxChar ch;
            while(pos)
            {
                ch = GetCharAt(--pos);
                if(ch != ' ' && ch != '\n' && ch != '\r' && ch != '\t' && ch != '{' && ch != '}') word.Prepend(ch);
                else break;
            }

            wxString* tips = getCallTipManager().find(word);
            if(tips != NULL)
            {
                CallTipShow(pos, *tips);
            }
        }
    }
}
예제 #10
0
void OutputPane::OnMouseDClick(wxScintillaEvent &event)
{
	long pos = event.GetPosition();
	int fifWinIndex = CaptionToIndex(OutputPane::FIND_IN_FILES_WIN);
	int buildWinIndex = CaptionToIndex(OutputPane::BUILD_WIN);

	wxScintilla *win = dynamic_cast<wxScintilla*>(m_book->GetPage(m_book->GetSelection()));
	if( !win ){
		return;
	}

	int line = win->LineFromPosition(pos);
	wxString lineText = win->GetLine(line);

	//remove selection
	win->SetSelectionStart(pos);
	win->SetSelectionEnd(pos);
	if( fifWinIndex == m_book->GetSelection() )
	{
		//Find in files
		OnFindInFilesDClick(lineText);
	}
	else if(buildWinIndex == m_book->GetSelection())
	{
		//build window
		lineText.Replace(wxT("\\"), wxT("/"));
		OnBuildWindowDClick(lineText, line);
	}
}
예제 #11
0
void VObjEvtHandler::OnMarginClick ( wxScintillaEvent& event )
{
	wxScintilla* scintilla = wxDynamicCast( m_window, wxScintilla );
	if ( scintilla != NULL )
	{
		if ( event.GetMargin() == 1 )
		{
			int lineClick = scintilla->LineFromPosition( event.GetPosition() );
			int levelClick = scintilla->GetFoldLevel( lineClick );
			if ( ( levelClick & wxSCI_FOLDLEVELHEADERFLAG ) > 0 )
			{
				scintilla->ToggleFold( lineClick );
			}
		}
	}
	event.Skip();
}
예제 #12
0
void ScintillaEditor::OnCharAdded(wxScintillaEvent &event)
{
    char ch = event.GetKey();
    int currentLine = GetCurrentLine();
    int pos = GetCurrentPos();

    if (ch == wxT('\n') && currentLine > 0)
    {
        BeginUndoAction();

        wxString indent = getLineIndentString(currentLine - 1);

        wxChar b = getLastNonWhitespaceChar();
        if(b == wxT('{'))
        {
            if(GetUseTabs())
                indent << wxT("\t");
            else
                indent << wxT("    ");
        }

        InsertText(pos, indent);
        GotoPos((int)(pos + indent.Length()));
        ChooseCaretX();

        EndUndoAction();
    }
    else if(ch == wxT('}'))
    {
        BeginUndoAction();

        wxString line = GetLine(currentLine);
        line.Trim(false);
        line.Trim(true);
        if(line.Matches(wxT("}")))
        {
            pos = GetCurrentPos() - 2;
            pos = findBlockStart(pos, wxT('{'), wxT('}'));

            if(pos != -1)
            {
                wxString indent = getLineIndentString(LineFromPosition(pos));
                indent << wxT('}');
                DelLineLeft();
                DelLineRight();
                pos = GetCurrentPos();
                InsertText(pos, indent);
                GotoPos((int)(pos + indent.Length()));
                ChooseCaretX();
            }
        }

        EndUndoAction();
    }

    setDirty(true);
}
예제 #13
0
void PythonCodeCtrl::OnCharAdded(wxScintillaEvent& ke)
{
    //User has pressed enter
    //if the cursor is at the end of a completed statement, submit the statement to the interpreter
    //otherwise, do auto-indentation
    if (ke.GetKey() == _T('\n'))
    {
        //int pos = GetCurrentPos();
        int line = LineFromPosition(GetCurrentPos());

        if(line>0)
        {
            wxString prevlinetext = GetLine(line-1).Trim();
            int indentation = GetLineIndentation(line-1);

            if((indentation==0) //submit a return pressed on an unindented line
                || (indentation>0 && prevlinetext==wxEmptyString)) // or an indented block where the previous line was empty
            {
                long rs,re;
                GetSelection(&rs,&re);
                //if(rs==re && GetLastPosition()==rs)
                if(rs==re && GetLength()==rs) // only submit if the cursor is at the end of the control (and there is no selection)
                {
                    m_pyctrl->DispatchCode(GetValue());
                    ke.Skip();
                }
            }

            // Otherwise indent the code if necessary
            if (GetLine(line-1).Trim().EndsWith(_T(":")))
            {
                if(GetStyleAt(GetLineEndPosition(line-1)-1) == wxSCI_P_OPERATOR)
                    indentation+=GetIndent();
            }
            if (indentation>0)
            {
                SetLineIndentation(line,indentation);
                SetCurrentPos(PositionFromLine(line)+indentation);
                SetAnchor(PositionFromLine(line)+indentation);
            }
        }
    }
    ke.Skip();
}
void SmartIndentCpp::OnEditorHook(cbEditor* ed, wxScintillaEvent& event) const
{

    // check if smart indent is enabled
    // check the event type and the currently set language
    // if it is not a CharAdded event or the language is not C/C++, D, or Java return

    if (!ed)
        return;

    if ( !SmartIndentEnabled() )
        return;

    wxEventType type = event.GetEventType();
    if ( type != wxEVT_SCI_CHARADDED )
        return;

    cbStyledTextCtrl* stc = ed->GetControl();
    if (!stc)
        return;

    wxString langname = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ed->GetLanguage());
    if ( langname != wxT("D") && (stc->GetLexer() != wxSCI_LEX_CPP || langname == wxT("Hitachi asm"))) return;

    ed->AutoIndentDone(); // we are responsible.

    const int pos = stc->GetCurrentPos();
    int currLine = stc->LineFromPosition(pos);

    if (currLine == 0)
        return;

    const wxChar ch = event.GetKey();

    if ( SelectionBraceCompletionEnabled() || stc->IsBraceShortcutActive() )
        DoSelectionBraceCompletion(stc, ch);

    DoSmartIndent(ed, ch);

    if ( BraceCompletionEnabled() )
        DoBraceCompletion(stc, ch);
}
예제 #15
0
void ClangCodeCompletion::OnEditorHook(cbEditor* ed, wxScintillaEvent& event)
{
    event.Skip();
    bool clearIndicator = false;
    bool reparse = false;
    //if (!m_pClangPlugin->IsProviderFor(ed))
    //    return;
    cbStyledTextCtrl* stc = ed->GetControl();
    if (event.GetEventType() == wxEVT_SCI_MODIFIED)
    {
        m_ReparseTimer.Stop();
        if (event.GetModificationType() & (wxSCI_MOD_INSERTTEXT | wxSCI_MOD_DELETETEXT))
        {
            reparse = true;
            clearIndicator = true;
        }
    }
    else if (event.GetEventType() == wxEVT_SCI_UPDATEUI)
    {
        //fprintf(stdout,"wxEVT_SCI_UPDATEUI\n");
        if (event.GetUpdated() & wxSCI_UPDATE_SELECTION)
        {
            m_HightlightTimer.Stop();
            m_HightlightTimer.Start(HIGHTLIGHT_DELAY, wxTIMER_ONE_SHOT);
        }
        clearIndicator = true;
    }
    else if (event.GetEventType() == wxEVT_SCI_CHANGE)
    {
        //fprintf(stdout,"wxEVT_SCI_CHANGE\n");
    }
    if (clearIndicator)
    {
        const int theIndicator = 16;
        stc->SetIndicatorCurrent(theIndicator);
        stc->IndicatorClearRange(0, stc->GetLength());
    }
    if (reparse)
    {
        RequestReparse();
    }
}
예제 #16
0
void Highlighter::Call(cbEditor* ctrl, wxScintillaEvent &event) const
{
    // return if this event is not fired from the active editor (is it possible that an editor which is not active fires an event?)
    if ( Manager::Get()->GetEditorManager()->GetActiveEditor() != ctrl  ) return;

    // check the event type if it is an update event
    if ( event.GetEventType() == wxEVT_SCI_UPDATEUI ||
         event.GetEventType() == wxEVT_SCI_PAINTED )
    {
        HighlightOccurrencesOfSelection(ctrl);
        OnEditorUpdateUI(ctrl);
    }
    else if ( event.GetEventType() == wxEVT_SCI_MODIFIED)
    {
        if(event.GetModificationType() & wxSCI_MOD_INSERTTEXT)
        {
            OnEditorChangeTextRange(ctrl, event.GetPosition(), event.GetPosition() + event.GetLength());
        }
        else if (event.GetModificationType() & wxSCI_MOD_DELETETEXT)
        {
            OnEditorChangeTextRange(ctrl, event.GetPosition(), event.GetPosition());
        }
        else if (event.GetModificationType() & wxSCI_MOD_CHANGESTYLE)
        {
            OnEditorChangeTextRange(ctrl, event.GetPosition(), event.GetPosition() + event.GetLength());
        }
    }

}
예제 #17
0
void CCManager::OnEditorHook(cbEditor* ed, wxScintillaEvent& event)
{
    wxEventType evtType = event.GetEventType();
    if (evtType == wxEVT_SCI_CHARADDED)
    {
        const wxChar ch = event.GetKey();
        CCPluginCharMap::const_iterator ctChars = m_CallTipChars.find(GetProviderFor(ed));
        if (ctChars == m_CallTipChars.end())
            ctChars = m_CallTipChars.find(nullptr); // default
        if (ctChars->second.find(ch) != ctChars->second.end())
        {
            CodeBlocksEvent evt(cbEVT_SHOW_CALL_TIP);
            Manager::Get()->ProcessEvent(evt);
        }
        else
        {
            cbStyledTextCtrl* stc = ed->GetControl();
            const int pos = stc->GetCurrentPos();
            const int wordStartPos = stc->WordStartPosition(pos, true);
            CCPluginCharMap::const_iterator alChars = m_AutoLaunchChars.find(GetProviderFor(ed));
            if (alChars == m_AutoLaunchChars.end())
                alChars = m_AutoLaunchChars.find(nullptr); // default
            // TODO: read settings
            if (   (pos - wordStartPos >= 3 && !stc->AutoCompActive())
                || pos - wordStartPos == 3 + 4 )
            {
                CodeBlocksEvent evt(cbEVT_COMPLETE_CODE);
                Manager::Get()->ProcessEvent(evt);
            }
            else if (alChars->second.find(ch) != alChars->second.end())
            {
                m_AutoLaunchTimer.Start(10, wxTIMER_ONE_SHOT);
                m_AutocompPosition = pos;
            }
        }
    }
    else if (evtType == wxEVT_SCI_UPDATEUI)
    {
        if (event.GetUpdated() & (wxSCI_UPDATE_V_SCROLL|wxSCI_UPDATE_H_SCROLL))
        {
            cbStyledTextCtrl* stc = ed->GetControl();
            if (stc->CallTipActive())
            {
                static_cast<wxScintilla*>(stc)->CallTipCancel();
                if (m_CallTipActive != wxSCI_INVALID_POSITION && CCManagerHelper::IsPosVisible(m_CallTipActive, stc))
                    m_CallTipTimer.Start(SCROLL_REFRESH_DELAY, wxTIMER_ONE_SHOT);
            }
            else if (m_CallTipTimer.IsRunning())
            {
                if (CCManagerHelper::IsPosVisible(stc->GetCurrentPos(), stc))
                    m_CallTipTimer.Start(SCROLL_REFRESH_DELAY, wxTIMER_ONE_SHOT);
                else
                {
                    m_CallTipTimer.Stop();
                    m_CallTipActive = wxSCI_INVALID_POSITION;
                }
            }
            if (m_AutoLaunchTimer.IsRunning())
            {
                if (CCManagerHelper::IsPosVisible(stc->GetCurrentPos(), stc))
                    m_AutoLaunchTimer.Start(SCROLL_REFRESH_DELAY, wxTIMER_ONE_SHOT);
                else
                    m_AutoLaunchTimer.Stop();
            }
            else if (stc->AutoCompActive())
            {
                stc->AutoCompCancel();
                m_AutocompPosition = stc->GetCurrentPos();
                if (CCManagerHelper::IsPosVisible(m_AutocompPosition, stc))
                    m_AutoLaunchTimer.Start(SCROLL_REFRESH_DELAY, wxTIMER_ONE_SHOT);
            }
        }
    }
    else if (evtType == wxEVT_SCI_KEY)
    {
        cbStyledTextCtrl* stc = ed->GetControl();
        switch (event.GetKey())
        {
            case wxSCI_KEY_LEFT:
            case wxSCI_KEY_RIGHT:
                if (!stc->CallTipActive() && !stc->AutoCompActive())
                    m_CallTipActive = wxSCI_INVALID_POSITION;
                // fall through
            case wxSCI_KEY_UP:
            case wxSCI_KEY_DOWN:
                if (m_CallTipActive != wxSCI_INVALID_POSITION && !stc->AutoCompActive())
                    m_CallTipTimer.Start(CALLTIP_REFRESH_DELAY, wxTIMER_ONE_SHOT);
                break;

            default:
                break;
        }
    }
    else if (evtType == wxEVT_SCI_MODIFIED)
    {
        if (event.GetModificationType() & wxSCI_PERFORMED_UNDO)
        {
            cbStyledTextCtrl* stc = ed->GetControl();
            if (m_CallTipActive != wxSCI_INVALID_POSITION && stc->GetCurrentPos() >= m_CallTipActive)
                m_CallTipTimer.Start(CALLTIP_REFRESH_DELAY, wxTIMER_ONE_SHOT);
            else
                static_cast<wxScintilla*>(stc)->CallTipCancel();
        }
    }
    else if (evtType == wxEVT_SCI_AUTOCOMP_SELECTION)
    {
        DoHidePopup();
        cbCodeCompletionPlugin* ccPlugin = GetProviderFor(ed);
        if (ccPlugin && m_OwnsAutocomp)
        {
            if (   m_LastAutocompIndex != wxNOT_FOUND
                && m_LastAutocompIndex < (int)m_AutocompTokens.size() )
            {
                ccPlugin->DoAutocomplete(m_AutocompTokens[m_LastAutocompIndex], ed);
            }
            else
            {
                ccPlugin->DoAutocomplete(event.GetText(), ed);
            }
        }
    }
    else if (evtType == wxEVT_SCI_AUTOCOMP_CANCELLED)
        DoHidePopup();
    else if (evtType == wxEVT_SCI_CALLTIP_CLICK)
    {
        switch (event.GetPosition())
        {
            case 1: // up
                --m_CurCallTip;
                DoUpdateCallTip(ed);
                break;

            case 2: // down
                ++m_CurCallTip;
                DoUpdateCallTip(ed);
                break;

            case 0: // elsewhere
            default:
                break;
        }
    }
    event.Skip();
}
예제 #18
0
void OutputTabWindow::OnMarginClick(wxScintillaEvent& e)
{
	if (m_sci && e.GetMargin() == 4) {
		m_sci->ToggleFold(m_sci->LineFromPosition(e.GetPosition()));
	}
}
예제 #19
0
	/// Modified mark may be set, if any.
	void OnModified(wxScintillaEvent &event) {
		if (event.GetModificationType()
			& (wxSCI_MOD_INSERTTEXT | wxSCI_MOD_DELETETEXT)) {
			ChangeModified(true);
		}
	}
예제 #20
0
void SmartIndentFortran::OnEditorHook(cbEditor* ed, wxScintillaEvent& event) const
{
    // check if smart indent is enabled
    // check the event type and the currently set language
    // if it is not a CharAdded event or the language is not Fortran return

    if (!ed)
        return;

    if ( !SmartIndentEnabled() )
        return;

    wxEventType type = event.GetEventType();
    if ( type != wxEVT_SCI_CHARADDED )
        return;

    cbStyledTextCtrl* stc = ed->GetControl();
    if (!stc)
        return;

    wxString langname = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ed->GetLanguage());
    if ( langname != wxT("Fortran") && langname != wxT("Fortran77") ) return;

    ed->AutoIndentDone(); // we are responsible.

    const int pos = stc->GetCurrentPos();
    wxChar ch = event.GetKey();

    if ( (ch == _T('\n')) || ( (stc->GetEOLMode() == wxSCI_EOL_CR) && (ch == _T('\r')) ) )
    {
        const bool autoIndent = AutoIndentEnabled();

        stc->BeginUndoAction();

        int currLine = stc->LineFromPosition(pos);

        // auto indent
        if (autoIndent && currLine > 0)
        {
            wxString indent = ed->GetLineIndentString(currLine - 1);
            stc->InsertText(pos, indent);
            stc->GotoPos(pos + indent.Length());
            stc->ChooseCaretX();
        }

        // smart indent
        bool smartIndent = SmartIndentEnabled();
        if (smartIndent && currLine > 0)
        {
            int start = stc->GetLineIndentPosition(currLine - 1);
            int endt  = stc->WordEndPosition(start, true);
            wxString text = stc->GetTextRange(start, endt).Lower();
            wxString lineText = stc->GetLine(currLine - 1).BeforeFirst('!').Lower();
            wxString lastText = lineText.AfterLast(')').Trim().Trim(false);
            wxString secText = lineText.Trim(false).Mid(text.Length()).Trim(false);
            if (  (text == _T("if") && lastText == _T("then"))
                || text == _T("else")
                || text == _T("elseif")
                || text == _T("enum")
                ||(text == _T("where") && lastText.IsEmpty())
                || text == _T("elsewhere")
                || text == _T("block")
                || text == _T("blockdata")
                ||(text == _T("forall") && lastText.IsEmpty())
                || text == _T("while")
                || text == _T("case")
                || text == _T("associate")
                || text == _T("block")
                || text == _T("critical")
                || text == _T("do")
                ||(text == _T("type") && !secText.StartsWith(_T("(")))
                || text == _T("program")
                || text == _T("function")
                || text == _T("subroutine")
                || text == _T("interface")
                ||(    text == _T("module")
                   && !secText.StartsWith(_T("procedure "))
                   && !secText.StartsWith(_T("procedure:")) ) )
            {
                stc->Tab();
            }
        }

        stc->EndUndoAction();
    }

    bool braceCompleted = false;
    if ( SelectionBraceCompletionEnabled() || stc->IsBraceShortcutActive() )
        braceCompleted = stc->DoSelectionBraceCompletion(ch);
    if (!braceCompleted && BraceCompletionEnabled())
        stc->DoBraceCompletion(ch);
}
예제 #21
0
void OutputTabWindow::OnMouseDClick(wxScintillaEvent& e)
{
	e.Skip();
}