summaryrefslogtreecommitdiffstats
path: root/src/message-context.h
blob: cfe155aa37115eae9ed2cc34f7005eb8da3132b7 (plain)
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
// SPDX-License-Identifier: GPL-2.0-or-later
/** \file
 * Interface for locally managing a current status message
 */

/*
 * Authors:
 *   MenTaLguY <mental@rydia.net>
 *
 * Copyright (C) 2004 MenTaLguY
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SEEN_INKSCAPE_MESSAGE_CONTEXT_H
#define SEEN_INKSCAPE_MESSAGE_CONTEXT_H

#include <cstdarg>
#include <memory>
#include <glib.h>

#include "message.h"

namespace Inkscape {

class MessageStack;

/** A convenience class for working with MessageStacks.
  *
  * In general, a particular piece of code will only want to display
  * one status message at a time.  This class takes care of tracking
  * a "current" message id in a particular stack for us, and provides
  * a convenient means to remove or replace it.
  *
  * @see Inkscape::MessageStack
  */
class MessageContext {
public:
    /** Constructs an Inkscape::MessageContext referencing a particular
      * Inkscape::MessageStack, which will be used for our messages
      *
      * MessageContexts retain references to the MessageStacks they use.
      *
      * @param stack the Inkscape::MessageStack to use for our messages
      */
    MessageContext(std::shared_ptr<MessageStack> stack);
    ~MessageContext();

    /** @brief pushes a message on the stack, replacing our old message
      *
      * @param type the message type
      * @param message the message text
      */
    void set(MessageType type, char const *message);

    /** @brief pushes a message on the stack using prinf-style formatting,
      *        and replacing our old message
      *
      * @param type the message type
      * @param format a printf-style formatting string
      */
    void setF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);

    /** @brief pushes a message on the stack using printf-style formatting,
      *        and a stdarg argument list
      *
      * @param type the message type
      * @param format a printf-style formatting string
      * @param args printf-style arguments
      */
    void setVF(MessageType type, char const *format, va_list args);

    /** @brief pushes a message onto the stack for a brief period of time
      *        without disturbing our "current" message
      *
      * @param type the message type
      * @param message the message text
      */
    void flash(MessageType type, char const *message);

    /** @brief pushes a message onto the stack for a brief period of time
      *        using printf-style formatting, without disturbing our current
      *        message
      *
      * @param type the message type
      * @param format a printf-style formatting string
      */
    void flashF(MessageType type, char const *format, ...) G_GNUC_PRINTF(3,4);

    /** @brief pushes a message onto the stack for a brief period of time
      *        using printf-style formatting and a stdarg argument list;
      *        it does not disturb our "current" message
      *
      * @param type the message type
      * @param format a printf-style formatting string
      * @param args printf-style arguments
      */
    void flashVF(MessageType type, char const *format, va_list args);

    /** @brief removes our current message from the stack */
    void clear();

private:
    std::shared_ptr<MessageStack> _stack; ///< the message stack to use
    MessageId _message_id; ///< our current message id, or 0
    MessageId _flash_message_id; ///< current flashed message id, or 0
};

}

#endif
/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :