texteditorsettings.cpp 23.5 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

con's avatar
con committed
26 27
#include "texteditorsettings.h"

28
#include "fontsettings.h"
29
#include "texteditor.h"
30
#include "behaviorsettings.h"
31
#include "behaviorsettingspage.h"
32
#include "completionsettings.h"
33
#include "marginsettings.h"
con's avatar
con committed
34
#include "displaysettings.h"
35
#include "displaysettingspage.h"
con's avatar
con committed
36
#include "fontsettingspage.h"
Jarek Kobus's avatar
Jarek Kobus committed
37
#include "typingsettings.h"
con's avatar
con committed
38 39
#include "storagesettings.h"
#include "tabsettings.h"
40
#include "extraencodingsettings.h"
Jarek Kobus's avatar
Jarek Kobus committed
41 42
#include "icodestylepreferences.h"
#include "icodestylepreferencesfactory.h"
43
#include "completionsettingspage.h"
44 45
#include <texteditor/generichighlighter/highlightersettingspage.h>
#include <texteditor/snippets/snippetssettingspage.h>
con's avatar
con committed
46

47
#include <extensionsystem/pluginmanager.h>
48
#include <coreplugin/icore.h>
hjk's avatar
hjk committed
49 50
#include <utils/qtcassert.h>

51
#include <QApplication>
con's avatar
con committed
52 53 54

using namespace TextEditor;
using namespace TextEditor::Constants;
55 56 57 58 59 60 61 62 63 64 65
using namespace TextEditor::Internal;

namespace TextEditor {
namespace Internal {

class TextEditorSettingsPrivate
{
public:
    FontSettingsPage *m_fontSettingsPage;
    BehaviorSettingsPage *m_behaviorSettingsPage;
    DisplaySettingsPage *m_displaySettingsPage;
66
    HighlighterSettingsPage *m_highlighterSettingsPage;
67
    SnippetsSettingsPage *m_snippetsSettingsPage;
68
    CompletionSettingsPage *m_completionSettingsPage;
69

Orgad Shaneh's avatar
Orgad Shaneh committed
70
    QMap<Core::Id, ICodeStylePreferencesFactory *> m_languageToFactory;
71

Orgad Shaneh's avatar
Orgad Shaneh committed
72 73 74
    QMap<Core::Id, ICodeStylePreferences *> m_languageToCodeStyle;
    QMap<Core::Id, CodeStylePool *> m_languageToCodeStylePool;
    QMap<QString, Core::Id> m_mimeTypeToLanguage;
75 76 77 78 79
};

} // namespace Internal
} // namespace TextEditor

con's avatar
con committed
80

81 82
static TextEditorSettingsPrivate *d = 0;
static TextEditorSettings *m_instance = 0;
con's avatar
con committed
83

