JX Application Framework
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
JXDocumentManager Class Reference

#include <JXDocumentManager.h>

Inheritance diagram for JXDocumentManager:
[legend]

Classes

class  DocMenuNeedsUpdate
 

Public Types

enum  { kNoShortcutForDoc = -1 }
 
enum  SafetySaveReason {
  kTimer ,
  kServerDead ,
  kKillSignal ,
  kAssertFired
}
 

Public Member Functions

 JXDocumentManager (const bool wantShortcuts=true)
 
 ~JXDocumentManager () override
 
bool WillSafetySave () const
 
void ShouldSafetySave (const bool doIt)
 
JSize GetSafetySaveInterval () const
 
void SetSafetySaveInterval (const JSize deltaSeconds)
 
void SafetySave (const SafetySaveReason reason)
 
bool HasDocuments () const
 
JSize GetDocumentCount () const
 
bool DocumentsNeedSave () const
 
bool SaveAllFileDocuments (const bool saveUntitled)
 
void CloseDocuments ()
 
JString GetNewFileName ()
 
void DocumentMustStayOpen (JXDocument *doc, const bool stayOpen)
 
bool FileDocumentIsOpen (const JString &fileName, JXFileDocument **doc) const
 
virtual bool FindFile (const JString &fileName, const JString &currPath, JString *newFileName, const bool askUser=true) const
 
virtual void DocumentCreated (JXDocument *doc)
 
virtual void DocumentDeleted (JXDocument *doc)
 
bool OKToCloseDocument (JXDocument *doc) const
 
const JXImageGetDefaultMenuIcon () const
 
void UpdateDocumentMenu (JXDocumentMenu *menu)
 
void ActivateDocument (const JIndex index)
 
bool GetDocument (const JIndex index, JXDocument **doc) const
 
- Public Member Functions inherited from JBroadcaster
 JBroadcaster ()
 
virtual ~JBroadcaster ()
 
JBroadcasteroperator= (const JBroadcaster &source)
 
bool HasSenders () const
 
JSize GetSenderCount () const
 
bool HasRecipients () const
 
JSize GetRecipientCount () const
 
virtual JString ToString () const
 
template<class T >
void ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f)
 

Static Public Attributes

static const JUtf8BytekDocMenuNeedsUpdate
 

Friends

class JXUpdateDocMenuTask
 

Additional Inherited Members

- Protected Member Functions inherited from JBroadcaster
 JBroadcaster (const JBroadcaster &source)
 
void ListenTo (const JBroadcaster *sender)
 
void StopListening (const JBroadcaster *sender)
 
void ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember)
 
void StopListening (const JBroadcaster *sender, const std::type_info &messageType)
 
template<class T >
void Send (JBroadcaster *recipient, const T &message)
 
template<class T >
void Broadcast (const T &message)
 
virtual void Receive (JBroadcaster *sender, const Message &message)
 
void SendWithFeedback (JBroadcaster *recipient, Message *message)
 
void BroadcastWithFeedback (Message *message)
 
virtual void ReceiveWithFeedback (JBroadcaster *sender, Message *message)
 
virtual void ReceiveGoingAway (JBroadcaster *sender)
 

Detailed Description

Singleton class that manages all JXDocuments and provides the following
services:

1)  GetNewFileName()

    Convenient source of names for newly created documents.

2)  JXDocumentMenu

    Instant menu of all open documents

3)  Safety save

    Periodically save all unsaved documents in temporary files.
    Also protects against X Server crashes and calls to assert().

    While it would be nice to also catch Ctrl-C, this must remain
    uncaught because it provides a way to quickly stop a runaway
    program.  Also, in practice, X programs are usually backgrounded,
    in which case Ctrl-C is irrelevant.

4)  Dependencies between documents

    Classes derived from JXDocument can override NeedDocument()
    if they require that other documents stay open.  When closed,
    such required documents merely deactivate.

5)  Searching for files that are supposed to exist

    Dependencies between documents usually imply that one document
    stores the file names of other documents that it has to open.
    If the user moves or renames these files, call FindFile() to
    search for them.

    Derived classes can override this function to search application
    specific directories.

A derived class is the best place to put all the code associated
with determining a file's type and creating the appropriate derived
class of JXDocument.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kNoShortcutForDoc 

◆ SafetySaveReason

