From 4578d013b21686e3c9b63c205766d838d44e46a3 Mon Sep 17 00:00:00 2001 From: Rodney Date: Dec 27 2019 20:54:15 +0000 Subject: Merge pull request #2961 from martinvanzijl/double-click-to-open-scene-in-file-browser-and-browser-room Allow double-click to open scenes in File Browser and Browser Room --- diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp index 4583567..a5efd7a 100644 --- a/toonz/sources/toonz/filebrowser.cpp +++ b/toonz/sources/toonz/filebrowser.cpp @@ -2303,6 +2303,22 @@ void FileBrowser::enableGlobalSelection(bool enabled) { void FileBrowser::selectNone() { m_itemViewer->selectNone(); } +//----------------------------------------------------------------------------- + +void FileBrowser::enableDoubleClickToOpenScenes() { + // perhaps this should disconnect existing signal handlers first + connect(this, SIGNAL(filePathDoubleClicked(const TFilePath &)), + this, SLOT(tryToOpenScene(const TFilePath &))); +} + +//----------------------------------------------------------------------------- + +void FileBrowser::tryToOpenScene(const TFilePath &filePath) { + if (filePath.getType() == "tnz") { + IoCmd::loadScene(filePath); + } +} + //============================================================================= // FCData methods //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/filebrowser.h b/toonz/sources/toonz/filebrowser.h index e528325..b36d838 100644 --- a/toonz/sources/toonz/filebrowser.h +++ b/toonz/sources/toonz/filebrowser.h @@ -124,6 +124,12 @@ types to be displayed in the file browser. QSplitter *getMainSplitter() const { return m_mainSplitter; } + // Enable double-click to open a scene. + // This is not always desirable (e.g. if a user double-clicks on a file in + // a "Save As" dialog, they expect the file will be saved to, not opened). + // So it is disabled by default. + void enableDoubleClickToOpenScenes(); + protected: int findIndexWithPath(TFilePath path); void getExpandedFolders(DvDirModelNode *node, @@ -198,6 +204,9 @@ protected slots: void onFileSystemChanged(const QString &folderPath); + // If filePath is a valid scene file, open it. Otherwise do nothing. + void tryToOpenScene(const TFilePath &filePath); + signals: void filePathClicked(const TFilePath &); diff --git a/toonz/sources/toonz/tpanels.cpp b/toonz/sources/toonz/tpanels.cpp index 36627cd..a03604e 100644 --- a/toonz/sources/toonz/tpanels.cpp +++ b/toonz/sources/toonz/tpanels.cpp @@ -1089,6 +1089,7 @@ public: TFilePath currentProjectFolder = TProjectManager::instance()->getCurrentProjectPath().getParentDir(); browser->setFolder(currentProjectFolder, true); + browser->enableDoubleClickToOpenScenes(); } } browserFactory;