84
TextEditorSettings::TextEditorSettings(QObject *parent)
con's avatar
con committed
85 86
    : QObject(parent)
{
hjk's avatar
hjk committed
87
    QTC_ASSERT(!m_instance, return);
con's avatar
con committed
88
    m_instance = this;
89
    d = new Internal::TextEditorSettingsPrivate;
con's avatar
con committed
90 91 92 93

    // Note: default background colors are coming from FormatDescription::background()

    // Add font preference page
94
    FormatDescriptions formatDescr;
95 96 97 98
    formatDescr.reserve(C_LAST_STYLE_SENTINEL);
    formatDescr.emplace_back(C_TEXT, tr("Text"), tr("Generic text.\nApplied to "
                                                    "text, if no other "
                                                    "rules matching."));
con's avatar
con committed
99 100 101

    // Special categories
    const QPalette p = QApplication::palette();
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    formatDescr.emplace_back(C_LINK, tr("Link"),
                             tr("Links that follow symbol under cursor."), Qt::blue);
    formatDescr.emplace_back(C_SELECTION, tr("Selection"), tr("Selected text."),
                             p.color(QPalette::HighlightedText));
    formatDescr.emplace_back(C_LINE_NUMBER, tr("Line Number"),
                             tr("Line numbers located on the left side of the editor."),
                             FormatDescription::AllControlsExceptUnderline);
    formatDescr.emplace_back(C_SEARCH_RESULT, tr("Search Result"),
                             tr("Highlighted search results inside the editor."),
                             FormatDescription::ShowBackgroundControl);
    formatDescr.emplace_back(C_SEARCH_SCOPE, tr("Search Scope"),
                             tr("Section where the pattern is searched in."),
                             FormatDescription::ShowBackgroundControl);
    formatDescr.emplace_back(C_PARENTHESES, tr("Parentheses"),
                             tr("Displayed when matching parentheses, square brackets "
                                "or curly brackets are found."));
    formatDescr.emplace_back(C_PARENTHESES_MISMATCH, tr("Mismatched Parentheses"),
                             tr("Displayed when mismatched parentheses, "
                                "square brackets, or curly brackets are found."));
    formatDescr.emplace_back(C_CURRENT_LINE, tr("Current Line"),
                             tr("Line where the cursor is placed in."),
                             FormatDescription::ShowBackgroundControl);

    FormatDescription currentLineNumber(C_CURRENT_LINE_NUMBER,
                                        tr("Current Line Number"),
                                        tr("Line number located on the left side of the "
                                           "editor where the cursor is placed in."),
                                        Qt::darkGray,
                                        FormatDescription::AllControlsExceptUnderline);
131
    currentLineNumber.format().setBold(true);
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    formatDescr.push_back(std::move(currentLineNumber));


    formatDescr.emplace_back(C_OCCURRENCES, tr("Occurrences"),
                             tr("Occurrences of the symbol under the cursor.\n"
                                "(Only the background will be applied.)"),
                             FormatDescription::ShowBackgroundControl);
    formatDescr.emplace_back(C_OCCURRENCES_UNUSED,
                             tr("Unused Occurrence"),
                             tr("Occurrences of unused variables."),
                             Qt::darkYellow,
                             QTextCharFormat::SingleUnderline);
    formatDescr.emplace_back(C_OCCURRENCES_RENAME, tr("Renaming Occurrence"),
                             tr("Occurrences of a symbol that will be renamed."),
                             FormatDescription::ShowBackgroundControl);
147

con's avatar
con committed
148
    // Standard categories
149 150 151 152 153 154 155 156 157 158 159
    formatDescr.emplace_back(C_NUMBER, tr("Number"), tr("Number literal."),
                             Qt::darkBlue);
    formatDescr.emplace_back(C_STRING, tr("String"),
                             tr("Character and string literals."), Qt::darkGreen);
    formatDescr.emplace_back(C_PRIMITIVE_TYPE, tr("Primitive Type"),
                             tr("Name of a primitive data type."), Qt::darkYellow);
    formatDescr.emplace_back(C_TYPE, tr("Type"), tr("Name of a type."),
                             Qt::darkMagenta);
    formatDescr.emplace_back(C_LOCAL, tr("Local"), tr("Local variables."));
    formatDescr.emplace_back(C_FIELD, tr("Field"),
                             tr("Class' data members."), Qt::darkRed);
160
    formatDescr.emplace_back(C_GLOBAL, tr("Global"), tr("Global variables."));
161 162
    formatDescr.emplace_back(C_ENUMERATION, tr("Enumeration"),
                             tr("Applied to enumeration items."), Qt::darkMagenta);
163

164
    Format functionFormat;
165 166
    formatDescr.emplace_back(C_FUNCTION, tr("Function"), tr("Name of a function."),
                             functionFormat);
167
    functionFormat.setItalic(true);
168 169 170
    formatDescr.emplace_back(C_VIRTUAL_METHOD, tr("Virtual Function"),
                             tr("Name of function declared as virtual."),
                             functionFormat);
171

172 173 174 175
    formatDescr.emplace_back(C_BINDING, tr("QML Binding"),
                             tr("QML item property, that allows a "
                                "binding to another property."),
                             Qt::darkRed);
176

177 178
    Format qmlLocalNameFormat;
    qmlLocalNameFormat.setItalic(true);
179 180 181 182 183 184 185 186 187 188 189 190 191
    formatDescr.emplace_back(C_QML_LOCAL_ID, tr("QML Local Id"),
                             tr("QML item id within a QML file."), qmlLocalNameFormat);
    formatDescr.emplace_back(C_QML_ROOT_OBJECT_PROPERTY,
                             tr("QML Root Object Property"),
                             tr("QML property of a parent item."), qmlLocalNameFormat);
    formatDescr.emplace_back(C_QML_SCOPE_OBJECT_PROPERTY,
                             tr("QML Scope Object Property"),
                             tr("Property of the same QML item."), qmlLocalNameFormat);
    formatDescr.emplace_back(C_QML_STATE_NAME, tr("QML State Name"),
                             tr("Name of a QML state."), qmlLocalNameFormat);

    formatDescr.emplace_back(C_QML_TYPE_ID, tr("QML Type Name"),
                             tr("Name of a QML type."), Qt::darkMagenta);
192 193 194

    Format qmlExternalNameFormat = qmlLocalNameFormat;
    qmlExternalNameFormat.setForeground(Qt::darkBlue);
195 196 197 198 199 200 201
    formatDescr.emplace_back(C_QML_EXTERNAL_ID, tr("QML External Id"),
                             tr("QML id defined in another QML file."),
                             qmlExternalNameFormat);
    formatDescr.emplace_back(C_QML_EXTERNAL_OBJECT_PROPERTY,
                             tr("QML External Object Property"),
                             tr("QML property defined in another QML file."),
                             qmlExternalNameFormat);
202

203 204 205
    Format jsLocalFormat;
    jsLocalFormat.setForeground(QColor(41, 133, 199)); // very light blue
    jsLocalFormat.setItalic(true);
206 207 208
    formatDescr.emplace_back(C_JS_SCOPE_VAR, tr("JavaScript Scope Var"),
                             tr("Variables defined inside the JavaScript file."),
                             jsLocalFormat);
209 210 211 212

    Format jsGlobalFormat;
    jsGlobalFormat.setForeground(QColor(0, 85, 175)); // light blue
    jsGlobalFormat.setItalic(true);
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    formatDescr.emplace_back(C_JS_IMPORT_VAR, tr("JavaScript Import"),
                             tr("Name of a JavaScript import inside a QML file."),
                             jsGlobalFormat);
    formatDescr.emplace_back(C_JS_GLOBAL_VAR, tr("JavaScript Global Variable"),
                             tr("Variables defined outside the script."),
                             jsGlobalFormat);

    formatDescr.emplace_back(C_KEYWORD, tr("Keyword"),
                             tr("Reserved keywords of the programming language except "
                                "keywords denoting primitive types."), Qt::darkYellow);
    formatDescr.emplace_back(C_OPERATOR, tr("Operator"),
                             tr("Operators (for example operator++ or operator-=)."));
    formatDescr.emplace_back(C_PREPROCESSOR, tr("Preprocessor"),
                             tr("Preprocessor directives."), Qt::darkBlue);
    formatDescr.emplace_back(C_LABEL, tr("Label"), tr("Labels for goto statements."),
                             Qt::darkRed);
    formatDescr.emplace_back(C_COMMENT, tr("Comment"),
                             tr("All style of comments except Doxygen comments."),
                             Qt::darkGreen);
    formatDescr.emplace_back(C_DOXYGEN_COMMENT, tr("Doxygen Comment"),
                             tr("Doxygen comments."), Qt::darkBlue);
    formatDescr.emplace_back(C_DOXYGEN_TAG, tr("Doxygen Tag"), tr("Doxygen tags."),
                             Qt::blue);
    formatDescr.emplace_back(C_VISUAL_WHITESPACE, tr("Visual Whitespace"),
                             tr("Whitespace.\nWill not be applied to whitespace "
                                "in comments and strings."), Qt::lightGray);
    formatDescr.emplace_back(C_DISABLED_CODE, tr("Disabled Code"),
                             tr("Code disabled by preprocessor directives."));
con's avatar
con committed
241 242

    // Diff categories
243 244 245 246 247 248 249 250 251 252 253
    formatDescr.emplace_back(C_ADDED_LINE, tr("Added Line"),
                             tr("Applied to added lines in differences (in diff editor)."),
                             QColor(0, 170, 0));
    formatDescr.emplace_back(C_REMOVED_LINE, tr("Removed Line"),
                             tr("Applied to removed lines in differences (in diff editor)."),
                             Qt::red);
    formatDescr.emplace_back(C_DIFF_FILE, tr("Diff File"),
                             tr("Compared files (in diff editor)."), Qt::darkBlue);
    formatDescr.emplace_back(C_DIFF_LOCATION, tr("Diff Location"),
                             tr("Location in the files where the difference is "
                                "(in diff editor)."), Qt::blue);
254

jkobus's avatar
jkobus committed
255
    // New diff categories
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
    formatDescr.emplace_back(C_DIFF_FILE_LINE, tr("Diff File Line"),
                             tr("Applied to lines with file information "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(255, 255, 0)));
    formatDescr.emplace_back(C_DIFF_CONTEXT_LINE, tr("Diff Context Line"),
                             tr("Applied to lines describing hidden context "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(175, 215, 231)));
    formatDescr.emplace_back(C_DIFF_SOURCE_LINE, tr("Diff Source Line"),
                             tr("Applied to source lines with changes "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(255, 223, 223)));
    formatDescr.emplace_back(C_DIFF_SOURCE_CHAR, tr("Diff Source Character"),
                             tr("Applied to removed characters "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(255, 175, 175)));
    formatDescr.emplace_back(C_DIFF_DEST_LINE, tr("Diff Destination Line"),
                             tr("Applied to destination lines with changes "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(223, 255, 223)));
    formatDescr.emplace_back(C_DIFF_DEST_CHAR, tr("Diff Destination Character"),
                             tr("Applied to added characters "
                                "in differences (in side-by-side diff editor)."),
                             Format(QColor(), QColor(175, 255, 175)));

    formatDescr.emplace_back(C_LOG_CHANGE_LINE, tr("Log Change Line"),
                             tr("Applied to lines describing changes in VCS log."),
                             Format(QColor(192, 0, 0), QColor()));

    formatDescr.emplace_back(C_ERROR,
                             tr("Error"),
                             tr("Underline color of error diagnostics."),
                             QColor(255,0, 0),
                             QTextCharFormat::SingleUnderline,
                             FormatDescription::ShowUnderlineControl);
    formatDescr.emplace_back(C_ERROR_CONTEXT,
                             tr("Error Context"),
                             tr("Underline color of the contexts of error diagnostics."),
                             QColor(255,0, 0),
                             QTextCharFormat::DotLine,
                             FormatDescription::ShowUnderlineControl);
    formatDescr.emplace_back(C_WARNING,
                             tr("Warning"),
                             tr("Underline color of warning diagnostics."),
                             QColor(255, 190, 0),
                             QTextCharFormat::SingleUnderline,
                             FormatDescription::ShowUnderlineControl);
    formatDescr.emplace_back(C_WARNING_CONTEXT,
                             tr("Warning Context"),
                             tr("Underline color of the contexts of warning diagnostics."),
                             QColor(255, 190, 0),
                             QTextCharFormat::DotLine,
                             FormatDescription::ShowUnderlineControl);
309 310 311 312
    formatDescr.emplace_back(C_DECLARATION,
                             tr("Declaration"),
                             tr("Declaration of a function, variable, and so on."),
                             FormatDescription::ShowFontAndUnderlineControls);
313

314
    d->m_fontSettingsPage = new FontSettingsPage(formatDescr,
hjk's avatar
hjk committed
315
                                                   Constants::TEXT_EDITOR_FONT_SETTINGS,
316
                                                   this);
317
    ExtensionSystem::PluginManager::addObject(d->m_fontSettingsPage);
con's avatar
con committed
318

319
    // Add the GUI used to configure the tab, storage and interaction settings
320
    BehaviorSettingsPageParameters behaviorSettingsPageParameters;
hjk's avatar
hjk committed
321
    behaviorSettingsPageParameters.id = Constants::TEXT_EDITOR_BEHAVIOR_SETTINGS;
322
    behaviorSettingsPageParameters.displayName = tr("Behavior");
323
    behaviorSettingsPageParameters.settingsPrefix = QLatin1String("text");
324 325
    d->m_behaviorSettingsPage = new BehaviorSettingsPage(behaviorSettingsPageParameters, this);
    ExtensionSystem::PluginManager::addObject(d->m_behaviorSettingsPage);
326

327
    DisplaySettingsPageParameters displaySettingsPageParameters;
hjk's avatar
hjk committed
328
    displaySettingsPageParameters.id = Constants::TEXT_EDITOR_DISPLAY_SETTINGS;
329
    displaySettingsPageParameters.displayName = tr("Display");
330
    displaySettingsPageParameters.settingsPrefix = QLatin1String("text");
331 332
    d->m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
    ExtensionSystem::PluginManager::addObject(d->m_displaySettingsPage);
con's avatar
con committed
333

334
    d->m_highlighterSettingsPage =
hjk's avatar
hjk committed
335
        new HighlighterSettingsPage(Constants::TEXT_EDITOR_HIGHLIGHTER_SETTINGS, this);
336
    ExtensionSystem::PluginManager::addObject(d->m_highlighterSettingsPage);
337

338
    d->m_snippetsSettingsPage =
hjk's avatar
hjk committed
339
        new SnippetsSettingsPage(Constants::TEXT_EDITOR_SNIPPETS_SETTINGS, this);
340
    ExtensionSystem::PluginManager::addObject(d->m_snippetsSettingsPage);
341

342 343 344
    d->m_completionSettingsPage = new CompletionSettingsPage(this);
    ExtensionSystem::PluginManager::addObject(d->m_completionSettingsPage);

345 346 347 348 349 350 351 352 353 354 355 356 357 358
    connect(d->m_fontSettingsPage, &FontSettingsPage::changed,
            this, &TextEditorSettings::fontSettingsChanged);
    connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::typingSettingsChanged,
            this, &TextEditorSettings::typingSettingsChanged);
    connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::storageSettingsChanged,
            this, &TextEditorSettings::storageSettingsChanged);
    connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::behaviorSettingsChanged,
            this, &TextEditorSettings::behaviorSettingsChanged);
    connect(d->m_behaviorSettingsPage, &BehaviorSettingsPage::extraEncodingSettingsChanged,
            this, &TextEditorSettings::extraEncodingSettingsChanged);
    connect(d->m_displaySettingsPage, &DisplaySettingsPage::marginSettingsChanged,
            this, &TextEditorSettings::marginSettingsChanged);
    connect(d->m_displaySettingsPage, &DisplaySettingsPage::displaySettingsChanged,
            this, &TextEditorSettings::displaySettingsChanged);
