size_t CController::currentDiskIndex(Panel p) const { const auto& drives = _diskEnumerator.drives(); for (size_t i = 0; i < drives.size(); ++i) { if (CFileSystemObject(panel(p).currentDirPathNative()).isChildOf(drives[i].fileSystemObject)) return i; } return std::numeric_limits<int>::max(); }
void CFileSystemObject::setPath(const QString& path) { if (path.isEmpty()) { *this = CFileSystemObject(); return; } _rootFileSystemId = std::numeric_limits<uint64_t>::max(); _fileInfo.setFile(expandEnvironmentVariables(path)); refreshInfo(); }
void scanDirectory(const CFileSystemObject& root, const std::function<void(const CFileSystemObject&)>& observer, const std::atomic<bool>& abort) { if (observer) observer(root); if (!root.isDir() || abort) return; const auto list = root.qDir().entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::System); for (const auto& entry : list) { scanDirectory(CFileSystemObject(entry), observer, abort); if (abort) return; } }
bool CController::createFile(const QString &parentFolder, const QString &name) { QDir parentDir(parentFolder); if (!parentDir.exists()) return false; const QString newFilePath = parentDir.absolutePath() + "/" + name; if (QFile(newFilePath).open(QFile::WriteOnly)) { if (toNativeSeparators(parentDir.absolutePath()) == activePanel().currentDirPathNative()) { // This is required for the UI to know to set the cursor at the new file setCursorPositionForCurrentFolder(CFileSystemObject(newFilePath).hash()); } return true; } else return false; }
bool CController::createFolder(const QString &parentFolder, const QString &name) { QDir parentDir(parentFolder); if (!parentDir.exists()) return false; const QString posixName = toPosixSeparators(name); if (parentDir.mkpath(posixName)) { if (parentDir.absolutePath() == activePanel().currentDirObject().qDir().absolutePath()) { const int slashPosition = posixName.indexOf('/'); const QString newFolderPath = parentDir.absolutePath() + "/" + (slashPosition > 0 ? posixName.left(posixName.indexOf('/')) : posixName); // This is required for the UI to know to set the cursor at the new folder setCursorPositionForCurrentFolder(CFileSystemObject(newFolderPath).hash()); } return true; } else return false; }
bool CTextViewerPlugin::canViewFile(const QString& fileName, const QMimeType& /*type*/) const { return CFileSystemObject(fileName).isFile(); }
void CMainWindow::createFile() { if (!_currentFileList) return; const auto currentItem = _currentFileList->currentItemHash() != 0 ? _controller->itemByHash(_currentFileList->panelPosition(), _currentFileList->currentItemHash()) : CFileSystemObject(); const QString currentItemName = !currentItem.isCdUp() ? currentItem.fullName() : QString(); const QString fileName = QInputDialog::getText(this, tr("New file"), tr("Enter the name for the new file"), QLineEdit::Normal, currentItemName); if (!fileName.isEmpty()) { if (!_controller->createFile(_currentFileList->currentDir(), fileName)) QMessageBox::warning(this, tr("Failed to create a file"), tr("Failed to create the file %1").arg(fileName)); } }