Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "gui/dialogs/formula_debugger.hpp"
00019
00020 #include "gui/dialogs/helper.hpp"
00021 #include "gui/widgets/button.hpp"
00022 #include "gui/widgets/settings.hpp"
00023 #include "gui/widgets/window.hpp"
00024 #include "../../foreach.hpp"
00025 #include "../../formula_debugger.hpp"
00026
00027 #include <boost/bind.hpp>
00028
00029 namespace gui2 {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 REGISTER_DIALOG(formula_debugger)
00066
00067 void tformula_debugger::pre_show(CVideo& , twindow& window)
00068 {
00069
00070 tcontrol* stack_label = find_widget<tcontrol>(
00071 &window, "stack", false, true);
00072
00073 std::stringstream stack_text;
00074 std::string indent = " ";
00075 int c = 0;
00076 foreach (const game_logic::debug_info &i, fdb_.get_call_stack()) {
00077 for(int d = 0; d < c; ++d) {
00078 stack_text << indent;
00079 }
00080 stack_text << "#<span color=\"green\">" << i.counter()
00081 <<"</span>: \"<span color=\"green\">"<< i.name()
00082 << "</span>\": '" << i.str() << "' " << std::endl;
00083 ++c;
00084 }
00085
00086 stack_label->set_use_markup(true);
00087 stack_label->set_label(stack_text.str());
00088 window.keyboard_capture(stack_label);
00089
00090
00091 tcontrol* execution_label = find_widget<tcontrol>(
00092 &window, "execution", false, true);
00093
00094 std::stringstream execution_text;
00095 foreach (const game_logic::debug_info &i, fdb_.get_execution_trace()) {
00096 for(int d = 0; d < i.level(); ++d) {
00097 execution_text << indent;
00098 }
00099 if(!i.evaluated()) {
00100 execution_text << "#<span color=\"green\">" << i.counter()
00101 << "</span>: \"<span color=\"green\">" << i.name()
00102 << "</span>\": '" << i.str() << "' " << std::endl;
00103 } else {
00104 execution_text << "#<span color=\"yellow\">" << i.counter()
00105 << "</span>: \"<span color=\"yellow\">" << i.name()
00106 << "</span>\": '" << i.str() << "' = "
00107 << "<span color=\"red\">"
00108 << i.value().to_debug_string(NULL,false)
00109 <<"</span>" << std::endl;
00110 }
00111 }
00112
00113 execution_label->set_use_markup(true);
00114 execution_label->set_label(execution_text.str());
00115
00116
00117 std::string state_str;
00118 bool is_end = false;
00119 if(!fdb_.get_current_breakpoint()) {
00120 state_str = "";
00121 } else {
00122 state_str = fdb_.get_current_breakpoint()->name();
00123 if(state_str=="End") {
00124 is_end = true;
00125 }
00126 }
00127
00128 find_widget<tcontrol>(&window, "state", false).set_label(state_str);
00129
00130
00131 tbutton& step_button = find_widget<tbutton>(&window, "step", false);
00132 connect_signal_mouse_left_click(step_button, boost::bind(
00133 &tformula_debugger::callback_step_button
00134 , this
00135 , boost::ref(window)));
00136
00137 tbutton& stepout_button = find_widget<tbutton>(&window, "stepout", false);
00138 connect_signal_mouse_left_click(stepout_button, boost::bind(
00139 &tformula_debugger::callback_stepout_button
00140 , this
00141 , boost::ref(window)));
00142
00143 tbutton& next_button = find_widget<tbutton>(&window, "next", false);
00144 connect_signal_mouse_left_click(next_button, boost::bind(
00145 &tformula_debugger::callback_next_button
00146 , this
00147 , boost::ref(window)));
00148
00149 tbutton& continue_button = find_widget<tbutton>(&window, "continue", false);
00150 connect_signal_mouse_left_click(continue_button, boost::bind(
00151 &tformula_debugger::callback_continue_button
00152 , this
00153 , boost::ref(window)));
00154
00155 if(is_end) {
00156 step_button.set_active(false);
00157 stepout_button.set_active(false);
00158 next_button.set_active(false);
00159 continue_button.set_active(false);
00160 }
00161 }
00162
00163 void tformula_debugger::callback_continue_button(twindow& window)
00164 {
00165 fdb_.add_breakpoint_continue_to_end();
00166 window.set_retval(twindow::OK);
00167 }
00168
00169 void tformula_debugger::callback_next_button(twindow& window)
00170 {
00171 fdb_.add_breakpoint_next();
00172 window.set_retval(twindow::OK);
00173 }
00174
00175 void tformula_debugger::callback_step_button(twindow& window)
00176 {
00177 fdb_.add_breakpoint_step_into();
00178 window.set_retval(twindow::OK);
00179 }
00180
00181 void tformula_debugger::callback_stepout_button(twindow& window)
00182 {
00183 fdb_.add_breakpoint_step_out();
00184 window.set_retval(twindow::OK);
00185 }
00186
00187 }