| 634 | } |
| 635 | |
| 636 | wxString TableFrame::PromptRenameColName(TableInterface* ti, int curr_col, |
| 637 | const wxString& initial_name) |
| 638 | { |
| 639 | bool is_group_col = ti->IsColTimeVariant(curr_col); |
| 640 | wxString initial_msg; |
| 641 | wxString dlg_title; |
| 642 | if (is_group_col) { |
| 643 | dlg_title << _("Rename Space-Time Variable"); |
| 644 | initial_msg << _("New space-time variable name"); |
| 645 | } else { |
| 646 | dlg_title << _("Rename Variable"); |
| 647 | initial_msg << _("New variable name"); |
| 648 | } |
| 649 | |
| 650 | bool done = false; |
| 651 | wxString curr_name = ti->GetColName(curr_col); |
| 652 | wxString new_name = initial_name; |
| 653 | wxString error_pre_msg = wxEmptyString; |
| 654 | error_pre_msg = _("Variable name is either a duplicate or is invalid. Please\nenter an alternative, non-duplicate variable name.\n\n"); |
| 655 | wxString error_msg = wxEmptyString; |
| 656 | |
| 657 | bool first = true; |
| 658 | // rename field name may allow different case, e.g. ID->id |
| 659 | bool case_sensitive = project->IsFieldCaseSensitive(); |
| 660 | |
| 661 | while (!done) { |
| 662 | wxString m = is_group_col ? error_pre_msg : error_pre_msg + error_msg; |
| 663 | wxTextEntryDialog dlg(this, (first ? initial_msg : m), dlg_title, |
| 664 | new_name); |
| 665 | if (dlg.ShowModal() == wxID_OK) { |
| 666 | new_name = dlg.GetValue(); |
| 667 | new_name.Trim(false); |
| 668 | new_name.Trim(true); |
| 669 | |
| 670 | bool is_name_exist = false; |
| 671 | bool case_change = new_name.CmpNoCase(curr_name) == 0; |
| 672 | if ( !case_change && ti->DoesNameExist(new_name, false)) { |
| 673 | is_name_exist = true; |
| 674 | } |
| 675 | |
| 676 | // is_name_exist includes if new_name equals (case) curr_name |
| 677 | if (is_name_exist == false ) { |
| 678 | if (is_group_col) { |
| 679 | if (ti->IsValidGroupName(new_name)) { |
| 680 | done = true; |
| 681 | } |
| 682 | } else { |
| 683 | if (ti->IsValidDBColName(new_name, &error_msg)) { |
| 684 | done = true; |
| 685 | } |
| 686 | } |
| 687 | } |
| 688 | first = false; |
| 689 | } else { |
| 690 | new_name = ""; |
| 691 | done = true; |
| 692 | } |
| 693 | } |
nothing calls this directly
no test coverage detected