| 2791 | } |
| 2792 | |
| 2793 | bool App::loadFileFromPath( |
| 2794 | std::string path, bool inNewTab, UICodeEditor* codeEditor, |
| 2795 | std::function<void( UICodeEditor* codeEditor, const std::string& path )> onLoaded, |
| 2796 | bool openBinaryAsDocument, bool tryFindMimeType ) { |
| 2797 | std::string ext = FileSystem::fileExtension( path ); |
| 2798 | |
| 2799 | if ( ext == "lnk" ) { |
| 2800 | auto target = Sys::getShortcutTarget( path ); |
| 2801 | if ( !target.empty() ) { |
| 2802 | if ( FileSystem::fileExists( target ) ) |
| 2803 | path = target; |
| 2804 | else |
| 2805 | return false; |
| 2806 | } else if ( !FileSystem::fileExists( path ) ) |
| 2807 | return false; |
| 2808 | } |
| 2809 | |
| 2810 | if ( ( Image::isImageExtension( path ) || tryFindMimeType ) && Image::isImage( path ) && |
| 2811 | ext != "svg" ) { |
| 2812 | loadImageFromPath( path ); |
| 2813 | } else if ( ( SoundFileFactory::isKnownFileExtension( path ) || tryFindMimeType ) && |
| 2814 | SoundFileFactory::isValidAudioFile( path ) ) { |
| 2815 | loadAudioFromPath( path ); |
| 2816 | } else if ( !openBinaryAsDocument && PathHelper::isOpenExternalExtension( ext ) ) { |
| 2817 | Engine::instance()->openURI( path ); |
| 2818 | } else if ( tryFindMimeType && TextDocument::fileMightBeBinary( path ) ) { |
| 2819 | // Trigger the warning message box with the message "File looks like a binary file" |
| 2820 | openFileFromPath( path ); |
| 2821 | } else { |
| 2822 | UITab* tab = mSplitter->isDocumentOpen( path ); |
| 2823 | |
| 2824 | if ( tab && tab->getOwnedWidget()->isType( UI_TYPE_CODEEDITOR ) ) { |
| 2825 | UICodeEditor* editor = tab->getOwnedWidget()->asType<UICodeEditor>(); |
| 2826 | if ( inNewTab ) { |
| 2827 | auto d = mSplitter->loadDocumentInNewTab( editor->getDocumentRef() ); |
| 2828 | updateEditorTitle( d.second ); |
| 2829 | } else { |
| 2830 | mSplitter->loadDocument( editor->getDocumentRef(), editor ); |
| 2831 | updateEditorTitle( editor ); |
| 2832 | } |
| 2833 | } else { |
| 2834 | if ( inNewTab ) { |
| 2835 | mSplitter->loadAsyncFileFromPathInNewTab( path, onLoaded ); |
| 2836 | } else { |
| 2837 | mSplitter->loadAsyncFileFromPath( path, codeEditor, onLoaded ); |
| 2838 | } |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | return true; |
| 2843 | } |
| 2844 | |
| 2845 | void App::hideGlobalSearchBar() { |
| 2846 | mGlobalSearchController->hideGlobalSearchBar(); |
no test coverage detected