From 079b613d373c9ea317d49941728da146dad32356 Mon Sep 17 00:00:00 2001 From: saturneric Date: Tue, 23 Jan 2024 20:27:30 +0800 Subject: feat: add a setting to enable gpgme debug log --- src/ui/widgets/FileTreeView.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/ui/widgets/FileTreeView.cpp') diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 0c299a97..450acbad 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -159,7 +159,7 @@ auto FileTreeView::SlotDeleteSelectedItem() -> void { if (ret == QMessageBox::Cancel) return; - GF_UI_LOG_DEBUG("delete item: {}", data.toString().toStdString()); + GF_UI_LOG_DEBUG("delete item: {}", data.toString()); if (!dir_model_->remove(index)) { QMessageBox::critical(this, tr("Error"), @@ -194,25 +194,17 @@ void FileTreeView::SlotMkdirBelowAtSelectedItem() { } void FileTreeView::SlotTouch() { -#ifdef WINDOWS - auto root_path_str = dir_model_->rootPath().toStdU16String(); -#else - auto root_path_str = dir_model_->rootPath().toStdString(); -#endif - std::filesystem::path root_path(root_path_str); + auto root_path = dir_model_->rootPath(); QString new_file_name; bool ok; + new_file_name = QInputDialog::getText( this, tr("Create Empty File"), tr("Filename (you can given extension)"), QLineEdit::Normal, new_file_name, &ok); if (ok && !new_file_name.isEmpty()) { -#ifdef WINDOWS - auto file_path = root_path / new_file_name.toStdU16String(); -#else - auto file_path = root_path / new_file_name.toStdString(); -#endif - QFile new_file(file_path.u8string().c_str()); + auto file_path = root_path + "/" + new_file_name; + QFile new_file(file_path); if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) { QMessageBox::critical(this, tr("Error"), tr("Unable to create the file.")); @@ -257,7 +249,7 @@ void FileTreeView::keyPressEvent(QKeyEvent* event) { void FileTreeView::SlotOpenSelectedItemBySystemApplication() { QFileInfo const info(selected_path_); if (info.isDir()) { - const auto file_path = info.filePath().toUtf8().toStdString(); + const auto file_path = info.filePath().toUtf8(); QDesktopServices::openUrl(QUrl::fromLocalFile(selected_path_)); } else { @@ -377,11 +369,11 @@ void FileTreeView::slot_calculate_hash() { CommonUtils::WaitForOpera( this->parentWidget(), tr("Calculating"), [=](const OperaWaitingHd& hd) { RunOperaAsync( - [=](DataObjectPtr data_object) { + [=](const DataObjectPtr& data_object) { data_object->Swap({CalculateHash(this->GetSelectedPath())}); return 0; }, - [hd](int rtn, DataObjectPtr data_object) { + [hd](int rtn, const DataObjectPtr& data_object) { hd(); if (rtn < 0 || !data_object->Check()) { return; -- cgit v1.2.3 From 9fa19d9dae8153ae360e666887fbd079620c5022 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 24 Jan 2024 12:50:42 +0800 Subject: fix: solve an issue that switch tab but crypto menu won't update --- src/ui/widgets/FileTreeView.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/ui/widgets/FileTreeView.cpp') diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 450acbad..0350bb09 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -394,4 +394,8 @@ void FileTreeView::paintEvent(QPaintEvent* event) { this->resizeColumnToContents(i); } } + +void FileTreeView::mousePressEvent(QMouseEvent* event) { + QTreeView::mousePressEvent(event); +} } // namespace GpgFrontend::UI -- cgit v1.2.3 From 38c9d2ce81b2c4d33caa120d07fe9605525722bf Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 24 Jan 2024 14:32:56 +0800 Subject: fix: improve file page --- src/ui/widgets/FileTreeView.cpp | 53 +++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'src/ui/widgets/FileTreeView.cpp') diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 0350bb09..91536cdf 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -49,6 +49,7 @@ FileTreeView::FileTreeView(QWidget* parent, const QString& target_path) slot_create_popup_menu(); this->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, &QWidget::customContextMenuRequested, this, &FileTreeView::slot_show_custom_context_menu); connect(this, &QTreeView::doubleClicked, this, @@ -204,6 +205,8 @@ void FileTreeView::SlotTouch() { QLineEdit::Normal, new_file_name, &ok); if (ok && !new_file_name.isEmpty()) { auto file_path = root_path + "/" + new_file_name; + GF_UI_LOG_DEBUG("new file path: {}", file_path); + QFile new_file(file_path); if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) { QMessageBox::critical(this, tr("Error"), @@ -215,6 +218,7 @@ void FileTreeView::SlotTouch() { void FileTreeView::SlotTouchBelowAtSelectedItem() { auto root_path(selected_path_); + if (root_path.isEmpty()) root_path = dir_model_->rootPath(); QString new_file_name; bool ok; @@ -223,6 +227,7 @@ void FileTreeView::SlotTouchBelowAtSelectedItem() { QLineEdit::Normal, new_file_name, &ok); if (ok && !new_file_name.isEmpty()) { auto file_path = root_path + "/" + new_file_name; + GF_UI_LOG_DEBUG("new file path: {}", file_path); QFile new_file(file_path); if (!new_file.open(QIODevice::WriteOnly | QIODevice::NewOnly)) { @@ -326,16 +331,16 @@ void FileTreeView::slot_create_popup_menu() { connect(action_open_with_system_default_application, &QAction::triggered, this, &FileTreeView::SlotOpenSelectedItemBySystemApplication); - auto* new_item_action_menu = new QMenu(this); - new_item_action_menu->setTitle(tr("New")); - new_item_action_menu->addAction(action_create_empty_file_); - new_item_action_menu->addAction(action_make_directory_); + new_item_action_menu_ = new QMenu(this); + new_item_action_menu_->setTitle(tr("New")); + new_item_action_menu_->addAction(action_create_empty_file_); + new_item_action_menu_->addAction(action_make_directory_); popup_menu_->addAction(action_open_file_); popup_menu_->addAction(action_open_with_system_default_application); popup_menu_->addSeparator(); - popup_menu_->addMenu(new_item_action_menu); + popup_menu_->addMenu(new_item_action_menu_); popup_menu_->addSeparator(); popup_menu_->addAction(action_rename_file_); @@ -346,22 +351,40 @@ void FileTreeView::slot_create_popup_menu() { void FileTreeView::slot_show_custom_context_menu(const QPoint& point) { auto target_path = this->GetPathByClickPoint(point); + auto select_path = GetSelectedPath(); + + GF_UI_LOG_DEBUG("file tree view, target path: {}, select path: {}", + target_path, select_path); + if (target_path.isEmpty() && !select_path.isEmpty()) { + target_path = select_path; + } + + QFileInfo file_info(target_path); - if (!target_path.isEmpty()) { - action_open_file_->setEnabled(true); + action_open_file_->setEnabled(false); + action_rename_file_->setEnabled(false); + action_delete_file_->setEnabled(false); + action_calculate_hash_->setEnabled(false); + action_make_directory_->setEnabled(false); + action_create_empty_file_->setEnabled(false); + action_calculate_hash_->setEnabled(false); + + if (file_info.exists()) { + action_open_file_->setEnabled(file_info.isFile() && file_info.isReadable()); action_rename_file_->setEnabled(true); action_delete_file_->setEnabled(true); - QFileInfo const info(this->GetSelectedPath()); - action_calculate_hash_->setEnabled(info.isFile() && info.isReadable()); - + action_make_directory_->setEnabled(file_info.isDir() && + file_info.isWritable()); + action_create_empty_file_->setEnabled(file_info.isDir() && + file_info.isWritable()); + action_calculate_hash_->setEnabled(file_info.isFile() && + file_info.isReadable()); } else { - action_open_file_->setEnabled(false); - action_rename_file_->setEnabled(false); - action_delete_file_->setEnabled(false); - - action_calculate_hash_->setEnabled(false); + action_create_empty_file_->setEnabled(true); + action_make_directory_->setEnabled(true); } + popup_menu_->exec(this->GetMousePointGlobal(point)); } -- cgit v1.2.3 From 8cb450e916b15f50599d14ee36b707a2703423f5 Mon Sep 17 00:00:00 2001 From: saturneric Date: Wed, 24 Jan 2024 17:52:51 +0800 Subject: fix: try to solve bugs at universal file operations --- src/ui/widgets/FileTreeView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/widgets/FileTreeView.cpp') diff --git a/src/ui/widgets/FileTreeView.cpp b/src/ui/widgets/FileTreeView.cpp index 91536cdf..b0241b63 100644 --- a/src/ui/widgets/FileTreeView.cpp +++ b/src/ui/widgets/FileTreeView.cpp @@ -271,7 +271,7 @@ void FileTreeView::SlotRenameSelectedItem() { auto file_info = QFileInfo(selected_path_); auto new_name_path = file_info.absolutePath() + "/" + text; GF_UI_LOG_DEBUG("new filename path: {}", new_name_path); - if (QDir().rename(file_info.absoluteFilePath(), new_name_path)) { + if (!QDir().rename(file_info.absoluteFilePath(), new_name_path)) { QMessageBox::critical(this, tr("Error"), tr("Unable to rename the file or folder.")); return; -- cgit v1.2.3