359 360 361 362
    connect(d->m_completionSettingsPage, &CompletionSettingsPage::completionSettingsChanged,
            this, &TextEditorSettings::completionSettingsChanged);
    connect(d->m_completionSettingsPage, &CompletionSettingsPage::commentsSettingsChanged,
            this, &TextEditorSettings::commentsSettingsChanged);
con's avatar
con committed
363 364 365 366
}

TextEditorSettings::~TextEditorSettings()
{
367 368 369 370 371
    ExtensionSystem::PluginManager::removeObject(d->m_fontSettingsPage);
    ExtensionSystem::PluginManager::removeObject(d->m_behaviorSettingsPage);
    ExtensionSystem::PluginManager::removeObject(d->m_displaySettingsPage);
    ExtensionSystem::PluginManager::removeObject(d->m_highlighterSettingsPage);
    ExtensionSystem::PluginManager::removeObject(d->m_snippetsSettingsPage);
372
    ExtensionSystem::PluginManager::removeObject(d->m_completionSettingsPage);
373

374
    delete d;
con's avatar
con committed
375 376 377 378 379 380 381 382 383

    m_instance = 0;
}

TextEditorSettings *TextEditorSettings::instance()
{
    return m_instance;
}

384
const FontSettings &TextEditorSettings::fontSettings()
mae's avatar
mae committed
385
{
386
    return d->m_fontSettingsPage->fontSettings();
mae's avatar
mae committed
387 388
}

