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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
|
/*
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "stdafx.h"
#include "preferences_form.h"
#include "mforms/widgets.h"
#include "mforms/sectionbox.h"
#include "base/string_utilities.h"
#include "base/util_functions.h"
#include "snippet_popover.h"
#include "mforms/textbox.h"
#if defined(_WIN32) || defined(__APPLE__)
#define HAVE_BUNDLED_MYSQLDUMP
#endif
using namespace base;
using namespace mforms;
static mforms::Label *new_label(const std::string &text, bool right_align=false, bool help=false)
{
mforms::Label *label= mforms::manage(new mforms::Label());
label->set_text(text);
if (right_align)
label->set_text_align(mforms::MiddleRight);
if (help)
label->set_style(mforms::SmallHelpTextStyle);
return label;
}
class OptionTable : public mforms::Panel
{
PreferencesForm *_owner;
mforms::Table _table;
int _rows;
bool _help_column;
public:
OptionTable(PreferencesForm *owner, const std::string &title, bool help_column)
: mforms::Panel(mforms::TitledBoxPanel), _owner(owner), _rows(0), _help_column(help_column)
{
set_title(title);
add(&_table);
_table.set_padding(8);
_table.set_row_spacing(12);
_table.set_column_spacing(8);
_table.set_column_count(_help_column ? 3 : 2);
}
void add_option(mforms::View *control, const std::string &caption, const std::string &help)
{
_table.set_row_count(++_rows);
#ifdef _WIN32
TableItemFlags descriptionFlags = mforms::HFillFlag;
TableItemFlags helpFlags = mforms::HFillFlag | mforms::HExpandFlag;
bool right_aligned = false;
#else
TableItemFlags descriptionFlags = mforms::HFillFlag | mforms::HExpandFlag;
TableItemFlags helpFlags = mforms::HFillFlag;
bool right_aligned = true;
#endif
mforms::Label* label = new_label(caption, right_aligned);
_table.add(label, 0, 1, _rows-1, _rows, descriptionFlags);
label->set_size(170, -1);
_table.add(control, 1, 2, _rows-1, _rows, mforms::HFillFlag | mforms::HExpandFlag);
control->set_size(150, -1);
_table.add(new_label(help, false, true), 2, 3, _rows-1, _rows, helpFlags);
}
void add_entry_option(const std::string &option, const std::string &caption, const std::string &tooltip)
{
_table.set_row_count(++_rows);
mforms::TextEntry *entry = _owner->new_entry_option(option, false);
entry->set_tooltip(tooltip);
#ifdef _WIN32
TableItemFlags descriptionFlags = mforms::HFillFlag;
bool right_aligned = false;
#else
TableItemFlags descriptionFlags = mforms::HFillFlag | mforms::HExpandFlag;
bool right_aligned = true;
#endif
mforms::Label* label = new_label(caption, right_aligned);
_table.add(label, 0, 1, _rows-1, _rows, descriptionFlags);
label->set_size(170, -1);
_table.add(entry, 1, 2, _rows-1, _rows, mforms::HFillFlag);
}
void add_checkbox_option(const std::string &option, const std::string &caption, const std::string &tooltip)
{
_table.set_row_count(++_rows);
mforms::CheckBox *cb = _owner->new_checkbox_option(option);
cb->set_text(caption);
cb->set_tooltip(tooltip);
#ifdef _WIN32
int start_column = 0;
#else
int start_column = 1;
#endif
_table.add(cb, start_column, 2, _rows - 1, _rows, mforms::HFillFlag);
}
};
PreferencesForm::PreferencesForm(wb::WBContextUI *wbui, const std::string &model_id)
: Form(NULL, mforms::FormResizable), _top_box(false), _bottom_box(true), _button_box(true),
_font_list(mforms::TreeDefault), _tabview(mforms::TabViewDocument)
{
_wbui= wbui;
_model_id= model_id;
if (model_id.empty())
set_title(_("Workbench Preferences"));
else
set_title(_("Model Options"));
set_size(700, 680);
set_content(&_top_box);
#ifdef _WIN32
set_back_color("#283752");
#endif
_top_box.set_padding(4);
_top_box.set_spacing(4);
_top_box.add(&_tabview, true, true);
_top_box.add(&_bottom_box, false);
_bottom_box.add_end(&_button_box, false, true);
_button_box.set_padding(7);
_button_box.set_spacing(8);
_button_box.set_homogeneous(true);
scoped_connect(_ok_button.signal_clicked(),boost::bind(&PreferencesForm::ok_clicked, this));
scoped_connect(_cancel_button.signal_clicked(),boost::bind(&PreferencesForm::cancel_clicked, this));
_cancel_button.set_text(_("Cancel"));
_cancel_button.enable_internal_padding(true);
_button_box.add_end(&_cancel_button, false, true);
_ok_button.set_text(_("OK"));
_ok_button.enable_internal_padding(true);
_button_box.add_end(&_ok_button, false, true);
if (!model_id.empty())
{
_use_global.set_text(_("Use Global Settings"));
#ifdef _WIN32
_use_global.set_front_color("#FFFFFF");
#endif
_bottom_box.add(&_use_global, true, true);
scoped_connect(_use_global.signal_clicked(),boost::bind(&PreferencesForm::toggle_use_global, this));
}
if (model_id.empty())
{
create_general_page();
create_admin_page();
create_sqlide_page();
}
create_model_page();
create_mysql_page();
create_diagram_page();
if (model_id.empty())
create_appearance_page();
#if defined(_DEBUG) || defined(ENABLE_DEBUG)
create_test_page();
#endif
center();
show_values();
}
void PreferencesForm::show()
{
run_modal(&_ok_button, &_cancel_button);
}
void PreferencesForm::show_values()
{
for (std::list<Option*>::const_iterator iter= _options.begin(); iter != _options.end(); ++iter)
(*iter)->show_value();
if (_model_id.empty())
{
show_colors_and_fonts();
}
if (!_model_id.empty())
{
std::string value;
_wbui->get_wb_options_value(_model_id, "useglobal", value);
if (value == "1")
{
_use_global.set_active(true);
_tabview.set_enabled(false);
}
}
}
void PreferencesForm::update_values()
{
grt::AutoUndo undo(_wbui->get_wb()->get_grt(), _model_id.empty());
if (!_model_id.empty())
{
_wbui->set_wb_options_value(_model_id, "useglobal", _use_global.get_active() ? "1" : "0");
}
if (_model_id.empty() || !_use_global.get_active())
{
for (std::list<Option*>::const_iterator iter= _options.begin(); iter != _options.end(); ++iter)
{
(*iter)->update_value();
}
update_colors_and_fonts();
}
undo.end(_("Change Options"));
}
grt::DictRef PreferencesForm::get_options(bool global)
{
if (_model_id.empty() || global)
return _wbui->get_wb()->get_wb_options();
else
return _wbui->get_model_options(_model_id);
}
void PreferencesForm::show_entry_option(const std::string &option_name, mforms::TextEntry *entry, bool numeric)
{
std::string value;
_wbui->get_wb_options_value(_model_id, option_name, value);
entry->set_value(value);
}
void PreferencesForm::update_entry_option(const std::string &option_name, mforms::TextEntry *entry, bool numeric)
{
if (numeric)
_wbui->set_wb_options_value(_model_id, option_name, entry->get_string_value(), grt::AnyType);
else
_wbui->set_wb_options_value(_model_id, option_name, entry->get_string_value(), grt::StringType);
}
void PreferencesForm::show_path_option(const std::string &option_name, mforms::FsObjectSelector *entry)
{
std::string value;
_wbui->get_wb_options_value(_model_id, option_name, value);
entry->set_filename(value);
}
void PreferencesForm::update_path_option(const std::string &option_name, mforms::FsObjectSelector *entry)
{
_wbui->set_wb_options_value(_model_id, option_name, entry->get_filename(), grt::StringType);
}
void PreferencesForm::update_entry_option_numeric(const std::string &option_name, mforms::TextEntry *entry, int minrange, int maxrange)
{
long value= atoi(entry->get_string_value().c_str());
if (value < minrange)
value= minrange;
else if (value > maxrange)
value= maxrange;
_wbui->set_wb_options_value(_model_id, option_name, strfmt("%li", value));
}
void PreferencesForm::show_checkbox_option(const std::string &option_name, mforms::CheckBox *checkbox)
{
std::string value;
_wbui->get_wb_options_value(_model_id, option_name, value);
checkbox->set_active(atoi(value.c_str()) != 0);
}
void PreferencesForm::update_checkbox_option(const std::string &option_name, mforms::CheckBox *checkbox)
{
std::string value = checkbox->get_active() ? "1" : "0";
_wbui->set_wb_options_value(_model_id, option_name, value, grt::IntegerType);
#ifdef _WIN32
// On Windows we have to write the following value also to the registry as our options are not
// available yet when we need that value.
if (option_name == "SingleInstance")
set_value_to_registry(HKEY_CURRENT_USER, "Software\\Oracle\\MySQL Workbench", "SingleInstance", value.c_str());
#endif
}
void PreferencesForm::show_selector_option(const std::string &option_name, mforms::Selector *selector,
const std::vector<std::string> &choices)
{
std::string value;
_wbui->get_wb_options_value(_model_id, option_name, value);
selector->set_selected(std::find(choices.begin(), choices.end(), value) - choices.begin());
}
void PreferencesForm::update_selector_option(const std::string &option_name, mforms::Selector *selector,
const std::vector<std::string> &choices, const std::string &default_value, bool as_number)
{
if (as_number)
{
if (selector->get_selected_index() < 0)
_wbui->set_wb_options_value(_model_id, option_name, default_value, grt::IntegerType);
else
_wbui->set_wb_options_value(_model_id, option_name, choices[selector->get_selected_index()], grt::IntegerType);
}
else
{
if (selector->get_selected_index() < 0)
_wbui->set_wb_options_value(_model_id, option_name, default_value);
else
_wbui->set_wb_options_value(_model_id, option_name, choices[selector->get_selected_index()]);
}
}
mforms::TextEntry *PreferencesForm::new_entry_option(const std::string &option_name, bool numeric)
{
Option *option= new Option();
mforms::TextEntry *entry= new mforms::TextEntry();
option->view= mforms::manage(entry);
option->show_value= boost::bind(&PreferencesForm::show_entry_option, this, option_name, entry, numeric);
option->update_value= boost::bind(&PreferencesForm::update_entry_option, this, option_name, entry, numeric);
_options.push_back(option);
return entry;
}
mforms::FsObjectSelector *PreferencesForm::new_path_option(const std::string &option_name, bool file)
{
Option *option= new Option();
mforms::FsObjectSelector *entry= new mforms::FsObjectSelector();
entry->initialize("", file ? mforms::OpenFile : mforms::OpenDirectory, "");
option->view= mforms::manage(entry);
option->show_value= boost::bind(&PreferencesForm::show_path_option, this, option_name, entry);
option->update_value= boost::bind(&PreferencesForm::update_path_option, this, option_name, entry);
_options.push_back(option);
return entry;
}
mforms::TextEntry *PreferencesForm::new_numeric_entry_option(const std::string &option_name, int minrange, int maxrange)
{
Option *option= new Option();
mforms::TextEntry *entry= new mforms::TextEntry();
option->view= mforms::manage(entry);
option->show_value= boost::bind(&PreferencesForm::show_entry_option, this, option_name, entry, true);
option->update_value= boost::bind(&PreferencesForm::update_entry_option_numeric, this, option_name, entry, minrange, maxrange);
_options.push_back(option);
return entry;
}
mforms::CheckBox *PreferencesForm::new_checkbox_option(const std::string &option_name)
{
Option *option= new Option();
mforms::CheckBox *checkbox= new mforms::CheckBox();
option->view= mforms::manage(checkbox);
option->show_value= boost::bind(&PreferencesForm::show_checkbox_option, this, option_name, checkbox);
option->update_value= boost::bind(&PreferencesForm::update_checkbox_option, this, option_name, checkbox);
_options.push_back(option);
return checkbox;
}
mforms::Selector *PreferencesForm::new_selector_option(const std::string &option_name, std::string choices_string, bool as_number)
{
Option *option= new Option();
mforms::Selector *selector= new mforms::Selector();
if (choices_string.empty())
_wbui->get_wb_options_value(_model_id, "@"+option_name+"/Items", choices_string);
std::vector<std::string> choices, parts= base::split(choices_string, ",");
for (std::vector<std::string>::const_iterator iter= parts.begin();
iter != parts.end(); ++iter)
{
std::vector<std::string> tmp= base::split(*iter, ":", 1);
if (tmp.size() == 1)
{
selector->add_item(*iter);
choices.push_back(*iter);
}
else
{
selector->add_item(tmp[0]);
choices.push_back(tmp[1]);
}
}
option->view= mforms::manage(selector);
option->show_value= boost::bind(&PreferencesForm::show_selector_option, this, option_name, selector, choices);
option->update_value= boost::bind(&PreferencesForm::update_selector_option, this, option_name, selector, choices, choices.empty() ? "" : choices[0], as_number);
_options.push_back(option);
return selector;
}
PreferencesForm::~PreferencesForm()
{
for (std::list<Option*>::iterator iter= _options.begin(); iter != _options.end(); ++iter)
delete *iter;
}
//--------------------------------------------------------------------------------------------------
void PreferencesForm::ok_clicked()
{
update_values();
mforms::Form::show(false);
}
//--------------------------------------------------------------------------------------------------
void PreferencesForm::cancel_clicked()
{
mforms::Form::show(false);
}
//--------------------------------------------------------------------------------------------------
void PreferencesForm::create_admin_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Data Export and Import"));
mforms::Table *table= mforms::manage(new mforms::Table());
table->set_padding(8);
table->set_row_spacing(12);
table->set_column_spacing(8);
table->set_row_count(3);
table->set_column_count(3);
frame->add(table);
mforms::FsObjectSelector *pathsel;
table->add(new_label(_("Path to mysqldump Tool:"), true), 0, 1, 0, 1, mforms::HFillFlag);
pathsel= new_path_option("mysqldump", true);
pathsel->get_entry()->set_tooltip(_("Specifiy the full path to the mysqldump tool, which is needed for the Workbench Administrator.\nIt usually comes bundled with the MySQL server and/or client packages."));
table->add(pathsel, 1, 2, 0, 1, mforms::HFillFlag|mforms::HExpandFlag);
#ifdef HAVE_BUNDLED_MYSQLDUMP
table->add(new_label(_("Leave blank to use bundled version."), false, true), 2, 3, 0, 1, mforms::HFillFlag);
#else
table->add(new_label(_("Full path to the mysqldump tool\nif it's not in your PATH."), false, true), 2, 3, 0, 1, mforms::HFillFlag);
#endif
table->add(new_label(_("Path to mysql Tool:"), true), 0, 1, 1, 2, mforms::HFillFlag);
pathsel= new_path_option("mysqlclient", true);
pathsel->get_entry()->set_tooltip(_("Specifiy the full path to the mysql command line client tool, which is needed for the Workbench Administrator.\nIt usually comes bundled with the MySQL server and/or client packages."));
table->add(pathsel, 1, 2, 1, 2, mforms::HFillFlag|mforms::HExpandFlag);
#ifdef HAVE_BUNDLED_MYSQLDUMP
table->add(new_label(_("Leave blank to use bundled version."), false, true), 2, 3, 1, 2, mforms::HFillFlag);
#else
table->add(new_label(_("Full path to the mysql tool\nif it's not in your PATH."), false, true), 2, 3, 1, 2, mforms::HFillFlag);
#endif
table->add(new_label(_("Export Directory Path:"), true), 0, 1, 2, 3, mforms::HFillFlag);
pathsel= new_path_option("dumpdirectory", false);
pathsel->get_entry()->set_tooltip(_("Specifiy the full path to the directory where dump files should be placed by default."));
table->add(pathsel, 1, 2, 2, 3, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("Location where dump files should\nbe placed by default."), false, true), 2, 3, 2, 3, mforms::HFillFlag);
box->add(frame, false);
}
_tabview.add_page(box, _("Administrator"));
}
void PreferencesForm::create_sqlide_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
_tabview.add_page(box, _("SQL Editor"));
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("SQL"));
box->add(frame, false);
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Default SQL_MODE:"), true), false, false);
mforms::TextEntry *entry= new_entry_option("SqlMode", false);
entry->set_tooltip(_(
"Value of SQL_MODE DBMS session variable customizes the rules and restrictions for SQL syntax and semantics. See MySQL Server reference for details.\n"
"This globally defined parameter determines initial value for same named parameter in each newly created model. "
"Model scoped same named parameter in its turn affects SQL parsing within the model, and defines the value of SQL_MODE session variable when connecting to DBMS.\n"
"Note: Empty value for this parameter will cause Workbench to treat SQL_MODE as empty string when parsing SQL within the model, but will leave DBMS session variable at its default value.\n"
"To force Workbench to reset SQL_MODE session variable as well, this parameter needs to be set to a whitespace symbol."));
tbox->add(entry, true, true);
}
{
mforms::CheckBox *check= new_checkbox_option("SqlIdentifiersCS");
check->set_text(_("SQL Identifiers are Case Sensitive"));
check->set_tooltip(_(
"Whether to treat identifiers separately if their names differ only in letter case."));
vbox->add(check, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Non-Standard SQL Delimiter:"), true), false, false);
mforms::TextEntry *entry= new_entry_option("SqlDelimiter", false);
entry->set_size(50, -1);
entry->set_tooltip(_(
"SQL statement delimiter different from the normally used one (ie, shouldn't be ;). Change this only if the delimiter you normally use, specially in stored routines, happens to be the current setting."));
tbox->add(entry, false, false);
}
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Query Editor"));
box->add(frame, false);
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:ShowSchemaTreeSchemaContents");
check->set_text(_("Show Schema Contents in Schema Tree"));
check->set_tooltip(_(
"Whether to show schema contents (tables, views and routine names) in schema tree."));
vbox->add(check, false);
}
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:ShowMetadataSchemata");
check->set_text(_("Show Metadata Schemata"));
check->set_tooltip(_(
"Whether to show metadata/internal schemata in schema tree and overview panel (eg INFORMATION_SCHEMA and mysql)."));
vbox->add(check, false);
}
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:ContinueOnError");
check->set_text(_("Continue on SQL Script Error (by default)"));
check->set_tooltip(_(
"Whether to continue bypassing failed SQL statements when running script."));
vbox->add(check, false);
}
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:SafeUpdates");
check->set_text(_("\"Safe Updates\". Forbid UPDATEs and DELETEs with no key in WHERE clause or no LIMIT clause. Requires a reconnection."));
check->set_tooltip(_(
"Enables the SQL_SAFE_UPDATES option for the session.\n"
"If enabled, MySQL aborts UPDATE or DELETE statements\n"
"that do not use a key in the WHERE clause or a LIMIT clause.\n"
"This makes it possible to catch UPDATE or DELETE statements\n"
"where keys are not used properly and that would probably change\n"
"or delete a large number of rows. \n"
"Changing this option requires a reconnection (Query -> Reconnect to Server)"));
vbox->add(check, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Max syntax error count:"), true), false, false);
mforms::TextEntry *entry= new_entry_option("SqlEditor::SyntaxCheck::MaxErrCount", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Maximum number of errors to stop syntax check.\n"
"Syntax errors aren't highlighted beyond this threshold.\n"
"Set to 0 to show all errors."));
tbox->add(entry, false, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Progress status update interval (in milliseconds):"), true), false, false);
mforms::TextEntry *entry= new_entry_option("DbSqlEditor:ProgressStatusUpdateInterval", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Time interval between UI updates when running SQL script."));
tbox->add(entry, false, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("DBMS connection keep-alive interval (in seconds):"), true), false, false);
mforms::TextEntry *entry= new_entry_option("DbSqlEditor:KeepAliveInterval", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Time interval between sending keep-alive messages to DBMS.\n"
"Set to 0 to not send keep-alive messages."));
tbox->add(entry, false, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("DBMS connection read time out (in seconds):"), true), false, false);
mforms::TextEntry *entry= new_entry_option("DbSqlEditor:ReadTimeOut", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Max time the a query can take to return data from the DBMS"));
tbox->add(entry, false, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Max. query length to store in history (in bytes):"), true), false, false);
mforms::TextEntry *entry= new_entry_option("DbSqlEditor:MaxQuerySizeToHistory", false);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Queries beyond specified size will not be saved in the history when executed.\n"
"Set to 0 to save any executed query or script"));
tbox->add(entry, false, false);
}
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Query Results"));
box->add(frame, false);
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
{
mforms::CheckBox *check= new_checkbox_option("SqlEditor:LimitRows");
check->set_text(_("Limit Rows"));
check->set_tooltip(_(
"Whether every select query to be implicitly adjusted to limit result set to specified number of rows by appending the LIMIT keyword to the query.\n"
"If enabled it's still possible to load entire result set by pressing \"Fetch All\" button."));
vbox->add(check, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Limit Rows Count:"), true), false, false);
mforms::TextEntry *entry= new_entry_option("SqlEditor:LimitRowsCount", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Every select query to be implicitly adjusted to limit result set to specified number of rows."));
tbox->add(entry, false, false);
}
{
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_spacing(4);
vbox->add(tbox, false);
tbox->add(new_label(_("Max. Field Value Length to Display (in bytes):"), true), false, false);
mforms::TextEntry *entry= new_entry_option("Recordset:FieldValueTruncationThreshold", false);
entry->set_max_length(5);
entry->set_size(50, -1);
entry->set_tooltip(_(
"Symbols beyond specified threashold will be truncated when showing in the grid. Doesn't affect editing field values.\n"
"Set to -1 to disable truncation."));
tbox->add(entry, false, false);
}
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:MySQL:TreatBinaryAsText");
check->set_text(_("Treat BINARY/VARBINARY as nonbinary character string"));
check->set_tooltip(_(
"Whether to treat binary byte strings as nonbinary character strings.\n"
"Binary byte string values do not appear in results grid and are marked as a BLOB values that are supposed to be viewed/edited by means of BLOB editor.\n"
"Nonbinary character string values are shown right in results grid and can be edited with either cell's in-place editor or BLOB editor.\n"
"Warning: Since binary byte strings tend to contain zero-bytes in their values, turning this option on may lead to data truncation when viewing/editing.\n"
"Note: Application restart is needed to get new option value in affect."));
vbox->add(check, false);
}
{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:IsDataChangesCommitWizardEnabled");
check->set_text(_("Enable Data Changes Commit Wizard"));
check->set_tooltip(_(
"Whether to use wizard providing more control over applying changes to table data."));
vbox->add(check, false);
}
/*{
mforms::CheckBox *check= new_checkbox_option("DbSqlEditor:IsLiveObjectAlterationWizardEnabled");
check->set_text(_("Enable Live Object Alteration Wizard"));
check->set_tooltip(_(
"Whether to use wizard providing more control over applying changes to live database object."));
vbox->add(check, false);
}*/
}
}
void PreferencesForm::create_general_page()
{
mforms::Box *top_box = mforms::manage(new mforms::Box(false));
top_box->set_padding(12);
top_box->set_spacing(8);
OptionTable *table;
table = mforms::manage(new OptionTable(this, _("EER Modeler"), true));
top_box->add(table, false, true);
{
table->add_checkbox_option("workbench.AutoReopenLastModel", _("Automatically reopen previous model at start"), "");
#ifndef __APPLE__
table->add_checkbox_option("workbench:ForceSWRendering", _("Force use of software based rendering for EER diagrams"),
_("Enable this option if you have drawing problems in Workbench modeling.\nYou must restart Workbench for the option to take effect."));
#endif
{
mforms::TextEntry *entry= new_numeric_entry_option("workbench:UndoEntries", 1, 500);
entry->set_max_length(5);
entry->set_size(100, -1);
table->add_option(entry, _("Model undo history size:"),
_("Allowed values are from 1 up.\nNote: using high values (> 100) will increase memory usage\nand slow down operation."));
}
{
static const char *auto_save_intervals= "disable:0,10 seconds:10,15 seconds:15,30 seconds:30,1 minute:60,5 minutes:300,10 minutes:600,20 minutes:1200";
mforms::Selector *sel = new_selector_option("workbench:AutoSaveModelInterval", auto_save_intervals, true);
table->add_option(sel, _("Auto-save model interval:"),
_("Interval to perform auto-saving of the open model.\nThe model will be restored from the last auto-saved version\nif Workbench unexpectedly quits."));
}
}
table = mforms::manage(new OptionTable(this, _("SQL Editor"), true));
top_box->add(table, false, true);
{
table->add_checkbox_option("workbench:SaveSQLWorkspaceOnClose",
_("Save snapshot of open editors on close"),
_("A snapshot of all open scripts is saved when the SQL Editor is closed. Next time it is opened to the same connection that state is restored. Unsaved files will remain unsaved, but their contents will be preserved."));
{
static const char *auto_save_intervals= "disable:0,10 seconds:10,15 seconds:15,30 seconds:30,1 minute:60,5 minutes:300,10 minutes:600,20 minutes:1200";
mforms::Selector *sel = new_selector_option("workbench:AutoSaveScriptsInterval", auto_save_intervals, true);
table->add_option(sel, _("Auto-save scripts interval:"),
_("Interval to perform auto-saving of all open script tabs.\nThe scripts will be restored from the last auto-saved version\nif Workbench unexpectedly quits."));
}
}
table = mforms::manage(new OptionTable(this, _("Others"), true));
top_box->add(table, false, true);
{
table->add_checkbox_option("Sidebar:RightAligned", _("Place sidebar on the right side"),
_("Whether to place sidebar on the left or right side in module windows.\n"
"Clear this checbox to place sidebar on the left side."));
#ifdef _WIN32
table->add_checkbox_option("SingleInstance", _("Only allow one instance of MySQL Workbench to run"),
_("Determines if only one or multiple instances of MySQL Workbench can run at the same time for "
"a single user.\nThis option requires a restart."));
#endif
mforms::Selector *combo= new_selector_option("grtshell:ShellLanguage");
table->add_option(combo, _("Interactive GRT Shell language:"),
_("Select the language to use in the interactive GRT shell.\n"
"Scripts, modules and plugins will work regardless of this setting.\n"
"This option requires a restart."));
}
_tabview.add_page(top_box, _("General"));
}
void PreferencesForm::create_model_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("When Deleting Physical Model Figures in Diagram"));
mforms::Box *rbox= mforms::manage(new mforms::Box(true));
rbox->set_padding(8);
frame->add(rbox);
rbox->add(new_label(""), false);
mforms::Selector* selector= new_selector_option("workbench.physical:DeleteObjectConfirmation");
selector->set_size(300, -1);
rbox->add(selector, true, false);
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Column Defaults"));
mforms::Table *table= mforms::manage(new mforms::Table());
table->set_padding(12);
table->set_column_spacing(4);
table->set_row_spacing(8);
table->set_column_count(4);
table->set_row_count(2);
frame->add(table);
mforms::TextEntry *entry;
table->add(new_label(_("PK Name:"), true), 0, 1, 0, 1, mforms::HFillFlag);
entry= new_entry_option("PkColumnNameTemplate", false);
entry->set_tooltip(_("Substitutions:\n"
"%table% - name of the table\n"
"May be used as %table|upper% %table|lower% or %table|capitalize%"));
table->add(entry, 1, 2, 0, 1, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("PK Type:"), true), 2, 3, 0, 1, mforms::HFillFlag);
entry= new_entry_option("DefaultPkColumnType", false);
entry->set_tooltip(_("Default type for use in newly added primary key columns.\nSpecify a column type name or a user defined type.\nFlags such as UNSIGNED are not accepted."));
table->add(entry, 3, 4, 0, 1, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("Column Name:"), true), 0, 1, 1, 2, mforms::HFillFlag);
entry= new_entry_option("ColumnNameTemplate", false);
entry->set_tooltip(_("Substitutions:\n"
"%table% - name of the table"));
table->add(entry, 1, 2, 1, 2, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("Column Type:"), true), 2, 3, 1, 2, mforms::HFillFlag);
entry= new_entry_option("DefaultColumnType", false);
entry->set_tooltip(_("Default type for use in newly added columns.\nSpecify a column type name or a user defined type.\nFlags such as UNSIGNED are not accepted."));
table->add(entry, 3, 4, 1, 2, mforms::HFillFlag|mforms::HExpandFlag);
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Foreign Key/Relationship Defaults"));
mforms::Table *table= mforms::manage(new mforms::Table());
table->set_padding(8);
frame->add(table);
table->set_row_spacing(8);
table->set_column_spacing(8);
table->set_row_count(3);
table->set_column_count(4);
mforms::TextEntry *entry;
table->add(new_label(_("FK Name:"), true), 0, 1, 0, 1, mforms::HFillFlag);
entry= new_entry_option("FKNameTemplate", false);
#define SUBS_HELP\
_("Substitutions:\n"\
"%table%, %stable% - name of the source table\n"\
"%dtable% - name of the destination table (where FK is added)\n"\
"%column%, %scolumn% - name of the source column\n"\
"%dcolumn% - name of the destination column\n"\
"May be used as %table|upper% %table|lower% or %table|capitalize%"\
)
entry->set_tooltip(SUBS_HELP);
table->add(entry, 1, 2, 0, 1, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("Column Name:"), true), 2, 3, 0, 1, mforms::HFillFlag);
entry= new_entry_option("FKColumnNameTemplate", false);
entry->set_tooltip(SUBS_HELP);
table->add(entry, 3, 4, 0, 1, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("ON UPDATE:"), true), 0, 1, 1, 2, mforms::HFillFlag);
table->add(new_selector_option("db.ForeignKey:updateRule"), 1, 2, 1, 2, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("ON DELETE:"), true), 2, 3, 1, 2, mforms::HFillFlag);
table->add(new_selector_option("db.ForeignKey:deleteRule"), 3, 4, 1, 2, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("Associative Table Name:"), true), 0, 1, 2, 3, mforms::HFillFlag);
entry= new_entry_option("AuxTableTemplate", false);
entry->set_tooltip(_("Substitutions:\n"
"%stable% - name of the source table\n"
"%dtable% - name of the destination table"));
table->add(entry, 1, 2, 2, 3, mforms::HFillFlag|mforms::HExpandFlag);
table->add(new_label(_("for n:m relationships")), 2, 4, 2, 3, mforms::HFillFlag);
box->add(frame, false);
}
_tabview.add_page(box, _("Model"));
}
void PreferencesForm::create_mysql_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Model Table Defaults"));
mforms::Box *tbox= mforms::manage(new mforms::Box(true));
tbox->set_padding(8);
frame->add(tbox);
tbox->add(new_label(_("Default Storage Engine:"), true), false, false);
tbox->add(new_selector_option("db.mysql.Table:tableEngine"), true, true);
box->add(frame, false);
}
_tabview.add_page(box, _("Model: MySQL"));
}
void PreferencesForm::create_diagram_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("All Objects"));
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
mforms::CheckBox *check;
check= new_checkbox_option("workbench.physical.ObjectFigure:Expanded");
check->set_text(_("Expand New Objects"));
check->set_tooltip(_("Set the initial state of newly created objects to expanded (or collapsed)"));
vbox->add(check, false);
check= new_checkbox_option("SynchronizeObjectColors");
check->set_text(_("Propagate Object Color Changes to All Diagrams"));
check->set_tooltip(_("If an object figure's color is changed, all figures in all diagrams that represent the same object are also updated"));
vbox->add(check, false);
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Tables"));
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
mforms::CheckBox *check;
check= new_checkbox_option("workbench.physical.TableFigure:ShowColumnTypes");
check->set_text(_("Show Column Types"));
check->set_tooltip(_("Show the column types along their names in table figures"));
vbox->add(check, false);
{
mforms::Box *hbox= mforms::manage(new mforms::Box(true));
mforms::TextEntry *entry= new_entry_option("workbench.physical.TableFigure:MaxColumnTypeLength", true);
hbox->set_spacing(4);
//label->set_size(200, -1);
entry->set_max_length(5);
entry->set_size(50, -1);
hbox->add(new_label(_("Max. Length of ENUMs and SETs to Display:"), true), false, false);
hbox->add(entry, false);
vbox->add(hbox, false);
}
check= new_checkbox_option("workbench.physical.TableFigure:ShowColumnFlags");
check->set_text(_("Show Column Flags"));
check->set_tooltip(_("Show column flags such as NOT NULL or UNSIGNED along their names in table figures"));
vbox->add(check, false);
{
mforms::Box *hbox= mforms::manage(new mforms::Box(true));
mforms::TextEntry *entry= new_entry_option("workbench.physical.TableFigure:MaxColumnsDisplayed", true);
mforms::Label *descr= mforms::manage(new mforms::Label());
hbox->set_spacing(4);
//label->set_size(200, -1);
entry->set_max_length(5);
entry->set_size(50, -1);
descr->set_text(_("Larger tables will be truncated."));
descr->set_style(mforms::SmallHelpTextStyle);
hbox->add(new_label(_("Max. Number of Columns to Display:"), true), false, false);
hbox->add(entry, false);
hbox->add(descr, true, true);
vbox->add(hbox, false);
}
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Routines"));
mforms::Box *hbox= mforms::manage(new mforms::Box(true));
hbox->set_padding(8);
hbox->set_spacing(4);
frame->add(hbox);
mforms::TextEntry *entry;
hbox->add(new_label(_("Trim Routine Names Longer Than")), false);
entry= new_entry_option("workbench.physical.RoutineGroupFigure:MaxRoutineNameLength", true);
entry->set_size(60, -1);
entry->set_max_length(3);
hbox->add(entry, false);
hbox->add(new_label(_("characters")), false);
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Relationships/Connections"));
mforms::Box *vbox= mforms::manage(new mforms::Box(false));
vbox->set_padding(8);
vbox->set_spacing(4);
frame->add(vbox);
mforms::CheckBox *check;
check= new_checkbox_option("workbench.physical.Diagram:DrawLineCrossings");
check->set_text(_("Draw Line Crossings (slow in large diagrams)"));
vbox->add(check, false);
check= new_checkbox_option("workbench.physical.Connection:HideCaptions");
check->set_text(_("Hide Captions"));
vbox->add(check, false);
check= new_checkbox_option("workbench.physical.Connection:CenterCaptions");
check->set_text(_("Center Captions Over Line"));
vbox->add(check, false);
box->add(frame, false);
}
_tabview.add_page(box, _("Diagram"));
}
static void show_text_option(grt::DictRef options, const std::string &option_name, mforms::TextBox *text)
{
text->set_value(options.get_string(option_name));
}
static void update_text_option(grt::DictRef options, const std::string &option_name, mforms::TextBox *text)
{
options.gset(option_name, text->get_string_value());
}
void PreferencesForm::create_appearance_page()
{
mforms::Box *box= mforms::manage(new mforms::Box(false));
box->set_padding(12);
box->set_spacing(8);
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Color Presets"));
mforms::Table *table= mforms::manage(new mforms::Table());
table->set_padding(8);
table->set_row_spacing(4);
table->set_column_spacing(4);
table->set_row_count(2);
table->set_column_count(2);
frame->add(table);
mforms::TextBox *text;
table->add(new_label(_("Colors available for tables, views etc")), 0, 1, 0, 1, mforms::HFillFlag);
text= new mforms::TextBox(mforms::VerticalScrollBar);
text->set_size(200, 100);
table->add(text, 0, 1, 1, 2, mforms::FillAndExpand);
Option *option= new Option();
_options.push_back(option);
option->view= text;
option->show_value= boost::bind(show_text_option, get_options(), "workbench.model.ObjectFigure:ColorList", text);
option->update_value= boost::bind(update_text_option, get_options(), "workbench.model.ObjectFigure:ColorList", text);
table->add(new_label(_("Colors available for layers, notes etc")), 1, 2, 0, 1, mforms::HFillFlag);
text= new mforms::TextBox(mforms::VerticalScrollBar);
text->set_size(200, 100);
table->add(text, 1, 2, 1, 2, mforms::FillAndExpand);
option= new Option();
_options.push_back(option);
option->view= text;
option->show_value= boost::bind(&show_text_option, get_options(), "workbench.model.Figure:ColorList", text);
option->update_value= boost::bind(&update_text_option, get_options(), "workbench.model.Figure:ColorList", text);
box->add(frame, false);
}
{
mforms::Panel *frame= mforms::manage(new mforms::Panel(mforms::TitledBoxPanel));
frame->set_title(_("Fonts"));
mforms::Table *table= mforms::manage(new mforms::Table());
table->set_padding(8);
table->set_row_spacing(4);
table->set_column_spacing(4);
table->set_row_count(2);
table->set_column_count(2);
frame->add(table);
_font_list.add_column(mforms::StringColumnType, _("Location"), 150, false);
_font_list.add_column(mforms::StringColumnType, _("Font"), 150, true);
_font_list.end_columns();
table->add(&_font_list, 0, 1, 0, 1, mforms::FillAndExpand);
box->add(frame, true, true);
}
_tabview.add_page(box, _("Appearance"));
}
#if defined(_DEBUG) || defined(ENABLE_DEBUG)
/**
* Used to create a forms page and attach it to the options form as a general playground
* e.g. for testing mforms, creating other pages etc.
*/
void PreferencesForm::create_test_page()
{
Box* content= manage(new Box(false));
_test_button = manage(new Button());
content->add(_test_button, false, true);
_test_button->set_text("popover");
scoped_connect(_test_button->signal_clicked(), boost::bind(&PreferencesForm::test_clicked, this));
_tabview.add_page(content, _("Test page"));
}
void PreferencesForm::test_clicked()
{
static wb::SnippetPopover* popover = NULL;
if (popover == NULL)
{
popover = new wb::SnippetPopover();
popover->set_size(376, 257);
popover->set_read_only(true);
int x = _test_button->get_x();
int y = _test_button->get_y();
_test_button->client_to_screen(x, y);
popover->show(x + _test_button->get_width() / 2, y + _test_button->get_height() / 2, mforms::Below);
}
else
{
popover->close();
delete popover;
popover = NULL;
}
}
#endif
static std::string separate_camel_word(const std::string &word)
{
std::string result;
for (std::string::const_iterator c= word.begin(); c != word.end(); ++c)
{
if (!result.empty() && *c >= 'A' && *c <= 'Z')
result.append(" ");
result.append(1, *c);
}
return result;
}
void PreferencesForm::show_colors_and_fonts()
{
std::vector<std::string> options= _wbui->get_wb_options_keys("");
_font_options.clear();
_font_list.clear_rows();
for (std::vector<std::string>::const_iterator iter= options.begin();
iter != options.end(); ++iter)
{
if (bec::has_suffix(*iter, "Font") && bec::has_prefix(*iter, "workbench."))
{
std::string::size_type pos= iter->find(':');
if (pos != std::string::npos)
{
try
{
std::string part= iter->substr(pos + 1);
std::string figure= base::split(iter->substr(0, pos), ".")[2];
std::string caption;
part= part.substr(0, part.length() - 4);
// substitute some figure names
figure= bec::replace_string(figure, "NoteFigure", "TextFigure");
caption= separate_camel_word(figure) + " " + part;
int row= _font_list.add_row();
std::string value;
_wbui->get_wb_options_value("", *iter, value);
_font_list.set(row, 0, caption);
_font_list.set(row, 1, value);
_font_options.push_back(*iter);
}
catch (...)
{
}
}
}
}
}
void PreferencesForm::update_colors_and_fonts()
{
for (int c= _font_list.count(), i= 0; i < c; i++)
{
std::string value= _font_list.get_string(i, 1);
_wbui->set_wb_options_value("", _font_options[i], value);
}
}
void PreferencesForm::toggle_use_global()
{
_tabview.set_enabled(!_use_global.get_active());
}
|