[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Bugfix: new interface KTextEditor::EditInterfaceExt
From:       Hamish Rodda <rodda () kde ! org>
Date:       2003-11-11 12:46:49
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Quanta and Kile have been having problems with integrating katepart because 
they need to do multiple step editing actions so that 1) they are integrated
into one undo step and 2) there is no text view flicker inbetween.

Thus, I have come up with a very simple KTextEditor interface to allow them to
merge their edit actions into one.  There has long been talk of doing this, 
but up until now nobody has done so.  It is only because of a recently 
recognized, definite, bugfixing-only need in Quanta (namely within the Kafka 
VPL editor) (and secondarily, I hear that Kile needs this too) that I am 
proposing this very simple extension to KTextEditor be included in KDE 3.2.

The only thing this extension does is expose well-known and thoroughly tested 
existing code within Kate, and so long as the application using it does not 
violate the terms of the api (that is, return to the event loop in between 
calling editStart() and editEnd()), I cannot forsee any bugs being introduced 
by this new API.  Editor parts which do not support the new API will simply 
act as before; Quanta and Kile only embed Katepart anyway, as far as I know.

This has been reviewed and given the thumbs up by the following people on 
kwrite-devel and quanta-devel:

Joseph Wenninger
Andras Mantia
Jeroen Wijnhout
Christoph Cullmann (personal communication)

Should this change be rejected (and I have no stake in it either way, really, 
it's more Quanta's problem), I think it is possible to come up with a 
sub-optimal solution within kate, but I'm not certain of that yet.

Other than answering technical questions, I'll now shut up and let the 
Quanta / Kile guys do the arguing about whether this gets included :)

Thanks for your consideration,

Hamish.

PS. should you want to see this in action, Quanta has the appropriate support 
#ifdef'd out; apply the patch in kdelibs/kate/part and add the interface 
files to kdelibs/interfaces/ktexteditor.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/sNo5H8BtnSmIlUYRAlIlAKDP7JNwf11/IlYc4EEOiiEXr9B/nACgy4TQ
rxRLRijwzzvhQgZWr5XmYQk=
=T05/
-----END PGP SIGNATURE-----

["editinterfaceext.cpp" (text/x-c++src)]

#include "editinterfaceext.h"
#include "document.h"

using namespace KTextEditor;

uint EditInterfaceExt::globalEditInterfaceExtNumber = 0;

EditInterfaceExt::EditInterfaceExt()
	: d(0L)
{
  globalEditInterfaceExtNumber++;
  myEditInterfaceExtNumber = globalEditInterfaceExtNumber;
}

EditInterfaceExt::~EditInterfaceExt()
{
}

uint EditInterfaceExt::editInterfaceExtNumber() const
{
  return myEditInterfaceExtNumber;
}

EditInterfaceExt *KTextEditor::editInterfaceExt (Document *doc)
{
  if (!doc)
    return 0;

  return static_cast<EditInterfaceExt*>(doc->qt_cast("KTextEditor::EditInterfaceExt"));
}


["editinterfaceext.h" (text/x-chdr)]

/* This file is part of the KDE libraries
   Copyright (C) 2003 Hamish Rodda <rodda@kde.org>
   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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#ifndef __ktexteditor_editinterfaceext_h__
#define __ktexteditor_editinterfaceext_h__

#include <qstring.h>

namespace KTextEditor
{

/**
* This is the main interface for accessing and modifying
* text of the Document class.
*/
class EditInterfaceExt
{
  friend class PrivateEditInterfaceExt;

  public:
    EditInterfaceExt();
    virtual ~EditInterfaceExt();

    uint editInterfaceExtNumber() const;

    /**
	 * Begin an editing sequence.  Edit commands during this sequence will be
	 * bunched together such that they represent a single undo command in the
	 * editor, and so that repaint events do not occur inbetween.
	 *
	 * Your application should not return control to the event loop while it
	 * has an unterminated (no matching editEnd() call) editing sequence
	 * (result undefined) - so do all of your work in one go...
	 */
    virtual void editBegin() = 0;