389
const TypingSettings &TextEditorSettings::typingSettings()
Jarek Kobus's avatar
Jarek Kobus committed
390
{
391
    return d->m_behaviorSettingsPage->typingSettings();
Jarek Kobus's avatar
Jarek Kobus committed
392 393
}

394
const StorageSettings &TextEditorSettings::storageSettings()
con's avatar
con committed
395
{
396
    return d->m_behaviorSettingsPage->storageSettings();
con's avatar
con committed
397 398
}

399
const BehaviorSettings &TextEditorSettings::behaviorSettings()
con's avatar
con committed
400
{
401
    return d->m_behaviorSettingsPage->behaviorSettings();
con's avatar
con committed
402 403
}

404 405 406 407 408
const MarginSettings &TextEditorSettings::marginSettings()
{
    return d->m_displaySettingsPage->marginSettings();
}

409
const DisplaySettings &TextEditorSettings::displaySettings()
con's avatar
con committed
410
{
411
    return d->m_displaySettingsPage->displaySettings();
con's avatar
con committed
412 413
}

414
const CompletionSettings &TextEditorSettings::completionSettings()
415
{
416
    return d->m_completionSettingsPage->completionSettings();
417 418
}

419
const HighlighterSettings &TextEditorSettings::highlighterSettings()
420
{
421
    return d->m_highlighterSettingsPage->highlighterSettings();
422 423
}

