1 /*
2 Copyright (C) 2002 Kai Sterker <kai.sterker@gmail.com>
3 Part of the Adonthell Project <http://adonthell.nongnu.org>
4
5 Dlgedit 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 2 of the License, or
8 (at your option) any later version.
9
10 Dlgedit 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.
14
15 You should have received a copy of the GNU General Public License
16 along with Dlgedit. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20 * @file dlg_circle_entry.cc
21 *
22 * @author Kai Sterker
23 * @brief The contents of a DlgCircle.
24 */
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include <cstring>
31 #include <algorithm>
32 #include "gettext.h"
33 #include "gui_dlgedit.h"
34 #include "dlg_circle_entry.h"
35
36 // Default Constructor
DlgCircleEntry()37 DlgCircleEntry::DlgCircleEntry ()
38 {
39 loop_ = false;
40 text_ = "";
41 annotation_ = "";
42 npc_ = "Default";
43 code_ = "";
44 condition_ = "";
45 }
46
47 // get the dialogue text
text()48 std::string DlgCircleEntry::text ()
49 {
50 // in case we are in preview mode, we need to translate the text first
51 if (GuiDlgedit::window && GuiDlgedit::window->mode () == L10N_PREVIEW)
52 return gettext (text_.c_str ());
53
54 // usually, we just need to return the text
55 return text_;
56 }
57
58 // set the dialogue text
setText(std::string t)59 void DlgCircleEntry::setText (std::string t)
60 {
61 unsigned long pos = 0;
62 text_ = t;
63
64 // Make text safe:
65 // replace linebreaks with space
66 replace (text_.begin (), text_.end (), '\n', ' ');
67
68 // escape quotes
69 while ((pos = text_.find ("\"", pos)) != text_.npos)
70 {
71 if (pos > 0) {
72 if (text_[pos-1] != '\\') text_.insert (pos, "\\");
73 }
74 else text_.insert (pos, "\\");
75
76 pos++;
77 }
78 }
79
80 // set the node's condition
setCondition(std::string c)81 void DlgCircleEntry::setCondition (std::string c)
82 {
83 if (c == "")
84 {
85 condition_ = c;
86 return;
87 }
88
89 // remove all whitespace from the edges of the condition
90 condition_ = c.substr (c.find_first_not_of (" \n\t"), c.find_last_not_of (" \n\t") + 1);
91
92 // replace 'else if' by the shorter 'elif'
93 if (strncmp ("else if", condition_.c_str (), 7) == 0)
94 condition_.replace (0, 7, "elif");
95 }
96