	/**
	 * End and editing sequence.
	 */
    virtual void editEnd() = 0;

  public:
  /**
  * only for the interface itself - REAL PRIVATE
  */
  private:
    class PrivateEditInterfaceExt *d;
    static uint globalEditInterfaceExtNumber;
    uint myEditInterfaceExtNumber;
};

EditInterfaceExt *editInterfaceExt (class Document *doc);

}

#endif

["kate-20031102.patch" (text/x-diff)]

Index: katedocument.h
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katedocument.h,v
retrieving revision 1.247
diff -u -3 -p -r1.247 katedocument.h
--- katedocument.h	17 Oct 2003 22:41:35 -0000	1.247
+++ katedocument.h	1 Nov 2003 15:19:50 -0000
@@ -29,6 +29,7 @@
 #include <ktexteditor/configinterfaceextension.h>
 #include <ktexteditor/encodinginterface.h>
 #include <ktexteditor/sessionconfiginterface.h>
+#include <ktexteditor/editinterfaceext.h>

 #include <kservice.h>
 #include <dcopobject.h>
@@ -79,7 +80,9 @@ namespace Kate
 //
 class KateDocument : public Kate::Document,
                      public KTextEditor::ConfigInterfaceExtension,
-                     public KTextEditor::EncodingInterface, public KTextEditor::SessionConfigInterface,
+                     public KTextEditor::EncodingInterface,
+                     public KTextEditor::SessionConfigInterface,
+                     public KTextEditor::EditInterfaceExt,
                      public DCOPObject
 {
   K_DCOP
@@ -179,8 +182,9 @@ class KateDocument : public Kate::Docume
     //
     // start edit / end edit (start/end undo, cursor update, view update)
     //
-    void editStart (bool withUndo = true);
-    void editEnd ();
+    virtual void editBegin() { editStart(); }
+    void editStart(bool withUndo = true);
+    virtual void editEnd();

     //
     // functions for insert/remove stuff (atomic)
@@ -287,7 +291,7 @@ class KateDocument : public Kate::Docume
     bool lineIsSelection (int line);

     QPtrList<KateSuperCursor> m_superCursors;
-
+
     // stores the current selection
     KateSuperCursor selectStart;
     KateSuperCursor selectEnd;
@@ -447,7 +451,7 @@ class KateDocument : public Kate::Docume
   //
   public:
     bool openURL( const KURL &url );
-
+
     /* Anders:
       I reimplemented this, since i need to check if backup succeeded
       if requested */
@@ -455,17 +459,17 @@ class KateDocument : public Kate::Docume

     bool openFile (KIO::Job * job);
     bool openFile ();
-
+
     bool saveFile ();

     void setReadWrite ( bool rw = true );

     void setModified( bool m );
-
+
   private slots:
     void slotDataKate ( KIO::Job* kio_job, const QByteArray &data );
     void slotFinishedKate ( KIO::Job * job );
-
+
   private:
     void abortLoadKate();

@@ -509,8 +513,8 @@ class KateDocument : public Kate::Docume

     // Repaint all of all of the views
     void repaintViews(bool paintOnlyDirty = true);
-
-    Highlight *highlight () { return m_highlight; }
+
+    Highlight *highlight () { return m_highlight; }

   public slots:    //please keep prototypes and implementations in same order
     void tagLines(int start, int end);
@@ -755,7 +759,7 @@ class KateDocument : public Kate::Docume

   private:
     void makeAttribs ();
-
+
     void locatePosition( uint pos, uint& line, uint& col );
     KSpell*         m_kspell;
     int             m_mispellCount;
@@ -764,7 +768,7 @@ class KateDocument : public Kate::Docume

   public:
     static bool checkOverwrite( KURL u );
-
+
     static void setDefaultEncoding (const QString &encoding);

   /**
@@ -818,10 +822,10 @@ class KateDocument : public Kate::Docume

     static QRegExp kvLine;
     static QRegExp kvVar;
-
+
     KIO::TransferJob *m_job;
     KTempFile *m_tempFile;
-
+
   k_dcop:
     uint documentNumber () const;



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic