diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f145b..a84fa09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ ################################################################################ cmake_minimum_required (VERSION 2.8) +set(CMAKE_CXX_FLAGS "-stdlib=libc++") set(CMAKE_CXX_STANDARD 11) project(Tyro) @@ -32,9 +33,12 @@ else() message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.") endif() -# Silence some useless errors + if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + # Silence some useless errors set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-potentially-evaluated-expression") + # Set the correct standard lib + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") endif() # wxwidgets stuff diff --git a/cmake.sh b/cmake.sh index 6093dfb..747a71e 100755 --- a/cmake.sh +++ b/cmake.sh @@ -4,10 +4,10 @@ mkdir -p build unset MACOSX_DEPLOYMENT_TARGET unset CMAKE_OSX_SYSROOT -export MACOSX_DEPLOYMENT_TARGET="10.7" -export CMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk" +export MACOSX_DEPLOYMENT_TARGET="10.9" +export CMAKE_OSX_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk" cd build -cmake .. +cmake -stdlib=libc++ .. make "$@" cd .. diff --git a/src/TyroApp.cpp b/src/TyroApp.cpp index 08b8618..266d43e 100644 --- a/src/TyroApp.cpp +++ b/src/TyroApp.cpp @@ -43,7 +43,7 @@ public: { if ( ! wxApp::OnInit()) return false; - this->SetSystemOptions(); + TyroApp::SetSystemOptions(); this->SetAppName(APP_NAME); this->SetVendorName(APP_VENDOR); @@ -162,7 +162,7 @@ private: wxLogDebug("Current display: %ix%i", mode.w, mode.h); - wxSize base((int)((float)mode.w * 0.8), (int)((float)mode.h * 0.8)); + wxSize base((int)((float)mode.w * 0.9), (int)((float)mode.h * 0.9)); return base; } @@ -170,13 +170,14 @@ private: /** * Toolkit-specific settings */ - void SetSystemOptions() + void static SetSystemOptions() { #ifdef __WXMAC__ wxSystemOptions::SetOption("osx.openfiledialog.always-show-types", 1); #endif - #ifdef __WXMSW__ + #ifdef __WXMSW_ + wxSystemOptions::SetOption("msw.remap", 0);_ wxSystemOptions::SetOption("msw.display.directdraw", 1); #endif } diff --git a/src/definitions.h b/src/definitions.h index 88f6b0e..8f367c2 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -6,7 +6,7 @@ // Application config const wxString APP_NAME = "Tyro"; const wxString APP_VENDOR = "Aviat Ion"; -const wxString APP_VERSION = "0.9.1"; +const wxString APP_VERSION = "0.10.0"; const wxString APP_VERSION_MORE = "Pre-release"; // Command-line arguments diff --git a/src/widgets/FilePane.cpp b/src/widgets/FilePane.cpp index 9c21364..1a68643 100644 --- a/src/widgets/FilePane.cpp +++ b/src/widgets/FilePane.cpp @@ -1,3 +1,5 @@ +#include + #include "src/widgets/FilePane.h" #include "src/widgets/MainFrame.h" @@ -34,7 +36,6 @@ FilePane::FilePane( wxALIGN_LEFT, wxCOL_RESIZABLE | wxCOL_SORTABLE); - } FilePane::~FilePane() @@ -61,86 +62,113 @@ void FilePane::OpenFolder(wxTreeListEvent& event) * Iterates through the specified folder and creates the tree view * * @access private - * @param wxString &path - * @param wxTreeListItem &root */ -void FilePane::CreateTree(const wxString &path, wxTreeListItem &root, int level) +void FilePane::CreateTree(const wxString &path, wxTreeListItem &root) { - // So yeah, this doesn't really work right. - // It seems I need to create a tree from the list of file paths, - // after which this should be much simpler. - // @TODO Fix - auto *files = new wxArrayString(); wxDir::GetAllFiles(path, files); - - vector examined; - vector::iterator it; - - for (const wxString &item : *files) - { - wxFileName filename(item); - // For loose files, just add directly to the tree - if (filename.GetDirCount() == 1) - { - auto fullFileName = filename.GetFullPath(); + // std::unordered_set dirs; - auto fileData = new wxStringClientData(); - fileData->SetData(fullFileName); + for (const wxString &file: *files) + { + wxFileName fileName(file); - examined.push_back(fullFileName); + if (fileName.DirExists(".")) + { + fileName.RemoveDir(0); + } - this->AppendItem(root, filename.GetFullName(), Icon_File, Icon_File, fileData); - continue; - } + auto dir = std::string(fileName.GetPath()); - // Remove the directory component closest to the root - /* filename.RemoveDir(0); + if (dir.empty()) + { + continue; + } - wxArrayString folders = filename.GetDirs(); + this->dir_set.insert(dir); + } - wxTreeListItem newRootNode = root; - - for (const wxString &curr_folder: folders) - { - wxLogDebug(curr_folder); - - // Check if directory has already been created - it = find(examined.begin(), examined.end(), curr_folder); - - if (it != examined.end()) continue; - - // Create the directory node if it doesn't exist - auto fileData = new wxStringClientData(); - fileData->SetData(curr_folder); - - wxTreeListItem current = this->AppendItem( - newRootNode, - curr_folder, - Icon_FolderClosed, - Icon_FolderOpened, - fileData); - examined.push_back(curr_folder); - - newRootNode = current; - - this->CreateTree(curr_folder, root); - } */ - } + for (auto& dir: this->dir_set) + { + wxString wdir = wxString(dir); + wxLogDebug("Creating Dir Tree: %s", wdir); + this->DirToTree(wdir, root, wxString(".")); + } } -/*void FilePane::CreateFolderTree(StringVector dirList, wxTreeListItem &root) +/** + * Recursively create directory tree from list of files + * + * @access private + */ +void FilePane::DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent) { - -}*/ + auto fullPath = parent.Clone(); + fullPath += "/"; + fullPath += path; + auto *files = new wxArrayString(); + wxDir::GetAllFiles(path, files); + + for (const wxString &item: *files) + { + wxFileName filename(item); + + // Remove the directory component closest to the root + if (filename.GetDirCount() > 1) + { + filename.RemoveDir(0); + } + + const wxArrayString dirs = filename.GetDirs(); + + // See if the path already exists on the tree + /* for (const wxString &dir: dirs) + { + this->dir_it = find(this->examined.begin(), this->examined.end(), dir); + + if (dir_it != this->examined.end()) + { + break; + } + + auto fileData = new wxStringClientData(); + fileData->SetData(dir); + + auto dir_node = this->AppendItem(root, dir, Icon_FolderClosed, Icon_FolderOpened, fileData); + + this->examined.push_back(dir); + + this->CreateTree(dir, dir_node); + break; + }*/ + + // If the file is at the root, add it to the tree + if (filename.GetDirCount() == 1) + { + filename.MakeAbsolute(); + + auto fileData = new wxStringClientData(); + fileData->SetData(filename.GetFullPath()); + + this->AppendItem(root, filename.GetFullName(), Icon_File, Icon_File, fileData); + continue; + } + } +} + +/** + * Open a file you double-click on the file list + */ void FilePane::OpenFileInEditor(wxTreeListEvent& event) { wxTreeListItem item = event.GetItem(); auto data = (wxStringClientData*)this->GetItemData(item); const wxString& path = data->GetData(); + wxLogDebug("Opening file from sidebar: %s", path); + wxString path_arr [1] = { path }; auto files = wxArrayString(1, *path_arr); Glob_main_frame->OpenFiles(files); diff --git a/src/widgets/FilePane.h b/src/widgets/FilePane.h index 3b4ebca..0725cc9 100644 --- a/src/widgets/FilePane.h +++ b/src/widgets/FilePane.h @@ -1,5 +1,6 @@ #pragma once +#include #include "src/widgets/widget.h" class FilePane : public wxTreeListCtrl { @@ -16,10 +17,13 @@ public: private: wxString curr_path = ""; wxImageList *img_list = nullptr; + unordered_set file_set; + unordered_set dir_set; void BindEvents(); void OpenFolder(wxTreeListEvent& event); void OpenFileInEditor(wxTreeListEvent& event); void InitImageList(); - void CreateTree(const wxString &path, wxTreeListItem &root, int level = 0); + void CreateTree(const wxString &path, wxTreeListItem &root); + void DirToTree(const wxString &path, wxTreeListItem &root, const wxString &parent); };