home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kate / document.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  12.4 KB  |  408 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18.  
  19. #ifndef _KATE_DOCUMENT_INCLUDE_
  20. #define _KATE_DOCUMENT_INCLUDE_
  21.  
  22. #include <ktexteditor/document.h>
  23. #include <ktexteditor/view.h>
  24. #include <ktexteditor/editinterface.h>
  25. #include <ktexteditor/undointerface.h>
  26. #include <ktexteditor/cursorinterface.h>
  27. #include <ktexteditor/documentinfo.h>
  28. #include <ktexteditor/selectioninterface.h>
  29. #include <ktexteditor/selectioninterfaceext.h>
  30. #include <ktexteditor/blockselectioninterface.h>
  31. #include <ktexteditor/searchinterface.h>
  32. #include <ktexteditor/highlightinginterface.h>
  33. #include <ktexteditor/configinterface.h>
  34. #include <ktexteditor/configinterfaceextension.h>
  35. #include <ktexteditor/markinterface.h>
  36. #include <ktexteditor/markinterfaceextension.h>
  37. #include <ktexteditor/wordwrapinterface.h>
  38. #include <ktexteditor/printinterface.h>
  39. #include <ktexteditor/variableinterface.h>
  40.  
  41. #include <kaction.h>
  42.  
  43. class KCompletion;
  44.  
  45. /**
  46.  * Kate namespace
  47.  * All classes in this namespace must stay BC
  48.  * during one major release series (e.g. 3.x, 4.x, ...)
  49.  */
  50. namespace Kate
  51. {
  52.  
  53. class View;
  54.  
  55. class KATEPARTINTERFACES_EXPORT Cursor : public KTextEditor::Cursor
  56. {
  57.   public:
  58.     Cursor () { ; };
  59.     virtual ~Cursor () { ; };
  60. };
  61.  
  62. class KATEPARTINTERFACES_EXPORT ConfigPage : public KTextEditor::ConfigPage
  63. {
  64.   Q_OBJECT
  65.  
  66.   public:
  67.     ConfigPage ( QWidget *parent=0, const char *name=0 ) : KTextEditor::ConfigPage (parent, name) { ; };
  68.     virtual ~ConfigPage () { ; };
  69.  
  70.   public slots:
  71.     virtual void apply () { ; };
  72.     virtual void reload () { ; };
  73.     virtual void reset () {};
  74.     virtual void defaults () {};
  75.  
  76.   protected slots:
  77.     void slotChanged();
  78. };
  79.  
  80. class KATEPARTINTERFACES_EXPORT ActionMenu : public KActionMenu
  81. {
  82.   Q_OBJECT
  83.  
  84.   public:
  85.     ActionMenu ( const QString& text, QObject* parent = 0, const char* name = 0 )
  86.       : KActionMenu(text, parent, name) { ; };
  87.     virtual ~ActionMenu () { ; };
  88.  
  89.   public:
  90.     virtual void updateMenu (class Document *) = 0;
  91. };
  92.  
  93. /**
  94.  * Kate Commands
  95.  */
  96. class KATEPARTINTERFACES_EXPORT Command
  97. {
  98.   public:
  99.     Command () {};
  100.     virtual ~Command () {};
  101.  
  102.   public:
  103.     /**
  104.      * Pure text start part of the commands which can be handled by this object
  105.      * which means i.e. for s/sdl/sdf/g => s or for char:1212 => char
  106.      */
  107.     virtual QStringList cmds () = 0;
  108.  
  109.     /**
  110.      * Execute this command for the given view and cmd string, return a bool
  111.      * about success, msg for status
  112.      */
  113.     virtual bool exec (View *view, const QString &cmd, QString &msg) = 0;
  114.  
  115.     /**
  116.      * Shows help for the given view and cmd string, return a bool
  117.      * about success, msg for status
  118.      */
  119.     virtual bool help (View *view, const QString &cmd, QString &msg) = 0;
  120. };
  121.  
  122. /**
  123.  * Extension to the Command interface, allowing to interact with commands
  124.  * during typing. This allows for completion and for example the isearch
  125.  * plugin. If you develop a command that wants to complete or process text
  126.  * as thu user types the arguments, or that has flags, you can have
  127.  * your command inherit this class.
  128.  */
  129. class CommandExtension
  130. {
  131.   public:
  132.     CommandExtension() {;}
  133.     virtual ~CommandExtension() {;}
  134.  
  135.     /**
  136.      * Fill in a list of flags to complete from. Each flag is a single letter,
  137.      * any following text in the string is taken to be a description of the
  138.      * flag's meaning, and showed to the user as a hint.
  139.      * Implement this method if your command has flags.
  140.      *
  141.      * This method is called each time the flag string in the typed command
  142.      * is changed, so that the available flags can be adjusted. When completions
  143.      * are displayed, existing flags are left out.
  144.      *
  145.      */ //### this is yet to be tried
  146.     virtual void flagCompletions( QStringList& /*list*/ ) {;}
  147.  
  148.     /**
  149.      * @return a KCompletion object that will substitute the command line default
  150.      * one while typing the first argument to the command. The text will be
  151.      * added to the command seperated by one space character.
  152.      *
  153.      * Implement this method if your command can provide a completion object.
  154.      *
  155.      * @param cmdname The command name associated with this request.
  156.      */
  157.     virtual KCompletion *completionObject( const QString & cmdname, Kate::View * /*view*/ ) { Q_UNUSED(cmdname); return 0L; }
  158.  
  159.     /**
  160.      * @return whether this command wants to process text interactively given the @p cmdname.
  161.      * If true, the command's processText() method is called when the
  162.      * text in the command line is changed.
  163.      *
  164.      * Reimplement this to return true, if your commands wants to process the
  165.      * text as typed.
  166.      *
  167.      * @param cmdname the command name associated with this query.
  168.      */
  169.     virtual bool wantsToProcessText( const QString &cmdname ) { Q_UNUSED(cmdname); return false; }
  170.  
  171.     /**
  172.      * This is called by the commandline each time the argument text for the
  173.      * command changes, if wantsToProcessText() returns true.
  174.      * @param view The current view
  175.      * @param text The current command text typed by the user.
  176.      */ // ### yet to be tested. The obvious candidate is isearch.
  177.     virtual void processText( Kate::View *view, const QString &text ) { Q_UNUSED(view); Q_UNUSED(text); }
  178. };
  179.  
  180. /** This interface provides access to the Kate Document class.
  181. */
  182. class KATEPARTINTERFACES_EXPORT Document : public KTextEditor::Document, public KTextEditor::EditInterface,
  183.                      public KTextEditor::UndoInterface, public KTextEditor::CursorInterface,
  184.                      public KTextEditor::SelectionInterface, public KTextEditor::SearchInterface,
  185.                      public KTextEditor::HighlightingInterface, public KTextEditor::BlockSelectionInterface,
  186.                      public KTextEditor::ConfigInterface, public KTextEditor::MarkInterface,
  187.                      public KTextEditor::PrintInterface, public KTextEditor::WordWrapInterface,
  188.                      public KTextEditor::MarkInterfaceExtension,
  189.                      public KTextEditor::SelectionInterfaceExt
  190. {
  191.   Q_OBJECT
  192.  
  193.   public:
  194.     Document ();
  195.     Document ( QObject* parent, const char* name );
  196.     virtual ~Document ();
  197.  
  198.   /**
  199.    * Commands handling
  200.    */
  201.   public:
  202.     static bool registerCommand (Command *cmd);
  203.     static bool unregisterCommand (Command *cmd);
  204.     static Command *queryCommand (const QString &cmd);
  205.  
  206.   public:
  207.     /**
  208.      * deprecated for KDE 4.0, just does reloadFile, which will ask
  209.      * the normal "do you want it really" questions
  210.      * @deprecated
  211.      */
  212.     virtual void isModOnHD(bool =false) { ; };
  213.  
  214.     /**
  215.      * Returns the document name.
  216.      */
  217.     virtual QString docName () { return 0L; };
  218.  
  219.     /**
  220.      * Sets the document name.
  221.      * deprecated for KDE 4.0, is done internally, calling it won't hurt
  222.      * but changes nothing beside triggers signal
  223.      * @deprecated
  224.      */
  225.     virtual void setDocName (QString ) { ; };
  226.  
  227.     virtual ActionMenu *hlActionMenu (const QString& , QObject* =0, const char* = 0) = 0;
  228.     virtual ActionMenu *exportActionMenu (const QString& , QObject* =0, const char* = 0) = 0;
  229.  
  230.   public slots:
  231.     // clear buffer/filename - update the views
  232.     virtual void flush () { ; };
  233.  
  234.     /**
  235.      * Reloads the current document from disk if possible
  236.      */
  237.     virtual void reloadFile() = 0;
  238.  
  239.     /**
  240.      * Spellchecking
  241.      */
  242.     virtual void spellcheck() {};
  243.  
  244.     virtual void exportAs(const QString &) = 0;
  245.  
  246.     virtual void applyWordWrap () = 0;
  247.  
  248.  
  249.   public:
  250.     virtual void setWordWrap (bool ) = 0;
  251.     virtual bool wordWrap () = 0;
  252.  
  253.     virtual void setWordWrapAt (unsigned int) = 0;
  254.     virtual uint wordWrapAt () = 0;
  255.  
  256.  
  257.     virtual void setEncoding (const QString &e) = 0;
  258.     virtual QString encoding() const = 0;
  259.  
  260.   /** @deprecated */
  261.   // FIXME: Remove when BIC allowed.
  262.   public:
  263.     /** @deprecated */
  264.     virtual ConfigPage *colorConfigPage (QWidget *) = 0;
  265.     /** @deprecated */
  266.     virtual ConfigPage *fontConfigPage (QWidget *) = 0;
  267.     /** @deprecated */
  268.     virtual ConfigPage *indentConfigPage (QWidget *) = 0;
  269.     /** @deprecated */
  270.     virtual ConfigPage *selectConfigPage (QWidget *) = 0;
  271.     /** @deprecated */
  272.     virtual ConfigPage *editConfigPage (QWidget *) = 0;
  273.     /** @deprecated */
  274.     virtual ConfigPage *keysConfigPage (QWidget *) = 0;
  275.     /** @deprecated */
  276.     virtual ConfigPage *kSpellConfigPage (QWidget *) { return 0L; }
  277.     /** @deprecated */
  278.     virtual ConfigPage *hlConfigPage (QWidget *) = 0;
  279.  
  280.   public:
  281.     virtual uint configFlags () = 0;
  282.     virtual void setConfigFlags (uint flags) = 0;
  283.  
  284.     // Flags for katedocument config !
  285.     enum ConfigFlags
  286.     {
  287.       cfAutoIndent= 0x1,
  288.       cfBackspaceIndents= 0x2,
  289.       cfWordWrap= 0x4,
  290.       cfReplaceTabs= 0x8,
  291.       cfRemoveSpaces = 0x10,
  292.       cfWrapCursor= 0x20,
  293.       cfAutoBrackets= 0x40,
  294.       cfPersistent= 0x80,
  295.       cfKeepSelection= 0x100,
  296.       cfDelOnInput= 0x400,
  297.       cfXorSelect= 0x800,
  298.       cfOvr= 0x1000,
  299.       cfMark= 0x2000,
  300.       cfKeepIndentProfile= 0x8000,
  301.       cfKeepExtraSpaces= 0x10000,
  302.       cfTabIndents= 0x80000,
  303.       cfShowTabs= 0x200000,
  304.       cfSpaceIndent= 0x400000,
  305.       cfSmartHome = 0x800000
  306.     };
  307.  
  308.   signals:
  309.     /**
  310.      * Indicate this file is modified on disk
  311.      * @param doc the Kate::Document object that represents the file on disk
  312.      * @param isModified indicates the file was modified rather than created or deleted
  313.      * @param reason the reason we are emitting the signal.
  314.      * @li 0  - nothing
  315.      * @li 1 - dirty
  316.      * @li 2 - created
  317.      * @li 3 - deleted
  318.      */
  319.     void modifiedOnDisc (Kate::Document *doc, bool isModified, unsigned char reason);
  320.  
  321.   /*
  322.    * there static methodes are usefull to turn on/off the dialogs
  323.    * kate part shows up on open file errors + file changed warnings
  324.    * open file errors default on, file changed warnings default off, better
  325.    * for other apps beside kate app using the part
  326.    */
  327.   public:
  328.     // default true
  329.     static void setOpenErrorDialogsActivated (bool on);
  330.  
  331.     // default false
  332.     static void setFileChangedDialogsActivated (bool on);
  333.  
  334.     static const QString &defaultEncoding ();
  335.  
  336.   protected:
  337.     static bool s_openErrorDialogsActivated;
  338.     static bool s_fileChangedDialogsActivated;
  339.  
  340.     static QString s_defaultEncoding;
  341. };
  342.  
  343. /**
  344.  * Extensions to the Document Interface
  345.  * @since 3.3
  346.  */
  347. class KATEPARTINTERFACES_EXPORT DocumentExt
  348.  : public KTextEditor::DocumentInfoInterface,
  349.    public KTextEditor::VariableInterface
  350. {
  351.   public:
  352.     DocumentExt ();
  353.     virtual ~DocumentExt ();
  354.  
  355.   public:
  356.     /**
  357.      * Reasons why a document is modified on disk.
  358.      */
  359.     enum ModifiedOnDiskReason {
  360.       Unmodified = 0, ///< Not modified
  361.       Modified = 1,   ///< The file was modified by another program
  362.       Created = 2,    ///< The file was created by another program
  363.       Deleted = 3     ///< The file was deleted
  364.     };
  365.  
  366.   public:
  367.     /**
  368.      * For client apps that want to deal with files modified on disk, it is
  369.      * nessecary to reset this property.
  370.      * @p reason is a ModifiedOnDiskReason.
  371.      */
  372.     virtual void setModifiedOnDisk( int reason ) = 0;
  373.  
  374.   /**
  375.    * These stuff is implemented as slots in the real document
  376.    */
  377.   public:
  378.     /**
  379.      * Ask the user what to do, if the file is modified on disk.
  380.      * The @p v argument is used to avoid asking again, when the
  381.      * editor regains focus after the dialog is hidden.
  382.      */
  383.     virtual void slotModifiedOnDisk( View *v=0 ) = 0;
  384. };
  385.  
  386. /**
  387.  * Check if given document is a Kate::Document
  388.  * @param doc KTextEditor document
  389.  * @return 0 if no success, else the Kate::Document
  390.  */
  391. KATEPARTINTERFACES_EXPORT Document *document (KTextEditor::Document *doc);
  392.  
  393. /**
  394.  * Check if given document is a Kate::DocumentExt
  395.  * @param doc KTextEditor document
  396.  * @return 0 if no success, else the Kate::DocumentExt
  397.  */
  398. KATEPARTINTERFACES_EXPORT DocumentExt *documentExt (KTextEditor::Document *doc);
  399.  
  400. /**
  401.  * Creates a new Kate::Document object
  402.  */
  403. KATEPARTINTERFACES_EXPORT Document *createDocument ( QObject *parent = 0, const char *name = 0 );
  404.  
  405. }
  406.  
  407. #endif
  408.