// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page creator-completing-code.html
    \if defined(qtdesignstudio)
    \previouspage qtquick-text-editor.html
    \else
    \previouspage creator-how-tos.html
    \endif

    \ingroup creator-how-to-edit
    \ingroup studio-how-to-code

    \title Complete code

    As you write code, \QC suggests properties, IDs, and code snippets to
    complete the code. It shows a list of suggestions to
    the statement currently under your cursor.

    Press \key Tab or \key Enter to accept the selected suggestion and complete
    the code.

    \if defined(qtcreator)
    \image qtcreator-codecompletion.png
    \caption Suggestions for completing C++ code.
    \endif

    \image qml-code-completion.png
    \caption Suggestions for completing QML code.

    To open the list of suggestions at any time, press \key {Ctrl+Space}.
    If only one option is available, \QC inserts it automatically.

    \section1 Summary of Available Types

    The following table lists available types for code completion and icon used
    for each.

    \table
        \header
            \li  Icon
            \li  Description
        \if defined(qtcreator)
        \row
            \li \inlineimage completion/class.png
            \li A class
        \row
            \li \inlineimage completion/enum.png
            \li An enum
        \row
            \li \inlineimage completion/enumerator.png
            \li An enumerator (value of an enum)
        \row
            \li \inlineimage completion/func.png
            \li A function
        \row
            \li \inlineimage completion/func_priv.png
            \li A private function
        \row
            \li \inlineimage completion/func_prot.png
            \li A protected function
        \row
            \li \inlineimage completion/var.png
            \li A variable
        \row
            \li \inlineimage completion/var_priv.png
            \li A private variable
        \row
            \li \inlineimage completion/var_prot.png
            \li A protected variable
        \row
            \li \inlineimage completion/signal.png
            \li A signal
        \row
            \li \inlineimage completion/slot.png
            \li A slot
        \row
            \li \inlineimage completion/slot_priv.png
            \li A private slot
        \row
            \li \inlineimage completion/slot_prot.png
            \li A protected slot
        \row
            \li \inlineimage completion/keyword.png
            \li A C++ keyword
        \row
            \li \inlineimage completion/snippet.png
            \li A C++ code snippet
        \endif
        \row
            \li \inlineimage completion/element.png
            \li A QML type
        \row
            \li \inlineimage completion/qmlsnippet.png
            \li A QML code snippet
        \if defined(qtcreator)
        \row
            \li \inlineimage completion/macro.png
            \li A macro
        \row
            \li \inlineimage completion/namespace.png
            \li A namespace
        \endif
    \endtable

    \section1 Complete code snippets

    Code snippets can consist of multiple variables that you specify values for.
    Select an item in the list and press \key Tab or \key Enter to complete the
    code. Press \key Tab to move between the variables and specify values for
    them. When you specify a value for a variable, all instances of the variable
    within the snippet are renamed.

    \if defined(qtcreator)
    \image qmldesigner-code-completion.png "Completing C++ code"
    \caption C++ code snippet.
    \endif

    \image qml-code-snippet.png
    \caption QML code snippet.

    \if defined(qtcreator)
    \sa {Complete CMake code}, {Nim}
    \endif

    \sa {Add code snippets to the auto-complete menu}, {Completion}, {Snippets}
*/

/*!
    \page creator-preferences-text-editor-completion.html
    \if defined(qtdesignstudio)
    \previouspage qtquick-text-editor.html
    \else
    \previouspage creator-reference.html
    \endif

    \ingroup creator-reference-preferences-text-editor
    \ingroup studio-preferences-code

    \title Completion

    \brief Set preferences for code completion and inserting matching characters
    in the text editor.

    To set preferences for code completion, select \preferences >
    \uicontrol {Text Editor} > \uicontrol Completion.

    \image qtcreator-preferences-texteditor-completion.webp {Text Editor Completion preferences}

    \section1 Code Completion Behavior

    By default, code completion does not consider case. To apply full or
    first-letter case-sensitivity, select \uicontrol Full or
    \uicontrol {First Letter} in the \uicontrol {Case-sensitivity} field.

    By default, code completion is always invoked, but you can change this
    behavior in the \uicontrol {Activate completion} field to invoke
    it \uicontrol Manually or \uicontrol {When Triggered}.

    You can set a timeout in milliseconds for code completion in the
    \uicontrol {Timeout in ms} field.

    In the \uicontrol {Character threshold} field, specify the number of
    characters you need to enter before code completion is triggered.

    When completion is invoked manually, \QC completes the common prefix of the
    list of suggestions. This is especially useful for classes with several
    similarly named members. To disable this functionality, deselect the
    \uicontrol {Autocomplete common prefix} check box.

    Select the \uicontrol {Automatically split strings} check box to split
    a string to two lines by adding an end quote at the cursor position when
    you press \key Enter and a start quote at the beginning of the next line,
    before the rest of the string. In addition, pressing \key {Shift+Enter}
    inserts an escape character at the cursor position and moves the rest of
    the string to the next line.

    \section1 Automatically Inserting Matching Characters

    When you have selected code and enter brackets or quotes, the matching
    closing character is added automatically at the end of the selection.

    By default, the automatically inserted text is highlighted and animated,
    skipped when you type, and removed when you press \key Backspace.

    \if defined(qtcreator)
    \sa {Complete CMake code}, {Enclose code in brackets or quotes}, {Nim}
    \endif

    \sa {Complete code}, {Snippets}
*/

