fix: solve an issue that switch tab but crypto menu won't update
This commit is contained in:
parent
bab198aa13
commit
9fa19d9dae
@ -71,6 +71,18 @@ class UISignalStation : public QObject {
|
||||
*/
|
||||
void SignalUIRefresh();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void SignalMainWindowOpenFile(QString);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
|
@ -99,7 +99,7 @@ void KeySetExpireDateDialog::init() {
|
||||
auto settings =
|
||||
GpgFrontend::GlobalSettingStation::GetInstance().GetSettings();
|
||||
|
||||
bool longer_expiration_date = longer_expiration_date =
|
||||
bool longer_expiration_date =
|
||||
settings.value("basic/longer_expiration_date").toBool();
|
||||
|
||||
auto max_date_time =
|
||||
|
@ -103,6 +103,12 @@ void MainWindow::Init() noexcept {
|
||||
[=](const QString &message, int timeout) {
|
||||
statusBar()->showMessage(message, timeout);
|
||||
});
|
||||
connect(UISignalStation::GetInstance(),
|
||||
&UISignalStation::SignalMainWindowlUpdateBasicalOperaMenu, this,
|
||||
&MainWindow::SlotUpdateCryptoMenuStatus);
|
||||
connect(UISignalStation::GetInstance(),
|
||||
&UISignalStation::SignalMainWindowOpenFile, this,
|
||||
&MainWindow::SlotOpenFile);
|
||||
|
||||
m_key_list_->AddMenuAction(append_selected_keys_act_);
|
||||
m_key_list_->AddMenuAction(append_key_create_date_to_editor_act_);
|
||||
|
@ -74,11 +74,6 @@ class MainWindow : public GeneralMainWindow {
|
||||
*/
|
||||
void Init() noexcept;
|
||||
|
||||
/**
|
||||
* @details refresh and enable specify crypto-menu actions.
|
||||
*/
|
||||
void SetCryptoMenuStatus(CryptoMenu::OperationType type);
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
@ -118,6 +113,11 @@ class MainWindow : public GeneralMainWindow {
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
* @details refresh and enable specify crypto-menu actions.
|
||||
*/
|
||||
void SlotUpdateCryptoMenuStatus(unsigned int type);
|
||||
|
||||
/**
|
||||
* @details Open a new tab for path
|
||||
*/
|
||||
|
@ -65,13 +65,8 @@ void MainWindow::slot_open_key_management() {
|
||||
void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); }
|
||||
|
||||
void MainWindow::slot_disable_tab_actions(int number) {
|
||||
bool disable;
|
||||
|
||||
disable = number == -1;
|
||||
|
||||
if (edit_->CurFilePage() != nullptr) {
|
||||
disable = true;
|
||||
}
|
||||
auto disable = number == -1;
|
||||
if (edit_->CurFilePage() != nullptr) disable = true;
|
||||
|
||||
print_act_->setDisabled(disable);
|
||||
save_act_->setDisabled(disable);
|
||||
@ -100,6 +95,12 @@ void MainWindow::slot_disable_tab_actions(int number) {
|
||||
|
||||
cut_pgp_header_act_->setDisabled(disable);
|
||||
add_pgp_header_act_->setDisabled(disable);
|
||||
|
||||
if (edit_->CurFilePage() != nullptr) {
|
||||
GF_UI_LOG_DEBUG("edit current page is file page");
|
||||
auto* file_page = edit_->CurFilePage();
|
||||
emit file_page->SignalCurrentTabChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slot_open_settings_dialog() {
|
||||
@ -184,9 +185,9 @@ void MainWindow::SlotSetRestartNeeded(int mode) {
|
||||
|
||||
int MainWindow::get_restart_needed() const { return this->restart_needed_; }
|
||||
|
||||
void MainWindow::SetCryptoMenuStatus(
|
||||
MainWindow::CryptoMenu::OperationType type) {
|
||||
GF_UI_LOG_DEBUG("type: {}", type);
|
||||
void MainWindow::SlotUpdateCryptoMenuStatus(unsigned int type) {
|
||||
MainWindow::CryptoMenu::OperationType opera_type = type;
|
||||
GF_UI_LOG_DEBUG("update crypto menu status, type: {}", opera_type);
|
||||
|
||||
// refresh status to disable all
|
||||
verify_act_->setDisabled(true);
|
||||
@ -197,22 +198,22 @@ void MainWindow::SetCryptoMenuStatus(
|
||||
decrypt_verify_act_->setDisabled(true);
|
||||
|
||||
// enable according to type
|
||||
if (type & MainWindow::CryptoMenu::Verify) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::Verify) != 0U) {
|
||||
verify_act_->setDisabled(false);
|
||||
}
|
||||
if (type & MainWindow::CryptoMenu::Sign) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::Sign) != 0U) {
|
||||
sign_act_->setDisabled(false);
|
||||
}
|
||||
if (type & MainWindow::CryptoMenu::Encrypt) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::Encrypt) != 0U) {
|
||||
encrypt_act_->setDisabled(false);
|
||||
}
|
||||
if (type & MainWindow::CryptoMenu::EncryptAndSign) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::EncryptAndSign) != 0U) {
|
||||
encrypt_sign_act_->setDisabled(false);
|
||||
}
|
||||
if (type & MainWindow::CryptoMenu::Decrypt) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::Decrypt) != 0U) {
|
||||
decrypt_act_->setDisabled(false);
|
||||
}
|
||||
if (type & MainWindow::CryptoMenu::DecryptAndVerify) {
|
||||
if ((opera_type & MainWindow::CryptoMenu::DecryptAndVerify) != 0U) {
|
||||
decrypt_verify_act_->setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
@ -96,14 +96,35 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
|
||||
[this](const QString& path) { this->ui_->pathEdit->setText(path); });
|
||||
connect(file_tree_view_, &FileTreeView::SignalPathChanged, this,
|
||||
&FilePage::SignalPathChanged);
|
||||
|
||||
auto* main_window = qobject_cast<MainWindow*>(this->parent());
|
||||
if (main_window != nullptr) {
|
||||
connect(file_tree_view_, &FileTreeView::SignalOpenFile, main_window,
|
||||
&MainWindow::SlotOpenFile);
|
||||
|
||||
connect(file_tree_view_, &FileTreeView::SignalOpenFile,
|
||||
UISignalStation::GetInstance(),
|
||||
&UISignalStation::SignalMainWindowOpenFile);
|
||||
connect(file_tree_view_, &FileTreeView::SignalSelectedChanged, this,
|
||||
[main_window](const QString& selected_path) {
|
||||
&FilePage::update_main_basical_opera_menu);
|
||||
connect(this, &FilePage::SignalCurrentTabChanged, this,
|
||||
[this]() { update_main_basical_opera_menu(GetSelected()); });
|
||||
connect(this, &FilePage::SignalMainWindowlUpdateBasicalOperaMenu,
|
||||
UISignalStation::GetInstance(),
|
||||
&UISignalStation::SignalMainWindowlUpdateBasicalOperaMenu);
|
||||
}
|
||||
|
||||
auto FilePage::GetSelected() const -> QString {
|
||||
return file_tree_view_->GetSelectedPath();
|
||||
}
|
||||
|
||||
void FilePage::SlotGoPath() {
|
||||
file_tree_view_->SlotGoPath(ui_->pathEdit->text());
|
||||
}
|
||||
|
||||
void FilePage::keyPressEvent(QKeyEvent* event) {
|
||||
GF_UI_LOG_DEBUG("file page notices key press by user: {}", event->key());
|
||||
if (ui_->pathEdit->hasFocus() &&
|
||||
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
|
||||
SlotGoPath();
|
||||
}
|
||||
}
|
||||
|
||||
void FilePage::update_main_basical_opera_menu(const QString& selected_path) {
|
||||
MainWindow::CryptoMenu::OperationType operation_type =
|
||||
MainWindow::CryptoMenu::None;
|
||||
|
||||
@ -124,44 +145,22 @@ FilePage::FilePage(QWidget* parent, const QString& target_path)
|
||||
operation_type |= MainWindow::CryptoMenu::EncryptAndSign;
|
||||
}
|
||||
|
||||
if (info.isFile() &&
|
||||
(info.suffix() == "gpg" || info.suffix() == "pgp" ||
|
||||
if (info.isFile() && (info.suffix() == "gpg" || info.suffix() == "pgp" ||
|
||||
info.suffix() == "asc")) {
|
||||
operation_type |= MainWindow::CryptoMenu::Decrypt;
|
||||
operation_type |= MainWindow::CryptoMenu::DecryptAndVerify;
|
||||
}
|
||||
|
||||
if (info.isFile() &&
|
||||
(info.suffix() != "gpg" && info.suffix() != "pgp" &&
|
||||
if (info.isFile() && (info.suffix() != "gpg" && info.suffix() != "pgp" &&
|
||||
info.suffix() != "sig" && info.suffix() != "asc")) {
|
||||
operation_type |= MainWindow::CryptoMenu::Sign;
|
||||
}
|
||||
|
||||
if (info.isFile() &&
|
||||
(info.suffix() == "sig" || info.suffix() == "gpg" ||
|
||||
if (info.isFile() && (info.suffix() == "sig" || info.suffix() == "gpg" ||
|
||||
info.suffix() == "pgp" || info.suffix() == "asc")) {
|
||||
operation_type |= MainWindow::CryptoMenu::Verify;
|
||||
}
|
||||
|
||||
main_window->SetCryptoMenuStatus(operation_type);
|
||||
});
|
||||
}
|
||||
emit SignalMainWindowlUpdateBasicalOperaMenu(operation_type);
|
||||
}
|
||||
|
||||
auto FilePage::GetSelected() const -> QString {
|
||||
return file_tree_view_->GetSelectedPath();
|
||||
}
|
||||
|
||||
void FilePage::SlotGoPath() {
|
||||
file_tree_view_->SlotGoPath(ui_->pathEdit->text());
|
||||
}
|
||||
|
||||
void FilePage::keyPressEvent(QKeyEvent* event) {
|
||||
GF_UI_LOG_DEBUG("file page notices key press by user: {}", event->key());
|
||||
if (ui_->pathEdit->hasFocus() &&
|
||||
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
|
||||
SlotGoPath();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace GpgFrontend::UI
|
||||
|
@ -71,7 +71,7 @@ class FilePage : public QWidget {
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
void SignalPathChanged(const QString& path);
|
||||
void SignalPathChanged(const QString&);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
@ -79,8 +79,20 @@ class FilePage : public QWidget {
|
||||
* @param text
|
||||
* @param verify_label_status
|
||||
*/
|
||||
void SignalRefreshInfoBoard(const QString& text,
|
||||
InfoBoardStatus verify_label_status);
|
||||
void SignalRefreshInfoBoard(const QString&, InfoBoardStatus);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void SignalCurrentTabChanged();
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
void SignalMainWindowlUpdateBasicalOperaMenu(unsigned int);
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -99,6 +111,14 @@ class FilePage : public QWidget {
|
||||
QMenu* popup_menu_{}; ///<
|
||||
QMenu* option_popup_menu_{}; ///<
|
||||
FileTreeView* file_tree_view_;
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
*/
|
||||
void update_main_basical_opera_menu(const QString&);
|
||||
};
|
||||
|
||||
} // namespace GpgFrontend::UI
|
||||
|
@ -394,4 +394,8 @@ void FileTreeView::paintEvent(QPaintEvent* event) {
|
||||
this->resizeColumnToContents(i);
|
||||
}
|
||||
}
|
||||
|
||||
void FileTreeView::mousePressEvent(QMouseEvent* event) {
|
||||
QTreeView::mousePressEvent(event);
|
||||
}
|
||||
} // namespace GpgFrontend::UI
|
||||
|
@ -88,6 +88,13 @@ class FileTreeView : public QTreeView {
|
||||
*/
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
|
@ -429,7 +429,7 @@ void KeyList::SetDoubleClickedAction(
|
||||
this->m_action_ = std::move(action);
|
||||
}
|
||||
|
||||
QString KeyList::GetSelectedKey() {
|
||||
auto KeyList::GetSelectedKey() -> QString {
|
||||
if (ui_->keyGroupTab->size().isEmpty()) return {};
|
||||
const auto& buffered_keys =
|
||||
m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user