424
const ExtraEncodingSettings &TextEditorSettings::extraEncodingSettings()
425
{
426
    return d->m_behaviorSettingsPage->extraEncodingSettings();
427 428
}

429
const CommentsSettings &TextEditorSettings::commentsSettings()
con's avatar
con committed
430
{
431
    return d->m_completionSettingsPage->commentsSettings();
con's avatar
con committed
432
}
433

Jarek Kobus's avatar
Jarek Kobus committed
434 435
void TextEditorSettings::registerCodeStyleFactory(ICodeStylePreferencesFactory *factory)
{
436
    d->m_languageToFactory.insert(factory->languageId(), factory);
Jarek Kobus's avatar
Jarek Kobus committed
437 438
}

jkobus's avatar
jkobus committed
439 440
void TextEditorSettings::unregisterCodeStyleFactory(Core::Id languageId)
{
441
    d->m_languageToFactory.remove(languageId);
jkobus's avatar
jkobus committed
442 443
}

444
QMap<Core::Id, ICodeStylePreferencesFactory *> TextEditorSettings::codeStyleFactories()
Jarek Kobus's avatar
Jarek Kobus committed
445
{
446
    return d->m_languageToFactory;
Jarek Kobus's avatar
Jarek Kobus committed
447 448
}

449
ICodeStylePreferencesFactory *TextEditorSettings::codeStyleFactory(Core::Id languageId)
Jarek Kobus's avatar
Jarek Kobus committed
450
{
451
    return d->m_languageToFactory.value(languageId);
Jarek Kobus's avatar
Jarek Kobus committed
452 453
}

