1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "texteditorsettings.h"
27
28 #include "behaviorsettings.h"
29 #include "behaviorsettingspage.h"
30 #include "completionsettings.h"
31 #include "completionsettingspage.h"
32 #include "displaysettings.h"
33 #include "displaysettingspage.h"
34 #include "extraencodingsettings.h"
35 #include "fontsettings.h"
36 #include "fontsettingspage.h"
37 #include "highlightersettingspage.h"
38 #include "icodestylepreferences.h"
39 #include "icodestylepreferencesfactory.h"
40 #include "marginsettings.h"
41 #include "storagesettings.h"
42 #include "tabsettings.h"
43 #include "texteditor.h"
44 #include "typingsettings.h"
45
46 #include <texteditor/snippets/snippetssettingspage.h>
47
48 #include <extensionsystem/pluginmanager.h>
49 #include <coreplugin/icore.h>
50 #include <coreplugin/messagemanager.h>
51 #include <utils/fancylineedit.h>
52 #include <utils/qtcassert.h>
53
54 #include <QApplication>
55
56 using namespace TextEditor::Constants;
57 using namespace TextEditor::Internal;
58
59 namespace TextEditor {
60 namespace Internal {
61
62 class TextEditorSettingsPrivate
63 {
64 Q_DECLARE_TR_FUNCTIONS(TextEditor::TextEditorSettings)
65
66 public:
67 FontSettings m_fontSettings;
68 FontSettingsPage m_fontSettingsPage{&m_fontSettings, initialFormats()};
69 BehaviorSettingsPage m_behaviorSettingsPage;
70 DisplaySettingsPage m_displaySettingsPage;
71 HighlighterSettingsPage m_highlighterSettingsPage;
72 SnippetsSettingsPage m_snippetsSettingsPage;
73 CompletionSettingsPage m_completionSettingsPage;
74
75 QMap<Utils::Id, ICodeStylePreferencesFactory *> m_languageToFactory;
76
77 QMap<Utils::Id, ICodeStylePreferences *> m_languageToCodeStyle;
78 QMap<Utils::Id, CodeStylePool *> m_languageToCodeStylePool;
79 QMap<QString, Utils::Id> m_mimeTypeToLanguage;
80
81 private:
82 static std::vector<FormatDescription> initialFormats();
83 };
84
initialFormats()85 FormatDescriptions TextEditorSettingsPrivate::initialFormats()
86 {
87 // Add font preference page
88 FormatDescriptions formatDescr;
89 formatDescr.reserve(C_LAST_STYLE_SENTINEL);
90 formatDescr.emplace_back(C_TEXT, tr("Text"),
91 tr("Generic text and punctuation tokens.\n"
92 "Applied to text that matched no other rule."),
93 Format{Qt::black, Qt::white});
94
95 // Special categories
96 const QPalette p = QApplication::palette();
97 formatDescr.emplace_back(C_LINK, tr("Link"),
98 tr("Links that follow symbol under cursor."), Qt::blue);
99 formatDescr.emplace_back(C_SELECTION, tr("Selection"), tr("Selected text."),
100 p.color(QPalette::HighlightedText));
101 formatDescr.emplace_back(C_LINE_NUMBER, tr("Line Number"),
102 tr("Line numbers located on the left side of the editor."),
103 FormatDescription::ShowAllAbsoluteControlsExceptUnderline);
104 formatDescr.emplace_back(C_SEARCH_RESULT, tr("Search Result"),
105 tr("Highlighted search results inside the editor."),
106 FormatDescription::ShowBackgroundControl);
107 formatDescr.emplace_back(C_SEARCH_RESULT_ALT1, tr("Search Result (Alternative 1)"),
108 tr("Highlighted search results inside the editor.\n"
109 "Used to mark read accesses to C++ symbols."),
110 FormatDescription::ShowBackgroundControl);
111 formatDescr.emplace_back(C_SEARCH_RESULT_ALT2, tr("Search Result (Alternative 2)"),
112 tr("Highlighted search results inside the editor.\n"
113 "Used to mark write accesses to C++ symbols."),
114 FormatDescription::ShowBackgroundControl);
115 formatDescr.emplace_back(C_SEARCH_SCOPE, tr("Search Scope"),
116 tr("Section where the pattern is searched in."),
117 FormatDescription::ShowBackgroundControl);
118 formatDescr.emplace_back(C_PARENTHESES, tr("Parentheses"),
119 tr("Displayed when matching parentheses, square brackets "
120 "or curly brackets are found."));
121 formatDescr.emplace_back(C_PARENTHESES_MISMATCH, tr("Mismatched Parentheses"),
122 tr("Displayed when mismatched parentheses, "
123 "square brackets, or curly brackets are found."));
124 formatDescr.emplace_back(C_AUTOCOMPLETE, tr("Auto Complete"),
125 tr("Displayed when a character is automatically inserted "
126 "like brackets or quotes."));
127 formatDescr.emplace_back(C_CURRENT_LINE, tr("Current Line"),
128 tr("Line where the cursor is placed in."),
129 FormatDescription::ShowBackgroundControl);
130
131 FormatDescription currentLineNumber(C_CURRENT_LINE_NUMBER,
132 tr("Current Line Number"),
133 tr("Line number located on the left side of the "
134 "editor where the cursor is placed in."),
135 Qt::darkGray,
136 FormatDescription::ShowAllAbsoluteControlsExceptUnderline);
137 currentLineNumber.format().setBold(true);
138 formatDescr.push_back(std::move(currentLineNumber));
139
140
141 formatDescr.emplace_back(C_OCCURRENCES, tr("Occurrences"),
142 tr("Occurrences of the symbol under the cursor.\n"
143 "(Only the background will be applied.)"),
144 FormatDescription::ShowBackgroundControl);
145 formatDescr.emplace_back(C_OCCURRENCES_UNUSED,
146 tr("Unused Occurrence"),
147 tr("Occurrences of unused variables."),
148 Qt::darkYellow,
149 QTextCharFormat::SingleUnderline);
150 formatDescr.emplace_back(C_OCCURRENCES_RENAME, tr("Renaming Occurrence"),
151 tr("Occurrences of a symbol that will be renamed."),
152 FormatDescription::ShowBackgroundControl);
153
154 // Standard categories
155 formatDescr.emplace_back(C_NUMBER, tr("Number"), tr("Number literal."),
156 Qt::darkBlue);
157 formatDescr.emplace_back(C_STRING, tr("String"),
158 tr("Character and string literals."), Qt::darkGreen);
159 formatDescr.emplace_back(C_PRIMITIVE_TYPE, tr("Primitive Type"),
160 tr("Name of a primitive data type."), Qt::darkYellow);
161 formatDescr.emplace_back(C_TYPE, tr("Type"), tr("Name of a type."),
162 Qt::darkMagenta);
163 formatDescr.emplace_back(C_LOCAL, tr("Local"),
164 tr("Local variables."), QColor(9, 46, 100));
165 formatDescr.emplace_back(C_PARAMETER, tr("Parameter"),
166 tr("Function or method parameters."), QColor(9, 46, 100));
167 formatDescr.emplace_back(C_FIELD, tr("Field"),
168 tr("Class' data members."), Qt::darkRed);
169 formatDescr.emplace_back(C_GLOBAL, tr("Global"),
170 tr("Global variables."), QColor(206, 92, 0));
171 formatDescr.emplace_back(C_ENUMERATION, tr("Enumeration"),
172 tr("Applied to enumeration items."), Qt::darkMagenta);
173
174 Format functionFormat;
175 functionFormat.setForeground(QColor(0, 103, 124));
176 formatDescr.emplace_back(C_FUNCTION, tr("Function"), tr("Name of a function."),
177 functionFormat);
178 Format declarationFormat;
179 declarationFormat.setBold(true);
180 formatDescr.emplace_back(C_DECLARATION,
181 tr("Function Declaration"),
182 tr("Style adjustments to (function) declarations."),
183 declarationFormat,
184 FormatDescription::ShowAllControls);
185 formatDescr.emplace_back(C_FUNCTION_DEFINITION,
186 tr("Function Definition"),
187 tr("Name of function at its definition."),
188 FormatDescription::ShowAllControls);
189 Format virtualFunctionFormat(functionFormat);
190 virtualFunctionFormat.setItalic(true);
191 formatDescr.emplace_back(C_VIRTUAL_METHOD, tr("Virtual Function"),
192 tr("Name of function declared as virtual."),
193 virtualFunctionFormat);
194
195 formatDescr.emplace_back(C_BINDING, tr("QML Binding"),
196 tr("QML item property, that allows a "
197 "binding to another property."),
198 Qt::darkRed);
199
200 Format qmlLocalNameFormat;
201 qmlLocalNameFormat.setItalic(true);
202 formatDescr.emplace_back(C_QML_LOCAL_ID, tr("QML Local Id"),
203 tr("QML item id within a QML file."), qmlLocalNameFormat);
204 formatDescr.emplace_back(C_QML_ROOT_OBJECT_PROPERTY,
205 tr("QML Root Object Property"),
206 tr("QML property of a parent item."), qmlLocalNameFormat);
207 formatDescr.emplace_back(C_QML_SCOPE_OBJECT_PROPERTY,
208 tr("QML Scope Object Property"),
209 tr("Property of the same QML item."), qmlLocalNameFormat);
210 formatDescr.emplace_back(C_QML_STATE_NAME, tr("QML State Name"),
211 tr("Name of a QML state."), qmlLocalNameFormat);
212
213 formatDescr.emplace_back(C_QML_TYPE_ID, tr("QML Type Name"),
214 tr("Name of a QML type."), Qt::darkMagenta);
215
216 Format qmlExternalNameFormat = qmlLocalNameFormat;
217 qmlExternalNameFormat.setForeground(Qt::darkBlue);
218 formatDescr.emplace_back(C_QML_EXTERNAL_ID, tr("QML External Id"),
219 tr("QML id defined in another QML file."),
220 qmlExternalNameFormat);
221 formatDescr.emplace_back(C_QML_EXTERNAL_OBJECT_PROPERTY,
222 tr("QML External Object Property"),
223 tr("QML property defined in another QML file."),
224 qmlExternalNameFormat);
225
226 Format jsLocalFormat;
227 jsLocalFormat.setForeground(QColor(41, 133, 199)); // very light blue
228 jsLocalFormat.setItalic(true);
229 formatDescr.emplace_back(C_JS_SCOPE_VAR, tr("JavaScript Scope Var"),
230 tr("Variables defined inside the JavaScript file."),
231 jsLocalFormat);
232
233 Format jsGlobalFormat;
234 jsGlobalFormat.setForeground(QColor(0, 85, 175)); // light blue
235 jsGlobalFormat.setItalic(true);
236 formatDescr.emplace_back(C_JS_IMPORT_VAR, tr("JavaScript Import"),
237 tr("Name of a JavaScript import inside a QML file."),
238 jsGlobalFormat);
239 formatDescr.emplace_back(C_JS_GLOBAL_VAR, tr("JavaScript Global Variable"),
240 tr("Variables defined outside the script."),
241 jsGlobalFormat);
242
243 formatDescr.emplace_back(C_KEYWORD, tr("Keyword"),
244 tr("Reserved keywords of the programming language except "
245 "keywords denoting primitive types."), Qt::darkYellow);
246 formatDescr.emplace_back(C_PUNCTUATION, tr("Punctuation"),
247 tr("Punctuation excluding operators."));
248 formatDescr.emplace_back(C_OPERATOR, tr("Operator"),
249 tr("Non user-defined language operators.\n"
250 "To style user-defined operators, use Overloaded Operator."),
251 FormatDescription::ShowAllControls);
252 formatDescr.emplace_back(C_OVERLOADED_OPERATOR,
253 tr("Overloaded Operators"),
254 tr("Calls and declarations of overloaded (user-defined) operators."),
255 functionFormat,
256 FormatDescription::ShowAllControls);
257 formatDescr.emplace_back(C_PREPROCESSOR, tr("Preprocessor"),
258 tr("Preprocessor directives."), Qt::darkBlue);
259 formatDescr.emplace_back(C_LABEL, tr("Label"), tr("Labels for goto statements."),
260 Qt::darkRed);
261 formatDescr.emplace_back(C_COMMENT, tr("Comment"),
262 tr("All style of comments except Doxygen comments."),
263 Qt::darkGreen);
264 formatDescr.emplace_back(C_DOXYGEN_COMMENT, tr("Doxygen Comment"),
265 tr("Doxygen comments."), Qt::darkBlue);
266 formatDescr.emplace_back(C_DOXYGEN_TAG, tr("Doxygen Tag"), tr("Doxygen tags."),
267 Qt::blue);
268 formatDescr.emplace_back(C_VISUAL_WHITESPACE, tr("Visual Whitespace"),
269 tr("Whitespace.\nWill not be applied to whitespace "
270 "in comments and strings."), Qt::lightGray);
271 formatDescr.emplace_back(C_DISABLED_CODE, tr("Disabled Code"),
272 tr("Code disabled by preprocessor directives."));
273
274 // Diff categories
275 formatDescr.emplace_back(C_ADDED_LINE, tr("Added Line"),
276 tr("Applied to added lines in differences (in diff editor)."),
277 QColor(0, 170, 0));
278 formatDescr.emplace_back(C_REMOVED_LINE, tr("Removed Line"),
279 tr("Applied to removed lines in differences (in diff editor)."),
280 Qt::red);
281 formatDescr.emplace_back(C_DIFF_FILE, tr("Diff File"),
282 tr("Compared files (in diff editor)."), Qt::darkBlue);
283 formatDescr.emplace_back(C_DIFF_LOCATION, tr("Diff Location"),
284 tr("Location in the files where the difference is "
285 "(in diff editor)."), Qt::blue);
286
287 // New diff categories
288 formatDescr.emplace_back(C_DIFF_FILE_LINE, tr("Diff File Line"),
289 tr("Applied to lines with file information "
290 "in differences (in side-by-side diff editor)."),
291 Format(QColor(), QColor(255, 255, 0)));
292 formatDescr.emplace_back(C_DIFF_CONTEXT_LINE, tr("Diff Context Line"),
293 tr("Applied to lines describing hidden context "
294 "in differences (in side-by-side diff editor)."),
295 Format(QColor(), QColor(175, 215, 231)));
296 formatDescr.emplace_back(C_DIFF_SOURCE_LINE, tr("Diff Source Line"),
297 tr("Applied to source lines with changes "
298 "in differences (in side-by-side diff editor)."),
299 Format(QColor(), QColor(255, 223, 223)));
300 formatDescr.emplace_back(C_DIFF_SOURCE_CHAR, tr("Diff Source Character"),
301 tr("Applied to removed characters "
302 "in differences (in side-by-side diff editor)."),
303 Format(QColor(), QColor(255, 175, 175)));
304 formatDescr.emplace_back(C_DIFF_DEST_LINE, tr("Diff Destination Line"),
305 tr("Applied to destination lines with changes "
306 "in differences (in side-by-side diff editor)."),
307 Format(QColor(), QColor(223, 255, 223)));
308 formatDescr.emplace_back(C_DIFF_DEST_CHAR, tr("Diff Destination Character"),
309 tr("Applied to added characters "
310 "in differences (in side-by-side diff editor)."),
311 Format(QColor(), QColor(175, 255, 175)));
312
313 formatDescr.emplace_back(C_LOG_CHANGE_LINE, tr("Log Change Line"),
314 tr("Applied to lines describing changes in VCS log."),
315 Format(QColor(192, 0, 0), QColor()));
316 formatDescr.emplace_back(C_LOG_AUTHOR_NAME, tr("Log Author Name"),
317 tr("Applied to author names in VCS log."),
318 Format(QColor(0x007af4), QColor()));
319 formatDescr.emplace_back(C_LOG_COMMIT_DATE, tr("Log Commit Date"),
320 tr("Applied to commit dates in VCS log."),
321 Format(QColor(0x006600), QColor()));
322 formatDescr.emplace_back(C_LOG_COMMIT_HASH, tr("Log Commit Hash"),
323 tr("Applied to commit hashes in VCS log."),
324 Format(QColor(0xff0000), QColor()));
325 formatDescr.emplace_back(C_LOG_DECORATION, tr("Log Decoration"),
326 tr("Applied to commit decorations in VCS log."),
327 Format(QColor(0xff00ff), QColor()));
328 formatDescr.emplace_back(C_LOG_COMMIT_SUBJECT, tr("Log Commit Subject"),
329 tr("Applied to commit subjects in VCS log."),
330 Format{QColor{}, QColor{}});
331
332 // Mixin categories
333 formatDescr.emplace_back(C_ERROR,
334 tr("Error"),
335 tr("Underline color of error diagnostics."),
336 QColor(255,0, 0),
337 QTextCharFormat::SingleUnderline,
338 FormatDescription::ShowAllControls);
339 formatDescr.emplace_back(C_ERROR_CONTEXT,
340 tr("Error Context"),
341 tr("Underline color of the contexts of error diagnostics."),
342 QColor(255,0, 0),
343 QTextCharFormat::DotLine,
344 FormatDescription::ShowAllControls);
345 formatDescr.emplace_back(C_WARNING,
346 tr("Warning"),
347 tr("Underline color of warning diagnostics."),
348 QColor(255, 190, 0),
349 QTextCharFormat::SingleUnderline,
350 FormatDescription::ShowAllControls);
351 formatDescr.emplace_back(C_WARNING_CONTEXT,
352 tr("Warning Context"),
353 tr("Underline color of the contexts of warning diagnostics."),
354 QColor(255, 190, 0),
355 QTextCharFormat::DotLine,
356 FormatDescription::ShowAllControls);
357 Format outputArgumentFormat;
358 outputArgumentFormat.setItalic(true);
359 formatDescr.emplace_back(C_OUTPUT_ARGUMENT,
360 tr("Output Argument"),
361 tr("Writable arguments of a function call."),
362 outputArgumentFormat,
363 FormatDescription::ShowAllControls);
364
365 return formatDescr;
366 }
367
368 } // namespace Internal
369
370
371 static TextEditorSettingsPrivate *d = nullptr;
372 static TextEditorSettings *m_instance = nullptr;
373
TextEditorSettings()374 TextEditorSettings::TextEditorSettings()
375 {
376 QTC_ASSERT(!m_instance, return);
377 m_instance = this;
378 d = new Internal::TextEditorSettingsPrivate;
379
380 // Note: default background colors are coming from FormatDescription::background()
381
382 auto updateGeneralMessagesFontSettings = []() {
383 Core::MessageManager::setFont(d->m_fontSettings.font());
384 };
385 connect(this, &TextEditorSettings::fontSettingsChanged,
386 this, updateGeneralMessagesFontSettings);
387 updateGeneralMessagesFontSettings();
388 auto updateGeneralMessagesBehaviorSettings = []() {
389 bool wheelZoom = d->m_behaviorSettingsPage.behaviorSettings().m_scrollWheelZooming;
390 Core::MessageManager::setWheelZoomEnabled(wheelZoom);
391 };
392 connect(this, &TextEditorSettings::behaviorSettingsChanged,
393 this, updateGeneralMessagesBehaviorSettings);
394 updateGeneralMessagesBehaviorSettings();
395
396 auto updateCamelCaseNavigation = [] {
397 Utils::FancyLineEdit::setCamelCaseNavigationEnabled(behaviorSettings().m_camelCaseNavigation);
398 };
399 connect(this, &TextEditorSettings::behaviorSettingsChanged,
400 this, updateCamelCaseNavigation);
401 updateCamelCaseNavigation();
402 }
403
~TextEditorSettings()404 TextEditorSettings::~TextEditorSettings()
405 {
406 delete d;
407
408 m_instance = nullptr;
409 }
410
instance()411 TextEditorSettings *TextEditorSettings::instance()
412 {
413 return m_instance;
414 }
415
fontSettings()416 const FontSettings &TextEditorSettings::fontSettings()
417 {
418 return d->m_fontSettings;
419 }
420
typingSettings()421 const TypingSettings &TextEditorSettings::typingSettings()
422 {
423 return d->m_behaviorSettingsPage.typingSettings();
424 }
425
storageSettings()426 const StorageSettings &TextEditorSettings::storageSettings()
427 {
428 return d->m_behaviorSettingsPage.storageSettings();
429 }
430
behaviorSettings()431 const BehaviorSettings &TextEditorSettings::behaviorSettings()
432 {
433 return d->m_behaviorSettingsPage.behaviorSettings();
434 }
435
marginSettings()436 const MarginSettings &TextEditorSettings::marginSettings()
437 {
438 return d->m_displaySettingsPage.marginSettings();
439 }
440
displaySettings()441 const DisplaySettings &TextEditorSettings::displaySettings()
442 {
443 return d->m_displaySettingsPage.displaySettings();
444 }
445
completionSettings()446 const CompletionSettings &TextEditorSettings::completionSettings()
447 {
448 return d->m_completionSettingsPage.completionSettings();
449 }
450
highlighterSettings()451 const HighlighterSettings &TextEditorSettings::highlighterSettings()
452 {
453 return d->m_highlighterSettingsPage.highlighterSettings();
454 }
455
extraEncodingSettings()456 const ExtraEncodingSettings &TextEditorSettings::extraEncodingSettings()
457 {
458 return d->m_behaviorSettingsPage.extraEncodingSettings();
459 }
460
commentsSettings()461 const CommentsSettings &TextEditorSettings::commentsSettings()
462 {
463 return d->m_completionSettingsPage.commentsSettings();
464 }
465
registerCodeStyleFactory(ICodeStylePreferencesFactory * factory)466 void TextEditorSettings::registerCodeStyleFactory(ICodeStylePreferencesFactory *factory)
467 {
468 d->m_languageToFactory.insert(factory->languageId(), factory);
469 }
470
unregisterCodeStyleFactory(Utils::Id languageId)471 void TextEditorSettings::unregisterCodeStyleFactory(Utils::Id languageId)
472 {
473 d->m_languageToFactory.remove(languageId);
474 }
475
codeStyleFactories()476 const QMap<Utils::Id, ICodeStylePreferencesFactory *> &TextEditorSettings::codeStyleFactories()
477 {
478 return d->m_languageToFactory;
479 }
480
codeStyleFactory(Utils::Id languageId)481 ICodeStylePreferencesFactory *TextEditorSettings::codeStyleFactory(Utils::Id languageId)
482 {
483 return d->m_languageToFactory.value(languageId);
484 }
485
codeStyle()486 ICodeStylePreferences *TextEditorSettings::codeStyle()
487 {
488 return d->m_behaviorSettingsPage.codeStyle();
489 }
490
codeStyle(Utils::Id languageId)491 ICodeStylePreferences *TextEditorSettings::codeStyle(Utils::Id languageId)
492 {
493 return d->m_languageToCodeStyle.value(languageId, codeStyle());
494 }
495
codeStyles()496 QMap<Utils::Id, ICodeStylePreferences *> TextEditorSettings::codeStyles()
497 {
498 return d->m_languageToCodeStyle;
499 }
500
registerCodeStyle(Utils::Id languageId,ICodeStylePreferences * prefs)501 void TextEditorSettings::registerCodeStyle(Utils::Id languageId, ICodeStylePreferences *prefs)
502 {
503 d->m_languageToCodeStyle.insert(languageId, prefs);
504 }
505
unregisterCodeStyle(Utils::Id languageId)506 void TextEditorSettings::unregisterCodeStyle(Utils::Id languageId)
507 {
508 d->m_languageToCodeStyle.remove(languageId);
509 }
510
codeStylePool()511 CodeStylePool *TextEditorSettings::codeStylePool()
512 {
513 return d->m_behaviorSettingsPage.codeStylePool();
514 }
515
codeStylePool(Utils::Id languageId)516 CodeStylePool *TextEditorSettings::codeStylePool(Utils::Id languageId)
517 {
518 return d->m_languageToCodeStylePool.value(languageId);
519 }
520
registerCodeStylePool(Utils::Id languageId,CodeStylePool * pool)521 void TextEditorSettings::registerCodeStylePool(Utils::Id languageId, CodeStylePool *pool)
522 {
523 d->m_languageToCodeStylePool.insert(languageId, pool);
524 }
525
unregisterCodeStylePool(Utils::Id languageId)526 void TextEditorSettings::unregisterCodeStylePool(Utils::Id languageId)
527 {
528 d->m_languageToCodeStylePool.remove(languageId);
529 }
530
registerMimeTypeForLanguageId(const char * mimeType,Utils::Id languageId)531 void TextEditorSettings::registerMimeTypeForLanguageId(const char *mimeType, Utils::Id languageId)
532 {
533 d->m_mimeTypeToLanguage.insert(QString::fromLatin1(mimeType), languageId);
534 }
535
languageId(const QString & mimeType)536 Utils::Id TextEditorSettings::languageId(const QString &mimeType)
537 {
538 return d->m_mimeTypeToLanguage.value(mimeType);
539 }
540
setFontZoom(int zoom)541 static void setFontZoom(int zoom)
542 {
543 d->m_fontSettingsPage.setFontZoom(zoom);
544 d->m_fontSettings.setFontZoom(zoom);
545 d->m_fontSettings.toSettings(Core::ICore::settings());
546 emit m_instance->fontSettingsChanged(d->m_fontSettings);
547 }
548
increaseFontZoom(int step)549 int TextEditorSettings::increaseFontZoom(int step)
550 {
551 const int previousZoom = d->m_fontSettings.fontZoom();
552 const int newZoom = qMax(10, previousZoom + step);
553 if (newZoom != previousZoom)
554 setFontZoom(newZoom);
555 return newZoom;
556 }
557
resetFontZoom()558 void TextEditorSettings::resetFontZoom()
559 {
560 setFontZoom(100);
561 }
562
563 } // TextEditor
564