Git commit 0abf8a5420c75a6d1cbbe6e8fcb4ebf7381e4289 by Gerald Senarclens de Grancy. Committed on 03/05/2013 at 22:56. Pushed by geralds into branch 'master'.
added 'indent-pasted-text' mode variable Added a mode variable to disable/ enable adjusting indentation for code pasted from the clipboard. Used it in the global modeline for Python. This is required for Python b/c adjusting the indentation is dangerous and can lead to bugs. REVIEW: 110219 M +2 -2 doc/kate/configuring-part.docbook M +6 -0 doc/kate/configuring.docbook M +3 -0 part/data/katemoderc M +7 -0 part/document/katedocument.cpp M +10 -1 part/utils/katecmds.cpp M +6 -0 part/variableeditor/variablelineedit.cpp http://commits.kde.org/kate/0abf8a5420c75a6d1cbbe6e8fcb4ebf7381e4289 diff --git a/doc/kate/configuring-part.docbook b/doc/kate/configuring-part.docbook index 03adbba..26fde08 100644 --- a/doc/kate/configuring-part.docbook +++ b/doc/kate/configuring-part.docbook @@ -695,9 +695,9 @@ level aligns a line to a multiple of the width specified in <guilabel>Indentation width</guilabel>.</para></listitem> </varlistentry> <varlistentry> -<term><guilabel>Adjust indentation of code pasted from the clipboard</guilabel></term> +<term><guilabel>Adjust indentation of text pasted from the clipboard</guilabel></term> <listitem> -<para>If this option is selected, pasted code from the clipboard is indented. +<para>If this option is selected, text pasted from the clipboard is indented. Triggering the <guimenuitem>Undo</guimenuitem> action removes the indentation.</para> </listitem> </varlistentry> diff --git a/doc/kate/configuring.docbook b/doc/kate/configuring.docbook index a768cfe..13c7b90 100644 --- a/doc/kate/configuring.docbook +++ b/doc/kate/configuring.docbook @@ -483,6 +483,12 @@ be evaluated to a valid color, for example <userinput>#ff0000</userinput>.</para <xref linkend="kate-part-autoindent"/> for details.</para></listitem> </varlistentry> +<varlistentry id="variable-indent-pasted-text"> +<term><cmdsynopsis><command>indent-pasted-text</command><arg>BOOL</arg></cmdsynopsis></term> +<listitem><para>Enable/disable adjusting indentation of text pasted from the clipboard.</para> +<para>Since: Kate 3.11 (KDE 4.11)</para></listitem> +</varlistentry> + <varlistentry id="variable-indent-width"> <term><cmdsynopsis><command>indent-width</command><arg>INT</arg></cmdsynopsis></term> <listitem><para>Set the indentation width.</para></listitem> diff --git a/part/data/katemoderc b/part/data/katemoderc index 7ac52ae..9a5872d 100644 --- a/part/data/katemoderc +++ b/part/data/katemoderc @@ -1,5 +1,8 @@ [Makefile] Variables=kate: tab-width 8; indent-width 8; replace-tabs off; replace-tabs-save off; +[Python] +Variables=kate: indent-pasted-text false; + [YAML] Variables=kate: space-indent true; diff --git a/part/document/katedocument.cpp b/part/document/katedocument.cpp index 37e6635..722d3db 100644 --- a/part/document/katedocument.cpp +++ b/part/document/katedocument.cpp @@ -5,6 +5,7 @@ Copyright (C) 2006 Hamish Rodda <rodda at kde.org> Copyright (C) 2007 Mirko Stocker <me at misto.ch> Copyright (C) 2009-2010 Michel Ludwig <michel.ludwig at kdemail.net> + Copyright (C) 2013 Gerald Senarclens de Grancy <oss at senarclens.eu> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -4043,6 +4044,8 @@ void KateDocument::readVariableLine( QString t, bool onlyViewAndRenderer ) // FIXME should this be optimized to only a few calls? how? else if ( var == "backspace-indents" && checkBoolValue( val, &state ) ) m_config->setBackspaceIndents( state ); + else if ( var == "indent-pasted-text" && checkBoolValue( val, &state ) ) + m_config->setIndentPastedText( state ); else if ( var == "replace-tabs" && checkBoolValue( val, &state ) ) { m_config->setReplaceTabsDyn( state ); @@ -4529,6 +4532,8 @@ QVariant KateDocument::configValue(const QString &key) return m_config->backupPrefix(); } else if (key == "replace-tabs") { return m_config->replaceTabsDyn(); + } else if (key == "indent-pasted-text") { + return m_config->indentPastedText(); } // return invalid variant @@ -4565,6 +4570,8 @@ void KateDocument::setConfigValue(const QString &key, const QVariant &value) m_config->setBackupFlags(f); } else if (key == "replace-tabs") { m_config->setReplaceTabsDyn(bValue); + } else if (key == "indent-pasted-text") { + m_config->setIndentPastedText(bValue); } } } diff --git a/part/utils/katecmds.cpp b/part/utils/katecmds.cpp index 5a81437..c47e773 100644 --- a/part/utils/katecmds.cpp +++ b/part/utils/katecmds.cpp @@ -78,7 +78,7 @@ const QStringList &KateCommands::CoreCommands::cmds() << "set-indent-width" << "set-indent-mode" << "set-auto-indent" << "set-line-numbers" << "set-folding-markers" << "set-icon-border" - << "set-word-wrap" << "set-word-wrap-column" + << "set-indent-pasted-text" << "set-word-wrap" << "set-word-wrap-column" << "set-replace-tabs-save" << "set-remove-trailing-spaces" << "set-highlight" << "set-mode" << "set-show-indent" << "print"; @@ -113,6 +113,12 @@ bool KateCommands::CoreCommands::help(KTextEditor::View *, const QString &cmd, Q msg=i18n("<p>goto <b>line number</b></p>" "<p>This command navigates to the specified line number.</p>"); return true; + } else if (realcmd=="set-indent-pasted-text") { + msg=i18n("<p>set-indent-pasted-text <b>enable</b></p>" + "<p>If enabled, indentation of text pasted from the clipboard is adjusted using the current indenter.</p>" + "<p>Possible true values: 1 on true<br/>" + "possible false values: 0 off false</p>"); + return true; } else if (realcmd=="kill-line") { msg=i18n("Deletes the current line."); return true; @@ -429,6 +435,7 @@ bool KateCommands::CoreCommands::exec(KTextEditor::View *view, // ALL commands that takes 1 boolean argument. else if ( cmd == "set-icon-border" || cmd == "set-folding-markers" || + cmd == "set-indent-pasted-text" || cmd == "set-line-numbers" || cmd == "set-replace-tabs" || cmd == "set-show-tabs" || @@ -451,6 +458,8 @@ bool KateCommands::CoreCommands::exec(KTextEditor::View *view, v->setLineNumbersOn( enable ); else if ( cmd == "set-show-indent" ) v->renderer()->setShowIndentLines( enable ); + else if (cmd == "set-indent-pasted-text") + config->setIndentPastedText( enable ); else if ( cmd == "set-replace-tabs" ) config->setReplaceTabsDyn( enable ); else if ( cmd == "set-show-tabs" ) diff --git a/part/variableeditor/variablelineedit.cpp b/part/variableeditor/variablelineedit.cpp index 44f14b6..6198903 100644 --- a/part/variableeditor/variablelineedit.cpp +++ b/part/variableeditor/variablelineedit.cpp @@ -1,6 +1,7 @@ /* This file is part of the KDE project Copyright (C) 2011 Dominik Haumann <dhaumann kde org> + Copyright (C) 2013 Gerald Senarclens de Grancy <oss at senarclens.eu> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -236,6 +237,11 @@ void VariableLineEdit::addKateItems(VariableListView* listview) item->setHelpText(i18nc("short translation please", "Set the auto indentation style.")); listview->addItem(item); + // Add 'indent-pasted-text' to list + item = new VariableBoolItem("indent-pasted-text", docConfig->indentPastedText()); + item->setHelpText(i18nc("short translation please", "Adjust indentation of text pasted from the clipboard.")); + listview->addItem(item); + // Add 'indent-width' to list item = new VariableIntItem("indent-width", docConfig->indentationWidth()); static_cast<VariableIntItem*>(item)->setRange(1, 16);