454
ICodeStylePreferences *TextEditorSettings::codeStyle()
455
{
456
    return d->m_behaviorSettingsPage->codeStyle();
457 458
}

459
ICodeStylePreferences *TextEditorSettings::codeStyle(Core::Id languageId)
460
{
461
    return d->m_languageToCodeStyle.value(languageId, codeStyle());
462 463
}

464
QMap<Core::Id, ICodeStylePreferences *> TextEditorSettings::codeStyles()
465
{
466
    return d->m_languageToCodeStyle;
467 468
}

Orgad Shaneh's avatar
Orgad Shaneh committed
469
void TextEditorSettings::registerCodeStyle(Core::Id languageId, ICodeStylePreferences *prefs)
470
{
471
    d->m_languageToCodeStyle.insert(languageId, prefs);
472 473
}

jkobus's avatar
jkobus committed
474 475
void TextEditorSettings::unregisterCodeStyle(Core::Id languageId)
{
476
    d->m_languageToCodeStyle.remove(languageId);
jkobus's avatar
jkobus committed
477 478
}

479
CodeStylePool *TextEditorSettings::codeStylePool()
480
{
481
    return d->m_behaviorSettingsPage->codeStylePool();
482 483
}

484
CodeStylePool *TextEditorSettings::codeStylePool(Core::Id languageId)
485
{
486
    return d->m_languageToCodeStylePool.value(languageId);
487 488
}

Orgad Shaneh's avatar
Orgad Shaneh committed
489
void TextEditorSettings::registerCodeStylePool(Core::Id languageId, CodeStylePool *pool)
490
{
491
    d->m_languageToCodeStylePool.insert(languageId, pool);
492 493
}

jkobus's avatar
jkobus committed
494 495
void TextEditorSettings::unregisterCodeStylePool(Core::Id languageId)
{
496
    d->m_languageToCodeStylePool.remove(languageId);
jkobus's avatar
jkobus committed
497 498
}

499
void TextEditorSettings::registerMimeTypeForLanguageId(const char *mimeType, Core::Id languageId)
500
{
501
    d->m_mimeTypeToLanguage.insert(QString::fromLatin1(mimeType), languageId);
502 503 504 505 506
}

Core::Id TextEditorSettings::languageId(const QString &mimeType)
{
    return d->m_mimeTypeToLanguage.value(mimeType);
507 508
}

509
int TextEditorSettings::increaseFontZoom(int step)
510
{
511
    FontSettings &fs = const_cast<FontSettings&>(d->m_fontSettingsPage->fontSettings());
512
    const int previousZoom = fs.fontZoom();
513 514 515 516
    const int newZoom = qMax(10, previousZoom + step);
    if (newZoom != previousZoom) {
        fs.setFontZoom(newZoom);
        d->m_fontSettingsPage->saveSettings();
517
    }
518
    return newZoom;
519 520
}

521
void TextEditorSettings::resetFontZoom()
522 523 524 525 526
{
    FontSettings &fs = const_cast<FontSettings&>(d->m_fontSettingsPage->fontSettings());
    fs.setFontZoom(100);
    d->m_fontSettingsPage->saveSettings();
}