1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 * This file contains the Editor class.
30 #include "SavableTypes.h"
33 * This class defines an interface for UBSocket to use in handling lines from the user.
40 /** Constructs an Editor with the specified socket. */
41 Editor(UBSocket
* sock
);
43 /** Destructor, a noop. */
44 virtual ~Editor(void);
47 /** This function is called whenever the user sends an empty line. */
48 virtual void OnEmptyLine() {}
51 * This function is called whenever a user sends a line.
53 * The default implementation will handle the input and use <code>lookup</code> to find the matching command.
54 * If matched it will dispatch it with the <code>dispatch</code> functions.
59 virtual void OnLine(const std::string
& line
);
61 /** This function is called whenever this editor becomes the editor that has the focus. */
62 virtual void OnFocus() { }
65 /** Returns the name of this editor. */
66 virtual std::string
name() = 0;
68 /** Returns the prompt for this editor. */
69 virtual std::string
prompt(); // { return Global::Get()->EmptyString; };
71 /** Returns the full name of a command of the specified action. */
72 virtual std::string
lookup(const std::string
& action
); // { return Global::Get()->EmptyString; };
74 /** Dispatches the specified action with the specified argument. */
75 virtual void dispatch(const std::string
& action
, const std::string
& argument
) { return; };
77 /** Whether the current editor is capable of receiving messages from the specified channel. */
78 virtual bool canReceiveChannel(mud::ChannelPtr channel
) const;
80 /** Whether prefixes should be handled in the current editor. */
81 virtual bool supportPrefixes() const;
84 /** Send a message to the user. */
85 void Send(const std::string
& msg
);
87 /** Send a formatted message to the user. */
88 void Sendf(const char* format
, ...);
90 /** Disconnect the user. */
94 UBSocket
* m_sock
; /**< The socket this Editor is associated with. */
97 /** Hide the copy constructor. */
98 Editor(const Editor
& rhs
);