Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 1808 Lines • ▼ Show 20 Line(s) | 1800 | { | |||
---|---|---|---|---|---|
1809 | } | 1809 | } | ||
1810 | 1810 | | |||
1811 | return w; | 1811 | return w; | ||
1812 | } | 1812 | } | ||
1813 | 1813 | | |||
1814 | // BEGIN KTextEditor::HighlightingInterface stuff | 1814 | // BEGIN KTextEditor::HighlightingInterface stuff | ||
1815 | bool KTextEditor::DocumentPrivate::setMode(const QString &name) | 1815 | bool KTextEditor::DocumentPrivate::setMode(const QString &name) | ||
1816 | { | 1816 | { | ||
1817 | updateFileType(name); | 1817 | return updateFileType(name); | ||
1818 | return true; | | |||
1819 | } | 1818 | } | ||
1820 | 1819 | | |||
1821 | KTextEditor::DefaultStyle KTextEditor::DocumentPrivate::defaultStyleAt(const KTextEditor::Cursor &position) const | 1820 | KTextEditor::DefaultStyle KTextEditor::DocumentPrivate::defaultStyleAt(const KTextEditor::Cursor &position) const | ||
1822 | { | 1821 | { | ||
1823 | // TODO, FIXME KDE5: in surrogate, use 2 bytes before | 1822 | // TODO, FIXME KDE5: in surrogate, use 2 bytes before | ||
1824 | if (!isValidTextPosition(position)) { | 1823 | if (!isValidTextPosition(position)) { | ||
1825 | return dsNormal; | 1824 | return dsNormal; | ||
1826 | } | 1825 | } | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 1927 | } else { | |||
1929 | completed(); // perhaps this should be emitted at the end of this function | 1928 | completed(); // perhaps this should be emitted at the end of this function | ||
1930 | } | 1929 | } | ||
1931 | } else { | 1930 | } else { | ||
1932 | completed(); // perhaps this should be emitted at the end of this function | 1931 | completed(); // perhaps this should be emitted at the end of this function | ||
1933 | } | 1932 | } | ||
1934 | 1933 | | |||
1935 | if (!flags.contains(QStringLiteral("SkipMode"))) { | 1934 | if (!flags.contains(QStringLiteral("SkipMode"))) { | ||
1936 | // restore the filetype | 1935 | // restore the filetype | ||
1937 | if (kconfig.hasKey("Mode")) { | 1936 | // NOTE: if the session config file contains an invalid Mode | ||
1938 | updateFileType(kconfig.readEntry("Mode", fileType())); | 1937 | // (for example, one that was deleted or renamed), do not apply it | ||
1939 | 1938 | if (kconfig.hasKey("Mode") && updateFileType(kconfig.readEntry("Mode"))) { | |||
1940 | // restore if set by user, too! | 1939 | // restore if set by user, too! | ||
1941 | m_fileTypeSetByUser = kconfig.readEntry("Mode Set By User", false); | 1940 | m_fileTypeSetByUser = kconfig.readEntry("Mode Set By User", false); | ||
1942 | } | 1941 | } | ||
1943 | } | 1942 | } | ||
1944 | 1943 | | |||
1945 | if (!flags.contains(QStringLiteral("SkipHighlighting"))) { | 1944 | if (!flags.contains(QStringLiteral("SkipHighlighting"))) { | ||
1946 | // restore the hl stuff | 1945 | // restore the hl stuff | ||
1947 | if (kconfig.hasKey("Highlighting")) { | 1946 | if (kconfig.hasKey("Highlighting")) { | ||
▲ Show 20 Lines • Show All 3177 Lines • ▼ Show 20 Line(s) | 5095 | { | |||
5125 | editEnd(); | 5124 | editEnd(); | ||
5126 | 5125 | | |||
5127 | // enable word wrap again, if it was enabled (see bug #328900) | 5126 | // enable word wrap again, if it was enabled (see bug #328900) | ||
5128 | if (wordWrapEnabled) { | 5127 | if (wordWrapEnabled) { | ||
5129 | setWordWrap(true); // see begin of this function | 5128 | setWordWrap(true); // see begin of this function | ||
5130 | } | 5129 | } | ||
5131 | } | 5130 | } | ||
5132 | 5131 | | |||
5133 | void KTextEditor::DocumentPrivate::updateFileType(const QString &newType, bool user) | 5132 | bool KTextEditor::DocumentPrivate::updateFileType(const QString &newType, bool user) | ||
5134 | { | 5133 | { | ||
5135 | if (user || !m_fileTypeSetByUser) { | 5134 | if (user || !m_fileTypeSetByUser) { | ||
5136 | if (!newType.isEmpty()) { | 5135 | if (newType.isEmpty()) { | ||
5136 | return false; | ||||
5137 | } | ||||
5138 | KateFileType fileType = KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType); | ||||
5139 | // if the mode "newType" does not exist | ||||
5140 | if (fileType.name.isEmpty()) { | ||||
5141 | return false; | ||||
5142 | } | ||||
5143 | | ||||
5137 | // remember that we got set by user | 5144 | // remember that we got set by user | ||
5138 | m_fileTypeSetByUser = user; | 5145 | m_fileTypeSetByUser = user; | ||
5139 | 5146 | | |||
5140 | m_fileType = newType; | 5147 | m_fileType = newType; | ||
5141 | 5148 | | |||
5142 | m_config->configStart(); | 5149 | m_config->configStart(); | ||
5143 | 5150 | | |||
5144 | // NOTE: if the user changes the Mode, the Highlighting also changes. | 5151 | // NOTE: if the user changes the Mode, the Highlighting also changes. | ||
5145 | // m_hlSetByUser avoids resetting the highlight when saving the document, if | 5152 | // m_hlSetByUser avoids resetting the highlight when saving the document, if | ||
5146 | // the current hl isn't stored (eg, in sftp:// or fish:// files) (see bug #407763) | 5153 | // the current hl isn't stored (eg, in sftp:// or fish:// files) (see bug #407763) | ||
5147 | if ((user || !m_hlSetByUser) && !KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).hl.isEmpty()) { | 5154 | if ((user || !m_hlSetByUser) && !fileType.hl.isEmpty()) { | ||
5148 | int hl(KateHlManager::self()->nameFind(KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).hl)); | 5155 | int hl(KateHlManager::self()->nameFind(fileType.hl)); | ||
5149 | 5156 | | |||
5150 | if (hl >= 0) { | 5157 | if (hl >= 0) { | ||
5151 | m_buffer->setHighlight(hl); | 5158 | m_buffer->setHighlight(hl); | ||
5152 | } | 5159 | } | ||
5153 | } | 5160 | } | ||
5154 | 5161 | | |||
5155 | /** | 5162 | /** | ||
5156 | * set the indentation mode, if any in the mode... | 5163 | * set the indentation mode, if any in the mode... | ||
5157 | * and user did not set it before! | 5164 | * and user did not set it before! | ||
5158 | * NOTE: KateBuffer::setHighlight() also sets the indentation. | 5165 | * NOTE: KateBuffer::setHighlight() also sets the indentation. | ||
5159 | */ | 5166 | */ | ||
5160 | if (!m_indenterSetByUser && !KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).indenter.isEmpty()) { | 5167 | if (!m_indenterSetByUser && !fileType.indenter.isEmpty()) { | ||
5161 | config()->setIndentationMode(KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).indenter); | 5168 | config()->setIndentationMode(fileType.indenter); | ||
5162 | } | 5169 | } | ||
5163 | 5170 | | |||
5164 | // views! | 5171 | // views! | ||
5165 | for (auto v : qAsConst(m_views)) { | 5172 | for (auto v : qAsConst(m_views)) { | ||
5166 | v->config()->configStart(); | 5173 | v->config()->configStart(); | ||
5167 | v->renderer()->config()->configStart(); | 5174 | v->renderer()->config()->configStart(); | ||
5168 | } | 5175 | } | ||
5169 | 5176 | | |||
5170 | bool bom_settings = false; | 5177 | bool bom_settings = false; | ||
5171 | if (m_bomSetByUser) { | 5178 | if (m_bomSetByUser) { | ||
5172 | bom_settings = m_config->bom(); | 5179 | bom_settings = m_config->bom(); | ||
5173 | } | 5180 | } | ||
5174 | readVariableLine(KTextEditor::EditorPrivate::self()->modeManager()->fileType(newType).varLine); | 5181 | readVariableLine(fileType.varLine); | ||
5175 | if (m_bomSetByUser) { | 5182 | if (m_bomSetByUser) { | ||
5176 | m_config->setBom(bom_settings); | 5183 | m_config->setBom(bom_settings); | ||
5177 | } | 5184 | } | ||
5178 | m_config->configEnd(); | 5185 | m_config->configEnd(); | ||
5179 | for (auto v : qAsConst(m_views)) { | 5186 | for (auto v : qAsConst(m_views)) { | ||
5180 | v->config()->configEnd(); | 5187 | v->config()->configEnd(); | ||
5181 | v->renderer()->config()->configEnd(); | 5188 | v->renderer()->config()->configEnd(); | ||
5182 | } | 5189 | } | ||
5183 | } | 5190 | } | ||
5184 | } | | |||
5185 | 5191 | | |||
5186 | // fixme, make this better... | 5192 | // fixme, make this better... | ||
5187 | emit modeChanged(this); | 5193 | emit modeChanged(this); | ||
5194 | return true; | ||||
5188 | } | 5195 | } | ||
5189 | 5196 | | |||
5190 | void KTextEditor::DocumentPrivate::slotQueryClose_save(bool *handled, bool *abortClosing) | 5197 | void KTextEditor::DocumentPrivate::slotQueryClose_save(bool *handled, bool *abortClosing) | ||
5191 | { | 5198 | { | ||
5192 | *handled = true; | 5199 | *handled = true; | ||
5193 | *abortClosing = true; | 5200 | *abortClosing = true; | ||
5194 | if (this->url().isEmpty()) { | 5201 | if (this->url().isEmpty()) { | ||
5195 | QWidget *parentWidget(dialogParent()); | 5202 | QWidget *parentWidget(dialogParent()); | ||
▲ Show 20 Lines • Show All 877 Lines • Show Last 20 Lines |