Enumerator
kTimer 
kServerDead 
kKillSignal 
kAssertFired 

Constructor & Destructor Documentation

◆ JXDocumentManager()

JXDocumentManager::JXDocumentManager ( const bool  wantShortcuts = true)

◆ ~JXDocumentManager()

JXDocumentManager::~JXDocumentManager ( )
override

Member Function Documentation

◆ ActivateDocument()

void JXDocumentManager::ActivateDocument ( const JIndex  index)

◆ CloseDocuments()

void JXDocumentManager::CloseDocuments ( )

Close invisible documents that are no longer needed by any other documents.

An iterator would be cleaner, but since it is recursive and keeps looping until nothing more is closed, this method wastes less stack space.

◆ DocumentCreated()

void JXDocumentManager::DocumentCreated ( JXDocument doc)
virtual

◆ DocumentDeleted()

void JXDocumentManager::DocumentDeleted ( JXDocument doc)
virtual

Automatically called by ~JXDocument.

◆ DocumentMustStayOpen()

void JXDocumentManager::DocumentMustStayOpen ( JXDocument doc,
const bool  stayOpen 
)

Call this with true if a document must remain open even if nobody else needs it.

◆ DocumentsNeedSave()

bool JXDocumentManager::DocumentsNeedSave ( ) const

◆ FileDocumentIsOpen()

bool JXDocumentManager::FileDocumentIsOpen ( const JString fileName,
JXFileDocument **  doc 
) const

If there is a JXFileDocument that uses the specified file, we return it.

With full RTTI support to allow safe downcasting, this could be generalized to DocumentIsOpen() by defining a pure virtual IsEqual() function in JXDocument and requiring derived classes to implement it appropriately.

◆ FindFile()

bool JXDocumentManager::FindFile ( const JString fileName,
const JString currPath,
JString newFileName,
const bool  askUser = true 
) const
virtual

Searches for the given file, assuming that it has been moved elsewhere. currPath should be the path the user selected. This can help in the cases where an entire directory subtree was moved because then the requested file is probably still somewhere in the subtree.

This function is virtual so derived classes can provide additional search techniques.

◆ GetDefaultMenuIcon()

const JXImage * JXDocumentManager::GetDefaultMenuIcon ( ) const
inline

◆ GetDocument()

bool JXDocumentManager::GetDocument ( const JIndex  index,
JXDocument **  doc 
) const

The index is the JXDocumentMenu item index.

We return bool because the document might have been closed while the menu was open.

◆ GetDocumentCount()

JSize JXDocumentManager::GetDocumentCount ( ) const
inline

◆ GetNewFileName()

JString JXDocumentManager::GetNewFileName ( )

Return a suitable name for a new document. Since this is often called in the constructor for JXFileDocument, we return a JString&

◆ GetSafetySaveInterval()

JSize JXDocumentManager::GetSafetySaveInterval ( ) const

Returns the safety save interval in seconds.

◆ HasDocuments()

bool JXDocumentManager::HasDocuments ( ) const
inline

◆ OKToCloseDocument()

bool JXDocumentManager::OKToCloseDocument ( JXDocument doc) const

Returns true if the given document can be closed.

◆ SafetySave()

void JXDocumentManager::SafetySave ( const SafetySaveReason  reason)

◆ SaveAllFileDocuments()

bool JXDocumentManager::SaveAllFileDocuments ( const bool  saveUntitled)

◆ SetSafetySaveInterval()

void JXDocumentManager::SetSafetySaveInterval ( const JSize  deltaSeconds)

◆ ShouldSafetySave()

void JXDocumentManager::ShouldSafetySave ( const bool  doIt)

◆ UpdateDocumentMenu()

void JXDocumentManager::UpdateDocumentMenu ( JXDocumentMenu menu)

◆ WillSafetySave()

bool JXDocumentManager::WillSafetySave ( ) const
inline

Friends And Related Symbol Documentation

◆ JXUpdateDocMenuTask

friend class JXUpdateDocMenuTask
friend

Member Data Documentation

◆ kDocMenuNeedsUpdate

const JUtf8Byte * JXDocumentManager::kDocMenuNeedsUpdate
static
Initial value:
=
"DocMenuNeedsUpdate::JXDocumentManager"

The documentation for this class was generated from the following files: