comparison mainwindow.cpp @ 17:9b52042baf39

Implemented multiple selection to work folder list (and changes to add/commit logic).
author Jari Korhonen <jtkorhonen@gmail.com>
date Tue, 18 May 2010 01:45:20 +0300
parents 8689cc000ddf
children 36e03b1f719e
comparison
equal deleted inserted replaced
16:3a0ff6f7b317 17:9b52042baf39
41 *************************************************************************************/ 41 *************************************************************************************/
42 42
43 #include <QtGui> 43 #include <QtGui>
44 #include <QStringList> 44 #include <QStringList>
45 #include <QDir> 45 #include <QDir>
46 #include <QHostAddress>
47 #include <QHostInfo>
46 48
47 #include "mainwindow.h" 49 #include "mainwindow.h"
48 #include "settingsdialog.h" 50 #include "settingsdialog.h"
49 51
50 52
250 { 252 {
251 QStringList params; 253 QStringList params;
252 254
253 QString currentFile = hgExp -> getCurrentFileListLine(); 255 QString currentFile = hgExp -> getCurrentFileListLine();
254 256
255 if (isSelectedUntracked(hgExp -> workFolderFileList)) 257 if (areAllSelectedUntracked(hgExp -> workFolderFileList))
256 { 258 {
257 //User wants to add one file 259 //User wants to add selected file(s)
258 params << "add" << currentFile.mid(2); 260 params << "add";
261
262 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems();
263
264 for (int i = 0; i < selList.size(); ++i)
265 {
266 QString tmp = selList.at(i)->text();
267 params.append(tmp.mid(2));
268 }
259 } 269 }
260 else 270 else
261 { 271 {
262 //Add all untracked files 272 //Add all untracked files
263 params << "add"; 273 params << "add";
314 { 324 {
315 if (!comment.isEmpty()) 325 if (!comment.isEmpty())
316 { 326 {
317 QString currentFile = hgExp -> getCurrentFileListLine(); 327 QString currentFile = hgExp -> getCurrentFileListLine();
318 328
319 if (isSelectedCommitable(hgExp -> workFolderFileList)) 329 if (areAllSelectedCommitable(hgExp -> workFolderFileList))
320 { 330 {
321 //User wants to commit only one file 331 //User wants to commit selected file(s)
322 params << "commit" << "--message" << comment << "--user" << userInfo << currentFile.mid(2); 332 params << "commit" << "--message" << comment << "--user" << userInfo;
333
334 QList <QListWidgetItem *> selList = hgExp -> workFolderFileList -> selectedItems();
335 for (int i = 0; i < selList.size(); ++i)
336 {
337 QString tmp = selList.at(i)->text();
338 params.append(tmp.mid(2));
339 }
323 } 340 }
324 else 341 else
325 { 342 {
326 //Commit all changes 343 //Commit all changes
327 params << "commit" << "--message" << comment << "--user" << userInfo; 344 params << "commit" << "--message" << comment << "--user" << userInfo;
527 runningAction = ACT_PUSH; 544 runningAction = ACT_PUSH;
528 } 545 }
529 } 546 }
530 547
531 548
549 QString MainWindow::findMyIps()
550 {
551 QString ret;
552 QHostInfo info = QHostInfo::fromName(QHostInfo::localHostName());
553 QList <QHostAddress> ipList = info.addresses();
554
555 if (!ipList.isEmpty())
556 {
557 QHostAddress addr = ipList.at(0);
558 ret = addr.toString();
559 }
560 else
561 {
562 ret = "unknown";
563 }
564
565 return ret;
566 }
567
532 void MainWindow::hgServe() 568 void MainWindow::hgServe()
533 { 569 {
534 if (runningAction == ACT_NONE) 570 if (runningAction == ACT_NONE)
535 { 571 {
536 QStringList params; 572 QStringList params;
538 params << "serve"; 574 params << "serve";
539 575
540 runner -> startProc(getHgBinaryName(), workFolderPath, params, false); 576 runner -> startProc(getHgBinaryName(), workFolderPath, params, false);
541 runningAction = ACT_SERVE; 577 runningAction = ACT_SERVE;
542 578
543 QMessageBox::information(this, "Serve", "Server running on port 8000", QMessageBox::Close); 579 QString msg;
580
581 QTextStream(&msg) << "Server running on http://" << findMyIps() << ":8000/";
582 QMessageBox::information(this, "Serve", msg, QMessageBox::Close);
544 runner -> killProc(); 583 runner -> killProc();
545 } 584 }
546 } 585 }
547 586
548 587
599 QMessageBox::information(this, tr("HgExplorer"), tr("Mercurial command did not return any output.")); 638 QMessageBox::information(this, tr("HgExplorer"), tr("Mercurial command did not return any output."));
600 } 639 }
601 } 640 }
602 641
603 642
604 bool MainWindow::isSelectedCommitable(QListWidget *workList) 643 bool MainWindow::areAllSelectedCommitable(QListWidget *workList)
644 {
645 QList<QListWidgetItem *> selList = workList -> selectedItems();
646 for (int i = 0; i < selList.size(); ++i)
647 {
648 QString tmp = selList.at(i) -> text().mid(0, 1);
649 if (tmp == "A")
650 {
651 //scheduled to be added, ok to commit
652 }
653 else if (tmp == "M")
654 {
655 //locally modified, ok to commit
656 }
657 else if (tmp == "R")
658 {
659 //user wants to remove from repo, ok to commit
660 }
661 else
662 {
663 return false;
664 }
665 }
666 return true;
667 }
668
669 bool MainWindow::isSelectedDeletable(QListWidget *workList)
605 { 670 {
606 QList<QListWidgetItem *> selList = workList -> selectedItems(); 671 QList<QListWidgetItem *> selList = workList -> selectedItems();
607 if (selList.count() == 1) 672 if (selList.count() == 1)
608 { 673 {
609 QString tmp = selList.at(0)->text().mid(0, 1); 674 QString tmp = selList.at(0)->text().mid(0, 1);
610 if (tmp == "A") 675 if (tmp == "A")
611 { 676 {
612 //scheduled to be added, ok to commit 677 //scheduled to be added, ok to remove (won't go to repo)
613 return true; 678 return true;
614 } 679 }
680 else if (tmp == "C")
681 {
682 //Tracked but unchanged, ok to remove
683 return true;
684 }
615 else if (tmp == "M") 685 else if (tmp == "M")
616 { 686 {
617 //locally modified, ok to commit 687 //locally modified, ok to remove from repo
618 return true; 688 return true;
619 } 689 }
690 else if (tmp == "!")
691 {
692 //locally deleted, ok to remove from repo
693 return true;
694 }
620 } 695 }
621 return false; 696 return false;
622 } 697 }
623 698
624 bool MainWindow::isSelectedDeletable(QListWidget *workList) 699
700 bool MainWindow::areAllSelectedUntracked(QListWidget *workList)
701 {
702 QList<QListWidgetItem *> selList = workList -> selectedItems();
703 for (int i = 0; i < selList.size(); ++i)
704 {
705 QString tmp = selList.at(i) -> text();
706
707 if (tmp.mid(0,1) != "?")
708 {
709 return false;
710 }
711 }
712 return true;
713 }
714
715
716 bool MainWindow::isSelectedModified(QListWidget *workList)
625 { 717 {
626 QList<QListWidgetItem *> selList = workList -> selectedItems(); 718 QList<QListWidgetItem *> selList = workList -> selectedItems();
627 if (selList.count() == 1) 719 if (selList.count() == 1)
628 { 720 {
629 QString tmp = selList.at(0)->text().mid(0, 1); 721 if (selList.at(0)->text().mid(0, 1) == "M")
630 if (tmp == "A") 722 {
631 {
632 //scheduled to be added, ok to remove (won't go to repo)
633 return true; 723 return true;
634 } 724 }
635 else if (tmp == "C")
636 {
637 //Tracked but unchanged, ok to remove
638 return true;
639 }
640 else if (tmp == "M")
641 {
642 //locally modified, ok to remove from repo
643 return true;
644 }
645 else if (tmp == "!")
646 {
647 //locally deleted, ok to remove from repo
648 return true;
649 }
650 } 725 }
651 return false; 726 return false;
652 } 727 }
653 728
654 729 void MainWindow::countModifications(QListWidget *workList, int& added, int& modified, int& removed, int& notTracked,
655 bool MainWindow::isSelectedUntracked(QListWidget *workList) 730 int& selected,
656 { 731 int& selectedAdded, int& selectedModified, int& selectedRemoved, int& selectedNotTracked)
657 QList<QListWidgetItem *> selList = workList -> selectedItems();
658 if (selList.count() == 1)
659 {
660 if (selList.at(0)->text().mid(0, 1) == "?")
661 {
662 return true;
663 }
664 }
665 return false;
666 }
667
668
669 bool MainWindow::isSelectedModified(QListWidget *workList)
670 {
671 QList<QListWidgetItem *> selList = workList -> selectedItems();
672 if (selList.count() == 1)
673 {
674 if (selList.at(0)->text().mid(0, 1) == "M")
675 {
676 return true;
677 }
678 }
679 return false;
680 }
681
682 void MainWindow::countAMRNModifications(QListWidget *workList, int& a, int& m, int& r, int& n)
683 { 732 {
684 int itemCount = workList -> count(); 733 int itemCount = workList -> count();
685 if (itemCount > 0) 734 if (itemCount > 0)
686 { 735 {
687 int A= 0; 736 int A= 0;
688 int M=0; 737 int M=0;
689 int R=0; 738 int R=0;
690 int N=0; 739 int N=0;
740 int S=0;
741 int SA=0;
742 int SM=0;
743 int SR=0;
744 int SN=0;
745
691 for (int i = 0; i < workList -> count(); i++) 746 for (int i = 0; i < workList -> count(); i++)
692 { 747 {
693 QListWidgetItem *currItem = workList -> item(i); 748 QListWidgetItem *currItem = workList -> item(i);
694 749
695 QString tmp = currItem->text().mid(0, 1); 750 QString tmp = currItem->text().mid(0, 1);
709 { 764 {
710 N++; 765 N++;
711 } 766 }
712 } 767 }
713 768
714 a = A; 769 added = A;
715 m = M; 770 modified = M;
716 r = R; 771 removed = R;
717 n = N; 772 notTracked = N;
773
774 QList <QListWidgetItem *> selList = workList -> selectedItems();
775
776 S = selList.size();
777 for (int i = 0; i < selList.size(); ++i)
778 {
779 QString tmp = selList.at(i) -> text();
780
781 if (tmp.mid(0,1) == "A")
782 {
783 SA++;
784 }
785 else if (tmp.mid(0,1) == "M")
786 {
787 SM++;
788 }
789 else if (tmp.mid(0,1) == "R")
790 {
791 SR++;
792 }
793 else if (tmp.mid(0,1) == "?")
794 {
795 SN++;
796 }
797 }
798
799 selected = S;
800 selectedAdded = SA;
801 selectedModified = SM;
802 selectedRemoved = SR;
803 selectedNotTracked = SN;
718 } 804 }
719 else 805 else
720 { 806 {
721 a = 0; 807 added = 0;
722 m = 0; 808 modified = 0;
723 r = 0; 809 removed = 0;
724 n = 0; 810 notTracked = 0;
811 selected = 0;
812 selectedAdded = 0;
813 selectedModified = 0;
814 selectedRemoved = 0;
815 selectedNotTracked = 0;
725 } 816 }
726 } 817 }
727 818
728 819
729 void MainWindow::timerEvent(QTimerEvent *) 820 void MainWindow::timerEvent(QTimerEvent *)
959 hgAnnotateAct -> setEnabled(localRepoActionsEnabled); 1050 hgAnnotateAct -> setEnabled(localRepoActionsEnabled);
960 hgServeAct -> setEnabled(localRepoActionsEnabled); 1051 hgServeAct -> setEnabled(localRepoActionsEnabled);
961 1052
962 hgExp -> enableDisableOtherTabs(); 1053 hgExp -> enableDisableOtherTabs();
963 1054
964 int a, m, r, n; 1055 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
965 countAMRNModifications(hgExp -> workFolderFileList, a, m, r, n); 1056
1057 countModifications(hgExp -> workFolderFileList,
1058 added, modified, removed, notTracked,
1059 selected,
1060 selectedAdded, selectedModified, selectedRemoved, selectedNotTracked);
966 1061
967 if (tabPage == WORKTAB) 1062 if (tabPage == WORKTAB)
968 { 1063 {
969 //Enable / disable actions according to workFolderFileList selections / currentSelection / count 1064 //Enable / disable actions according to workFolderFileList selections / currentSelection / count
970 hgChgSetDiffAct -> setEnabled(false); 1065 hgChgSetDiffAct -> setEnabled(false);
971 hgUpdateToRevAct -> setEnabled(false); 1066 hgUpdateToRevAct -> setEnabled(false);
972 1067
973 if (localRepoActionsEnabled) 1068 if (localRepoActionsEnabled)
974 { 1069 {
975 if ((a == 0) && (m == 0) && (r == 0)) 1070 if ((added == 0) && (modified == 0) && (removed == 0))
976 { 1071 {
977 hgCommitAct -> setEnabled(false); 1072 hgCommitAct -> setEnabled(false);
978 hgRevertAct -> setEnabled(false); 1073 hgRevertAct -> setEnabled(false);
979 } 1074 }
980 1075 else if (selected != 0)
981 if (m == 0) 1076 {
1077 if (selectedNotTracked != 0)
1078 {
1079 hgCommitAct -> setEnabled(false);
1080 }
1081 else if ((selectedAdded == 0) && (selectedModified == 0) && (selectedRemoved == 0))
1082 {
1083 hgCommitAct -> setEnabled(false);
1084 }
1085 }
1086
1087 if (modified == 0)
982 { 1088 {
983 hgFolderDiffAct -> setEnabled(false); 1089 hgFolderDiffAct -> setEnabled(false);
984 } 1090 }
985 1091
986 if (!isSelectedModified(hgExp -> workFolderFileList)) 1092 if (!isSelectedModified(hgExp -> workFolderFileList))
988 hgFileDiffAct -> setEnabled(false); 1094 hgFileDiffAct -> setEnabled(false);
989 hgRevertAct -> setEnabled(false); 1095 hgRevertAct -> setEnabled(false);
990 } 1096 }
991 1097
992 //JK 14.5.2010: Fixed confusing add button. Now this is simple: If we have something to add (any non-tracked files), add is enabled. 1098 //JK 14.5.2010: Fixed confusing add button. Now this is simple: If we have something to add (any non-tracked files), add is enabled.
993 if (n == 0) 1099 if (notTracked == 0)
994 { 1100 {
995 hgAddAct -> setEnabled(false); 1101 hgAddAct -> setEnabled(false);
996 } 1102 }
997 1103
998 if (!isSelectedDeletable(hgExp -> workFolderFileList)) 1104 if (!isSelectedDeletable(hgExp -> workFolderFileList))
1032 else 1138 else
1033 { 1139 {
1034 hgChgSetDiffAct -> setEnabled(false); 1140 hgChgSetDiffAct -> setEnabled(false);
1035 } 1141 }
1036 1142
1037 if ((a == 0) && (m == 0) && (r == 0)) 1143 if ((added == 0) && (modified == 0) && (removed == 0))
1038 { 1144 {
1039 if (historySelList.count() == 1) 1145 if (historySelList.count() == 1)
1040 { 1146 {
1041 hgUpdateToRevAct -> setEnabled(true); 1147 hgUpdateToRevAct -> setEnabled(true);
1042 } 1148 }
1095 1201
1096 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Undo changes"), this); 1202 hgRevertAct = new QAction(QIcon(":/images/undo.png"), tr("Undo changes"), this);
1097 hgRevertAct->setStatusTip(tr("Undo selected working folder file changes (return to local repository version)")); 1203 hgRevertAct->setStatusTip(tr("Undo selected working folder file changes (return to local repository version)"));
1098 1204
1099 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add files"), this); 1205 hgAddAct = new QAction(QIcon(":/images/add.png"), tr("Add files"), this);
1100 hgAddAct -> setStatusTip(tr("Add working folder files (selected one or all yet untracked) to local repository (on next commit)")); 1206 hgAddAct -> setStatusTip(tr("Add working folder file(s) (selected or all yet untracked) to local repository (on next commit)"));
1101 1207
1102 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove file"), this); 1208 hgRemoveAct = new QAction(QIcon(":/images/remove.png"), tr("Remove file"), this);
1103 hgRemoveAct -> setStatusTip(tr("Remove selected working folder file from local repository (on next commit)")); 1209 hgRemoveAct -> setStatusTip(tr("Remove selected working folder file from local repository (on next commit)"));
1104 1210
1105 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update working folder"), this); 1211 hgUpdateAct = new QAction(QIcon(":/images/update.png"), tr("Update working folder"), this);
1106 hgUpdateAct->setStatusTip(tr("Update working folder from local repository")); 1212 hgUpdateAct->setStatusTip(tr("Update working folder from local repository"));
1107 1213
1108 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit / Save change(s)"), this); 1214 hgCommitAct = new QAction(QIcon(":/images/commit.png"), tr("Commit / Save change(s)"), this);
1109 hgCommitAct->setStatusTip(tr("Save (selected file or all changed files in working folder (and all subfolders)) to local repository")); 1215 hgCommitAct->setStatusTip(tr("Save selected file(s) or all changed files in working folder (and all subfolders)) to local repository"));
1110 1216
1111 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this); 1217 hgMergeAct = new QAction(QIcon(":/images/merge.png"), tr("Merge"), this);
1112 hgMergeAct->setStatusTip(tr("Merge two local repository changesets to working folder")); 1218 hgMergeAct->setStatusTip(tr("Merge two local repository changesets to working folder"));
1113 1219
1114 //Advanced actions 1220 //Advanced actions
1224 initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt(); 1330 initialFileTypesBits = (unsigned char) settings.value("viewFileTypes", QVariant(DEFAULT_HG_STAT_BITS)).toInt();
1225 resize(size); 1331 resize(size);
1226 move(pos); 1332 move(pos);
1227 } 1333 }
1228 1334
1335
1229 void MainWindow::writeSettings() 1336 void MainWindow::writeSettings()
1230 { 1337 {
1231 QSettings settings("hgexplorer", "hgexplorer"); 1338 QSettings settings("hgexplorer", "hgexplorer");
1232 settings.setValue("pos", pos()); 1339 settings.setValue("pos", pos());
1233 settings.setValue("size", size()); 1340 settings.setValue("size", size());