File indexing completed on 2024-04-28 04:37:31

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Alexander Dymo <adymo@kdevelop.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_SUBLIMEDOCUMENT_H
0008 #define KDEVPLATFORM_SUBLIMEDOCUMENT_H
0009 
0010 #include <QObject>
0011 #include <QList>
0012 
0013 
0014 #include "sublimeexport.h"
0015 
0016 class QIcon;
0017 
0018 class QWidget;
0019 
0020 namespace Sublime {
0021 
0022 class Area;
0023 class View;
0024 class Controller;
0025 class DocumentPrivate;
0026 
0027 /**
0028 @short Abstract base class for all Sublime documents
0029 
0030 Subclass from Document and implement createViewWidget() method
0031 to return a new widget for a view.
0032 */
0033 class KDEVPLATFORMSUBLIME_EXPORT Document: public QObject {
0034     Q_OBJECT
0035 public:
0036     /**Creates a document and adds it to a @p controller.*/
0037     Document(const QString &title, Controller *controller);
0038     ~Document() override;
0039 
0040     /**@return the new view for this document.
0041     @note it will not create a widget, just return a view object.*/
0042     View *createView();
0043     /**@return the list of all views in all areas for this document.*/
0044     const QList<View*> &views() const;
0045 
0046     /**@return the controller for this document.*/
0047     Controller *controller() const;
0048 
0049     enum TitleType { Normal, Extended};
0050     /**@return the document title.*/
0051     virtual QString title(TitleType type = Normal) const;
0052     /**Set the document title.*/
0053     void setTitle(const QString& newTitle);
0054     void setToolTip(const QString& newToolTip);
0055     QString toolTip() const;
0056     /**@return the type of document which can be written to config.*/
0057     virtual QString documentType() const = 0;
0058 
0059     /**@return the specifics of this document which can be written to config.*/
0060     virtual QString documentSpecifier() const = 0;
0061 
0062     /**
0063      * If the document is in a state where data may be lost while closing,
0064      * asks the user whether he really wants to close the document.
0065      * 
0066      * This function may also take actions like saving the document before closing
0067      * if the user desires so.
0068      * 
0069      * @return true if the document is allowed to be closed, otherwise false.
0070      *
0071      * The default implementation always returns true.
0072      *
0073      * */
0074     virtual bool askForCloseFeedback();
0075     
0076     /**Should try closing the document, eventually asking the user for feedback.
0077       *
0078       *If closing is successful, all views should be deleted, and the document itself
0079       *be scheduled for deletion using deleteLater().
0080       *
0081       * @param silent If this is true, the user must not be asked.
0082       * 
0083       * Returns whether closing was successful (The user did not push 'Cancel') */
0084     virtual bool closeDocument(bool silent = false);
0085 
0086     void setStatusIcon(const QIcon& icon);
0087 
0088     /**
0089      * @return The status icon of the document.
0090      */
0091     QIcon statusIcon() const;
0092 
0093     /**
0094      * @return The status icon of the document, or, if none is present, an icon
0095      *         that resembles the document, i.e. based on its mime type.
0096      * @see defaultIcon()
0097      */
0098     QIcon icon() const;
0099 
0100     /**
0101      * Optionally override this to return a default icon when no status
0102      * icon is set for the document. The default returns an invalid icon.
0103      */
0104     virtual QIcon defaultIcon() const;
0105 
0106 Q_SIGNALS:
0107     /**Emitted when the document is about to be deleted but is still in valid state.*/
0108     void aboutToDelete(Sublime::Document *doc);
0109     /**Emitted when the document's title is changed.*/
0110     void titleChanged(Sublime::Document *doc);
0111    /**Emitted when the document status-icon has changed */
0112     void statusIconChanged(Sublime::Document *doc);
0113 
0114 protected:
0115     /**Creates and returns the new view. Reimplement in subclasses to instantiate
0116     views of derived from Sublime::View classes.*/
0117     virtual View *newView(Document *doc);
0118     /**Reimplement this to create and return the new widget to display
0119     this document in the view. This method is used by View class when it
0120     is asked for its widget.*/
0121     virtual QWidget *createViewWidget(QWidget *parent = nullptr) = 0;
0122     /** Closes all views associated to this document */
0123     virtual void closeViews();
0124 
0125 private:
0126     const QScopedPointer<class DocumentPrivate> d_ptr;
0127     Q_DECLARE_PRIVATE(Document)
0128 
0129     friend class DocumentPrivate;
0130     friend class View;
0131 };
0132 
0133 }
0134 
0135 #endif
0136