comparison mainwindow.cpp @ 95:d1be9712818a

* Update actions appropriately when selections are changed
author Chris Cannam
date Wed, 24 Nov 2010 16:29:05 +0000
parents 44ed7766d55a
children 87ef2fa9ee8b
comparison
equal deleted inserted replaced
94:44ed7766d55a 95:d1be9712818a
65 65
66 readSettings(); 66 readSettings();
67 67
68 tabPage = 0; 68 tabPage = 0;
69 justMerged = false; 69 justMerged = false;
70 hgExp = new HgExpWidget((QWidget *) this, remoteRepoPath, workFolderPath, initialFileTypesBits); 70 hgExp = new HgExpWidget((QWidget *) this, remoteRepoPath, workFolderPath);
71 setCentralWidget(hgExp); 71 setCentralWidget(hgExp);
72
73 connect(hgExp, SIGNAL(selectionChanged()),
74 this, SLOT(enableDisableActions()));
72 75
73 setUnifiedTitleAndToolBarOnMac(true); 76 setUnifiedTitleAndToolBarOnMac(true);
74 connectActions(); 77 connectActions();
75 enableDisableActions(); 78 enableDisableActions();
76 79
1059 else 1062 else
1060 { 1063 {
1061 QMessageBox::information(this, tr("HgExplorer"), tr("Mercurial command did not return any output.")); 1064 QMessageBox::information(this, tr("HgExplorer"), tr("Mercurial command did not return any output."));
1062 } 1065 }
1063 } 1066 }
1064
1065
1066 bool MainWindow::areAllSelectedCommitable(QListWidget *workList)
1067 {
1068 QList<QListWidgetItem *> selList = workList -> selectedItems();
1069 for (int i = 0; i < selList.size(); ++i)
1070 {
1071 QString tmp = selList.at(i) -> text().mid(0, 1);
1072 if (tmp == "A")
1073 {
1074 //scheduled to be added, ok to commit
1075 }
1076 else if (tmp == "M")
1077 {
1078 //locally modified, ok to commit
1079 }
1080 else if (tmp == "R")
1081 {
1082 //user wants to remove from repo, ok to commit
1083 }
1084 else
1085 {
1086 return false;
1087 }
1088 }
1089 return true;
1090 }
1091
1092 bool MainWindow::isSelectedDeletable(QListWidget *workList)
1093 {
1094 QList<QListWidgetItem *> selList = workList -> selectedItems();
1095 if (selList.count() == 1)
1096 {
1097 QString tmp = selList.at(0)->text().mid(0, 1);
1098 if (tmp == "A")
1099 {
1100 //scheduled to be added, ok to remove (won't go to repo)
1101 return true;
1102 }
1103 else if (tmp == "C")
1104 {
1105 //Tracked but unchanged, ok to remove
1106 return true;
1107 }
1108 else if (tmp == "M")
1109 {
1110 //locally modified, ok to remove from repo
1111 return true;
1112 }
1113 else if (tmp == "!")
1114 {
1115 //locally deleted, ok to remove from repo
1116 return true;
1117 }
1118 }
1119 return false;
1120 }
1121
1122
1123 bool MainWindow::areAllSelectedUntracked(QListWidget *workList)
1124 {
1125 QList<QListWidgetItem *> selList = workList -> selectedItems();
1126 for (int i = 0; i < selList.size(); ++i)
1127 {
1128 QString tmp = selList.at(i) -> text();
1129
1130 if (tmp.mid(0,1) != "?")
1131 {
1132 return false;
1133 }
1134 }
1135 return true;
1136 }
1137
1138
1139 bool MainWindow::isSelectedModified(QListWidget *workList)
1140 {
1141 QList<QListWidgetItem *> selList = workList -> selectedItems();
1142 if (selList.count() == 1)
1143 {
1144 if (selList.at(0)->text().mid(0, 1) == "M")
1145 {
1146 return true;
1147 }
1148 }
1149 return false;
1150 }
1151
1152 void MainWindow::countModifications(QListWidget *workList, int& added, int& modified, int& removed, int& notTracked,
1153 int& selected,
1154 int& selectedAdded, int& selectedModified, int& selectedRemoved, int& selectedNotTracked)
1155 {
1156 int itemCount = workList -> count();
1157 if (itemCount > 0)
1158 {
1159 int A= 0;
1160 int M=0;
1161 int R=0;
1162 int N=0;
1163 int S=0;
1164 int SA=0;
1165 int SM=0;
1166 int SR=0;
1167 int SN=0;
1168
1169 for (int i = 0; i < workList -> count(); i++)
1170 {
1171 QListWidgetItem *currItem = workList -> item(i);
1172
1173 QString tmp = currItem->text().mid(0, 1);
1174 if (tmp == "M")
1175 {
1176 M++;
1177 }
1178 else if (tmp == "R")
1179 {
1180 R++;
1181 }
1182 else if (tmp == "A")
1183 {
1184 A++;
1185 }
1186 else if (tmp == "?")
1187 {
1188 N++;
1189 }
1190 }
1191
1192 added = A;
1193 modified = M;
1194 removed = R;
1195 notTracked = N;
1196
1197 QList <QListWidgetItem *> selList = workList -> selectedItems();
1198
1199 S = selList.size();
1200 for (int i = 0; i < selList.size(); ++i)
1201 {
1202 QString tmp = selList.at(i) -> text();
1203
1204 if (tmp.mid(0,1) == "A")
1205 {
1206 SA++;
1207 }
1208 else if (tmp.mid(0,1) == "M")
1209 {
1210 SM++;
1211 }
1212 else if (tmp.mid(0,1) == "R")
1213 {
1214 SR++;
1215 }
1216 else if (tmp.mid(0,1) == "?")
1217 {
1218 SN++;
1219 }
1220 }
1221
1222 selected = S;
1223 selectedAdded = SA;
1224 selectedModified = SM;
1225 selectedRemoved = SR;
1226 selectedNotTracked = SN;
1227 }
1228 else
1229 {
1230 added = 0;
1231 modified = 0;
1232 removed = 0;
1233 notTracked = 0;
1234 selected = 0;
1235 selectedAdded = 0;
1236 selectedModified = 0;
1237 selectedRemoved = 0;
1238 selectedNotTracked = 0;
1239 }
1240 }
1241
1242 1067
1243 void MainWindow::updateFileSystemWatcher() 1068 void MainWindow::updateFileSystemWatcher()
1244 { 1069 {
1245 //!!! this needs to be incremental when something changes 1070 //!!! this needs to be incremental when something changes
1246 1071
1579 1404
1580 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl; 1405 DEBUG << "localRepoActionsEnabled = " << localRepoActionsEnabled << endl;
1581 DEBUG << "canCommit = " << hgExp->canCommit() << endl; 1406 DEBUG << "canCommit = " << hgExp->canCommit() << endl;
1582 1407
1583 //!!! new stuff: 1408 //!!! new stuff:
1409 hgAddAct->setEnabled(localRepoActionsEnabled && hgExp->canAdd());
1410 hgRemoveAct->setEnabled(localRepoActionsEnabled && hgExp->canRemove());
1584 hgCommitAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit()); 1411 hgCommitAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
1585 hgRevertAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit()); 1412 hgRevertAct->setEnabled(localRepoActionsEnabled && hgExp->canCommit());
1413 hgFolderDiffAct->setEnabled(localRepoActionsEnabled && hgExp->canDoDiff());
1586 1414
1587 /*!!! 1415 /*!!!
1588 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked; 1416 int added, modified, removed, notTracked, selected, selectedAdded, selectedModified, selectedRemoved, selectedNotTracked;
1589 1417
1590 countModifications(hgExp -> workFolderFileList, 1418 countModifications(hgExp -> workFolderFileList,
1842 1670
1843 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE)); 1671 workFolderToolBar = addToolBar(tr(WORKFOLDERMENU_TITLE));
1844 addToolBar(Qt::LeftToolBarArea, workFolderToolBar); 1672 addToolBar(Qt::LeftToolBarArea, workFolderToolBar);
1845 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE)); 1673 workFolderToolBar -> setIconSize(QSize(MY_ICON_SIZE, MY_ICON_SIZE));
1846 // workFolderToolBar->addSeparator(); 1674 // workFolderToolBar->addSeparator();
1847 workFolderToolBar->addAction(hgFileDiffAct); 1675 // workFolderToolBar->addAction(hgFileDiffAct);
1848 // workFolderToolBar->addAction(hgFolderDiffAct); 1676 workFolderToolBar->addAction(hgFolderDiffAct);
1849 workFolderToolBar->addSeparator(); 1677 workFolderToolBar->addSeparator();
1850 workFolderToolBar->addAction(hgRevertAct); 1678 workFolderToolBar->addAction(hgRevertAct);
1851 workFolderToolBar->addAction(hgUpdateAct); 1679 workFolderToolBar->addAction(hgUpdateAct);
1852 workFolderToolBar->addAction(hgCommitAct); 1680 workFolderToolBar->addAction(hgCommitAct);
1853 workFolderToolBar->addAction(hgMergeAct); 1681 workFolderToolBar->addAction(hgMergeAct);