Reload script file after modification

Если загруженный на вкладку sql файл был изменён вне pgAdmin3,
то при смене закладок или попытке выполнения
будет предложено загрузить файл заново.
This commit is contained in:
lsv 2022-07-25 11:40:21 +05:00
parent 966fe607b0
commit cc7945be5c
5 changed files with 26 additions and 0 deletions

View file

@ -68,6 +68,7 @@ ctlSQLBox::ctlSQLBox()
m_autocompDisabled = false;
process = 0;
processID = 0;
m_filename = wxEmptyString;
}
@ -238,10 +239,18 @@ int ctlSQLBox::GetOrigin()
{
return m_origin;
}
bool ctlSQLBox::IsFileModification()
{
if (!m_filename.IsEmpty()) {
return time_file_mod != wxFileModificationTime(m_filename);
}
return false;
}
void ctlSQLBox::SetFilename(wxString &filename)
{
m_filename = filename;
time_file_mod = wxFileModificationTime(filename);
UpdateTitle();
}

View file

@ -2441,6 +2441,7 @@ void frmQuery::OnSave(wxCommandEvent &event)
setExtendedTitle();
UpdateRecentFiles();
SqlBookUpdatePageTitle();
sqlQuery->SetFilename(filename);
}
else
{
@ -2942,6 +2943,7 @@ void frmQuery::OnExecute(wxCommandEvent &event)
if (!updateFromGqb(true))
return;
}
CheckModificationFile();
SaveTempFile();
wxString query = sqlQuery->GetSelectedText();
if (query.IsNull())
@ -4307,6 +4309,15 @@ void frmQuery::fileMarkerActive(bool addOrRemove, const wxString &sqlTabName) {
if (wxFileName::FileExists(fn)) wxRemoveFile(fn);
}
void frmQuery::CheckModificationFile() {
if (sqlQuery!=NULL && sqlQuery->IsFileModification()) {
if (wxMessageBox("File " + sqlQuery->GetFilename() + " has been changed.\nReload file?",
"Reload sql file",
wxICON_EXCLAMATION | wxYES_NO) == wxYES)
OpenLastFile();
}
}
void frmQuery::OnSqlBookPageChanged(wxAuiNotebookEvent &event)
{
// Try to always keep sqlQuery variable pointing to the currently selected SQLBox.
@ -4347,6 +4358,9 @@ void frmQuery::OnSqlBookPageChanged(wxAuiNotebookEvent &event)
sqlQuery->SetFocus();
if (sqlQueryBook->GetPageCount() > 1) fileMarkerActive(true, sqlQueryBook->GetPageText(sqlQueryBook->GetSelection()));
//wxMessageBox(wxT("OnSqlBookPageChanged "));
CheckModificationFile();
updateMenu(false);
wxTheApp->Yield(true);
}

View file

@ -91,6 +91,7 @@ public:
void SetOrigin(int origin);
int GetOrigin();
void SetFilename(wxString &filename);
bool IsFileModification();
wxString GetFilename();
void SetTitle(wxString &title);
wxString GetTitle(bool withChangeInd = true);
@ -125,6 +126,7 @@ private:
// Variables to track info per SQL box
wxString m_filename;
time_t time_file_mod;
wxString m_title;
wxString m_changestr;
bool m_changed;

View file

@ -311,6 +311,7 @@ private:
void OnSqlBookPageClose(wxAuiNotebookEvent &event);
void OnSqlBookPageClosed(wxAuiNotebookEvent &event);
void OnSqlBookPageChanged(wxAuiNotebookEvent &event);
void CheckModificationFile();
void OnSqlBookPageChanging(wxAuiNotebookEvent &event);
void OnSqlBookTabRDown(wxAuiNotebookEvent &event);
void OnNotebookOutpaneTabRDown(wxAuiNotebookEvent &event);

Binary file not shown.