Skip to content

Commit

Permalink
Fixed: closing a modified tab on Linux / macOS causes to lose modifie…
Browse files Browse the repository at this point in the history
…d changes

    closes issue #3367
  • Loading branch information
eranif committed May 24, 2024
1 parent 9ef399d commit 918a43f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DebugAdapterClient/DebugAdapterClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "StringUtils.h"
#include "asyncprocess.h"
#include "bookmark_manager.h"
#include "clAuiBook.hpp"
#include "clFileSystemWorkspace.hpp"
#include "clResizableTooltip.h"
#include "clWorkspaceManager.h"
Expand All @@ -51,7 +52,6 @@
#include "globals.h"
#include "macromanager.h"
#include "processreaderthread.h"
#include "clAuiBook.hpp"

#include <wx/aui/framemanager.h>
#include <wx/filename.h>
Expand Down Expand Up @@ -645,7 +645,7 @@ void DebugAdapterClient::DestroyUI()
if (m_textView) {
int index = clGetManager()->GetMainNotebook()->FindPage(m_textView);
if (index != wxNOT_FOUND) {
clGetManager()->GetMainNotebook()->RemovePage(index);
clGetManager()->GetMainNotebook()->RemovePage(index, false);
}
m_textView->Destroy();
m_textView = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Interfaces/imanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class clInfoBar;
class clGenericNotebook;
class clAuiBook;

#ifdef __WXMSW__
#if defined(__WXMSW__)
#define MAINBOOK_AUIBOOK 0
#else
#define MAINBOOK_AUIBOOK 1
Expand Down
6 changes: 3 additions & 3 deletions LiteEditor/mainbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,10 +927,10 @@ bool MainBook::ClosePage(wxWindow* page)
{
int pos = m_book->GetPageIndex(page);
if (pos != wxNOT_FOUND && m_book->GetPage(pos) == m_welcomePage) {
m_book->RemovePage(pos);
m_book->RemovePage(pos, false);
return true;
} else {
return pos != wxNOT_FOUND && m_book->DeletePage(pos);
return pos != wxNOT_FOUND && m_book->DeletePage(pos, true);
}
}

Expand Down Expand Up @@ -1536,7 +1536,7 @@ bool MainBook::ClosePage(IEditor* editor, bool notify)
if (!page)
return false;
int pos = m_book->GetPageIndex(page);
return (pos != wxNOT_FOUND) && (m_book->DeletePage(pos));
return (pos != wxNOT_FOUND) && (m_book->DeletePage(pos, true));
}

void MainBook::DoOpenFile(const wxString& filename, const wxString& content)
Expand Down
60 changes: 55 additions & 5 deletions Plugin/clAuiBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void clAuiBook::MoveActivePage(int newIndex)

wxString label = GetPageText(cursel);
wxBitmap bmp = GetPageBitmap(cursel);
if (RemovePage(cursel)) {
if (RemovePage(cursel, false)) {
InsertPage(newIndex, page, label, true, bmp);
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ void clAuiBook::OnPageChanged(wxAuiNotebookEvent& event)

// Send an event
wxBookCtrlEvent changed_event(wxEVT_BOOK_PAGE_CHANGED);
changed_event.SetEventObject(GetParent());
changed_event.SetEventObject(this);
changed_event.SetSelection(GetSelection());
GetEventHandler()->AddPendingEvent(changed_event);
}
Expand Down Expand Up @@ -415,9 +415,9 @@ void clAuiBook::OnPageDoubleClick(wxAuiNotebookEvent& event)
}
wxUnusedVar(event);
wxBookCtrlEvent e(wxEVT_BOOK_TAB_DCLICKED);
e.SetEventObject(GetParent());
e.SetEventObject(this);
e.SetSelection(GetSelection());
GetParent()->GetEventHandler()->AddPendingEvent(e);
GetEventHandler()->AddPendingEvent(e);
}

void clAuiBook::OnTabAreaDoubleClick(wxAuiNotebookEvent& event)
Expand All @@ -429,7 +429,7 @@ void clAuiBook::OnTabAreaDoubleClick(wxAuiNotebookEvent& event)
}

wxBookCtrlEvent e(wxEVT_BOOK_NEW_PAGE);
e.SetEventObject(GetParent());
e.SetEventObject(this);
GetEventHandler()->AddPendingEvent(e);
}

Expand Down Expand Up @@ -551,3 +551,53 @@ int clAuiBook::GetPageIndex(const wxString& name) const
}
return wxNOT_FOUND;
}

bool clAuiBook::DeletePage(size_t index, bool notify)
{
if (notify) {
wxBookCtrlEvent event(wxEVT_BOOK_PAGE_CLOSING);
event.SetEventObject(this);
event.SetSelection(index);
GetEventHandler()->ProcessEvent(event);
if (!event.IsAllowed()) {
// Vetoed
return false;
}
}

if (!wxAuiNotebook::DeletePage(index)) {
return false;
}

if (notify) {
wxBookCtrlEvent event(wxEVT_BOOK_PAGE_CLOSED);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
return true;
}

bool clAuiBook::RemovePage(size_t index, bool notify)
{
if (notify) {
wxBookCtrlEvent event(wxEVT_BOOK_PAGE_CLOSING);
event.SetEventObject(this);
event.SetSelection(index);
GetEventHandler()->ProcessEvent(event);
if (!event.IsAllowed()) {
// Vetoed
return false;
}
}

if (!wxAuiNotebook::RemovePage(index)) {
return false;
}

if (notify) {
wxBookCtrlEvent event(wxEVT_BOOK_PAGE_CLOSED);
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
return true;
}
2 changes: 2 additions & 0 deletions Plugin/clAuiBook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class WXDLLIMPEXP_SDK clAuiBook : public wxAuiNotebook
void SetCanHaveCloseButton(bool b) { m_canHaveCloseButton = b; }
int GetPageIndex(const wxString& name) const;
int GetPageIndex(wxWindow* win) const;
bool DeletePage(size_t index, bool notify);
bool RemovePage(size_t index, bool notify);

protected:
void OnPageClosed(wxAuiNotebookEvent& event);
Expand Down

0 comments on commit 918a43f

Please sign in to comment.