# # # delete "guitone/src/view/FileAssignments.cpp" # # delete "guitone/src/view/FileAssignments.h" # # add_file "guitone/src/util/OpenFile.cpp" # content [649ef62a4c532bc7d42186d9d6131fa1366c8851] # # add_file "guitone/src/util/OpenFile.h" # content [f56a5026655603e84c3eb9cc18d94afd952c030e] # # patch "guitone/guitone.pro" # from [b03dd7c79d305cd0a61ebda2f2f6df58b60a9d16] # to [53a7ce08a5ec4f4e484adaa026cc23bd15a94eb6] # # patch "guitone/res/dialogs/preferences.ui" # from [ca6e42971070facfb334bdc8194ae2e51ab912a0] # to [459bc28645032f061fb7755b79e49d42e4a7a4c8] # # patch "guitone/res/i18n/guitone_de.ts" # from [04013dbbad7724af66c567c498af43814331a880] # to [16410dd4e15051aedd3225d9e133b9c26123e32b] # # patch "guitone/src/monotone/Monotone.cpp" # from [169a5fa6a658f48fba1c7185c8062719f5bd04a7] # to [dd255983550664ca1d829b065bc67ecda54e5c63] # # patch "guitone/src/monotone/Monotone.h" # from [02a04c161701e05523f3d7e592d10052025633b7] # to [f7c585fb41db9739d79b6cd907419f39954c0df3] # # patch "guitone/src/view/Guitone.cpp" # from [45ed8c1db4ca0e3a6614c1a2241dfba3ff60c4e5] # to [db42effec993b8448908de78104a99e7c383901d] # # patch "guitone/src/view/Guitone.h" # from [1a33007147710762f4429edd383c4e7db0660b2c] # to [9f28936da1b590f83b470db5c091b8364ed453b4] # # patch "guitone/src/view/InventoryView.cpp" # from [b9d5f505d528a2d7e30abc0b404b04c568dd74b1] # to [2403be0ec75d8d3a348f3e46c96108941b0a8a81] # # patch "guitone/src/view/InventoryView.h" # from [3343bdca9c2444705454763a8ac39e684b3822b1] # to [89ca6e4bfe2a01af39b97963f752a96fe2f04941] # # patch "guitone/src/view/TreeView.h" # from [91b3758772b3ad8e038f31bb1e46693aaf05b70e] # to [ccb16a995ac6da02a782e0100cbd3171ff6fed84] # # patch "guitone/src/view/dialogs/Preferences.cpp" # from [f621ddf5b91e44b27dfc798985d0af4603099102] # to [0521f0b9c40bbfcd7100fbf12ff91ea68ce14279] # ============================================================ --- guitone/src/util/OpenFile.cpp 649ef62a4c532bc7d42186d9d6131fa1366c8851 +++ guitone/src/util/OpenFile.cpp 649ef62a4c532bc7d42186d9d6131fa1366c8851 @@ -0,0 +1,56 @@ +#include "openfile.h" + +#include +#include + +#ifdef Q_WS_WIN +#include +#endif + +bool OpenFile::open(QWidget *widget, const QString &filename) +{ + bool retval = false; + + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); +#ifdef Q_WS_X11 + + Q_UNUSED(widget); + // Assume we have KDE + string s("kfmclient exec \""); + s += filename.toUtf8().data(); + s += "\""; + retval = (system(s.c_str()) == 0); + // If that doesn't work, try the Gnome version + // If this still doesn't work, then we're clueless + if (!retval) + { + string s("gnome-open \""); + s += filename.toUtf8().data(); + s += "\""; + retval = (system(s.c_str()) == 0); + } +#endif + +#ifdef Q_WS_MACX + // Running on a Mac in OS X + Q_UNUSED(widget); + string s("open \""); + s += filename.toUtf8().data(); + s += "\""; + retval = (system(s.c_str()) == 0); +#endif + +#ifdef Q_WS_WIN + // Running in an MS Windows environment + if (NULL != widget) + { + filename.replace(QChar('/'), QString("\\")); + retval = (reinterpret_cast(ShellExecute(widget->winId(), "open", + filename.toUtf8().data(), NULL, NULL, SW_SHOW)) > 32); + } +#endif + + QApplication::restoreOverrideCursor(); + return retval; +} + ============================================================ --- guitone/src/util/OpenFile.h f56a5026655603e84c3eb9cc18d94afd952c030e +++ guitone/src/util/OpenFile.h f56a5026655603e84c3eb9cc18d94afd952c030e @@ -0,0 +1,55 @@ +// +// The following code is public domain, with slight modifications, taken from +// http://hrabia.ibib.waw.pl/~winnie/qtopen.html +// It opens a file with the associated program on the specific platform +// Original author: Chris Thompson +// +#ifndef OPENFILE_H +#define OPENFILE_H + +#include +#include + +#ifdef Q_WS_X11 +#include +#endif + +#ifdef Q_WS_MACX +#include +#include +#endif + +#include + +using namespace std; + + +/*! +* \class OpenFile +* \version $Revision$ +* \brief Open a given file using the underlying operating +* system's default method. We would typically use this +* to open a URL using the default browser, for example. +* Its use is undefined if the operating system does not +* know how to handle the file we pass it. +*/ +class OpenFile +{ +public: + /*! + * \brief Open the specified URL. This will attempt to open + * the specified url in the user's favourite browser using + * operating-system dependent techniques. It is theorised + * that files could be opened, at least on the Windows + * platform, using this code without any modifications. + * \warning The URL is assumed to be valid. No security + * checks are performed. + * \arg QWidget *widget The parent to the browser. This is + * not used on some platforms. + * \arg const string &filename The URL to open. + */ + static bool open(QWidget *widget, const QString &filename); +}; + +#endif + ============================================================ --- guitone/guitone.pro b03dd7c79d305cd0a61ebda2f2f6df58b60a9d16 +++ guitone/guitone.pro 53a7ce08a5ec4f4e484adaa026cc23bd15a94eb6 @@ -12,7 +12,6 @@ HEADERS += src/view/Guitone.h \ src/view/AttributesView.h \ src/view/DiffView.h \ src/view/DiffStatusView.h \ - src/view/FileAssignments.h \ src/view/dialogs/SwitchWorkspaceRevision.h \ src/view/dialogs/Preferences.h \ src/view/dialogs/AncestryGraph.h \ @@ -38,7 +37,8 @@ HEADERS += src/view/Guitone.h \ src/util/StanzaParser.h \ src/util/Settings.h \ src/util/DiffParser.h \ - src/util/SignalWaiter.h + src/util/SignalWaiter.h \ + src/util/OpenFile.h SOURCES += src/view/Guitone.cpp \ src/view/TreeView.cpp \ src/view/Splitter.cpp \ @@ -46,7 +46,6 @@ SOURCES += src/view/Guitone.cpp \ src/view/AttributesView.cpp \ src/view/DiffView.cpp \ src/view/DiffStatusView.cpp \ - src/view/FileAssignments.cpp \ src/view/dialogs/SwitchWorkspaceRevision.cpp \ src/view/dialogs/Preferences.cpp \ src/view/dialogs/AncestryGraph.cpp \ @@ -73,6 +72,7 @@ SOURCES += src/view/Guitone.cpp \ src/util/Settings.cpp \ src/util/DiffParser.cpp \ src/util/SignalWaiter.cpp \ + src/util/OpenFile.cpp \ src/main.cpp FORMS += res/dialogs/switch_workspace.ui \ res/dialogs/preferences.ui \ ============================================================ --- guitone/res/dialogs/preferences.ui ca6e42971070facfb334bdc8194ae2e51ab912a0 +++ guitone/res/dialogs/preferences.ui 459bc28645032f061fb7755b79e49d42e4a7a4c8 @@ -5,8 +5,8 @@ 0 0 - 431 - 316 + 393 + 141 @@ -90,71 +90,6 @@ - - - Open file assignments - - - - 9 - - - 6 - - - - - 0 - - - 6 - - - - - - - - 0 - - - 6 - - - - - Add - - - - - - - Remove - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 @@ -195,13 +130,6 @@ - - - FileAssignments - QTreeView -
../FileAssignments.h
-
-
mtnExecutablePath selectMtnExecutable ============================================================ --- guitone/res/i18n/guitone_de.ts 04013dbbad7724af66c567c498af43814331a880 +++ guitone/res/i18n/guitone_de.ts 16410dd4e15051aedd3225d9e133b9c26123e32b @@ -266,17 +266,17 @@ Bereit - + Select your workspace... Wählen Sie Ihren Arbeitsbereich aus... - + Loading aborted Laden abgebrochen - + Invalid workspace Ungültiger Arbeitsbereich @@ -296,7 +296,7 @@ Das Inventar konnte nicht gelesen werden. Vielleicht läuft noch ein anderer Prozess? - + Loading workspace... Lade Arbeitsbereich... @@ -313,7 +313,7 @@ STRG+Q - + The chosen directory is no monotone workspace! Das gewählte Verzeichnis ist kein monotone-Arbeitsverzeichnis! @@ -323,7 +323,7 @@ &Importiere Arbeitsbereich - + Critical Monotone Error Kritischer monotone-Fehler @@ -359,12 +359,12 @@ Arbeitsbereich &öffnen - + &%1 %2 &%1 %2 - + No previous workspaces available. Keine vorherigen Arbeitsbereiche verfügbar. @@ -419,12 +419,12 @@ &Schlüsselverwaltung - + Unable to execute command Konnte Kommando nicht ausführen - + Unable to execute '%1' - maybe another command is still running? Konnte '%1' nicht ausführen - eventuell läuft noch ein anderes Kommando? @@ -444,22 +444,22 @@ Der Pfad zur ausführbaren Datei von monotone ist entweder ungültig oder zeigt auf eine ältere Version von monotone. Guitone benötigt monotone Version %1 oder ein monotone mit einer Interface-Version %2 oder neuer. - + Hide &ignored files &Ignorierte Dateien verstecken - + Show only &changed files Zeige nur &geänderte Dateien - + Show &ignored files &Ignorierte Dateien anzeigen - + Show &all files A&lle Dateien anzeigen @@ -469,18 +469,18 @@ one level up - ein Verzeichnis höher + ein Verzeichnis höher InventoryItem - + File Datei - + Status Status @@ -490,27 +490,27 @@ ein Verzeichnis höher - + Rename Source Quelle für Umbenennen - + Rename Target Ziel für Umbenennen - + Added hinzugefügt - + Dropped entfernt - + Missing fehlend @@ -520,22 +520,22 @@ verändert - + Unchanged unverändert - + Unknown unbekannt - + Ignored ignoriert - + Modified Verändert @@ -543,133 +543,120 @@ InventoryView - + &Add &Hinzufügen - - Ctrl+A - Add - - - - + Add to workspace Zum Arbeitsbereich hinzufügen - + &Remove En&tfernen - - Ctrl+R - Remove - - - - + Remove from workspace Vom Arbeitsbereich entfernen - + &Commit &Einpflegen - - Ctrl+C - Commit - - - - + Commit Einpflegen - + I&gnore Datei &ignorieren - - Ctrl+G - Ignore - - - - + Ignore file Datei ignorieren - + &Unignore Datei nicht ign&orieren - - Ctrl+U - Unignore - - - - + Unignore file Datei nicht mehr ignorieren - + R&evert &Zurücksetzen - - Ctrl+E - Revert - - - - + Revert uncommitted changes Nicht eingepflegte Änderungen verwerfen - + Rena&me Um&benennen - - Ctrl+M - Rename - - - - + Rename file Datei umbenennen - + D&iff U&nterschiede anzeigen - - Ctrl+D - Diff - + + Diff against base revision + Unterschiede im Vergleich zur Basisrevision anzeigen - - Diff against base revision - Unterschiede im Vergleich zur Basisrevision anzeigen + + &Go into + &Wechseln zu + + + Go into the directory + Wechsle in das Verzeichnis + + + + &Open + &Öffnen + + + + Open in default program + In Standardprogramm öffnen + + + + Error + Fehler + + + + The file you're trying to open does not exist. + Die Datei, die Sie versucht haben zu öffnen, existiert nicht. + + + + Unable to open files on your platform - please contact the author about this problem. + Kann keine Dateien auf Ihrer Plattform öffnen - bitte kontaktieren Sie den Autor über dieses Problem. + KeyManagement @@ -863,17 +850,17 @@ korrekt installiert? korrekt installiert? - + Unable to process command '%1': %2 Das Kommando '%1' konnte nicht abgearbeitet werden: %2 - + Monotone failed to start (Code %1). Please configure the path in the Preferences dialog. Monotone konnte nicht gestartet werden (Code %1). Bitte konfigurieren Sie den Pfad im Eintellungsdialog. - + The connection to the monotone process was terminated (Code %1). Check your configuration and reload the current workspace afterwards. Die Verbindung zum monotone-Prozess wurde beendet (Code %1). Prüfen Sie Ihre Konfiguration und laden Sie ggf. den Arbeitsbereich danach neu. @@ -924,30 +911,40 @@ korrekt installiert? PreferencesDialog - + Preferences Einstellungen - + Path to monotone executable Pfad zur ausführbaren Datei von monotone - + Browse Durchsuchen - + OK OK - + Cancel Abbrechen + + + Add + Hinzufügen + + + + Remove + Entfernen + SandboxItem ============================================================ --- guitone/src/monotone/Monotone.cpp 169a5fa6a658f48fba1c7185c8062719f5bd04a7 +++ guitone/src/monotone/Monotone.cpp dd255983550664ca1d829b065bc67ecda54e5c63 @@ -139,6 +139,7 @@ void Monotone::setup(QDir *workingDirect ); + workDir = workingDirectory; process->setWorkingDirectory(workingDirectory->absolutePath()); QStringList args; @@ -167,6 +168,11 @@ Monotone* Monotone::singleton(QObject * return instance; } +QString Monotone::getWorkspaceDir() const +{ + return workDir->absolutePath(); +} + void Monotone::startupError(QProcess::ProcessError error) { if (isCleanExit) return; ============================================================ --- guitone/src/monotone/Monotone.h 02a04c161701e05523f3d7e592d10052025633b7 +++ guitone/src/monotone/Monotone.h f7c585fb41db9739d79b6cd907419f39954c0df3 @@ -42,6 +42,7 @@ class Monotone : public QObject void setup(QDir*); virtual ~Monotone(); + QString getWorkspaceDir() const; bool triggerCommand(AutomateCommand*, const QStringList &); bool triggerCommand(AutomateCommand*, const QStringList &, const QStringList &); @@ -68,6 +69,7 @@ class Monotone : public QObject bool isCleanExit; static Monotone* instance; QProcess * process; + QDir * workDir; private slots: void readAndProcessCommand(); ============================================================ --- guitone/src/view/Guitone.cpp 45ed8c1db4ca0e3a6614c1a2241dfba3ff60c4e5 +++ guitone/src/view/Guitone.cpp db42effec993b8448908de78104a99e7c383901d @@ -238,60 +238,16 @@ void Guitone::buildConnections() attrModel, SLOT(readAttributes(const QModelIndex &)) ); - // double-click actions on list items (i.e. chdir, file diff, etc.) connect( - treeView, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(slotMapFolderTreeToFileList(const QModelIndex &)) + treeView, SIGNAL(directoryChanged(const QModelIndex &)), + listView, SLOT(slotChdir(const QModelIndex &)) ); connect( - listView, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(slotMapFileListToFolderTree(const QModelIndex &)) + listView, SIGNAL(directoryChanged(const QModelIndex &)), + treeView, SLOT(slotChdir(const QModelIndex &)) ); } -void Guitone::slotMapFolderTreeToFileList(const QModelIndex &proxyIndex) -{ - QModelIndex index = proxyModelFolderTree->mapToSource(proxyIndex); - index = proxyModelFileList->mapFromSource(index); - listView->setRootIndex(index); -} - -void Guitone::slotMapFileListToFolderTree(const QModelIndex &proxyFileIndex) -{ - // get the model index of the Inventory model - QModelIndex workspaceIndex = proxyModelFileList->mapToSource(proxyFileIndex); - InventoryItem *item = static_cast(workspaceIndex.internalPointer()); - - // nothing todo since we didn't receive a click on a folder - if (!item->isDirectory()) { return; } - - - // check if this is a pseudo diretory with which we actually go up - // and not down in the hierarchy - if (item->isCdUp()) - { - // for cdUp items select the parent in the actual model instead of - // the proxy model, since it is filtered out in proxyModelFolderTree - workspaceIndex = workspaceIndex.parent().parent(); - // list the contents of the parent of the parent directory - listView->setRootIndex(proxyFileIndex.parent().parent()); - } - else - { - listView->setRootIndex(proxyFileIndex); - } - - // map the workspace model index on the proxy model index of the folder tree - QModelIndex proxyFolderIndex = proxyModelFolderTree->mapFromSource(workspaceIndex); - // expand the selection if needed - if (item->hasChildDirs()) { treeView->expand(proxyFolderIndex); } - // select the item - treeView->selectionModel()->setCurrentIndex( - proxyFolderIndex, - QItemSelectionModel::ClearAndSelect - ); -} - void Guitone::criticalMtnError(const QString & msg) { if (gotError == false) ============================================================ --- guitone/src/view/Guitone.h 1a33007147710762f4429edd383c4e7db0660b2c +++ guitone/src/view/Guitone.h 9f28936da1b590f83b470db5c091b8364ed453b4 @@ -45,9 +45,7 @@ private slots: void chooseWorkspace(); void openRecentWorkspace(); void criticalMtnError(const QString &); - void slotMapFolderTreeToFileList(const QModelIndex &); - void slotMapFileListToFolderTree(const QModelIndex &); - void showHideIgnoredFiles(); + void showHideIgnoredFiles(); void showHideChangedFiles(); void openSwitchWorkspaceRevisionDialog(); void openPreferencesDialog(); ============================================================ --- guitone/src/view/InventoryView.cpp b9d5f505d528a2d7e30abc0b404b04c568dd74b1 +++ guitone/src/view/InventoryView.cpp 2403be0ec75d8d3a348f3e46c96108941b0a8a81 @@ -20,13 +20,16 @@ #include "InventoryView.h" #include "../util/Settings.h" +#include "../util/OpenFile.h" #include "../model/InventoryItem.h" +#include "../monotone/Monotone.h" #include "dialogs/FileDiff.h" #include #include #include #include +#include InventoryView::InventoryView(QWidget* parent, Type type_, QString objName) : TreeView(parent, objName), type(type_) @@ -51,15 +54,34 @@ InventoryView::InventoryView(QWidget* pa createAndConnectContextActions(); - // diff a patched file on double click connect( this, SIGNAL(doubleClicked(const QModelIndex &)), - this, SLOT(slotDiff(void)) + this, SLOT(slotItemClicked(const QModelIndex &)) ); + + // in a folder tree a single click will already trigger actions + if (type == FolderTree) + { + connect( + this, SIGNAL(clicked(const QModelIndex &)), + this, SLOT(slotItemClicked(const QModelIndex &)) + ); + } } InventoryView::~InventoryView() {} +// ensure that we only accept sortfilterproxymodels +void InventoryView::setModel(QAbstractItemModel * model) +{ + Q_ASSERT(false); +} + +void InventoryView::setModel(QSortFilterProxyModel * model) +{ + TreeView::setModel(model); +} + // adds elements to the popup menu based on the selected items // since not all actions may apply on all items void InventoryView::contextMenuEvent(QContextMenuEvent* ev) @@ -90,8 +112,14 @@ void InventoryView::contextMenuEvent(QCo InventoryItem* item = static_cast(sourceIndex.internalPointer()); - qDebug("Item Status: %d", item->getStatus()); + if (item->isDirectory()) + { + menu.addAction(actChdir); + } + + menu.addAction(actOpen); + if (item->hasStatus(InventoryItem::Unknown)) { menu.addAction(actAdd); @@ -128,6 +156,33 @@ void InventoryView::contextMenuEvent(QCo } } + // + // determine the default action + // + QFont activeFont; + activeFont.setBold(true); + QFont normalFont; + normalFont.setBold(false); + + if (item->isDirectory()) + { + actOpen->setFont(normalFont); + actChdir->setFont(activeFont); + } + else + { + if (item->hasStatus(InventoryItem::Patched)) + { + actDiff->setFont(activeFont); + actOpen->setFont(normalFont); + } + else + { + actDiff->setFont(normalFont); + actOpen->setFont(activeFont); + } + } + // TODO: special items for directories to add/remove/commit/revert // items in subdirectories via getStatusRecursive and friends @@ -161,72 +216,128 @@ void InventoryView::createAndConnectCont void InventoryView::createAndConnectContextActions(void) { + actChdir = new QAction(tr("&Go into"), this); + actChdir->setStatusTip(tr("Go into the directory")); + connect(actChdir, SIGNAL(triggered()), this, SLOT(slotChdir(QModelIndex()))); + + actOpen = new QAction(tr("&Open"), this); + actOpen->setStatusTip(tr("Open in default program")); + connect(actOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); + actAdd = new QAction(tr("&Add"), this); - actAdd->setShortcut(tr("Ctrl+A", "Add")); actAdd->setStatusTip(tr("Add to workspace")); connect(actAdd, SIGNAL(triggered()), this, SLOT(slotAdd())); actRemove = new QAction(tr("&Remove"), this); - actRemove->setShortcut(tr("Ctrl+R", "Remove")); actRemove->setStatusTip(tr("Remove from workspace")); connect(actRemove, SIGNAL(triggered()), this, SLOT(slotRemove())); actCommit = new QAction(tr("&Commit"), this); - actCommit->setShortcut(tr("Ctrl+C", "Commit")); actCommit->setStatusTip(tr("Commit")); connect(actCommit, SIGNAL(triggered()), this, SLOT(slotCommit())); actIgnore = new QAction(tr("I&gnore"), this); - actIgnore->setShortcut(tr("Ctrl+G", "Ignore")); actIgnore->setStatusTip(tr("Ignore file")); connect(actIgnore, SIGNAL(triggered()), this, SLOT(slotIgnore())); actUnignore = new QAction(tr("&Unignore"), this); - actUnignore->setShortcut(tr("Ctrl+U","Unignore")); actUnignore->setStatusTip(tr("Unignore file")); connect(actUnignore, SIGNAL(triggered()), this, SLOT(slotUnignore())); actRevert = new QAction(tr("R&evert"), this); - actRevert->setShortcut(tr("Ctrl+E", "Revert")); actRevert->setStatusTip(tr("Revert uncommitted changes")); connect(actRevert, SIGNAL(triggered()), this, SLOT(slotRevert())); actDiff = new QAction(tr("D&iff"), this); - actDiff->setShortcut(tr("Ctrl+D", "Diff")); actDiff->setStatusTip(tr("Diff against base revision")); connect(actDiff, SIGNAL(triggered()), this, SLOT(slotDiff())); actRename = new QAction(tr("Rena&me"), this); - actRename->setShortcut(tr("Ctrl+M", "Rename")); actRename->setStatusTip(tr("Rename file")); connect(actRename, SIGNAL(triggered()), this, SLOT(slotRename())); } -void InventoryView::slotAdd(void) + +void InventoryView::slotChdir(const QModelIndex & proxyIndex) { - QItemSelectionModel *selectionModel = this->selectionModel(); - QList modelIndexList(selectionModel->selectedIndexes()); - - if(modelIndexList.size() == 0) - { - qDebug("InventoryView::slotAdd: You didn't select the file properly!"); - return; - } + QModelIndex source; + + if (!proxyIndex.isValid()) + { + source = getSingleSelection(); + } + else + { + source = static_cast(model())->mapToSource(proxyIndex); + } + + InventoryItem *item = static_cast(source.internalPointer()); + + if (type == FileList) + { + if (item->isCdUp()) + { + // list the contents of the parent of the parent directory + setRootIndex(proxyIndex.parent().parent()); + return; + } + setRootIndex(proxyIndex); + return; + } + + // retranslate the proxy index + QModelIndex proxyFolderIndex = static_cast(model())->mapFromSource(source); + // expand the selection if needed + if (item->hasChildDirs()) + { + expand(proxyFolderIndex); + } + + // select the item + selectionModel()->setCurrentIndex( + proxyFolderIndex, + QItemSelectionModel::ClearAndSelect + ); +} - QListIterator i(modelIndexList); - QModelIndex modelIndex; - while (i.hasNext()) - { - modelIndex = i.next(); - if(modelIndex.column() == 0) // Only Filename - { - QVariant fileName = this->model()->data(modelIndex, Qt::DisplayRole); - qDebug("InventoryView::slotAdd: Action Add for File: %s", qPrintable(fileName.toString())); - } - } - clearSelection(); +void InventoryView::slotOpen(void) +{ + QModelIndex index(getSingleSelection()); + if (!index.isValid()) return; + + InventoryItem * item = static_cast(index.internalPointer()); + + Monotone * mtn = Monotone::singleton(); + QFileInfo file(mtn->getWorkspaceDir() + "/" + item->getPath()); + if (!file.exists()) + { + + QMessageBox::critical( + this, + tr("Error"), + tr("The file you're trying to open does not exist."), + QMessageBox::Ok, 0, 0 + ); + return; + } + + if (!OpenFile::open(this, file.absoluteFilePath())) + { + QMessageBox::critical( + this, + tr("Error"), + tr("Unable to open files on your platform - please contact the " + "author about this problem."), + QMessageBox::Ok, 0, 0 + ); + } } +void InventoryView::slotAdd(void) +{ + qDebug("InventoryView::slotAdd!!!"); +} + void InventoryView::slotRemove(void) { qDebug("InventoryView::slotRemove!!!"); @@ -265,32 +376,67 @@ void InventoryView::slotDiff(void) void InventoryView::slotDiff(void) { + QModelIndex index(getSingleSelection()); + if (!index.isValid()) return; + + InventoryItem * item = static_cast(index.internalPointer()); + + if (item->isDirectory() || !item->hasStatus(InventoryItem::Patched)) + { + qDebug("InventoryView::slotDiff: File is a directory or not patched/unknown."); + return; + } + + FileDiff dlg(this, item->getPath()); + dlg.exec(); + + clearSelection(); +} + +QModelIndex InventoryView::getSingleSelection() +{ QItemSelectionModel *selectionModel = this->selectionModel(); - QList indexList(selectionModel->selectedIndexes()); + QList list(selectionModel->selectedIndexes()); - if (indexList.size() == 0) + if (list.size() == 0) { - qDebug("InventoryView::slotDiff: No file selection."); - return; + qDebug("InventoryView::getSingleSelection: No item selected."); + return QModelIndex(); } - - if (indexList.size() > 1) + + if (list.size() > 1) { - qWarning("InventoryView::slotDiff: Only diffing the first item of the selection"); + qDebug("InventoryView::getSingleSelection: Multiple items selected, only returning the first."); } - QModelIndex sourceIndex = static_cast(indexList[0].model())->mapToSource(indexList[0]); - InventoryItem * item = static_cast(sourceIndex.internalPointer()); + return + static_cast(list[0].model())->mapToSource(list[0]); - if (item->isDirectory() || !item->hasStatus(InventoryItem::Patched)) +} + +void InventoryView::slotItemClicked(const QModelIndex & index) +{ + if (!index.isValid()) return; + QModelIndex sourceIndex = + static_cast(index.model())->mapToSource(index); + + InventoryItem * item = static_cast(sourceIndex.internalPointer()); + + if (item->isDirectory()) { - qDebug("InventoryView::slotDiff: File is a directory or not patched/unknown."); + emit directoryChanged(index); + slotChdir(index); return; } - FileDiff dlg(this, item->getPath()); - dlg.exec(); - - clearSelection(); + if (item->hasStatus(InventoryItem::Patched)) + { + slotDiff(); + return; + } + + // default action on double click + slotOpen(); + return; } ============================================================ --- guitone/src/view/InventoryView.h 3343bdca9c2444705454763a8ac39e684b3822b1 +++ guitone/src/view/InventoryView.h 89ca6e4bfe2a01af39b97963f752a96fe2f04941 @@ -23,6 +23,7 @@ #include "TreeView.h" #include +#include class InventoryItem; @@ -39,12 +40,20 @@ public: InventoryView(QWidget*, Type, QString); ~InventoryView(); - void contextMenuEvent(QContextMenuEvent * ev); + void contextMenuEvent(QContextMenuEvent *); + void setModel(QSortFilterProxyModel *); + +signals: + void directoryChanged(const QModelIndex &); private: - void createAndConnectContextActions(void); + void setModel(QAbstractItemModel *); + void createAndConnectContextActions(void); void closeEvent(void); + QModelIndex getSingleSelection(); + QAction *actChdir; + QAction *actOpen; QAction *actAdd; QAction *actRemove; QAction *actCommit; @@ -57,6 +66,9 @@ private slots: Type type; private slots: + void slotChdir(const QModelIndex &); + void slotItemClicked(const QModelIndex & index); + void slotOpen(void); void slotAdd(void); void slotRemove(void); void slotCommit(void); ============================================================ --- guitone/src/view/TreeView.h 91b3758772b3ad8e038f31bb1e46693aaf05b70e +++ guitone/src/view/TreeView.h ccb16a995ac6da02a782e0100cbd3171ff6fed84 @@ -31,7 +31,7 @@ public: TreeView(QWidget*); TreeView(QWidget*, QString); ~TreeView(); - void setModel(QAbstractItemModel*); + virtual void setModel(QAbstractItemModel*); private slots: void saveHeaderViewState(); ============================================================ --- guitone/src/view/dialogs/Preferences.cpp f621ddf5b91e44b27dfc798985d0af4603099102 +++ guitone/src/view/dialogs/Preferences.cpp 0521f0b9c40bbfcd7100fbf12ff91ea68ce14279 @@ -36,16 +36,6 @@ Preferences::Preferences(QWidget* parent selectMtnExecutable, SIGNAL(clicked()), this, SLOT(openFileBrowser()) ); - - connect( - addAssignment, SIGNAL(clicked()), - fileAssignments, SLOT(addNewRow()) - ); - - connect( - removeAssignment, SIGNAL(clicked()), - fileAssignments, SLOT(removeCurrentRow()) - ); } Preferences::~Preferences() {}