/usr/include/ktexteditor/smartinterface.h is in kdelibs5-dev 4:4.14.16-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | /* This file is part of the KDE project
Copyright (C) 2005 Hamish Rodda <rodda@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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 KDELIBS_KTEXTEDITOR_SMARTINTERFACE_H
#define KDELIBS_KTEXTEDITOR_SMARTINTERFACE_H
#include <ktexteditor/ktexteditor_export.h>
#include <ktexteditor/smartrange.h>
class QMutex;
namespace KTextEditor
{
class Document;
class View;
class SmartCursor;
/**
* \brief A Document extension interface for handling SmartCursor%s and SmartRange%s.
*
* \ingroup kte_group_doc_extensions
*
* Topics:
* - \ref smartiface_intro
* - \ref smartiface_creation
* - \ref smartiface_highlight
* - \ref smartiface_action
* - \ref smartiface_access
*
* \section smartiface_intro Introduction
* Use this interface to:
* \li create new SmartCursor%s and SmartRange%s;
* \li create arbitrary highlighting; and
* \li associate KAction%s with ranges of text
*
* \section smartiface_creation Creation of SmartCursors and SmartRanges
* These functions must be used to create SmartCursor%s and SmartRange%s. This
* means that these objects cannot be derived from by third party applications.
*
* You then own these objects; upon deletion they de-register themselves from
* the Document with which they were associated. Alternatively, they are all
* deleted with the deletion of the owning Document.
*
* \section smartiface_highlight Arbitrary Highlighting
* Arbitrary highlighting of text can be achieved by creating SmartRange%s in a
* tree structure, and assigning appropriate Attributes to these ranges.
*
* To highlight all views, use addHighlightToDocument(); to highlight one or some
* of the views, use addHighlightToView(). You only need to call this function once
* per tree; just supply the top range you want to have highlighted. Calling
* this function more than once with ranges from the same tree may give undefined results.
*
* \section smartiface_action Action Binding
* Action binding can be used to associate KAction%s with specific ranges of text.
* These bound actions are automatically enabled and disabled when the caret enters
* their associated ranges, and context menus are automatically populated with the
* relevant actions.
*
* As with the arbitrary highlighting interface, to enable bound actions to be active,
* call addActionsToDocument() or addActionsToView() on the top SmartRange of a tree.
* If only small branches of a tree contain actions, it may be more efficient to simply add
* each of these branches instead (but this is unlikely unless the tree is complex).
*
* Note that actions can be bound either directly to the range via
* SmartRange::associateAction(), or indirectly via
* Attribute::associateAction(). Using attributes may be more convenient when
* you want all ranges of a specific type to have the same action associated
* with them.
*
* \todo extend this to provide a signal from the action indicating which range was
* used to activate it (if possible)
*
* \section smartiface_access Accessing the Interface
*
* The SmartInterface is supposed to be an extension interface for a Document,
* i.e. the Document inherits the interface \e provided that the
* KTextEditor library in use implements the interface. Use dynamic_cast to access
* the interface:
* \code
* // doc is of type KTextEditor::Document*
* KTextEditor::SmartInterface *iface =
* qobject_cast<KTextEditor::SmartInterface*>( doc );
*
* if( iface ) {
* // the implementation supports the interface
* // do stuff
* }
* \endcode
*
* \section smartiface_threadsafety Thread safety
* The smart interface is designed to be usable in multithreaded environments.
* If you use the interface from threads other than the main thread, you must
* lock the smartMutex() whenever you are making a non-const call to a smart object.
* This allows the text editor to guarantee that the objects will not change
* when it locks the mutex (for example, when performing layout or rendering).
* The useRevision function has only effect for the thread calling it. It will
* store the selected revision in a thread local storage to allow multiple threads
* to have different views on the same document in respect to the smart interface.
*
* \author Hamish Rodda \<rodda@kde.org\>
*/
class KTEXTEDITOR_EXPORT SmartInterface
{
friend class Attribute;
public:
SmartInterface();
virtual ~SmartInterface();
/**
* Provides access to the recursive mutex used to protect write access to
* smart interface objects (cursors + ranges and their associated properties).
* If you use this interface from a thread other than the main thread,
* you must lock this mutex whenever you call a non-const function on a smart object.
*/
QMutex* smartMutex() const;
/**
* Clears or deletes all instances of smart objects, ie:
* \li deletes all SmartCursor%s
* \li deletes all SmartRange%s
* \li clears all arbitrary highlight ranges
* \li clears all action binding
*
* Deletion occurs without modification to the underlying text.
*/
virtual void clearSmartInterface() = 0;
/**
* Returns whether the smart interface will be cleared on reload of the document.
*
* Defaults to true.
*/
bool clearOnDocumentReload() const;
/**
* Specify whether the smart interface should be cleared on reload of the document.
*
* \param clearOnReload set to true to enable clearing of the smart interface on reload (the default).
*/
void setClearOnDocumentReload(bool clearOnReload);
//BEGIN New cursor methods
/**
* Retrieve a token representing the current version of the document. This can
* be used later to create cursors and ranges as they would have been at this revision.
*
* Once you have finished with the token, release it with releaseRevision().
*/
virtual int currentRevision() const = 0;
/**
* Release a revision token provided by currentRevision(). You will no longer be able to
* create cursors and ranges against this revision.
*/
virtual void releaseRevision(int revision) const = 0;
/**
* Tell the smart interface to work against the given \a revision when creating cursors and
* ranges. This has only an effect for the thread calling this function, as this property
* is stored thread locally. This is not allowed to be called in the main gui thread.
* If you call it in the main gui thread, fatal error will occur.
*
* \param revision the token representing a revision retrieved by currentRevision(), or -1 to
* clear any previous setting and use the current document revision.
*/
virtual void useRevision(int revision) = 0;
/**
* Clear any previous setting to use a specific revision.
* Convenience wrapper for useRevision (-1).
*/
void clearRevision();
/**
* Translate the given \a cursor against the revision specified through useRevision(),
* using the given \a insertBehavior.
*
* If no revision is set, simply returns the cursor.
*/
virtual KTextEditor::Cursor translateFromRevision(const KTextEditor::Cursor& cursor, KTextEditor::SmartCursor::InsertBehavior insertBehavior = KTextEditor::SmartCursor::StayOnInsert) const;
/**
* Translate the given \a range against the revision specified through useRevision(),
* using the given \a insertBehavior.
*
* If no revision is set, simply returns the range.
*/
virtual KTextEditor::Range translateFromRevision(const KTextEditor::Range& range, KTextEditor::SmartRange::InsertBehaviors insertBehavior = KTextEditor::SmartRange::ExpandLeft | KTextEditor::SmartRange::ExpandRight) const;
/**
* \name Smart Cursors
*
* The following functions allow for creation and deletion of SmartCursor%s.
* \{
*/
/**
* Creates a new SmartCursor.
*
* You own this object, and may delete it when you are finished with it.
* Alternatively, you may call the various clear methods, or wait for the Document
* to be destroyed.
*
* \param position The initial cursor position assumed by the new cursor.
* If not specified, it will start at position (0, 0).
* \param insertBehavior Define whether the cursor should move when text is inserted at the cursor position.
*/
virtual SmartCursor* newSmartCursor(const Cursor& position = Cursor::start(), SmartCursor::InsertBehavior insertBehavior = SmartCursor::MoveOnInsert) = 0;
/**
* \overload
* \n \n
* Creates a new SmartCursor.
*
* You own this object, and may delete it when you are finished with it.
* Alternatively, you may call the various clear methods, or wait for the Document
* to be destroyed.
*
* \param line the line number of the cursor's initial position
* \param column the line number of the cursor's initial position
* \param insertBehavior Define whether the cursor should move when text is inserted at the cursor position.
*/
SmartCursor* newSmartCursor(int line, int column, SmartCursor::InsertBehavior insertBehavior = SmartCursor::MoveOnInsert);
/**
* Delete all SmartCursor%s from this document, with the exception of those
* cursors currently bound to ranges.
*/
virtual void deleteCursors() = 0;
//END
//BEGIN New range methods
/**
* \}
*
* \name Smart Ranges
*
* The following functions allow for creation of new SmartRange%s.
* \{
*/
/**
* Creates a new SmartRange.
* \param range The initial text range assumed by the new range.
* \param parent The parent SmartRange, if this is to be the child of an existing range.
* \param insertBehavior Define whether the range should expand when text is inserted adjacent to the range.
*/
virtual SmartRange* newSmartRange(const Range& range = Range(),
SmartRange* parent = 0L,
SmartRange::InsertBehaviors insertBehavior = SmartRange::DoNotExpand) = 0;
/**
* \overload
* \n \n
* Creates a new SmartRange.
* \param startPosition The start position assumed by the new range.
* \param endPosition The end position assumed by the new range.
* \param parent The parent SmartRange, if this is to be the child of an existing range.
* \param insertBehavior Define whether the range should expand when text is inserted adjacent to the range.
*/
SmartRange* newSmartRange(const Cursor& startPosition,
const Cursor& endPosition,
SmartRange* parent = 0L,
SmartRange::InsertBehaviors insertBehavior = SmartRange::DoNotExpand);
/**
* \overload
* \n \n
* Creates a new SmartRange.
* \param startLine The start line assumed by the new range.
* \param startColumn The start column assumed by the new range.
* \param endLine The end line assumed by the new range.
* \param endColumn The end column assumed by the new range.
* \param parent The parent SmartRange, if this is to be the child of an existing range.
* \param insertBehavior Define whether the range should expand when text is inserted adjacent to the range.
*/
SmartRange* newSmartRange(int startLine, int startColumn, int endLine, int endColumn, SmartRange* parent = 0L, SmartRange::InsertBehaviors insertBehavior = SmartRange::DoNotExpand);
/**
* Creates a new SmartRange from pre-existing SmartCursor%s. The cursors must not be part of any other range.
*
* \param start Start SmartCursor
* \param end End SmartCursor
* \param parent The parent SmartRange, if this is to be the child of an existing range.
* \param insertBehavior Define whether the range should expand when text is inserted at ends of the range.
*/
virtual SmartRange* newSmartRange(SmartCursor* start, SmartCursor* end, SmartRange* parent = 0L, SmartRange::InsertBehaviors insertBehavior = SmartRange::DoNotExpand) = 0;
/**
* Delete a SmartRange without deleting the SmartCursor%s which make up its start() and end().
*
* First, extract the cursors yourself using:
* \code
* SmartCursor* start = &range->smartStart();
* SmartCursor* end = &range->smartEnd();
* \endcode
*
* Then, call this function to delete the SmartRange instance. The underlying text will not be affected.
*
* \param range the range to dissociate from its smart cursors, and delete
*/
virtual void unbindSmartRange(SmartRange* range) = 0;
/**
* Delete all SmartRange%s from this document. This will also delete all
* cursors currently bound to ranges.
*
* This will not affect any underlying text.
*/
virtual void deleteRanges() = 0;
//END
//BEGIN Syntax highlighting extension
/**
* \}
*
* \name Arbitrary Highlighting
*
* The following functions enable highlighting processing for SmartRange%s with arbitrary
* highlighting information.
* \{
*/
/**
* Register a SmartRange tree as providing arbitrary highlighting information,
* and that it should be rendered on all of the views of a document.
*
* \param topRange the top range of the tree to add
* \param supportDynamic support dynamic highlighting attributes
*/
virtual void addHighlightToDocument(SmartRange* topRange, bool supportDynamic = false) = 0;
/**
* Remove a SmartRange tree from providing arbitrary highlighting information
* to all of the views of a document.
*
* \param topRange the top range of the tree to remove
*/
virtual void removeHighlightFromDocument(SmartRange* topRange) = 0;
/**
* Return a list of SmartRange%s which are currently registered as
* providing arbitrary highlighting information to all of the views of a
* document.
*/
virtual const QList<SmartRange*> documentHighlights() const = 0;
/**
* Clear the highlight ranges from a Document.
*/
virtual void clearDocumentHighlights() = 0;
/**
* Register a SmartRange tree as providing arbitrary highlighting information,
* and that it should be rendered on the specified \p view.
*
* \param view view on which to render the highlight
* \param topRange the top range of the tree to add
* \param supportDynamic support dynamic highlighting attributes
*/
virtual void addHighlightToView(View* view, SmartRange* topRange, bool supportDynamic = false) = 0;
/**
* Remove a SmartRange tree from providing arbitrary highlighting information
* to a specific view of a document.
*
* \note implementations should not take into account document-bound
* highlighting ranges when calling this function; it is intended solely
* to be the counter of addHighlightToView()
*
* \param view view on which the highlight was previously rendered
* \param topRange the top range of the tree to remove
*/
virtual void removeHighlightFromView(View* view, SmartRange* topRange) = 0;
/**
* Return a list of SmartRange%s which are currently registered as
* providing arbitrary highlighting information to a specific view of a
* document.
*
* \note implementations should not take into account document-bound
* highlighting ranges when returning the list; it is intended solely
* to show highlights added via addHighlightToView()
*
* \param view view to query for the highlight list
*/
virtual const QList<SmartRange*> viewHighlights(View* view) const = 0;
/**
* Clear the highlight ranges from a View.
*
* \param view view to clear highlights from
*/
virtual void clearViewHighlights(View* view) = 0;
//END
//BEGIN Action binding extension - not implemented
/* not implemented
* Register a SmartRange tree as providing bound actions,
* and that they should interact with all of the views of a document.
*
* \param topRange the top range of the tree to add
*/
virtual void addActionsToDocument(SmartRange* topRange) = 0;
/* not implemented
* Remove a SmartRange tree from providing bound actions
* to all of the views of a document.
*
* \param topRange the top range of the tree to remove
*/
virtual void removeActionsFromDocument(SmartRange* topRange) = 0;
/* not implemented
* Return a list of SmartRange%s which are currently registered as
* providing bound actions to all of the views of a document.
*/
virtual const QList<SmartRange*> documentActions() const = 0;
/* not implemented
* Remove all bound SmartRange%s which provide actions to the document.
*/
virtual void clearDocumentActions() = 0;
/* not implemented
* Register a SmartRange tree as providing bound actions,
* and that they should interact with the specified \p view.
*
* \param view view on which to use the actions
* \param topRange the top range of the tree to add
*/
virtual void addActionsToView(View* view, SmartRange* topRange) = 0;
/* not implemented
* Remove a SmartRange tree from providing bound actions
* to the specified \p view.
*
* \note implementations should not take into account document-bound
* action ranges when calling this function; it is intended solely
* to be the counter of addActionsToView()
*
* \param view view on which the actions were previously used
* \param topRange the top range of the tree to remove
*/
virtual void removeActionsFromView(View* view, SmartRange* topRange) = 0;
/* not implemented
* Return a list of SmartRange%s which are currently registered as
* providing bound actions to the specified \p view.
*
* \note implementations should not take into account document-bound
* action ranges when returning the list; it is intended solely
* to show actions added via addActionsToView()
*
* \param view view to query for the action list
*/
virtual const QList<SmartRange*> viewActions(View* view) const = 0;
/* not implemented
* Remove all bound SmartRange%s which provide actions to the specified \p view.
*
* \param view view from which to remove actions
*/
virtual void clearViewActions(View* view) = 0;
//END
protected:
/**
* \internal
* Used to notify implementations that an Attribute has gained
* a dynamic component and needs to be included in mouse and/or cursor
* tracking.
*/
virtual void attributeDynamic(Attribute::Ptr a) = 0;
/**
* \internal
* Used to notify implementations that an Attribute has lost
* all dynamic components and no longer needs to be included in mouse and cursor
* tracking.
*/
virtual void attributeNotDynamic(Attribute::Ptr a) = 0;
private:
class SmartInterfacePrivate* const d;
};
}
Q_DECLARE_INTERFACE(KTextEditor::SmartInterface, "org.kde.KTextEditor.SmartInterface")
#endif
// kate: space-indent on; indent-width 2; replace-tabs on;
|