summaryrefslogtreecommitdiffstats
path: root/kate/interfaces
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /kate/interfaces
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kate/interfaces')
-rw-r--r--kate/interfaces/.kateconfig1
-rw-r--r--kate/interfaces/Makefile.am12
-rw-r--r--kate/interfaces/document.h407
-rw-r--r--kate/interfaces/interfaces.cpp127
-rw-r--r--kate/interfaces/katecmd.cpp223
-rw-r--r--kate/interfaces/katecmd.h99
-rw-r--r--kate/interfaces/view.h303
7 files changed, 1172 insertions, 0 deletions
diff --git a/kate/interfaces/.kateconfig b/kate/interfaces/.kateconfig
new file mode 100644
index 000000000..5b0885abe
--- /dev/null
+++ b/kate/interfaces/.kateconfig
@@ -0,0 +1 @@
+kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/kate/interfaces/Makefile.am b/kate/interfaces/Makefile.am
new file mode 100644
index 000000000..175dcf381
--- /dev/null
+++ b/kate/interfaces/Makefile.am
@@ -0,0 +1,12 @@
+METASOURCES = document.moc view.moc
+
+lib_LTLIBRARIES = libkatepartinterfaces.la
+
+libkatepartinterfaces_la_SOURCES = interfaces.cpp katecmd.cpp
+libkatepartinterfaces_la_LIBADD = $(top_builddir)/interfaces/ktexteditor/libktexteditor.la
+libkatepartinterfaces_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -no-undefined
+
+kateinclude_HEADERS = document.h view.h
+kateincludedir = $(includedir)/kate
+
+INCLUDES= -I$(top_srcdir)/interfaces -I$(top_srcdir)/kparts -I$(top_srcdir) $(all_includes)
diff --git a/kate/interfaces/document.h b/kate/interfaces/document.h
new file mode 100644
index 000000000..6e7cb9a56
--- /dev/null
+++ b/kate/interfaces/document.h
@@ -0,0 +1,407 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KATE_DOCUMENT_INCLUDE_
+#define _KATE_DOCUMENT_INCLUDE_
+
+#include <ktexteditor/document.h>
+#include <ktexteditor/view.h>
+#include <ktexteditor/editinterface.h>
+#include <ktexteditor/undointerface.h>
+#include <ktexteditor/cursorinterface.h>
+#include <ktexteditor/documentinfo.h>
+#include <ktexteditor/selectioninterface.h>
+#include <ktexteditor/selectioninterfaceext.h>
+#include <ktexteditor/blockselectioninterface.h>
+#include <ktexteditor/searchinterface.h>
+#include <ktexteditor/highlightinginterface.h>
+#include <ktexteditor/configinterface.h>
+#include <ktexteditor/configinterfaceextension.h>
+#include <ktexteditor/markinterface.h>
+#include <ktexteditor/markinterfaceextension.h>
+#include <ktexteditor/wordwrapinterface.h>
+#include <ktexteditor/printinterface.h>
+#include <ktexteditor/variableinterface.h>
+
+#include <kaction.h>
+
+class KCompletion;
+
+/**
+ * Kate namespace
+ * All classes in this namespace must stay BC
+ * during one major release series (e.g. 3.x, 4.x, ...)
+ */
+namespace Kate
+{
+
+class View;
+
+class KATEPARTINTERFACES_EXPORT Cursor : public KTextEditor::Cursor
+{
+ public:
+ Cursor () { ; };
+ virtual ~Cursor () { ; };
+};
+
+class KATEPARTINTERFACES_EXPORT ConfigPage : public KTextEditor::ConfigPage
+{
+ Q_OBJECT
+
+ public:
+ ConfigPage ( QWidget *parent=0, const char *name=0 ) : KTextEditor::ConfigPage (parent, name) { ; };
+ virtual ~ConfigPage () { ; };
+
+ public slots:
+ virtual void apply () { ; };
+ virtual void reload () { ; };
+ virtual void reset () {};
+ virtual void defaults () {};
+
+ protected slots:
+ void slotChanged();
+};
+
+class KATEPARTINTERFACES_EXPORT ActionMenu : public KActionMenu
+{
+ Q_OBJECT
+
+ public:
+ ActionMenu ( const QString& text, QObject* parent = 0, const char* name = 0 )
+ : KActionMenu(text, parent, name) { ; };
+ virtual ~ActionMenu () { ; };
+
+ public:
+ virtual void updateMenu (class Document *) = 0;
+};
+
+/**
+ * Kate Commands
+ */
+class KATEPARTINTERFACES_EXPORT Command
+{
+ public:
+ Command () {};
+ virtual ~Command () {};
+
+ public:
+ /**
+ * Pure text start part of the commands which can be handled by this object
+ * which means i.e. for s/sdl/sdf/g => s or for char:1212 => char
+ */
+ virtual QStringList cmds () = 0;
+
+ /**
+ * Execute this command for the given view and cmd string, return a bool
+ * about success, msg for status
+ */
+ virtual bool exec (View *view, const QString &cmd, QString &msg) = 0;
+
+ /**
+ * Shows help for the given view and cmd string, return a bool
+ * about success, msg for status
+ */
+ virtual bool help (View *view, const QString &cmd, QString &msg) = 0;
+};
+
+/**
+ * Extension to the Command interface, allowing to interact with commands
+ * during typing. This allows for completion and for example the isearch
+ * plugin. If you develop a command that wants to complete or process text
+ * as thu user types the arguments, or that has flags, you can have
+ * your command inherit this class.
+ */
+class CommandExtension
+{
+ public:
+ CommandExtension() {;}
+ virtual ~CommandExtension() {;}
+
+ /**
+ * Fill in a list of flags to complete from. Each flag is a single letter,
+ * any following text in the string is taken to be a description of the
+ * flag's meaning, and showed to the user as a hint.
+ * Implement this method if your command has flags.
+ *
+ * This method is called each time the flag string in the typed command
+ * is changed, so that the available flags can be adjusted. When completions
+ * are displayed, existing flags are left out.
+ *
+ */ //### this is yet to be tried
+ virtual void flagCompletions( QStringList& /*list*/ ) {;}
+
+ /**
+ * @return a KCompletion object that will substitute the command line default
+ * one while typing the first argument to the command. The text will be
+ * added to the command seperated by one space character.
+ *
+ * Implement this method if your command can provide a completion object.
+ *
+ * @param cmdname The command name associated with this request.
+ */
+ virtual KCompletion *completionObject( const QString & cmdname, Kate::View * /*view*/ ) { Q_UNUSED(cmdname); return 0L; }
+
+ /**
+ * @return whether this command wants to process text interactively given the @p cmdname.
+ * If true, the command's processText() method is called when the
+ * text in the command line is changed.
+ *
+ * Reimplement this to return true, if your commands wants to process the
+ * text as typed.
+ *
+ * @param cmdname the command name associated with this query.
+ */
+ virtual bool wantsToProcessText( const QString &cmdname ) { Q_UNUSED(cmdname); return false; }
+
+ /**
+ * This is called by the commandline each time the argument text for the
+ * command changes, if wantsToProcessText() returns true.
+ * @param view The current view
+ * @param text The current command text typed by the user.
+ */ // ### yet to be tested. The obvious candidate is isearch.
+ virtual void processText( Kate::View *view, const QString &text ) { Q_UNUSED(view); Q_UNUSED(text); }
+};
+
+/** This interface provides access to the Kate Document class.
+*/
+class KATEPARTINTERFACES_EXPORT Document : public KTextEditor::Document, public KTextEditor::EditInterface,
+ public KTextEditor::UndoInterface, public KTextEditor::CursorInterface,
+ public KTextEditor::SelectionInterface, public KTextEditor::SearchInterface,
+ public KTextEditor::HighlightingInterface, public KTextEditor::BlockSelectionInterface,
+ public KTextEditor::ConfigInterface, public KTextEditor::MarkInterface,
+ public KTextEditor::PrintInterface, public KTextEditor::WordWrapInterface,
+ public KTextEditor::MarkInterfaceExtension,
+ public KTextEditor::SelectionInterfaceExt
+{
+ Q_OBJECT
+
+ public:
+ Document ();
+ Document ( QObject* parent, const char* name );
+ virtual ~Document ();
+
+ /**
+ * Commands handling
+ */
+ public:
+ static bool registerCommand (Command *cmd);
+ static bool unregisterCommand (Command *cmd);
+ static Command *queryCommand (const QString &cmd);
+
+ public:
+ /**
+ * deprecated for KDE 4.0, just does reloadFile, which will ask
+ * the normal "do you want it really" questions
+ * @deprecated
+ */
+ virtual void isModOnHD(bool =false) { ; };
+
+ /**
+ * Returns the document name.
+ */
+ virtual QString docName () { return 0L; };
+
+ /**
+ * Sets the document name.
+ * deprecated for KDE 4.0, is done internally, calling it won't hurt
+ * but changes nothing beside triggers signal
+ * @deprecated
+ */
+ virtual void setDocName (QString ) { ; };
+
+ virtual ActionMenu *hlActionMenu (const QString& , QObject* =0, const char* = 0) = 0;
+ virtual ActionMenu *exportActionMenu (const QString& , QObject* =0, const char* = 0) = 0;
+
+ public slots:
+ // clear buffer/filename - update the views
+ virtual void flush () { ; };
+
+ /**
+ * Reloads the current document from disk if possible
+ */
+ virtual void reloadFile() = 0;
+
+ /**
+ * Spellchecking
+ */
+ virtual void spellcheck() {};
+
+ virtual void exportAs(const QString &) = 0;
+
+ virtual void applyWordWrap () = 0;
+
+
+ public:
+ virtual void setWordWrap (bool ) = 0;
+ virtual bool wordWrap () = 0;
+
+ virtual void setWordWrapAt (unsigned int) = 0;
+ virtual uint wordWrapAt () = 0;
+
+
+ virtual void setEncoding (const QString &e) = 0;
+ virtual QString encoding() const = 0;
+
+ /** @deprecated */
+ // FIXME: Remove when BIC allowed.
+ public:
+ /** @deprecated */
+ virtual ConfigPage *colorConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *fontConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *indentConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *selectConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *editConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *keysConfigPage (QWidget *) = 0;
+ /** @deprecated */
+ virtual ConfigPage *kSpellConfigPage (QWidget *) { return 0L; }
+ /** @deprecated */
+ virtual ConfigPage *hlConfigPage (QWidget *) = 0;
+
+ public:
+ virtual uint configFlags () = 0;
+ virtual void setConfigFlags (uint flags) = 0;
+
+ // Flags for katedocument config !
+ enum ConfigFlags
+ {
+ cfAutoIndent= 0x1,
+ cfBackspaceIndents= 0x2,
+ cfWordWrap= 0x4,
+ cfReplaceTabs= 0x8,
+ cfRemoveSpaces = 0x10,
+ cfWrapCursor= 0x20,
+ cfAutoBrackets= 0x40,
+ cfPersistent= 0x80,
+ cfKeepSelection= 0x100,
+ cfDelOnInput= 0x400,
+ cfXorSelect= 0x800,
+ cfOvr= 0x1000,
+ cfMark= 0x2000,
+ cfKeepIndentProfile= 0x8000,
+ cfKeepExtraSpaces= 0x10000,
+ cfTabIndents= 0x80000,
+ cfShowTabs= 0x200000,
+ cfSpaceIndent= 0x400000,
+ cfSmartHome = 0x800000
+ };
+
+ signals:
+ /**
+ * Indicate this file is modified on disk
+ * @param doc the Kate::Document object that represents the file on disk
+ * @param isModified indicates the file was modified rather than created or deleted
+ * @param reason the reason we are emitting the signal.
+ * @li 0 - nothing
+ * @li 1 - dirty
+ * @li 2 - created
+ * @li 3 - deleted
+ */
+ void modifiedOnDisc (Kate::Document *doc, bool isModified, unsigned char reason);
+
+ /*
+ * there static methodes are usefull to turn on/off the dialogs
+ * kate part shows up on open file errors + file changed warnings
+ * open file errors default on, file changed warnings default off, better
+ * for other apps beside kate app using the part
+ */
+ public:
+ // default true
+ static void setOpenErrorDialogsActivated (bool on);
+
+ // default false
+ static void setFileChangedDialogsActivated (bool on);
+
+ static const QString &defaultEncoding ();
+
+ protected:
+ static bool s_openErrorDialogsActivated;
+ static bool s_fileChangedDialogsActivated;
+
+ static QString s_defaultEncoding;
+};
+
+/**
+ * Extensions to the Document Interface
+ * @since 3.3
+ */
+class KATEPARTINTERFACES_EXPORT DocumentExt
+ : public KTextEditor::DocumentInfoInterface,
+ public KTextEditor::VariableInterface
+{
+ public:
+ DocumentExt ();
+ virtual ~DocumentExt ();
+
+ public:
+ /**
+ * Reasons why a document is modified on disk.
+ */
+ enum ModifiedOnDiskReason {
+ Unmodified = 0, ///< Not modified
+ Modified = 1, ///< The file was modified by another program
+ Created = 2, ///< The file was created by another program
+ Deleted = 3 ///< The file was deleted
+ };
+
+ public:
+ /**
+ * For client apps that want to deal with files modified on disk, it is
+ * nessecary to reset this property.
+ * @p reason is a ModifiedOnDiskReason.
+ */
+ virtual void setModifiedOnDisk( int reason ) = 0;
+
+ /**
+ * These stuff is implemented as slots in the real document
+ */
+ public:
+ /**
+ * Ask the user what to do, if the file is modified on disk.
+ * The @p v argument is used to avoid asking again, when the
+ * editor regains focus after the dialog is hidden.
+ */
+ virtual void slotModifiedOnDisk( View *v=0 ) = 0;
+};
+
+/**
+ * Check if given document is a Kate::Document
+ * @param doc KTextEditor document
+ * @return 0 if no success, else the Kate::Document
+ */
+KATEPARTINTERFACES_EXPORT Document *document (KTextEditor::Document *doc);
+
+/**
+ * Check if given document is a Kate::DocumentExt
+ * @param doc KTextEditor document
+ * @return 0 if no success, else the Kate::DocumentExt
+ */
+KATEPARTINTERFACES_EXPORT DocumentExt *documentExt (KTextEditor::Document *doc);
+
+/**
+ * Creates a new Kate::Document object
+ */
+KATEPARTINTERFACES_EXPORT Document *createDocument ( QObject *parent = 0, const char *name = 0 );
+
+}
+
+#endif
diff --git a/kate/interfaces/interfaces.cpp b/kate/interfaces/interfaces.cpp
new file mode 100644
index 000000000..42bd35b7e
--- /dev/null
+++ b/kate/interfaces/interfaces.cpp
@@ -0,0 +1,127 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "document.h"
+#include "document.moc"
+
+#include "view.h"
+#include "view.moc"
+
+#include "katecmd.h"
+
+namespace Kate
+{
+
+bool Document::s_openErrorDialogsActivated = true;
+bool Document::s_fileChangedDialogsActivated = false;
+QString Document::s_defaultEncoding;
+
+Document::Document (QObject* parent, const char* name)
+ : KTextEditor::Document (parent, name)
+{
+}
+
+Document::Document () : KTextEditor::Document (0L, "Kate::Document")
+{
+}
+
+Document::~Document ()
+{
+}
+
+void Document::setOpenErrorDialogsActivated (bool on)
+{
+ s_openErrorDialogsActivated = on;
+}
+
+void Document::setFileChangedDialogsActivated (bool on)
+{
+ s_fileChangedDialogsActivated = on;
+}
+
+const QString &Document::defaultEncoding ()
+{
+ return s_defaultEncoding;
+}
+
+bool Document::registerCommand (Command *cmd)
+{
+ return KateCmd::self()->registerCommand (cmd);
+}
+
+bool Document::unregisterCommand (Command *cmd)
+{
+ return KateCmd::self()->unregisterCommand (cmd);
+}
+
+Command *Document::queryCommand (const QString &cmd)
+{
+ return KateCmd::self()->queryCommand (cmd);
+}
+
+View::View ( KTextEditor::Document *doc, QWidget *parent, const char *name ) : KTextEditor::View (doc, parent, name)
+{
+}
+
+View::~View ()
+{
+}
+
+void ConfigPage::slotChanged()
+{
+ emit changed();
+}
+
+DocumentExt::DocumentExt ()
+{
+}
+
+DocumentExt::~DocumentExt ()
+{
+}
+
+Document *document (KTextEditor::Document *doc)
+{
+ if (!doc)
+ return 0;
+
+ return static_cast<Document*>(doc->qt_cast("Kate::Document"));
+}
+
+DocumentExt *documentExt (KTextEditor::Document *doc)
+{
+ if (!doc)
+ return 0;
+
+ return static_cast<DocumentExt*>(doc->qt_cast("Kate::DocumentExt"));
+}
+
+Document *createDocument ( QObject *parent, const char *name )
+{
+ return (Document* ) KTextEditor::createDocument ("libkatepart", parent, name);
+}
+
+View *view (KTextEditor::View *view)
+{
+ if (!view)
+ return 0;
+
+ return static_cast<View*>(view->qt_cast("Kate::View"));
+}
+
+}
diff --git a/kate/interfaces/katecmd.cpp b/kate/interfaces/katecmd.cpp
new file mode 100644
index 000000000..e6a981dd5
--- /dev/null
+++ b/kate/interfaces/katecmd.cpp
@@ -0,0 +1,223 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001, 2003 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "katecmd.h"
+
+#include <kstaticdeleter.h>
+#include <kdebug.h>
+
+//BEGIN KateCmd
+#define CMD_HIST_LENGTH 256
+
+KateCmd *KateCmd::s_self = 0;
+
+KateCmd::KateCmd ()
+{
+}
+
+KateCmd::~KateCmd ()
+{
+}
+
+bool KateCmd::registerCommand (Kate::Command *cmd)
+{
+ QStringList l = cmd->cmds ();
+
+ for (uint z=0; z<l.count(); z++)
+ if (m_dict[l[z]])
+ return false;
+
+ for (uint z=0; z<l.count(); z++) {
+ m_dict.insert (l[z], cmd);
+ kdDebug()<<"Inserted command:"<<l[z]<<endl;
+ }
+
+ m_cmds += l;
+
+ return true;
+}
+
+bool KateCmd::unregisterCommand (Kate::Command *cmd)
+{
+ QStringList l;
+ QDictIterator<Kate::Command> it(m_dict);
+ for( ; it.current(); ++it )
+ if (it.current()==cmd) l<<it.currentKey();
+ for ( QStringList::Iterator it1 = l.begin(); it1 != l.end(); ++it1 ) {
+ m_dict.remove(*it1);
+ kdDebug()<<"Removed command:"<<*it1<<endl;
+ }
+ return true;
+}
+
+Kate::Command *KateCmd::queryCommand (const QString &cmd)
+{
+ // a command can be named ".*[\w\-]+" with the constrain that it must
+ // contain at least one letter.
+ uint f = 0;
+ bool b = false;
+ for ( ; f < cmd.length(); f++ )
+ {
+ if ( cmd[f].isLetter() )
+ b = true;
+ if ( b && ( ! cmd[f].isLetterOrNumber() && cmd[f] != '-' && cmd[f] != '_' ) )
+ break;
+ }
+ return m_dict[cmd.left(f)];
+}
+
+QStringList KateCmd::cmds ()
+{
+ return m_cmds;
+}
+
+static KStaticDeleter<KateCmd> sdCmd;
+
+KateCmd *KateCmd::self ()
+{
+ if (!s_self)
+ sdCmd.setObject(s_self, new KateCmd ());
+
+ return s_self;
+}
+
+void KateCmd::appendHistory( const QString &cmd )
+{
+ if ( !m_history.isEmpty() && m_history.last() == cmd )
+ return;
+
+ if ( m_history.count() == CMD_HIST_LENGTH )
+ m_history.remove( m_history.first() );
+
+ m_history.append( cmd );
+}
+
+const QString KateCmd::fromHistory( uint index ) const
+{
+ if ( index > m_history.count() - 1 )
+ return QString();
+ return m_history[ index ];
+}
+//END KateCmd
+
+//BEGIN KateCmdShellCompletion
+/*
+ A lot of the code in the below class is copied from
+ kdelibs/kio/kio/kshellcompletion.cpp
+ Copyright (C) 2000 David Smith <dsmith@algonet.se>
+ Copyright (C) 2004 Anders Lund <anders@alweb.dk>
+*/
+KateCmdShellCompletion::KateCmdShellCompletion()
+ : KCompletion()
+{
+ m_word_break_char = ' ';
+ m_quote_char1 = '\"';
+ m_quote_char2 = '\'';
+ m_escape_char = '\\';
+}
+
+QString KateCmdShellCompletion::makeCompletion( const QString &text )
+{
+ // Split text at the last unquoted space
+ //
+ splitText(text, m_text_start, m_text_compl);
+
+ // Make completion on the last part of text
+ //
+ return KCompletion::makeCompletion( m_text_compl );
+}
+
+void KateCmdShellCompletion::postProcessMatch( QString *match ) const
+{
+ if ( match->isNull() )
+ return;
+
+ match->prepend( m_text_start );
+}
+
+void KateCmdShellCompletion::postProcessMatches( QStringList *matches ) const
+{
+ for ( QStringList::Iterator it = matches->begin();
+ it != matches->end(); it++ )
+ if ( !(*it).isNull() )
+ (*it).prepend( m_text_start );
+}
+
+void KateCmdShellCompletion::postProcessMatches( KCompletionMatches *matches ) const
+{
+ for ( KCompletionMatches::Iterator it = matches->begin();
+ it != matches->end(); it++ )
+ if ( !(*it).value().isNull() )
+ (*it).value().prepend( m_text_start );
+}
+
+void KateCmdShellCompletion::splitText(const QString &text, QString &text_start,
+ QString &text_compl) const
+{
+ bool in_quote = false;
+ bool escaped = false;
+ QChar p_last_quote_char;
+ int last_unquoted_space = -1;
+ int end_space_len = 0;
+
+ for (uint pos = 0; pos < text.length(); pos++) {
+
+ end_space_len = 0;
+
+ if ( escaped ) {
+ escaped = false;
+ }
+ else if ( in_quote && text[pos] == p_last_quote_char ) {
+ in_quote = false;
+ }
+ else if ( !in_quote && text[pos] == m_quote_char1 ) {
+ p_last_quote_char = m_quote_char1;
+ in_quote = true;
+ }
+ else if ( !in_quote && text[pos] == m_quote_char2 ) {
+ p_last_quote_char = m_quote_char2;
+ in_quote = true;
+ }
+ else if ( text[pos] == m_escape_char ) {
+ escaped = true;
+ }
+ else if ( !in_quote && text[pos] == m_word_break_char ) {
+
+ end_space_len = 1;
+
+ while ( pos+1 < text.length() && text[pos+1] == m_word_break_char ) {
+ end_space_len++;
+ pos++;
+ }
+
+ if ( pos+1 == text.length() )
+ break;
+
+ last_unquoted_space = pos;
+ }
+ }
+
+ text_start = text.left( last_unquoted_space + 1 );
+
+ // the last part without trailing blanks
+ text_compl = text.mid( last_unquoted_space + 1 );
+}
+
+//END KateCmdShellCompletion
+
+
diff --git a/kate/interfaces/katecmd.h b/kate/interfaces/katecmd.h
new file mode 100644
index 000000000..8af9e1f6c
--- /dev/null
+++ b/kate/interfaces/katecmd.h
@@ -0,0 +1,99 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001, 2003 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KATE_CMD_H
+#define _KATE_CMD_H
+
+#include "document.h"
+
+#include <kcompletion.h>
+
+#include <qdict.h>
+#include <qstringlist.h>
+
+class KATEPARTINTERFACES_EXPORT KateCmd
+{
+ private:
+ KateCmd ();
+
+ public:
+ ~KateCmd ();
+
+ static KateCmd *self ();
+
+ bool registerCommand (Kate::Command *cmd);
+ bool unregisterCommand (Kate::Command *cmd);
+ Kate::Command *queryCommand (const QString &cmd);
+
+ QStringList cmds ();
+ void appendHistory( const QString &cmd );
+ const QString fromHistory( uint i ) const;
+ uint historyLength() const { return m_history.count(); }
+
+ private:
+ static KateCmd *s_self;
+ QDict<Kate::Command> m_dict;
+ QStringList m_cmds;
+ QStringList m_history;
+};
+
+/**
+ * A KCompletion object that completes last ?unquoted? word in the string
+ * passed. Dont mistake "shell" for anything related to quoting, this
+ * simply mimics shell tab completion by completing the last word in the
+ * provided text.
+ */
+class KATEPARTINTERFACES_EXPORT KateCmdShellCompletion : public KCompletion
+{
+ public:
+ KateCmdShellCompletion();
+
+ /**
+ * Finds completions to the given text.
+ * The first match is returned and emitted in the signal match().
+ * @param text the text to complete
+ * @return the first match, or QString::null if not found
+ */
+ QString makeCompletion(const QString &text);
+
+ protected:
+ // Called by KCompletion
+ void postProcessMatch( QString *match ) const;
+ void postProcessMatches( QStringList *matches ) const;
+ void postProcessMatches( KCompletionMatches *matches ) const;
+
+ private:
+ /**
+ * Split text at the last unquoted space
+ *
+ * @param text_start will be set to the text at the left, including the space
+ * @param text_compl Will be set to the text at the right. This is the text to complete.
+ */
+ void splitText( const QString &text, QString &text_start, QString &text_compl ) const;
+
+ QChar m_word_break_char;
+ QChar m_quote_char1;
+ QChar m_quote_char2;
+ QChar m_escape_char;
+
+ QString m_text_start;
+ QString m_text_compl;
+
+};
+
+#endif
diff --git a/kate/interfaces/view.h b/kate/interfaces/view.h
new file mode 100644
index 000000000..98290039e
--- /dev/null
+++ b/kate/interfaces/view.h
@@ -0,0 +1,303 @@
+/* This file is part of the KDE libraries
+ Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License version 2 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _KATE_VIEW_INCLUDE_
+#define _KATE_VIEW_INCLUDE_
+
+#include <ktexteditor/document.h>
+#include <ktexteditor/view.h>
+#include <ktexteditor/clipboardinterface.h>
+#include <ktexteditor/popupmenuinterface.h>
+#include <ktexteditor/markinterface.h>
+#include <ktexteditor/viewcursorinterface.h>
+#include <ktexteditor/codecompletioninterface.h>
+#include <ktexteditor/dynwordwrapinterface.h>
+
+class KConfig;
+
+namespace Kate
+{
+
+class Document;
+
+/**
+ The Kate::View text editor interface.
+ @author Cullmann Christoph, modified by rokrau (6/21/01)
+*/
+class KATEPARTINTERFACES_EXPORT View : public KTextEditor::View, public KTextEditor::ClipboardInterface,
+ public KTextEditor::PopupMenuInterface, public KTextEditor::ViewCursorInterface,
+ public KTextEditor::CodeCompletionInterface, public KTextEditor::DynWordWrapInterface
+{
+ Q_OBJECT
+
+ public:
+ /**
+ Return values for "save" related commands.
+ */
+ enum saveResult { SAVE_OK, SAVE_CANCEL, SAVE_RETRY, SAVE_ERROR };
+ /**
+ Constructor (should much rather take a reference to the document).
+ */
+ View ( KTextEditor::Document *, QWidget *, const char *name = 0 );
+ /**
+ Destructor, you need a destructor if Scott Meyers says so.
+ */
+ virtual ~View ();
+ /**
+ Set editor mode
+ */
+ virtual bool isOverwriteMode() const { return false; }
+ /**
+ Get editor mode
+ */
+ virtual void setOverwriteMode( bool ) { }
+ /**
+ Gets the text line where the cursor is on
+ */
+ virtual QString currentTextLine() { return 0L; }
+ /**
+ Gets the word where the cursor is on
+ */
+ virtual QString currentWord() { return 0L; }
+ /**
+ Gets the word at position x, y. Can be used to find
+ the word under the mouse cursor
+ */
+ virtual QString word(int , int ) { return 0L; }
+ /**
+ Insert text at the current cursor position.
+ @param mark is unused.
+ */
+ virtual void insertText(const QString &mark ) { Q_UNUSED(mark); }
+ /**
+ Works exactly like closeURL() of KParts::ReadWritePart
+ */
+ virtual bool canDiscard() { return false; }
+
+ public:
+ virtual int tabWidth() = 0;
+ virtual void setTabWidth(int) = 0;
+ virtual void setEncoding (QString e) = 0;
+
+ /**
+ Returns true if this editor is the only owner of its document
+ */
+ virtual bool isLastView() = 0;
+
+ public slots:
+ /**
+ Flushes the document of the text widget. The user is given
+ a chance to save the current document if the current document has
+ been modified.
+ */
+ virtual void flush () { ; };
+ /**
+ Saves the file under the current file name. If the current file
+ name is Untitled, as it is after a call to newFile(), this routine will
+ call saveAs().
+ */
+ virtual saveResult save() { return SAVE_CANCEL; };
+ /**
+ Allows the user to save the file under a new name.
+ */
+ virtual saveResult saveAs() { return SAVE_CANCEL; };
+ /**
+ Moves the current line or the selection one position to the right.
+ */
+ virtual void indent() { ; };
+ /**
+ Moves the current line or the selection one position to the left.
+ */
+ virtual void unIndent() { ; };
+ /**
+ Optimizes the selected indentation, replacing tabs and spaces as needed.
+ */
+ virtual void cleanIndent() { ; };
+ /**
+ Comments out current line.
+ */
+ virtual void comment() { ; };
+ /**
+ Removes comment signs in the current line.
+ */
+ virtual void uncomment() { ; };
+ /**
+ Some simply key commands.
+ */
+ virtual void keyReturn () { ; };
+ virtual void keyDelete () { ; };
+ virtual void backspace () { ; };
+ virtual void killLine () { ; };
+ /**
+ Move cursor in the view
+ */
+ virtual void cursorLeft () { ; };
+ virtual void shiftCursorLeft () { ; };
+ virtual void cursorRight () { ; };
+ virtual void shiftCursorRight () { ; };
+ virtual void wordLeft () { ; };
+ virtual void shiftWordLeft () { ; };
+ virtual void wordRight () { ; };
+ virtual void shiftWordRight () { ; };
+ virtual void home () { ; };
+ virtual void shiftHome () { ; };
+ virtual void end () { ; };
+ virtual void shiftEnd () { ; };
+ virtual void up () { ; };
+ virtual void shiftUp () { ; };
+ virtual void down () { ; };
+ virtual void shiftDown () { ; };
+ virtual void scrollUp () { ; };
+ virtual void scrollDown () { ; };
+ virtual void topOfView () { ; };
+ virtual void bottomOfView () { ; };
+ virtual void pageUp () { ; };
+ virtual void shiftPageUp () { ; };
+ virtual void pageDown () { ; };
+ virtual void shiftPageDown () { ; };
+ virtual void top () { ; };
+ virtual void shiftTop () { ; };
+ virtual void bottom () { ; };
+ virtual void shiftBottom () { ; };
+ /**
+ Presents a search dialog to the user.
+ */
+ virtual void find() { ; };
+ /**
+ Presents a replace dialog to the user.
+ */
+ virtual void replace() { ; };
+ /**
+ Presents a "Goto Line" dialog to the user.
+ */
+ virtual void gotoLine() { ; };
+
+ public:
+ /**
+ Reads session config out of the KConfig object. This also includes
+ the actual cursor position and the bookmarks.
+ */
+ virtual void readSessionConfig(KConfig *) { ; };
+ /**
+ Writes session config into the KConfig object.
+ */
+ virtual void writeSessionConfig(KConfig *) { ; };
+
+ public slots:
+ /**
+ Get the end of line mode (Unix, Macintosh or Dos).
+ */
+ virtual int getEol() { return 0L; }
+ /**
+ Set the end of line mode (Unix, Macintosh or Dos).
+ */
+ virtual void setEol(int) { }
+ /**
+ Set focus to the current window.
+ */
+ // Should remove this, it's redundant.
+ virtual void setFocus () { QWidget::setFocus(); }
+ /**
+ Searches for the last searched text forward from cursor position.
+ @param forward determines the search direction.
+ */
+ virtual void findAgain(bool forward ) { Q_UNUSED(forward); }
+ /**
+ Searches for the last searched text forward from cursor position.
+ Searches forward from current cursor position.
+ */
+ virtual void findAgain () { };
+ /**
+ Searches for the last searched text forward from cursor position.
+ Searches backward from current cursor position.
+ */
+ virtual void findPrev () { }
+ /**
+ Presents an edit command popup window, where the user can
+ apply a shell command to the contents of the current window.
+ */
+ virtual void slotEditCommand () { }
+
+ /**
+ Sets icon border on or off depending on
+ @param enable the flag
+ */
+ virtual void setIconBorder (bool enable ) { Q_UNUSED(enable); }
+ /**
+ Toggles icon border.
+ */
+ virtual void toggleIconBorder () { }
+ /**
+ Sets display of line numbers on/off depending on @p enable
+ @param enable the flag
+ */
+ virtual void setLineNumbersOn (bool enable) { Q_UNUSED(enable); }
+ /**
+ Toggles display of lineNumbers
+ */
+ virtual void toggleLineNumbersOn () {}
+
+ public:
+ /**
+ Returns whether iconborder is visible.
+ */
+ virtual bool iconBorder() { return false; }
+ /**
+ @return Wheather line numbers display is on
+ */
+ virtual bool lineNumbersOn() { return false; }
+ /**
+ Returns a pointer to the document of the view.
+ */
+ virtual Document *getDoc () { return 0L; }
+
+ public slots:
+ /**
+ Increase font size.
+ */
+ virtual void slotIncFontSizes () { }
+ /**
+ Decrease font size.
+ */
+ virtual void slotDecFontSizes () { }
+
+ virtual void gotoMark (KTextEditor::Mark *mark) = 0;
+
+ /**
+ * @deprecated No longer does anything. Use KTextEditor
+ * equivalents
+ */
+ // TODO: Remove when BIC is allowed
+ virtual void toggleBookmark () {}
+
+ virtual void gotoLineNumber( int ) = 0;
+
+ signals:
+ void gotFocus (View *);
+// void newStatus(); // Kate app connects to this signal, should be in the interface
+
+ public:
+ virtual void setActive (bool b) = 0;
+ virtual bool isActive () = 0;
+};
+
+KATEPARTINTERFACES_EXPORT View *view (KTextEditor::View *view);
+
+}
+
+#endif