/*!
    \page creator-preferences-text-editor-shippets.html
    \if defined(qtdesignstudio)
    \previouspage qtquick-text-editor.html
    \else
    \previouspage creator-reference.html
    \endif

    \ingroup creator-reference-preferences-text-editor
    \ingroup studio-preferences-code

    \title Snippets

    \brief Add, change, and remove snippets in the snippet editor.

    To add, change, and remove snippets in the snippet editor, select
    \preferences > \uicontrol {Text Editor} > \uicontrol Snippets.

    \QC has built-in snippets in the following categories:

    \list
        \li Text snippets, which can have any text string. For example, code
            comments
        \if defined(qtcreator)
        \li C++ code snippets, which specify C++ code constructs
        \li CMake code snippets that you can use when editing \c CMakeLists.txt
            files in the CMake editor
        \endif
        \li QML code snippets, which specify QML code constructs
        \if defined(qtcreator)
        \li Nim code snippets, which specify Nim code constructs
        \endif
    \endlist

    \if defined(qtcreator)
    \image qtcreator-edit-code-snippets.png {C++ snippet preferences}
    \caption Built-in C++ code snippets.
    \endif

    \image qml-snippet-editor.png
    \caption Built-in QML code snippets.

    \section1 Editing Snippets

    Select a snippet in the list to edit it in the snippet editor.

    The snippet editor offers:

    \list

        \li Highlighting

        \li Indentation

        \li Parentheses matching

        \li Basic code completion

    \endlist

    Specify the variables for the snippets in the following format:

    \code
    $variable$
    \endcode

    \if defined(qtcreator)
    Specify \QC variables in the following format:

    \code
    %{variable}
    \endcode

    For example, the following variable expands to the name of the
    project containing the file that is currently open in the editor:
    \c {%{CurrentDocument:Project:Name}}.

    Use unique variable names within a snippet because all instances of a
    variable are renamed when you specify a value for it.

    To determine the case of values you enter in snippets, use the following
    modifiers:

    \list

        \li \c {:c} converts the initial letter of the string to upper case

        \li \c {:l} converts the string to lower case

        \li \c {:u} converts the string to upper case

    \endlist

    For example, add the following line to the \c class snippet to specify that
    the function name is converted to all lower case characters regardless of
    how you specify the value of the \c{$name$} variable:

    \code
        void $name:l$() {}
    \endcode

    \image qtcreator-snippet-modifiers.png
    \endif

    The snippet editor does not check the syntax of the snippets that you edit
    or add. However, when you use the snippets, the code editor marks any
    errors by underlining them in red.

    To discard the changes you made to a built-in snippet, select
    \uicontrol {Revert Built-in}.

    \section1 Removing Snippets

    The list of suggestions might show several similar built-in snippets for
    different use cases. To make it shorter when you write code, remove the
    built-in snippets that you do not need. If you need them later, you can
    restore them.

    To remove snippets, select a snippet in the list, and then select
    \uicontrol Remove. To restore the removed snippets, select
    \uicontrol {Restore Removed Built-ins}.

    \section1 Resetting Snippets

    To remove all added snippets and to restore all removed snippets, select
    \uicontrol {Reset All}.

    \note If you now select \uicontrol OK or \uicontrol Apply, you permanently
    lose all your own snippets.

    \if defined(qtcreator)
    \sa {Complete CMake code}, {Document code}, {Use Qt Creator variables},
    {Nim}
    \endif

    \sa {Add code snippets to the auto-complete menu}, {Complete code},
    {Completion}
*/

/*!
    \page creator-how-to-add-code-snippets.html
    \if defined(qtdesignstudio)
    \previouspage qtquick-text-editor.html
    \else
    \previouspage creator-how-tos.html
    \endif

    \ingroup creator-how-to-configure-editors
    \ingroup studio-how-to-code

    \title Add code snippets to the auto-complete menu

    To add code or text snippets in the snippet editor:

    \list 1
        \li Select \preferences > \uicontrol {Text Editor} > \uicontrol Snippets.
            \image qtcreator-snippet-modifiers.png {Snippets preferences}
        \li In \uicontrol Group, select the type of snippet to add.
        \li Select \uicontrol Add.
        \li Specify a trigger. If the trigger is already in use, add an optional
            variant. They appear in the list of suggestions when you write code.
            \if defined(qtcreator)
            Also specify a text string or C++ or QML code construct
            in the snippet editor, depending on the snippet category.

            You can use \l{Use Qt Creator variables}{predefined variables} in
            snippets.
            \else
            Also specify a text string or QML code in the snippet editor, depending on
            the snippet category.
            \endif
    \endlist

    \if defined(qtcreator)
    \sa {Complete CMake code}, {Complete code}, {Use Qt Creator variables},
    {Nim}
    \endif
    \sa {Completion}, {Snippets}
*/
