Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: debugger/QT/SkDebuggerGUI.cpp

Issue 1462633002: Update debugger UI to auto-refresh the directory listing (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « debugger/QT/SkDebuggerGUI.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDebuggerGUI.h" 8 #include "SkDebuggerGUI.h"
9 #include "SkPicture.h" 9 #include "SkPicture.h"
10 #include <QListWidgetItem> 10 #include <QListWidgetItem>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 , fMenuView(this) 49 , fMenuView(this)
50 , fLoading(false) 50 , fLoading(false)
51 { 51 {
52 setupUi(this); 52 setupUi(this);
53 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection); 53 fListWidget.setSelectionMode(QAbstractItemView::ExtendedSelection);
54 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidge tItem*)), this, 54 connect(&fListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidge tItem*)), this,
55 SLOT(updateDrawCommandInfo())); 55 SLOT(updateDrawCommandInfo()));
56 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile())); 56 connect(&fActionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
57 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory() )); 57 connect(&fActionDirectory, SIGNAL(triggered()), this, SLOT(toggleDirectory() ));
58 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QList WidgetItem*)), this, SLOT(loadFile(QListWidgetItem *))); 58 connect(&fDirectoryWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QList WidgetItem*)), this, SLOT(loadFile(QListWidgetItem *)));
59 connect(&fDirectoryWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(po pulateDirectoryWidget()));
59 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete())); 60 connect(&fActionDelete, SIGNAL(triggered()), this, SLOT(actionDelete()));
60 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLO T(toggleBreakpoint())); 61 connect(&fListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLO T(toggleBreakpoint()));
61 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind())); 62 connect(&fActionRewind, SIGNAL(triggered()), this, SLOT(actionRewind()));
62 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay())); 63 connect(&fActionPlay, SIGNAL(triggered()), this, SLOT(actionPlay()));
63 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack())) ; 64 connect(&fActionStepBack, SIGNAL(triggered()), this, SLOT(actionStepBack())) ;
64 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForwa rd())); 65 connect(&fActionStepForward, SIGNAL(triggered()), this, SLOT(actionStepForwa rd()));
65 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoint s())); 66 connect(&fActionBreakpoint, SIGNAL(triggered()), this, SLOT(actionBreakpoint s()));
66 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector() )); 67 connect(&fActionInspector, SIGNAL(triggered()), this, SLOT(actionInspector() ));
67 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings())) ; 68 connect(&fActionSettings, SIGNAL(triggered()), this, SLOT(actionSettings())) ;
68 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QStrin g))); 69 connect(&fFilter, SIGNAL(activated(QString)), this, SLOT(toggleFilter(QStrin g)));
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 279
279 void SkDebuggerGUI::saveToFile(const SkString& filename) { 280 void SkDebuggerGUI::saveToFile(const SkString& filename) {
280 SkFILEWStream file(filename.c_str()); 281 SkFILEWStream file(filename.c_str());
281 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture()); 282 SkAutoTUnref<SkPicture> copy(fDebugger.copyPicture());
282 283
283 sk_tool_utils::PngPixelSerializer serializer; 284 sk_tool_utils::PngPixelSerializer serializer;
284 copy->serialize(&file, &serializer); 285 copy->serialize(&file, &serializer);
285 } 286 }
286 287
287 void SkDebuggerGUI::loadFile(QListWidgetItem *item) { 288 void SkDebuggerGUI::loadFile(QListWidgetItem *item) {
288 if (fDirectoryWidgetActive) { 289 if (item == nullptr) {
289 fFileName = fPath.toAscii().data(); 290 return;
290 // don't add a '/' to files in the local directory 291 }
291 if (fFileName.size() > 0) { 292
292 fFileName.append("/"); 293 SkString fileName(fPath.toAscii().data());
293 } 294 // don't add a '/' to files in the local directory
294 fFileName.append(item->text().toAscii().data()); 295 if (fileName.size() > 0) {
296 fileName.append("/");
297 }
298 fileName.append(item->text().toAscii().data());
299
300 if (!fileName.equals(fFileName)) {
301 fFileName = fileName;
295 loadPicture(fFileName); 302 loadPicture(fFileName);
296 } 303 }
297 } 304 }
298 305
299 void SkDebuggerGUI::openFile() { 306 void SkDebuggerGUI::openFile() {
300 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "", 307 QString temp = QFileDialog::getOpenFileName(this, tr("Open File"), "",
301 tr("Files (*.*)")); 308 tr("Files (*.*)"));
302 openFile(temp); 309 openFile(temp);
303 } 310 }
304 311
305 void SkDebuggerGUI::openFile(const QString &filename) { 312 void SkDebuggerGUI::openFile(const QString &filename) {
306 fDirectoryWidgetActive = false;
307 if (!filename.isEmpty()) { 313 if (!filename.isEmpty()) {
308 QFileInfo pathInfo(filename); 314 QFileInfo pathInfo(filename);
309 loadPicture(SkString(filename.toAscii().data())); 315 loadPicture(SkString(filename.toAscii().data()));
310 setupDirectoryWidget(pathInfo.path()); 316 setupDirectoryWidget(pathInfo.path());
311 } 317 }
312 fDirectoryWidgetActive = true;
313 } 318 }
314 319
315 void SkDebuggerGUI::pauseDrawing(bool isPaused) { 320 void SkDebuggerGUI::pauseDrawing(bool isPaused) {
316 fPausedRow = fListWidget.currentRow(); 321 fPausedRow = fListWidget.currentRow();
317 this->updateDrawCommandInfo(); 322 this->updateDrawCommandInfo();
318 } 323 }
319 324
320 void SkDebuggerGUI::updateDrawCommandInfo() { 325 void SkDebuggerGUI::updateDrawCommandInfo() {
321 int currentRow = -1; 326 int currentRow = -1;
322 if (!fLoading) { 327 if (!fLoading) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 fToolBar.addAction(&fActionPlay); 578 fToolBar.addAction(&fActionPlay);
574 fToolBar.addSeparator(); 579 fToolBar.addSeparator();
575 fToolBar.addAction(&fActionInspector); 580 fToolBar.addAction(&fActionInspector);
576 fToolBar.addAction(&fActionSettings); 581 fToolBar.addAction(&fActionSettings);
577 582
578 fToolBar.addSeparator(); 583 fToolBar.addSeparator();
579 fToolBar.addWidget(&fSpacer); 584 fToolBar.addWidget(&fSpacer);
580 fToolBar.addWidget(&fFilter); 585 fToolBar.addWidget(&fFilter);
581 fToolBar.addAction(&fActionCancel); 586 fToolBar.addAction(&fActionCancel);
582 587
583 // TODO(chudy): Remove static call.
584 fDirectoryWidgetActive = false;
585 fFileName = ""; 588 fFileName = "";
586 setupDirectoryWidget(""); 589 setupDirectoryWidget("");
587 fDirectoryWidgetActive = true;
588 590
589 // Menu Bar 591 // Menu Bar
590 fMenuFile.setTitle("File"); 592 fMenuFile.setTitle("File");
591 fMenuFile.addAction(&fActionOpen); 593 fMenuFile.addAction(&fActionOpen);
592 fMenuFile.addAction(&fActionSave); 594 fMenuFile.addAction(&fActionSave);
593 fMenuFile.addAction(&fActionSaveAs); 595 fMenuFile.addAction(&fActionSaveAs);
594 fMenuFile.addAction(&fActionClose); 596 fMenuFile.addAction(&fActionClose);
595 597
596 fMenuEdit.setTitle("Edit"); 598 fMenuEdit.setTitle("Edit");
597 fMenuEdit.addAction(&fActionDelete); 599 fMenuEdit.addAction(&fActionDelete);
(...skipping 28 matching lines...) Expand all
626 fMenuBar.addAction(fMenuView.menuAction()); 628 fMenuBar.addAction(fMenuView.menuAction());
627 fMenuBar.addAction(fMenuNavigate.menuAction()); 629 fMenuBar.addAction(fMenuNavigate.menuAction());
628 fMenuBar.addAction(fMenuWindows.menuAction()); 630 fMenuBar.addAction(fMenuWindows.menuAction());
629 631
630 SkDebuggerGUI->setMenuBar(&fMenuBar); 632 SkDebuggerGUI->setMenuBar(&fMenuBar);
631 QMetaObject::connectSlotsByName(SkDebuggerGUI); 633 QMetaObject::connectSlotsByName(SkDebuggerGUI);
632 } 634 }
633 635
634 void SkDebuggerGUI::setupDirectoryWidget(const QString& path) { 636 void SkDebuggerGUI::setupDirectoryWidget(const QString& path) {
635 fPath = path; 637 fPath = path;
636 QDir dir(path); 638 populateDirectoryWidget();
637 QRegExp r(".skp"); 639
638 fDirectoryWidget.clear(); 640 // clear the existing watched directory and setup a new directory to watch
639 const QStringList files = dir.entryList(); 641 if (!fDirectoryWatcher.directories().empty()) {
640 foreach (QString f, files) { 642 fDirectoryWatcher.removePaths(fDirectoryWatcher.directories());
641 if (f.contains(r)) 643 }
642 fDirectoryWidget.addItem(f); 644 if (!path.isEmpty()) {
645 fDirectoryWatcher.addPath(fPath);
643 } 646 }
644 } 647 }
645 648
649 void SkDebuggerGUI::populateDirectoryWidget() {
650 QDir dir(fPath);
651 QRegExp r(".skp");
652 const QStringList files = dir.entryList();
653
654 // check if a file has been removed
655 for (int i = fDirectoryWidget.count() - 1; i >= 0; i--) {
656 QListWidgetItem* item = fDirectoryWidget.item(i);
657 if (!files.contains(item->text())) {
658 fDirectoryWidget.removeItemWidget(item);
659 delete item;
660 }
661 }
662
663 // add any new files
664 foreach (QString f, files) {
665 if (f.contains(r) && fDirectoryWidget.findItems(f, Qt::MatchExactly).siz e() == 0) {
666 fDirectoryWidget.addItem(f);
667 }
668 }
669 }
670
646 void SkDebuggerGUI::loadPicture(const SkString& fileName) { 671 void SkDebuggerGUI::loadPicture(const SkString& fileName) {
647 fFileName = fileName; 672 fFileName = fileName;
648 fLoading = true; 673 fLoading = true;
649 SkAutoTDelete<SkStream> stream(new SkFILEStream(fileName.c_str())); 674 SkAutoTDelete<SkStream> stream(new SkFILEStream(fileName.c_str()));
650 675
651 SkPicture* picture = SkPicture::CreateFromStream(stream); 676 SkPicture* picture = SkPicture::CreateFromStream(stream);
652 677
653 if (nullptr == picture) { 678 if (nullptr == picture) {
654 QMessageBox::critical(this, "Error loading file", "Couldn't read file, s orry."); 679 QMessageBox::critical(this, "Error loading file", "Couldn't read file, s orry.");
655 return; 680 return;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 fCanvasWidget.drawTo(fPausedRow); 794 fCanvasWidget.drawTo(fPausedRow);
770 } else { 795 } else {
771 fCanvasWidget.drawTo(fListWidget.currentRow()); 796 fCanvasWidget.drawTo(fListWidget.currentRow());
772 } 797 }
773 } 798 }
774 799
775 void SkDebuggerGUI::updateHit(int newHit) { 800 void SkDebuggerGUI::updateHit(int newHit) {
776 fCommandHitBox.setText(QString::number(newHit)); 801 fCommandHitBox.setText(QString::number(newHit));
777 } 802 }
778 803
OLDNEW
« no previous file with comments | « debugger/QT/SkDebuggerGUI.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698