HaikuDepot: Added UndoableEditListener list to TextDocument
This is all work in progress. The plan is to move the code that does any actual changes to the TextDocument into UndoableEdit implementations, then emit these edits to interesed listeners. They can then store them to implement the edit history. If there are not listeners, the edits will simply be released after they've done their work. Implemented so far is only the support for storing the edit listeners.
This commit is contained in:
parent
b5cbbf8041
commit
4bf45bfb5d
@ -516,6 +516,20 @@ TextDocument::RemoveListener(const TextListenerRef& listener)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TextDocument::AddUndoListener(const UndoableEditListenerRef& listener)
|
||||
{
|
||||
return fUndoListeners.Add(listener);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TextDocument::RemoveUndoListener(const UndoableEditListenerRef& listener)
|
||||
{
|
||||
return fUndoListeners.Remove(listener);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextDocument::_NotifyTextChanging(TextChangingEvent& event) const
|
||||
{
|
||||
@ -549,3 +563,18 @@ TextDocument::_NotifyTextChanged(const TextChangedEvent& event) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TextDocument::_NotifyUndoableEditHappened(const UndoableEditRef& edit) const
|
||||
{
|
||||
// Copy listener list to have a stable list in case listeners
|
||||
// are added/removed from within the notification hook.
|
||||
UndoListenerList listeners(fUndoListeners);
|
||||
int32 count = listeners.CountItems();
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
const UndoableEditListenerRef& listener = listeners.ItemAtFast(i);
|
||||
if (listener.Get() == NULL)
|
||||
continue;
|
||||
listener->UndoableEditHappened(this, edit);
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,12 @@
|
||||
#include "List.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TextListener.h"
|
||||
#include "UndoableEditListener.h"
|
||||
|
||||
|
||||
typedef List<Paragraph, false> ParagraphList;
|
||||
typedef List<TextListenerRef, false> TextListenerList;
|
||||
typedef List<Paragraph, false> ParagraphList;
|
||||
typedef List<TextListenerRef, false> TextListenerList;
|
||||
typedef List<UndoableEditListenerRef, false> UndoListenerList;
|
||||
|
||||
class TextDocument;
|
||||
typedef BReference<TextDocument> TextDocumentRef;
|
||||
@ -83,12 +85,18 @@ public:
|
||||
// Listener support
|
||||
bool AddListener(const TextListenerRef& listener);
|
||||
bool RemoveListener(const TextListenerRef& listener);
|
||||
bool AddUndoListener(
|
||||
const UndoableEditListenerRef& listener);
|
||||
bool RemoveUndoListener(
|
||||
const UndoableEditListenerRef& listener);
|
||||
|
||||
private:
|
||||
void _NotifyTextChanging(
|
||||
TextChangingEvent& event) const;
|
||||
void _NotifyTextChanged(
|
||||
const TextChangedEvent& event) const;
|
||||
void _NotifyUndoableEditHappened(
|
||||
const UndoableEditRef& edit) const;
|
||||
|
||||
private:
|
||||
ParagraphList fParagraphs;
|
||||
@ -96,6 +104,7 @@ private:
|
||||
CharacterStyle fDefaultCharacterStyle;
|
||||
|
||||
TextListenerList fTextListeners;
|
||||
UndoListenerList fUndoListeners;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user