| 1 | // |
| 2 | // FilesrcListWin.cpp - List all source code filenames |
| 3 | // |
| 4 | // by Jean-Paul Mari |
| 5 | // |
| 6 | // JPM = Jean-Paul Mari <djipi.mari@gmail.com> |
| 7 | // |
| 8 | // Who When What |
| 9 | // --- ---------- ----------------------------------------------------------- |
| 10 | // JPM 09/23/2018 Created this file |
| 11 | // |
| 12 | |
| 13 | // STILL TO DO: |
| 14 | // Remove the 1st information, named '1', at the top |
| 15 | // To allow source code file opening / viewing |
| 16 | // |
| 17 | |
| 18 | #include "debugger/FilesrcListWin.h" |
| 19 | //#include "memory.h" |
| 20 | #include "debugger/DBGManager.h" |
| 21 | |
| 22 | |
| 23 | // |
| 24 | FilesrcListWindow::FilesrcListWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog), |
| 25 | layout(new QVBoxLayout), |
| 26 | treeView(new QTreeView), |
| 27 | standardModel(new QStandardItemModel), |
| 28 | rootNode(new QStandardItem), |
| 29 | filesrcItems(NULL), |
| 30 | statusbar(new QStatusBar), |
| 31 | nbItem(0) |
| 32 | { |
| 33 | // Setup root |
| 34 | rootNode = standardModel->invisibleRootItem(); |
| 35 | //register the model |
| 36 | treeView->setModel(standardModel); |
| 37 | treeView->expandAll(); |
| 38 | layout->addWidget(treeView); |
| 39 | |
| 40 | // Status bar |
| 41 | layout->addWidget(statusbar); |
| 42 | setLayout(layout); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | // |
| 47 | FilesrcListWindow::~FilesrcListWindow(void) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | |
| 52 | // |
| 53 | void FilesrcListWindow::Reset(void) |
| 54 | { |
| 55 | standardModel->setRowCount(0); |
| 56 | free(filesrcItems); |
| 57 | filesrcItems = NULL; |
| 58 | nbItem = 0; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | // |
| 63 | void FilesrcListWindow::RefreshContents(void) |
| 64 | { |
| 65 | size_t Error, Nbr; |
| 66 | char msg[1024]; |
| 67 | |
| 68 | if (!filesrcItems) |
| 69 | { |
| 70 | if ((Nbr = UpdateInfos())) |
| 71 | { |
| 72 | sprintf(msg, "%i files found", Nbr); |
| 73 | Error = FSL_NOERROR; |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | sprintf(msg, "No files found"); |
| 78 | Error = FSL_NOFILESRCLIST; |
| 79 | } |
| 80 | |
| 81 | // Display status bar |
| 82 | if (Error) |
| 83 | { |
| 84 | if ((Error & FSL_WARNING)) |
| 85 | { |
| 86 | statusbar->setStyleSheet("background-color: lightyellow; font: bold"); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | statusbar->setStyleSheet("background-color: tomato; font: bold"); |
| 91 | } |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | statusbar->setStyleSheet("background-color: lightgreen; font: bold"); |
| 96 | } |
| 97 | statusbar->showMessage(QString(msg)); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | // |
| 103 | size_t FilesrcListWindow::UpdateInfos(void) |
| 104 | { |
| 105 | size_t Nbr, i; |
| 106 | |
| 107 | Nbr = DBGManager_GetNbFullSourceFilename(); |
| 108 | |
| 109 | for (i = 0; i < Nbr; i++) |
| 110 | { |
| 111 | AddFilename(DBGManager_GetNumFullSourceFilename(i), rootNode, 0); |
| 112 | } |
| 113 | |
| 114 | return Nbr; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | // Add source code filename in the list |
| 119 | void FilesrcListWindow::AddFilename(char *FileName, QStandardItem *root, size_t ItemPos) |
| 120 | { |
| 121 | char *Ptr = FileName; |
| 122 | Sfilesrcitem *PtrNewFilesrc; |
| 123 | char Buffer[255]; |
| 124 | char a; |
| 125 | |
| 126 | #ifdef _WIN32 |
| 127 | while ((a = *Ptr++) && (a != '\\')); |
| 128 | #else |
| 129 | while ((a = *Ptr++) && (a != '/')); |
| 130 | #endif |
| 131 | if (a) |
| 132 | { |
| 133 | strncpy(Buffer, FileName, (Ptr - FileName - 1)); |
| 134 | Buffer[(Ptr - FileName - 1)] = 0; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | strcpy(Buffer, FileName); |
| 139 | } |
| 140 | PtrNewFilesrc = (Sfilesrcitem *)AddItem(Buffer, ItemPos); |
| 141 | if (!PtrNewFilesrc->PreviousItem) |
| 142 | { |
| 143 | PtrNewFilesrc->PreviousItem = root; |
| 144 | root->appendRow(PtrNewFilesrc->Item); |
| 145 | PtrNewFilesrc->Item->setEditable(false); |
| 146 | } |
| 147 | |
| 148 | if (a) |
| 149 | { |
| 150 | return (AddFilename(Ptr, PtrNewFilesrc->Item, (ItemPos + 1))); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | |
| 155 | // Add item to the list |
| 156 | // Return void * on new item or already existing one |
| 157 | void *FilesrcListWindow::AddItem(char *ItemName, size_t ItemPos) |
| 158 | { |
| 159 | Sfilesrcitem *Ptr = filesrcItems; |
| 160 | |
| 161 | // Look for already existing item |
| 162 | for (size_t i = 0; i < nbItem; i++) |
| 163 | { |
| 164 | if ((Ptr->column == ItemPos) && !strcmp(Ptr->Item->text().toLocal8Bit().constData(), ItemName)) |
| 165 | { |
| 166 | return Ptr; |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | Ptr++; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Add item in the list |
| 175 | filesrcItems = (Sfilesrcitem *)realloc(filesrcItems, (sizeof(Sfilesrcitem) * ++nbItem)); |
| 176 | (filesrcItems + (nbItem - 1))->column = ItemPos; |
| 177 | (filesrcItems + (nbItem - 1))->PreviousItem = NULL; |
| 178 | (filesrcItems + (nbItem - 1))->Item = new QStandardItem(ItemName); |
| 179 | return (filesrcItems + (nbItem - 1)); |
| 180 | } |