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 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// file name : subversion2.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// 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; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "subversion2.h"
#include "SvnCommitDialog.h"
#include "SvnLogDialog.h"
#include "SvnShowFileChangesHandler.h"
#include "SvnShowRecentChangesDlg.h"
#include "clGotoAnythingManager.h"
#include "clKeyboardManager.h"
#include "cl_standard_paths.h"
#include "detachedpanesinfo.h"
#include "dockablepane.h"
#include "event_notifier.h"
#include "fileutils.h"
#include "globals.h"
#include "procutils.h"
#include "subversion_password_db.h"
#include "subversion_strings.h"
#include "subversion_view.h"
#include "svn_command_handlers.h"
#include "svn_console.h"
#include "svn_login_dialog.h"
#include "svn_patch_dlg.h"
#include "svn_preferences_dialog.h"
#include "svn_sync_dialog.h"
#include "svnstatushandler.h"
#include "svnxml.h"
#include <algorithm>
#include <wx/app.h>
#include <wx/dir.h>
#include <wx/ffile.h>
#include <wx/fileconf.h>
#include <wx/filedlg.h>
#include <wx/filefn.h>
#include <wx/imaglist.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/msgdlg.h>
#include <wx/numdlg.h>
#include <wx/regex.h>
#include <wx/stdpaths.h>
#include <wx/textdlg.h>
#include <wx/tokenzr.h>
#include <wx/xrc/xmlres.h>
static Subversion2* thePlugin = NULL;
// Convert to Windows EOL
static void ConvertToWindowsEOL(wxString& str)
{
wxString newBuffer;
newBuffer.Alloc(str.Len());
for(size_t i = 0; i < str.Len(); i++) {
wxChar nextChar = '\0';
wxChar ch = str.GetChar(i);
if((i + 1) < str.Len()) {
nextChar = str.GetChar(i + 1);
}
if(ch == '\r' && nextChar == '\n') {
newBuffer << "\r\n";
i++;
} else if(ch == '\n') {
newBuffer << "\r\n";
} else if(ch == '\r' && nextChar != '\n') {
newBuffer << "\r\n";
} else {
newBuffer.Append(ch);
}
}
str.swap(newBuffer);
}
// Convert to Unix style
static void ConvertToUnixEOL(wxString& str)
{
wxString newBuffer;
newBuffer.Alloc(str.Len());
for(size_t i = 0; i < str.Len(); i++) {
wxChar nextChar = '\0';
wxChar ch = str.GetChar(i);
if((i + 1) < str.Len()) {
nextChar = str.GetChar(i + 1);
}
if(ch == '\r' && nextChar == '\n') {
newBuffer << "\n";
i++;
} else if(ch == '\r' && nextChar != '\n') {
newBuffer << "\n";
} else {
newBuffer.Append(ch);
}
}
str.swap(newBuffer);
}
// Define the plugin entry point
CL_PLUGIN_API IPlugin* CreatePlugin(IManager* manager)
{
if(thePlugin == 0) {
thePlugin = new Subversion2(manager);
}
return thePlugin;
}
CL_PLUGIN_API PluginInfo* GetPluginInfo()
{
static PluginInfo info;
info.SetAuthor("Eran Ifrah");
info.SetName("Subversion");
info.SetDescription(_("Subversion plugin for codelite2.0 based on the svn command line tool"));
info.SetVersion("v2.0");
return &info;
}
CL_PLUGIN_API int GetPluginInterfaceVersion() { return PLUGIN_INTERFACE_VERSION; }
Subversion2::Subversion2(IManager* manager)
: IPlugin(manager)
, m_explorerSepItem(NULL)
, m_projectSepItem(NULL)
, m_simpleCommand(this)
, m_diffCommand(this)
, m_blameCommand(this)
, m_svnClientVersion(0.0)
, m_skipRemoveFilesDlg(false)
, m_clientVersion(1700) // 1.7.0 (1*1000 + 7*100 + 0)
{
m_longName = _("Subversion plugin for codelite2.0 based on the svn command line tool");
m_shortName = "Subversion2";
DoInitialize();
GetManager()->GetTheApp()->Connect(XRCID("subversion2_settings"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSettings), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_commit"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnCommit), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_update"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnUpdate), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_add"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFolderAdd), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_delete"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnDeleteFolder), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_rename"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerRenameItem), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_revert"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerRevertItem), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_revert_to_revision"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnRevertToRevision), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_diff"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerDiff), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_log"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnLog), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_blame"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnBlame), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_ignore_file"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnIgnoreFile), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_ignore_file_pattern"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnIgnoreFilePattern), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_set_as_view"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSelectAsView), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_unlock"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnUnLockFile), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_lock"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnLockFile), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_workspace_sync"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSync), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_show_changes"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnShowFileChanges), NULL, this);
EventNotifier::Get()->Connect(wxEVT_GET_ADDITIONAL_COMPILEFLAGS, clBuildEventHandler(Subversion2::OnGetCompileLine),
NULL, this);
EventNotifier::Get()->Connect(wxEVT_WORKSPACE_CONFIG_CHANGED,
wxCommandEventHandler(Subversion2::OnWorkspaceConfigChanged), NULL, this);
EventNotifier::Get()->Connect(wxEVT_PROJ_FILE_REMOVED, clCommandEventHandler(Subversion2::OnProjectFileRemoved),
NULL, this);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FOLDER, &Subversion2::OnFolderContextMenu, this);
EventNotifier::Get()->Bind(wxEVT_CONTEXT_MENU_FILE, &Subversion2::OnFileContextMenu, this);
EventNotifier::Get()->Bind(wxEVT_FILE_DELETED, &Subversion2::OnFileDeleted, this);
EventNotifier::Get()->Bind(wxEVT_FOLDER_DELETED, &Subversion2::OnFolderDeleted, this);
EventNotifier::Get()->Bind(wxEVT_GOTO_ANYTHING_SHOWING, &Subversion2::OnGotoAnythingShowing, this);
clKeyboardManager::Get()->AddAccelerator("svn_options", _("Subversion"), _("Options..."));
// Register common SVN actins into the "Goto Anything" manager
// clGotoAnythingManager::Get().Add(clGotoEntry("Svn > Commit", "", XRCID("svn_commit")));
// clGotoAnythingManager::Get().Add(clGotoEntry("Svn > Update", "", XRCID("svn_update")));
}
Subversion2::~Subversion2() {}
void Subversion2::CreateToolBar(clToolBarGeneric* toolbar) { wxUnusedVar(toolbar); }
void Subversion2::CreatePluginMenu(wxMenu* pluginsMenu)
{
wxUnusedVar(pluginsMenu);
// You can use the below code a snippet:
wxMenu* menu = new wxMenu();
wxMenuItem* item(NULL);
item = new wxMenuItem(menu, XRCID("subversion2_settings"), _("Subversion Options"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
pluginsMenu->Append(wxID_ANY, _("Subversion2"), menu);
}
wxMenu* Subversion2::CreateProjectPopMenu()
{
wxMenu* menu = new wxMenu();
wxMenuItem* item(NULL);
item = new wxMenuItem(menu, XRCID("svn_workspace_sync"), _("Sync Project Files..."), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
return menu;
}
void Subversion2::HookPopupMenu(wxMenu* menu, MenuType type)
{
if(type == MenuTypeFileView_Project) {
if(!menu->FindItem(XRCID("SUBVERSION_PROJECT_POPUP"))) {
m_projectSepItem = menu->PrependSeparator();
menu->Prepend(XRCID("SUBVERSION_PROJECT_POPUP"), "Subversion", CreateProjectPopMenu());
}
}
}
wxMenu* Subversion2::CreateFileExplorerPopMenu(bool isFile)
{
// Create the popup menu for the file explorer
// The only menu that we are interested is the file explorer menu
wxMenu* menu = new wxMenu();
wxMenuItem* item(NULL);
if(!isFile) {
item = new wxMenuItem(menu, XRCID("svn_explorer_set_as_view"), _("Watch this folder"), wxEmptyString,
wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
}
item = new wxMenuItem(menu, XRCID("svn_explorer_update"), _("Update"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
item = new wxMenuItem(menu, XRCID("svn_explorer_commit"), _("Commit"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
item = new wxMenuItem(menu, XRCID("svn_explorer_delete"), _("Delete"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
item = new wxMenuItem(menu, XRCID("svn_explorer_revert"), _("Revert changes"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
if(isFile) {
item = new wxMenuItem(menu, XRCID("svn_explorer_lock"), _("Lock file"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
item = new wxMenuItem(menu, XRCID("svn_explorer_unlock"), _("UnLock file"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
item = new wxMenuItem(menu, XRCID("svn_explorer_show_changes"), _("Show Recent Changes"), wxEmptyString,
wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
}
item = new wxMenuItem(menu, XRCID("svn_explorer_add"), _("Add"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
item = new wxMenuItem(menu, XRCID("svn_explorer_rename"), _("Rename"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
item = new wxMenuItem(menu, XRCID("svn_explorer_revert_to_revision"), _("Revert to revision"), wxEmptyString,
wxITEM_NORMAL);
menu->Append(item);
menu->AppendSeparator();
item = new wxMenuItem(menu, XRCID("svn_explorer_diff"), _("Create Diff"), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
item = new wxMenuItem(menu, XRCID("svn_explorer_log"), _("Change Log..."), wxEmptyString, wxITEM_NORMAL);
menu->Append(item);
return menu;
}
void Subversion2::UnPlug()
{
EventNotifier::Get()->Unbind(wxEVT_CONTEXT_MENU_FOLDER, &Subversion2::OnFolderContextMenu, this);
EventNotifier::Get()->Unbind(wxEVT_CONTEXT_MENU_FILE, &Subversion2::OnFileContextMenu, this);
EventNotifier::Get()->Unbind(wxEVT_FILE_DELETED, &Subversion2::OnFileDeleted, this);
EventNotifier::Get()->Unbind(wxEVT_FOLDER_DELETED, &Subversion2::OnFolderDeleted, this);
EventNotifier::Get()->Unbind(wxEVT_GOTO_ANYTHING_SHOWING, &Subversion2::OnGotoAnythingShowing, this);
m_tabToggler.reset(NULL);
GetManager()->GetTheApp()->Disconnect(XRCID("subversion2_settings"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSettings), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_commit"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnCommit), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_update"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnUpdate), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_add"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFolderAdd), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_delete"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnDeleteFolder), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_rename"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerRenameItem), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_revert"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerRevertItem), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_diff"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnFileExplorerDiff), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_log"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnLog), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_blame"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnBlame), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_ignore_file"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnIgnoreFile), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_ignore_file_pattern"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnIgnoreFilePattern), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_explorer_set_as_view"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSelectAsView), NULL, this);
GetManager()->GetTheApp()->Disconnect(XRCID("svn_workspace_sync"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnSync), NULL, this);
GetManager()->GetTheApp()->Connect(XRCID("svn_explorer_show_changes"), wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler(Subversion2::OnShowFileChanges), NULL, this);
EventNotifier::Get()->Disconnect(wxEVT_GET_ADDITIONAL_COMPILEFLAGS,
clBuildEventHandler(Subversion2::OnGetCompileLine), NULL, this);
m_subversionView->DisconnectEvents();
// Remove the tab if it's actually docked in the workspace pane
int index(wxNOT_FOUND);
index = m_mgr->GetOutputPaneNotebook()->GetPageIndex(m_subversionView);
if(index != wxNOT_FOUND) {
m_mgr->GetOutputPaneNotebook()->RemovePage(index);
}
m_subversionView->Destroy();
}
void Subversion2::EnsureVisible()
{
// Ensure that the Output View is displayed
wxAuiPaneInfo& pi = GetManager()->GetDockingManager()->GetPane("Output View");
if(pi.IsOk() && !pi.IsShown()) {
pi.Show(true);
GetManager()->GetDockingManager()->Update();
}
Notebook* book = GetManager()->GetOutputPaneNotebook();
for(size_t i = 0; i < book->GetPageCount(); i++) {
if(m_subversionView == book->GetPage(i)) {
book->SetSelection(i);
break;
}
}
}
void Subversion2::DoInitialize()
{
m_svnBitmap = GetManager()->GetStdIcons()->LoadBitmap("subversion");
// create tab (possibly detached)
Notebook* book = m_mgr->GetOutputPaneNotebook();
auto images = book->GetBitmaps();
if(IsSubversionViewDetached()) {
// Make the window child of the main panel (which is the grand parent of the notebook)
DockablePane* cp = new DockablePane(book->GetParent()->GetParent(), book, svnCONSOLE_TEXT, false, wxNOT_FOUND,
wxSize(200, 200));
m_subversionView = new SubversionView(cp, this);
cp->SetChildNoReparent(m_subversionView);
} else {
m_subversionView = new SubversionView(book, this);
book->AddPage(m_subversionView, svnCONSOLE_TEXT, false, images->Add("subversion"));
}
m_tabToggler.reset(new clTabTogglerHelper(svnCONSOLE_TEXT, m_subversionView, "", NULL));
m_tabToggler->SetOutputTabBmp(images->Add("subversion"));
DoSetSSH();
// We need to perform a dummy call to svn so it will create all the default
// setup directory layout
wxString command;
wxArrayString output;
command << GetSvnExeName() << " --help ";
#ifndef __WXMSW__
command << "> /dev/null 2>&1";
#endif
ProcUtils::ExecuteCommand(command, output);
DoGetSvnVersion();
DoGetSvnClientVersion();
RecreateLocalSvnConfigFile();
}
SvnSettingsData Subversion2::GetSettings()
{
SvnSettingsData ssd;
GetManager()->GetConfigTool()->ReadObject("SvnSettingsData", &ssd);
return ssd;
}
void Subversion2::SetSettings(SvnSettingsData& ssd)
{
GetManager()->GetConfigTool()->WriteObject("SvnSettingsData", &ssd);
}
void Subversion2::OnSettings(wxCommandEvent& event)
{
wxUnusedVar(event);
EditSettings();
}
void Subversion2::DoSetSSH()
{
wxString sshClient = GetSettings().GetSshClient();
wxString sshClientArgs = GetSettings().GetSshClientArgs();
sshClient.Trim().Trim(false);
sshClientArgs.Trim().Trim(false);
// on Windows, SVN demands that the ssh client will not contain any
// backward slashes
sshClient.Replace("\\", "/");
if(sshClient.IsEmpty() == false) {
wxString env_value(sshClient + " " + sshClientArgs);
wxSetEnv("SVN_SSH", env_value.c_str());
}
}
////////////////////////////////////////////////
// File Explorer SVN command handlers
////////////////////////////////////////////////
void Subversion2::OnFolderAdd(wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(LoginIfNeeded(event, DoGetFileExplorerItemPath(), loginString) == false) {
return;
}
wxFileName workingDirectory(m_selectedFolder, "");
if(m_selectedFile.IsOk()) {
command << GetSvnExeName() << loginString << " add " << m_selectedFile.GetFullName();
} else {
wxString folderName = workingDirectory.GetDirs().Last();
::WrapWithQuotes(folderName);
workingDirectory.RemoveLastDir();
command << GetSvnExeName() << loginString << " add " << folderName;
}
GetConsole()->Execute(command, workingDirectory.GetPath(), new SvnStatusHandler(this, event.GetId(), this));
}
void Subversion2::OnCommit(wxCommandEvent& event)
{
// Coming from file explorer
wxArrayString paths;
if(!m_selectedFile.IsOk()) {
paths.Add(".");
} else {
paths.Add(m_selectedFile.GetFullName());
}
DoCommit(paths, m_selectedFolder, event);
}
void Subversion2::OnDeleteFolder(wxCommandEvent& event)
{
// Coming from file explorer
wxString command;
wxString loginString;
if(LoginIfNeeded(event, m_selectedFolder, loginString) == false) {
return;
}
// svn delete --force <folder-name>
wxFileName workingDirectory(m_selectedFolder, "");
if(!m_selectedFile.IsOk()) {
wxString folderName = workingDirectory.GetDirs().Last();
::WrapWithQuotes(folderName);
workingDirectory.RemoveLastDir();
command << GetSvnExeName() << loginString << " delete --force " << folderName;
} else {
command << GetSvnExeName() << loginString << " delete --force " << m_selectedFile.GetFullName();
}
GetConsole()->Execute(command, workingDirectory.GetPath(), new SvnDefaultCommandHandler(this, event.GetId(), this));
}
void Subversion2::OnFileExplorerRevertItem(wxCommandEvent& event)
{
// Coming from the file explorer
if(wxMessageBox(_("You are about to revert all your changes\nAre you sure?"), "CodeLite",
wxICON_WARNING | wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER) != wxYES) {
return;
}
wxString command;
if(m_selectedFile.FileExists()) {
// Revert was called on a file, revert only the file
command << GetSvnExeName() << " revert --recursive " << m_selectedFile.GetFullName();
} else {
// Revert the folder
command << GetSvnExeName() << " revert --recursive .";
}
GetConsole()->Execute(command, m_selectedFolder, new SvnDefaultCommandHandler(this, event.GetId(), this));
}
void Subversion2::OnUpdate(wxCommandEvent& event)
{
// Coming from explorer view
wxString command;
wxString loginString;
if(LoginIfNeeded(event, m_selectedFolder, loginString) == false) {
return;
}
// svn update .
command << GetSvnExeName() << loginString << " update " << m_selectedFile.GetFullName() << " ";
AddCommandLineOption(command, kOpt_ForceInteractive);
command << ".";
// Execute the command, but with console visible
GetConsole()->Execute(command, m_selectedFolder, new SvnUpdateHandler(this, event.GetId(), this), true, true);
}
void Subversion2::OnFileExplorerDiff(wxCommandEvent& event)
{
wxString diffAgainst("BASE");
diffAgainst = clGetTextFromUser(_("Svn Diff"), _("Insert base revision to diff against:"), "BASE", wxNOT_FOUND,
GetManager()->GetTheApp()->GetTopWindow());
if(diffAgainst.empty()) {
return;
}
wxString command;
wxString loginString;
if(LoginIfNeeded(event, m_selectedFolder, loginString) == false) {
return;
}
command << GetSvnExeNameNoConfigDir() << loginString;
SvnSettingsData ssd = GetSettings();
if(ssd.GetFlags() & SvnUseExternalDiff) {
command << " --diff-cmd=\"" << ssd.GetExternalDiffViewer() << "\" ";
}
wxFileName workingDirectory(m_selectedFolder, "");
command << "diff -r" << diffAgainst;
if(m_selectedFile.IsOk()) {
command << " " << m_selectedFile.GetFullName();
} else {
command << " .";
}
GetConsole()->Execute(command, workingDirectory.GetPath(), new SvnDiffHandler(this, event.GetId(), this), false);
}
wxString Subversion2::GetSvnExeName()
{
SvnSettingsData ssd = GetSettings();
wxString exeName = ssd.GetExecutable();
exeName.Trim().Trim(false);
::WrapWithQuotes(exeName);
exeName << " --config-dir";
wxString configDir = GetUserConfigDir();
::WrapWithQuotes(configDir);
exeName << " " << configDir;
return exeName;
}
wxString Subversion2::DoGetFileExplorerFilesAsString()
{
wxString s;
wxArrayString files = DoGetFileExplorerFiles();
for(size_t i = 0; i < files.GetCount(); i++) {
s << " \"" << files.Item(i) << "\" ";
}
return s;
}
wxArrayString Subversion2::DoGetFileExplorerFiles()
{
TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileExplorer);
return item.m_paths;
}
wxString Subversion2::DoGetFileExplorerItemFullPath()
{
TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileExplorer);
wxString filename(item.m_fileName.GetFullPath());
filename.Trim().Trim(false);
if(filename.EndsWith("\\")) {
filename.RemoveLast();
} else if(filename.EndsWith("/")) {
filename.RemoveLast();
}
return filename;
}
wxString Subversion2::DoGetFileExplorerItemPath()
{
TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileExplorer);
if(!item.m_paths.IsEmpty()) {
return item.m_paths.Item(0);
} else {
return wxEmptyString;
}
}
wxString Subversion2::GetUserConfigDir()
{
wxString configDir(clStandardPaths::Get().GetUserDataDir());
if(wxFileName::DirExists(configDir) == false) {
wxMkdir(configDir);
}
configDir << wxFileName::GetPathSeparator() << "subversion";
return configDir;
}
void Subversion2::RecreateLocalSvnConfigFile()
{
wxString configFile;
wxString configDir = GetUserConfigDir();
configFile << configDir << wxFileName::GetPathSeparator() << "config";
// Convert any whitespace to space
wxString ignorePatterns(GetSettings().GetIgnoreFilePattern());
ignorePatterns.Replace("\r\n", " ");
ignorePatterns.Replace("\n", " ");
ignorePatterns.Replace("\t", " ");
ignorePatterns.Replace("\v", " ");
wxString diffTool = GetSettings().GetExternalDiffViewer();
if(!(GetSettings().GetFlags() & SvnUseExternalDiff)) {
diffTool.Empty();
}
wxFileConfig iniConfig("", "", configFile, "", wxCONFIG_USE_LOCAL_FILE);
iniConfig.Write("miscellany/global-ignores", ignorePatterns);
iniConfig.Write("helpers/diff-cmd", diffTool);
iniConfig.Flush();
}
void Subversion2::DoGetSvnVersion()
{
wxString command;
command << GetSvnExeName() << " --version ";
m_simpleCommand.Execute(command, "", new SvnVersionHandler(this, wxNOT_FOUND, NULL), this);
}
void Subversion2::Patch(bool dryRun, const wxString& workingDirectory, wxEvtHandler* owner, int id)
{
PatchDlg dlg(GetManager()->GetTheApp()->GetTopWindow());
if(dlg.ShowModal() == wxID_OK) {
wxBusyCursor cursor;
wxString patchFile;
patchFile = dlg.GetFilePicker()->GetPath();
int eolPolicy = dlg.GetRadioBoxPolicy()->GetSelection();
bool removeFileWhenDone = false;
if(eolPolicy != 0) {
// Read the file
wxString fileContent;
if(ReadFileWithConversion(patchFile, fileContent)) {
switch(eolPolicy) {
case 1: // Windows EOL
ConvertToWindowsEOL(fileContent);
break;
case 2: // Convert to UNIX style
ConvertToUnixEOL(fileContent);
break;
}
// Write the content to a new file
wxFFile fileTemp;
wxString tmpFile = wxFileName::CreateTempFileName("clsvn", &fileTemp);
if(fileTemp.IsOpened()) {
if(fileTemp.Write(fileContent)) {
fileTemp.Close();
removeFileWhenDone = true;
patchFile = tmpFile;
}
}
}
}
if(patchFile.IsEmpty() == false) {
// execute the command
wxString command;
command << "patch -l -p0 ";
if(dryRun) {
command << " --dry-run ";
}
command << " -i \"" << patchFile << "\"";
SvnCommandHandler* handler(NULL);
if(dryRun) {
handler = new SvnPatchDryRunHandler(this, id, owner, removeFileWhenDone, patchFile);
} else {
handler = new SvnPatchHandler(this, id, owner, removeFileWhenDone, patchFile);
}
m_simpleCommand.Execute(command, workingDirectory, handler, this);
}
}
}
void Subversion2::OnLog(wxCommandEvent& event) { ChangeLog(m_selectedFolder, ".", event); }
bool Subversion2::GetNonInteractiveMode(wxCommandEvent& event) { return event.GetInt() != INTERACTIVE_MODE; }
bool Subversion2::LoginIfNeeded(wxCommandEvent& event, const wxString& workingDirectory, wxString& loginString)
{
RecreateLocalSvnConfigFile();
SvnInfo svnInfo;
wxString repoUrl;
if(event.GetInt() == LOGIN_REQUIRES_URL) {
repoUrl = event.GetString();
} else {
DoGetSvnInfoSync(svnInfo, workingDirectory);
repoUrl = svnInfo.m_url;
}
bool loginFailed = (event.GetInt() == LOGIN_REQUIRES) || (event.GetInt() == LOGIN_REQUIRES_URL);
SubversionPasswordDb db;
wxString user, password;
if(loginFailed) {
// if we got here, it means that we already tried to login with either user prompt / using the stored password
// to prevent an endless loop, remove the old entry from the password db
db.DeleteLogin(repoUrl);
}
if(db.GetLogin(repoUrl, user, password)) {
loginString << " --username " << user << " --password \"" << password << "\" ";
return true;
}
// Use the root URL as the key for the login here
loginString.Empty();
if(loginFailed) {
SvnLoginDialog dlg(GetManager()->GetTheApp()->GetTopWindow());
if(dlg.ShowModal() == wxID_OK) {
loginString << " --username " << dlg.GetUsername() << " --password \"" << dlg.GetPassword() << "\" ";
// Store the user name and password
db.SetLogin(repoUrl, dlg.GetUsername(), dlg.GetPassword());
return true;
} else {
return false;
}
}
return true;
}
void Subversion2::IgnoreFiles(const wxArrayString& files, bool pattern)
{
SvnSettingsData ssd = GetSettings();
wxArrayString ignorePatternArr = wxStringTokenize(ssd.GetIgnoreFilePattern(), " \r\n\t\v", wxTOKEN_STRTOK);
for(size_t i = 0; i < files.GetCount(); i++) {
wxString entry;
wxFileName fn(files.Item(i));
if(pattern) {
entry << "*." << fn.GetExt();
} else {
entry << fn.GetFullName();
}
if(ignorePatternArr.Index(entry) == wxNOT_FOUND) {
ignorePatternArr.Add(entry);
}
}
wxString ignorePatternStr;
for(size_t i = 0; i < ignorePatternArr.GetCount(); i++) {
ignorePatternStr << ignorePatternArr.Item(i) << " ";
}
ignorePatternStr.RemoveLast();
ssd.SetIgnoreFilePattern(ignorePatternStr);
// write down the changes
SetSettings(ssd);
// update the config file
RecreateLocalSvnConfigFile();
// refresh the view
GetSvnView()->BuildTree();
}
void Subversion2::OnIgnoreFile(wxCommandEvent& event) { IgnoreFiles(DoGetFileExplorerFiles(), false); }
void Subversion2::OnIgnoreFilePattern(wxCommandEvent& event) { IgnoreFiles(DoGetFileExplorerFiles(), true); }
void Subversion2::EditSettings()
{
SvnPreferencesDialog dlg(GetManager()->GetTheApp()->GetTopWindow(), this);
if(dlg.ShowModal() == wxID_OK) {
// Update the Subversion view
GetSvnView()->BuildTree();
DoSetSSH();
RecreateLocalSvnConfigFile();
}
}
bool Subversion2::IsSubversionViewDetached()
{
DetachedPanesInfo dpi;
m_mgr->GetConfigTool()->ReadObject("DetachedPanesList", &dpi);
wxArrayString detachedPanes = dpi.GetPanes();
return detachedPanes.Index(svnCONSOLE_TEXT) != wxNOT_FOUND;
}
void Subversion2::OnSelectAsView(wxCommandEvent& event)
{
wxUnusedVar(event);
GetSvnView()->BuildTree(m_selectedFolder);
}
void Subversion2::OnBlame(wxCommandEvent& event) { Blame(event, DoGetFileExplorerFiles()); }
void Subversion2::Blame(wxCommandEvent& event, const wxArrayString& files)
{
wxString command;
wxString loginString;
if(files.GetCount() == 0) {
return;
}
/*bool nonInteractive = unused var commented out*/
GetNonInteractiveMode(event);
if(LoginIfNeeded(event, files.Item(0), loginString) == false) {
return;
}
if(files.GetCount() != 1) {
return;
}
GetConsole()->EnsureVisible();
command << GetSvnExeName() << " blame " << loginString;
for(size_t i = 0; i < files.GetCount(); i++) {
command << "\"" << files.Item(i) << "\" ";
}
GetConsole()->AppendText(command + "\n");
m_blameCommand.Execute(command, GetSvnView()->GetRootDir(),
new SvnBlameHandler(this, event.GetId(), this, files.Item(0)), this);
}
void Subversion2::OnGetCompileLine(clBuildEvent& event)
{
if(!(GetSettings().GetFlags() & SvnExposeRevisionMacro)) {
return;
}
wxString macroName(GetSettings().GetRevisionMacroName());
macroName.Trim().Trim(false);
if(macroName.IsEmpty()) {
return;
}
wxString workingDirectory = m_subversionView->GetRootDir();
workingDirectory.Trim().Trim(false);
SvnInfo svnInfo;
DoGetSvnInfoSync(svnInfo, workingDirectory);
wxString content = event.GetCommand();
content << " -D";
content << macroName << "=\\\"";
content << svnInfo.m_revision << "\\\" ";
event.SetCommand(content);
event.Skip();
}
void Subversion2::DoGetSvnInfoSync(SvnInfo& svnInfo, const wxString& workingDirectory)
{
wxString svnInfoCommand;
wxString xmlStr;
svnInfoCommand << GetSvnExeName() << " info --xml ";
if(workingDirectory.Find(" ")) {
svnInfoCommand << "\"" << workingDirectory << "\"";
} else {
svnInfoCommand << workingDirectory;
}
#ifndef __WXMSW__
// Hide stderr
svnInfoCommand << " 2> /dev/null";
#endif
wxArrayString xmlArr;
IProcess::Ptr_t proc(::CreateSyncProcess(svnInfoCommand, IProcessCreateDefault | IProcessCreateWithHiddenConsole |
IProcessWrapInShell));
if(proc) {
proc->WaitForTerminate(xmlStr);
SvnXML::GetSvnInfo(xmlStr, svnInfo);
}
}
bool Subversion2::IsPathUnderSvn(const wxString& path)
{
wxFileName fn(path, ".svn");
// search until we find .svn folder
while(fn.GetDirCount()) {
if(wxFileName::DirExists(fn.GetFullPath())) {
return true;
}
fn.RemoveLastDir();
}
return false;
}
void Subversion2::OnSwitchURL(wxCommandEvent& event)
{
SvnInfo svnInfo;
wxString path = DoGetFileExplorerItemPath();
DoGetSvnInfoSync(svnInfo, path);
DoSwitchURL(DoGetFileExplorerItemPath(), svnInfo.m_sourceUrl, event);
}
void Subversion2::DoSwitchURL(const wxString& workingDirectory, const wxString& sourceUrl, wxCommandEvent& event)
{
SvnInfo svnInfo;
DoGetSvnInfoSync(svnInfo, workingDirectory);
wxString loginString;
if(LoginIfNeeded(event, workingDirectory, loginString) == false) {
return;
}
wxString targetUrl = wxGetTextFromUser(_("Enter new URL:"), _("Svn Switch..."), sourceUrl);
if(targetUrl.IsEmpty()) {
return;
}
wxString command;
command << GetSvnExeName() << " switch " << targetUrl << loginString;
GetConsole()->Execute(command, workingDirectory, new SvnDefaultCommandHandler(this, wxNOT_FOUND, NULL));
}
void Subversion2::ChangeLog(const wxString& path, const wxString& fullpath, wxCommandEvent& event)
{
SvnInfo info;
DoGetSvnInfoSync(info, path);
SvnLogDialog dlg(GetManager()->GetTheApp()->GetTopWindow());
dlg.GetTo()->SetValue("BASE");
dlg.GetCompact()->SetValue(true);
dlg.GetFrom()->SetFocus();
if(dlg.ShowModal() == wxID_OK) {
wxString command;
wxString loginString;
if(LoginIfNeeded(event, path, loginString) == false) {
return;
}
command << GetSvnExeName() << loginString << " log -r" << dlg.GetFrom()->GetValue() << ":"
<< dlg.GetTo()->GetValue() << " \"" << fullpath << "\"";
GetConsole()->Execute(
command, path,
new SvnLogHandler(this, info.m_sourceUrl, dlg.GetCompact()->IsChecked(), event.GetId(), this), false);
}
}
void Subversion2::OnLockFile(wxCommandEvent& event)
{
DoLockFile(m_selectedFile.GetPath(), DoGetFileExplorerFiles(), event, true);
}
void Subversion2::OnUnLockFile(wxCommandEvent& event)
{
DoLockFile(m_selectedFile.GetPath(), DoGetFileExplorerFiles(), event, false);
}
void Subversion2::DoLockFile(const wxString& workingDirectory, const wxArrayString& fullpaths, wxCommandEvent& event,
bool lock)
{
wxString command;
wxString loginString;
if(fullpaths.empty()) {
return;
}
if(LoginIfNeeded(event, workingDirectory, loginString) == false) {
return;
}
command << GetSvnExeName() << loginString;
if(lock) {
command << " lock ";
} else {
command << " unlock ";
}
for(size_t i = 0; i < fullpaths.size(); i++)
command << "\"" << fullpaths.Item(i) << "\" ";
GetConsole()->Execute(command, workingDirectory, new SvnDefaultCommandHandler(this, event.GetId(), this));
}
void Subversion2::OnWorkspaceConfigChanged(wxCommandEvent& event)
{
event.Skip();
m_subversionView->BuildTree();
}
void Subversion2::OnProjectFileRemoved(clCommandEvent& event)
{
event.Skip();
if(m_skipRemoveFilesDlg) {
m_skipRemoveFilesDlg = false;
return;
}
DoFilesDeleted(event.GetStrings());
}
void Subversion2::OnFileExplorerRenameItem(wxCommandEvent& event)
{
wxFileName workingDirectory(m_selectedFolder, "");
if(!m_selectedFile.IsOk()) {
wxString folderName = workingDirectory.GetDirs().Last();
workingDirectory.RemoveLastDir();
wxString newname = ::clGetTextFromUser(_("Svn Rename"), _("New name:"), folderName, folderName.length());
if(newname.IsEmpty() || newname == folderName) {
return;
}
::WrapWithQuotes(newname);
DoRename(workingDirectory.GetPath(), folderName, newname, event);
} else {
wxString newname = ::clGetTextFromUser(_("Svn Rename"), _("New name:"), m_selectedFile.GetFullName(),
m_selectedFile.GetName().length());
if(newname.IsEmpty() || newname == m_selectedFile.GetFullName()) {
return;
}
::WrapWithQuotes(newname);
DoRename(workingDirectory.GetPath(), m_selectedFile.GetFullName(), newname, event);
}
}
void Subversion2::DoRename(const wxString& workingDirectory, const wxString& oldname, const wxString& newname,
wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(LoginIfNeeded(event, workingDirectory, loginString) == false) {
return;
}
if(oldname.IsEmpty() || newname.IsEmpty() || workingDirectory.IsEmpty()) {
return;
}
command << GetSvnExeName() << loginString << " rename --force " << oldname << " " << newname;
GetConsole()->Execute(command, workingDirectory, new SvnDefaultCommandHandler(this, event.GetId(), this));
}
SvnConsole* Subversion2::GetConsole() { return GetSvnView()->GetSubversionConsole(); }
void Subversion2::DoCommit(const wxArrayString& files, const wxString& workingDirectory, wxCommandEvent& event)
{
wxString command;
wxString loginString;
if(LoginIfNeeded(event, workingDirectory, loginString) == false) {
return;
}
SvnInfo svnInfo;
if(!workingDirectory.IsEmpty()) {
DoGetSvnInfoSync(svnInfo, workingDirectory);
}
command << GetSvnExeName() << loginString << " commit ";
SvnCommitDialog dlg(EventNotifier::Get()->TopFrame(), files, svnInfo.m_sourceUrl, this, workingDirectory);
if(dlg.ShowModal() == wxID_OK) {
wxArrayString actualFiles = dlg.GetPaths();
if(actualFiles.IsEmpty()) {
return;
}
// Store the commit message into a temporary file
wxFileName tmpFile(clStandardPaths::Get().GetTempDir(), ".svn-commit");
if(!FileUtils::WriteFileContent(tmpFile, dlg.GetMesasge())) {
::wxMessageBox(_("Fail to write commit message to a temporary file!"), "CodeLite",
wxOK | wxCENTER | wxICON_ERROR);
return;
}
wxString filepath = tmpFile.GetFullPath();
::WrapWithQuotes(filepath);
command << " --file " << filepath << " ";
// Add the changed files
for(size_t i = 0; i < actualFiles.GetCount(); ++i) {
::WrapWithQuotes(actualFiles.Item(i));
command << actualFiles.Item(i) << " ";
}
GetConsole()->Execute(command, workingDirectory, new SvnCommitHandler(this, event.GetId(), this));
}
}
wxArrayString Subversion2::DoGetFileExplorerFilesToCommitRelativeTo(const wxString& wd)
{
wxArrayString files;
TreeItemInfo itemInfo = m_mgr->GetSelectedTreeItemInfo(TreeFileExplorer);
files.swap(itemInfo.m_paths);
for(size_t i = 0; i < files.GetCount(); i++) {
if(wxDir::Exists(files.Item(i))) {
// Get the list of modified files from the directory
wxArrayString modFiles = DoGetSvnStatusQuiet(files.Item(i));
for(size_t j = 0; j < modFiles.GetCount(); j++) {
wxFileName fn(modFiles.Item(j));
fn.MakeAbsolute(files.Item(i));
fn.MakeRelativeTo(wd);
if(files.Index(fn.GetFullPath()) == wxNOT_FOUND) {
files.Add(fn.GetFullPath());
}
}
} else {
wxFileName fn(files.Item(i));
fn.MakeRelativeTo(wd);
if(files.Index(fn.GetFullPath()) == wxNOT_FOUND) {
files.Add(fn.GetFullPath());
}
}
}
return files;
}
wxArrayString Subversion2::DoGetSvnStatusQuiet(const wxString& wd)
{
wxString command;
wxString output;
command << GetSvnExeName() << " status -q ";
command << "\"" << wd << "\"";
wxArrayString lines;
ProcUtils::ExecuteCommand(command, lines);
for(size_t i = 0; i < lines.GetCount(); i++) {
output << "\r\n" << lines.Item(i);
}
wxArrayString modFiles, conflictedFiles, unversionedFiles, newFiles, deletedFiles, lockedFiles, ignoredFiles;
SvnXML::GetFiles(output, modFiles, conflictedFiles, unversionedFiles, newFiles, deletedFiles, lockedFiles,
ignoredFiles);
modFiles.insert(modFiles.end(), newFiles.begin(), newFiles.end());
modFiles.insert(modFiles.end(), deletedFiles.begin(), deletedFiles.end());
return modFiles;
}
bool Subversion2::NormalizeDir(wxString& wd)
{
if(!wxFileName::DirExists(wd)) {
return false;
}
// gets rid of possible trailing slash and fixes mixed-case issues
wxFileName fn(wd);
fn.Normalize(); // wxPATH_NORM_CASE seems broken
wd = fn.GetFullPath();
if(wxPATH_DOS == wxFileName::GetFormat()) {
wd.LowerCase();
// Subversion *always* capitalizes Windows/Dos volume letters
wxChar volume = wd.GetChar(0);
volume = toupper(volume);
wd.SetChar(0, volume);
}
// get rid of possible trailing slash/backslash
if(wd.Last() == wxFileName::GetPathSeparator()) {
wd.RemoveLast();
}
return true;
}
std::vector<wxString> Subversion2::GetLocalAddsDels(const wxString& wd)
{
wxString command;
command << GetSvnExeName() << " status -q ";
command << "\"" << wd << "\"";
std::vector<wxString> aryFiles;
wxArrayString lines;
ProcUtils::ExecuteCommand(command, lines);
wxString fileName;
for(size_t i1 = 0; i1 < lines.GetCount(); i1++) {
wxChar stat = lines.Item(i1).GetChar(0);
if('A' == stat || 'D' == stat) {
fileName = lines.Item(i1).Mid(8);
if(!wxFileName::DirExists(fileName)) {
aryFiles.push_back(fileName);
}
}
}
return aryFiles;
}
std::vector<wxString> Subversion2::GetFilesMarkedBinary(const wxString& wd)
{
wxString command;
command << GetSvnExeName() << " propget svn:mime-type -R ";
command << "\"" << wd << "\"";
std::vector<wxString> aryFiles;
wxArrayString lines;
ProcUtils::ExecuteCommand(command, lines);
wxString fileName;
for(size_t i1 = 0; i1 < lines.GetCount(); i1++) {
lines.Item(i1).Trim(); // gets rid of \r\n, \n, etc.
if(lines.Item(i1).EndsWith(_(" - application/octet-stream"), &fileName)) {
aryFiles.push_back(fileName);
}
}
return aryFiles;
}
std::vector<wxString> Subversion2::RemoveExcludeExts(const std::vector<wxString>& aryInFiles,
const wxString& excludeExtensions)
{
std::vector<wxString> aryOutFiles;
wxStringTokenizer tok(excludeExtensions, " ;");
std::set<wxString> specMap;
while(tok.HasMoreTokens()) {
wxString v = tok.GetNextToken();
if(v == "*.*") {
// Just ignore the request to not add any files
continue;
}
v = v.AfterLast('*');
v = v.AfterLast('.').MakeLower();
specMap.insert(v);
}
for(size_t i1 = 0; i1 < aryInFiles.size(); i1++) {
if(specMap.empty()) {
aryOutFiles.push_back(aryInFiles[i1]);
continue;
}
wxFileName fn(aryInFiles[i1]);
if(specMap.find(fn.GetExt().MakeLower()) == specMap.end()) {
aryOutFiles.push_back(aryInFiles[i1]);
}
}
return aryOutFiles;
}
void Subversion2::OnSync(wxCommandEvent& event)
{
if(!m_mgr->GetWorkspace() || !m_mgr->IsWorkspaceOpen()) {
return;
}
TreeItemInfo item = m_mgr->GetSelectedTreeItemInfo(TreeFileView);
if(item.m_itemType != ProjectItem::TypeProject) {
return; // a project must be selected
}
// retrieve complete list of source files of the workspace
wxString project_name(item.m_text);
wxString err_msg;
ProjectPtr proj = m_mgr->GetWorkspace()->FindProjectByName(project_name, err_msg);
if(!proj) {
return;
}
wxString rawData = proj->GetPluginData("subversion2");
wxArrayString options = wxStringTokenize(rawData, "\n");
bool excludeBinary = true;
wxString rootDir;
wxString excludeExtensions;
if(options.GetCount() >= 1) {
if(options.Item(0) == _("false")) {
excludeBinary = false;
}
}
if(options.GetCount() >= 2) {
rootDir = options.Item(1);
}
if(options.GetCount() >= 3) {
excludeExtensions = options.Item(2);
} else {
excludeExtensions << "*.dll *.so *.o *.obj *.workspace *.project *.exe *.dylib";
}
SvnSyncDialog dlg(GetManager()->GetTheApp()->GetTopWindow(), this, rootDir, excludeBinary, excludeExtensions);
if(dlg.ShowModal() != wxID_OK) {
return;
}
excludeExtensions = dlg.GetExcludeExtensions();
excludeBinary = dlg.GetExcludeBin();
clDEBUG() << "excludeBinary=" << excludeBinary;
// attempt to update the project files
wxString workDir(dlg.GetRootDir());
NormalizeDir(workDir);
wxString command;
command << GetSvnExeName() << " list -R ";
command << "\"" << workDir << "\"";
// Calls FinishSyncProcess()
// Get password/authentication, if required
GetConsole()->Execute(
command, workDir,
new SvnRepoListHandler(this, proj, workDir, excludeBinary, excludeExtensions, wxNOT_FOUND, NULL));
}
void Subversion2::FinishSyncProcess(ProjectPtr& proj, const wxString& workDir, bool excludeBin,
const wxString& excludeExtensions, const wxString& output)
{
// Convert output of "svn list" into a list of files
// Note that svn list always uses '/' as path delimiter
std::vector<wxString> aryRepoList;
{
wxArrayString repoListOutput = wxStringTokenize(output, "\r\n");
wxFileName fn;
for(size_t i1 = 0; i1 < repoListOutput.GetCount(); i1++) {
if(repoListOutput.Item(i1).Last() != '/') {
fn.Assign(workDir + wxFileName::GetPathSeparator() + repoListOutput.Item(i1));
aryRepoList.push_back(fn.GetFullPath());
}
}
}
std::sort(aryRepoList.begin(), aryRepoList.end());
std::vector<wxString> aryNoBins;
if(excludeBin) {
std::vector<wxString> aryBinaries = GetFilesMarkedBinary(workDir);
std::sort(aryBinaries.begin(), aryBinaries.end());
std::set_symmetric_difference(aryRepoList.begin(), aryRepoList.end(), aryBinaries.begin(), aryBinaries.end(),
std::back_inserter(aryNoBins));
}
std::vector<wxString>& aryMaybeNoBins = excludeBin ? aryNoBins : aryRepoList;
// get local added or deleted files; then add or del from list
std::vector<wxString> aryUnfiltered;
{
std::vector<wxString> aryAddsDels = GetLocalAddsDels(workDir);
std::sort(aryAddsDels.begin(), aryAddsDels.end());
std::set_symmetric_difference(aryMaybeNoBins.begin(), aryMaybeNoBins.end(), aryAddsDels.begin(),
aryAddsDels.end(), std::back_inserter(aryUnfiltered));
}
std::vector<wxString> aryFinal = RemoveExcludeExts(aryUnfiltered, excludeExtensions);
m_skipRemoveFilesDlg = true;
m_mgr->RedefineProjFiles(proj, workDir, aryFinal);
// refresh project info
wxString err_msg;
ProjectPtr projRefreshed = m_mgr->GetWorkspace()->FindProjectByName(proj->GetName(), err_msg);
if(projRefreshed) {
wxChar delim = '\n';
wxString excludeBinTF;
if(excludeBin) {
excludeBinTF = _("true");
} else {
excludeBinTF = _("false");
}
wxString rawData = excludeBinTF + delim + workDir + delim + excludeExtensions;
clDEBUG() << "rawData=" << rawData;
projRefreshed->SetPluginData("subversion2", rawData);
}
}
wxString Subversion2::GetSvnExeNameNoConfigDir()
{
SvnSettingsData ssd = GetSettings();
wxString executeable = ssd.GetExecutable();
::WrapWithQuotes(executeable);
executeable << " ";
return executeable;
}
void Subversion2::OnRevertToRevision(wxCommandEvent& event)
{
wxString command;
wxString loginString;
wxString revision = wxGetTextFromUser(_("Set the revision number:"), _("Revert to revision"));
if(revision.IsEmpty()) {
// user canceled
return;
}
long nRevision;
if(!revision.ToCLong(&nRevision)) {
::wxMessageBox(_("Invalid revision number"), "codelite", wxOK | wxICON_ERROR | wxCENTER);
return;
}
wxFileName workingDirectory(m_selectedFolder, "");
if(m_selectedFile.IsOk()) {
command << GetSvnExeName() << loginString << " merge -r HEAD:" << nRevision << " "
<< m_selectedFile.GetFullName();
GetConsole()->Execute(command, workingDirectory.GetPath(),
new SvnDefaultCommandHandler(this, event.GetId(), this));
} else {
wxString folderName = workingDirectory.GetDirs().Last();
workingDirectory.RemoveLastDir();
::WrapWithQuotes(folderName);
command << GetSvnExeName() << loginString << " merge -r HEAD:" << nRevision << " " << folderName;
GetConsole()->Execute(command, workingDirectory.GetPath(),
new SvnDefaultCommandHandler(this, event.GetId(), this));
}
}
void Subversion2::DoGetSvnClientVersion()
{
static wxRegEx reSvnClient("svn, version ([0-9]+)\\.([0-9]+)\\.([0-9]+)");
wxString svnVersionCommand;
svnVersionCommand << GetSvnExeName() << " --version";
#ifndef __WXMSW__
// Hide stderr
svnVersionCommand << " 2> /dev/null";
#endif
wxString versionOutput = ProcUtils::SafeExecuteCommand(svnVersionCommand);
if(versionOutput.IsEmpty()) {
return;
}
versionOutput = versionOutput.BeforeFirst('\n');
if(reSvnClient.IsValid() && reSvnClient.Matches(versionOutput)) {
long major, minor, patch;
wxString sMajor = reSvnClient.GetMatch(versionOutput, 1);
wxString sMinor = reSvnClient.GetMatch(versionOutput, 2);
wxString sPatch = reSvnClient.GetMatch(versionOutput, 3);
sMajor.ToCLong(&major);
sMinor.ToCLong(&minor);
sPatch.ToCLong(&patch);
m_clientVersion = major * 1000 + minor * 100 + patch;
GetConsole()->AppendText(wxString() << "-- Svn client version: " << m_clientVersion << "\n");
GetConsole()->AppendText(wxString() << "-- " << versionOutput << "\n");
}
}
void Subversion2::AddCommandLineOption(wxString& command, Subversion2::eCommandLineOption opt)
{
switch(opt) {
case kOpt_ForceInteractive:
if(m_clientVersion >= 1800) {
command << " --force-interactive ";
}
break;
}
}
void Subversion2::OnFolderContextMenu(clContextMenuEvent& event)
{
event.Skip();
m_selectedFolder = event.GetPath();
m_selectedFile.Clear();
wxMenuItem* item =
new wxMenuItem(event.GetMenu(), wxID_ANY, "Svn", "", wxITEM_NORMAL, CreateFileExplorerPopMenu(false));
item->SetBitmap(m_svnBitmap);
event.GetMenu()->Append(item);
}
void Subversion2::OnFileContextMenu(clContextMenuEvent& event)
{
event.Skip();
if(event.GetStrings().size() == 1) {
m_selectedFile = event.GetStrings().Item(0);
m_selectedFolder = wxFileName(m_selectedFile).GetPath();
wxMenuItem* item =
new wxMenuItem(event.GetMenu(), wxID_ANY, "Svn", "", wxITEM_NORMAL, CreateFileExplorerPopMenu(true));
item->SetBitmap(m_svnBitmap);
event.GetMenu()->Append(item);
}
}
void Subversion2::DoFilesDeleted(const wxArrayString& files, bool isFolder)
{
if(!files.IsEmpty()) {
// test the first file, see if it is under SVN
wxFileName fn = isFolder ? wxFileName(files.Item(0), "") : wxFileName(files.Item(0));
if(IsPathUnderSvn(fn.GetPath())) {
// Build the message:
// Limit the message to maximum of 10 files
wxString filesString;
wxString msg;
if(isFolder) {
msg << _("Would you like to remove the following folders from SVN?\n\n");
} else {
msg << _("Would you like to remove the following files from SVN?\n\n");
}
size_t fileCount = files.GetCount();
for(size_t i = 0; i < files.GetCount(); i++) {
if(i < 10) {
msg << files.Item(i) << "\n";
filesString << "\"" << files.Item(i) << "\" ";
--fileCount;
} else {
break;
}
}
if(fileCount) {
if(isFolder) {
msg << _(".. and ") << fileCount << _(" more folders");
} else {
msg << _(".. and ") << fileCount << _(" more files");
}
}
if(wxMessageBox(msg, "Subversion", wxYES_NO | wxCANCEL | wxCENTER | wxNO_DEFAULT,
GetManager()->GetTheApp()->GetTopWindow()) == wxYES) {
wxString command;
RecreateLocalSvnConfigFile();
command << GetSvnExeName() << " delete --force " << filesString;
GetConsole()->Execute(command, m_subversionView->GetRootDir(),
new SvnDefaultCommandHandler(this, wxNOT_FOUND, this));
}
}
}
}
void Subversion2::OnFileDeleted(clFileSystemEvent& event)
{
event.Skip();
DoFilesDeleted(event.GetPaths());
}
void Subversion2::OnFolderDeleted(clFileSystemEvent& event)
{
event.Skip();
DoFilesDeleted(event.GetPaths(), true);
}
void Subversion2::OnShowFileChanges(wxCommandEvent& event)
{
wxUnusedVar(event);
ShowRecentChanges(m_selectedFile.GetFullPath());
}
void Subversion2::ShowRecentChanges(const wxString& file)
{
if(!wxFileName::FileExists(file)) {
return;
}
wxString filename(file);
::WrapWithQuotes(filename);
long numberOfChanges = wxGetNumberFromUser(_("How many recent changes you want to view?"), "",
_("Svn show recent changes"), 1, 1, 100);
if(numberOfChanges == wxNOT_FOUND) {
return; // cancel
}
// Build the command
wxString command;
command << GetSvnExeNameNoConfigDir() << " log --diff -l " << numberOfChanges << " " << filename;
GetConsole()->Execute(command, m_subversionView->GetRootDir(),
new SvnShowFileChangesHandler(this, wxNOT_FOUND, this));
}
void Subversion2::ShowRecentChangesDialog(const SvnShowDiffChunk::List_t& changes)
{
if(changes.empty()) {
return;
}
SvnShowRecentChangesDlg dlg(EventNotifier::Get()->TopFrame(), changes);
dlg.ShowModal();
}
void Subversion2::OnGotoAnythingShowing(clGotoEvent& e)
{
e.Skip();
// Add our entries
e.GetEntries().push_back(clGotoEntry("Svn > Commit", "", XRCID("gotoanything_svn_commit")));
e.GetEntries().push_back(clGotoEntry("Svn > Update", "", XRCID("gotoanything_svn_update")));
}
|