Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct enable/disable of session dialog buttons ECFLOW-1980 #128

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 9 additions & 59 deletions Viewer/ecflowUI/src/SessionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ SessionDialog::SessionDialog(QWidget* parent) : QDialog(parent) {
// what was saved last time?
std::string lastSessionName = SessionHandler::instance()->lastSessionName();
int index = SessionHandler::instance()->indexFromName(lastSessionName);
if (index != -1)
if (index != -1) {
savedSessionsList_->setCurrentItem(savedSessionsList_->topLevelItem(index)); // select this one in the table
}

if (SessionHandler::instance()->loadLastSessionAtStartup())
if (SessionHandler::instance()->loadLastSessionAtStartup()) {
restoreLastSessionCb_->setCheckState(Qt::Checked);
else
}
else {
restoreLastSessionCb_->setCheckState(Qt::Unchecked);
}

newButton_->setVisible(false); // XXX TODO: enable New Session functionality

// ensure the correct state of the Save button
on_sessionNameEdit__textChanged();
setButtonsEnabledStatus();
}

Expand Down Expand Up @@ -101,39 +103,7 @@ void SessionDialog::setButtonsEnabledStatus() {
cloneButton_->setEnabled(true);
}
}

bool SessionDialog::validSaveName(const std::string& /*name*/) {
/*
QString boxName(QObject::tr("Save session"));
// name empty?
if (name.empty())
{
QMessageBox::critical(0,boxName, tr("Please enter a name for the session"));
return false;
}


// is there already a session with this name?
bool sessionWithThisName = (SessionHandler::instance()->find(name) != NULL);

if (sessionWithThisName)
{
QMessageBox::critical(0,boxName, tr("A session with that name already exists - please choose another
name")); return false;
}
else
{
return true;
}*/
return true;
}

void SessionDialog::on_sessionNameEdit__textChanged() {
// only allow to save a non-empty session name
// saveButton_->setEnabled(!sessionNameEdit_->text().isEmpty());
}

void SessionDialog::on_savedSessionsList__currentRowChanged(int /*currentRow*/) {
void SessionDialog::on_savedSessionsList__currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous) {
setButtonsEnabledStatus();
}

Expand All @@ -142,6 +112,7 @@ void SessionDialog::on_cloneButton__clicked() {
assert(!sessionName.empty()); // it should not be possible for the name to be empty

SessionRenameDialog renameDialog;
renameDialog.setWindowTitle("Clone Session");
renameDialog.exec();

int result = renameDialog.result();
Expand Down Expand Up @@ -176,6 +147,7 @@ void SessionDialog::on_renameButton__clicked() {
assert(item); // it should not be possible for the name to be empty

SessionRenameDialog renameDialog;
renameDialog.setWindowTitle("Rename Session");
renameDialog.exec();

int result = renameDialog.result();
Expand All @@ -202,25 +174,3 @@ void SessionDialog::on_switchToButton__clicked() {

accept(); // close the dialogue and continue loading the main user interface
}

void SessionDialog::on_saveButton__clicked() {
/*
std::string name = sessionNameEdit_->text().toStdString();

if (validSaveName(name))
{
SessionItem* newSession =
SessionHandler::instance()->copySession(SessionHandler::instance()->current(), name); if (newSession)
{
//SessionHandler::instance()->add(name);
refreshListOfSavedSessions();
SessionHandler::instance()->current(newSession);
QMessageBox::information(0,tr("Session"), tr("Session saved"));
}
else
{
QMessageBox::critical(0,tr("Session"), tr("Failed to save session"));
}
close();
}*/
}
5 changes: 1 addition & 4 deletions Viewer/ecflowUI/src/SessionDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class SessionDialog : public QDialog, protected Ui::SessionDialog {
~SessionDialog() override;

public Q_SLOTS:
void on_saveButton__clicked();
void on_sessionNameEdit__textChanged();
void on_savedSessionsList__currentRowChanged(int currentRow);
void on_savedSessionsList__currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_cloneButton__clicked();
void on_deleteButton__clicked();
void on_renameButton__clicked();
Expand All @@ -39,7 +37,6 @@ public Q_SLOTS:
private:
// Ui::SaveSessionAsDialog *ui;
void addSessionToTable(SessionItem* s);
bool validSaveName(const std::string& name);
void refreshListOfSavedSessions();
void setButtonsEnabledStatus();
std::string selectedSessionName();
Expand Down
7 changes: 7 additions & 0 deletions Viewer/ecflowUI/src/SessionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ SessionItem::~SessionItem() {
}
}

void SessionItem::name(const std::string& name) {
name_ = name;
// Since the name changes, we need to update the related directory paths
dirPath_ = SessionHandler::sessionDirName(name_);
qtPath_ = SessionHandler::sessionQtDirName(name_);
}

void SessionItem::checkDir() {
dirPath_ = SessionHandler::sessionDirName(name_);
DirectoryHandler::createDir(dirPath_);
Expand Down
2 changes: 1 addition & 1 deletion Viewer/ecflowUI/src/SessionHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SessionItem {
explicit SessionItem(const std::string&);
virtual ~SessionItem();

void name(const std::string& name) { name_ = name; }
void name(const std::string& name);
const std::string& name() const { return name_; }

std::string sessionFile() const;
Expand Down
4 changes: 2 additions & 2 deletions Viewer/ecflowUI/src/SessionRenameDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Add variable</string>
<string></string>
</property>
<property name="modal">
<bool>true</bool>
Expand All @@ -26,7 +26,7 @@
</sizepolicy>
</property>
<property name="text">
<string>New name:</string>
<string></string>
</property>
</widget>
</item>
Expand Down
Loading