Skip to content

Commit

Permalink
Added Multi-Window support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Stigsen committed Oct 12, 2009
1 parent 5e061bc commit 00a68e1
Show file tree
Hide file tree
Showing 25 changed files with 647 additions and 327 deletions.
1 change: 0 additions & 1 deletion ecore/Catalyst.h
Expand Up @@ -345,7 +345,6 @@ class Catalyst {

// Settings functions
const wxLongLong& GetId() const;
void MoveOldSettings(eSettings& settings);

// List of documents
void GetDocList(vector<doc_id>& doclist) const;
Expand Down
Binary file modified ecore/ecore.lib
Binary file not shown.
Binary file modified ecore/ecored.lib
Binary file not shown.
4 changes: 2 additions & 2 deletions src/BundleItemEditorCtrl.cpp
Expand Up @@ -21,8 +21,8 @@
#include "images/tmLanguage.xpm"

/// Open a page saved from a previous session
BundleItemEditorCtrl::BundleItemEditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame, const wxPoint& pos, const wxSize& size):
EditorCtrl(page_id, cw, bitmap,parent,parentFrame,pos,size)
BundleItemEditorCtrl::BundleItemEditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame):
EditorCtrl(page_id, cw, bitmap, parent, parentFrame)
{
const PListHandler& plistHandler = m_syntaxHandler.GetPListHandler();
m_bundleType = plistHandler.GetBundleTypeFromUri(m_remotePath);
Expand Down
2 changes: 1 addition & 1 deletion src/BundleItemEditorCtrl.h
Expand Up @@ -7,7 +7,7 @@ class IUpdatePanel;

class BundleItemEditorCtrl : public EditorCtrl {
public:
BundleItemEditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame, const wxPoint& pos = wxPoint(-100,-100), const wxSize& size = wxDefaultSize);
BundleItemEditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame);

BundleItemEditorCtrl(CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame, const wxPoint& pos = wxPoint(-100,-100), const wxSize& size = wxDefaultSize);

Expand Down
8 changes: 4 additions & 4 deletions src/CompareDlg.cpp
Expand Up @@ -46,13 +46,13 @@ CompareDlg::CompareDlg(wxWindow *parent, eSettings& settings):

// Add recents
wxArrayString recentPaths;
m_settings.GetRecentDiffs(recentPaths, eSettings::SP_LEFT);
m_settings.GetRecentDiffs(recentPaths, SP_LEFT);
if (!recentPaths.empty()) {
m_leftPathCtrl->Append(recentPaths);
m_leftPathCtrl->SetSelection(0);
}
recentPaths.clear();
m_settings.GetRecentDiffs(recentPaths, eSettings::SP_RIGHT);
m_settings.GetRecentDiffs(recentPaths, SP_RIGHT);
if (!recentPaths.empty()) {
m_rightPathCtrl->Append(recentPaths);
m_rightPathCtrl->SetSelection(0);
Expand Down Expand Up @@ -81,8 +81,8 @@ void CompareDlg::OnButtonOk(wxCommandEvent& evt) {
const wxString leftPath = m_leftPathCtrl->GetValue();
const wxString rightPath = m_rightPathCtrl->GetValue();

m_settings.AddRecentDiff(leftPath, eSettings::SP_LEFT);
m_settings.AddRecentDiff(rightPath, eSettings::SP_RIGHT);
m_settings.AddRecentDiff(leftPath, SP_LEFT);
m_settings.AddRecentDiff(rightPath, SP_RIGHT);

// If we get here the paths are valid
evt.Skip();
Expand Down
4 changes: 2 additions & 2 deletions src/DiffPanel.cpp
Expand Up @@ -179,12 +179,12 @@ void DiffPanel::OnChildFocus(wxChildFocusEvent& event) {
}
}

void DiffPanel::SaveSettings(unsigned int i, eSettings& settings) {
void DiffPanel::SaveSettings(unsigned int i, eFrameSettings& settings) {
m_leftEditor->SaveSettings(i, settings, 1);
m_rightEditor->SaveSettings(i, settings, 2);
}

void DiffPanel::RestoreSettings(unsigned int i, eSettings& settings) {
void DiffPanel::RestoreSettings(unsigned int i, eFrameSettings& settings) {
m_leftEditor->RestoreSettings(i, settings, 1);
m_rightEditor->RestoreSettings(i, settings, 2);

Expand Down
5 changes: 3 additions & 2 deletions src/DiffPanel.h
Expand Up @@ -28,6 +28,7 @@ class EditorCtrl;
class DiffBar;
class DiffMarkBar;
class wxGridBagSizer;
class eFrameSettings;

class DiffPanel : public wxPanel, public ITabPage {
public:
Expand All @@ -41,8 +42,8 @@ class DiffPanel : public wxPanel, public ITabPage {
bool CmpPaths(const wxString& path1, const wxString& path2) const;
void UpdateMarkBars();

virtual void SaveSettings(unsigned int i, eSettings& settings);
void RestoreSettings(unsigned int i, eSettings& settings);
virtual void SaveSettings(unsigned int i, eFrameSettings& settings);
void RestoreSettings(unsigned int i, eFrameSettings& settings);

virtual EditorCtrl* GetActiveEditor();
virtual const char** RecommendedIcon() const;
Expand Down
90 changes: 44 additions & 46 deletions src/DocHistory.cpp
Expand Up @@ -40,7 +40,7 @@ END_EVENT_TABLE()
DocHistory::DocHistory(CatalystWrapper& cw, int win_id, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
: wxControl(parent, id, pos, size, wxNO_BORDER|wxWANTS_CHARS|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE),
m_catalyst(cw), m_dispatcher(cw.GetDispatcher()), m_doc(cw), m_mdc(), m_bitmap(1,1), m_cell(m_mdc, m_doc), m_hotNode(-1),
m_revTooltip(cw)
m_revTooltip(cw), m_editorCtrl(NULL), m_source_win_id(win_id)
{
m_revTooltip.Create(this);
m_tooltipTimer.SetOwner(this, ID_TOOLTIP_TIMER);
Expand All @@ -49,7 +49,6 @@ DocHistory::DocHistory(CatalystWrapper& cw, int win_id, wxWindow* parent, wxWind
// Initialize variables
m_needRedrawing = true; // Make sure the ctrl gets drawn on first idle event
m_document_id = -1;
m_source_win_id = win_id;
m_scrollPos = 0;
m_isScrolling = false;
m_lineHeight = 18;
Expand All @@ -65,6 +64,7 @@ DocHistory::DocHistory(CatalystWrapper& cw, int win_id, wxWindow* parent, wxWind
m_mdc.SetFont(wxFont(9, wxMODERN, wxNORMAL, wxNORMAL, false));

// Make sure we recieve notifications of new versions and updates
m_dispatcher.SubscribeC(wxT("WIN_CLOSEPAGE"), (CALL_BACK)OnClosePage, this);
m_dispatcher.SubscribeC(wxT("WIN_CHANGEDOC"), (CALL_BACK)OnChangeDoc, this);
m_dispatcher.SubscribeC(wxT("DOC_UPDATED"), (CALL_BACK)OnDocUpdated, this);
m_dispatcher.SubscribeC(wxT("DOC_DELETED"), (CALL_BACK)OnDocDeleted, this);
Expand All @@ -74,6 +74,7 @@ DocHistory::DocHistory(CatalystWrapper& cw, int win_id, wxWindow* parent, wxWind
}

DocHistory::~DocHistory() {
m_dispatcher.UnSubscribe(wxT("WIN_CLOSEPAGE"), (CALL_BACK)OnClosePage, this);
m_dispatcher.UnSubscribe(wxT("WIN_CHANGEDOC"), (CALL_BACK)OnChangeDoc, this);
m_dispatcher.UnSubscribe(wxT("DOC_UPDATED"), (CALL_BACK)OnDocUpdated, this);
m_dispatcher.UnSubscribe(wxT("DOC_DELETED"), (CALL_BACK)OnDocDeleted, this);
Expand All @@ -85,6 +86,7 @@ DocHistory::~DocHistory() {
void DocHistory::Clear() {
// Invalidate doc ref
m_sourceDoc.Invalidate();
m_editorCtrl = NULL;

// Clear data structures
m_items.clear();
Expand Down Expand Up @@ -475,9 +477,9 @@ void DocHistory::OnMouseLeftDown(wxMouseEvent& event) {
cxLOCK_READ(m_catalyst)
draft_head = catalyst.GetDraftHead(hot_doc.document_id);
cxENDLOCK
m_dispatcher.Notify(wxT("WIN_SETDOCUMENT"), &draft_head, m_source_win_id);
m_editorCtrl->SetDocument(draft_head);
}
else m_dispatcher.Notify(wxT("WIN_SETDOCUMENT"), &hot_doc, m_source_win_id);
else m_editorCtrl->SetDocument(hot_doc);
}
}

Expand Down Expand Up @@ -597,9 +599,9 @@ void DocHistory::OnVersionTreeSel(VersionTreeEvent& event) {
cxLOCK_READ(m_catalyst)
draft_head = catalyst.GetDraftHead(hot_doc.document_id);
cxENDLOCK
m_dispatcher.Notify(wxT("WIN_SETDOCUMENT"), &draft_head, m_source_win_id);
m_editorCtrl->SetDocument(draft_head);
}
else m_dispatcher.Notify(wxT("WIN_SETDOCUMENT"), &hot_doc, m_source_win_id);
else m_editorCtrl->SetDocument(hot_doc);
}

void DocHistory::OnVersionTreeTooltip(VersionTreeEvent& event) {
Expand Down Expand Up @@ -651,12 +653,38 @@ void DocHistory::OnEraseBackground(wxEraseEvent& WXUNUSED(event)) {
// # no evt.skip() as we don't want the control to erase the background
}

void DocHistory::HandleDocUpdate(const doc_id& di) {
if (di == m_editorCtrl->GetDocID()) {
SetDocument(di);
}
else {
bool isSameDoc;
cxLOCK_READ(m_catalyst)
isSameDoc = catalyst.InSameHistory(di, m_sourceDoc);
cxENDLOCK

// Doc has been changed in another editor, so we just redraw
if (isSameDoc) {
ReBuildTree();
m_isScrolling = false; // avoid moving old image if scrolling during update
wxClientDC dc(this);
DrawLayout(dc);
}
}
}

// static notification handler
void DocHistory::OnClosePage(DocHistory* self, void* data, int WXUNUSED(filter)) {
if (self->m_editorCtrl == (EditorCtrl*)data) self->Clear();
}

// static notification handler
void DocHistory::OnChangeDoc(DocHistory* self, void* data, int filter) {
const doc_id di = ((EditorCtrl*)data)->GetDocID();
if (filter != self->m_source_win_id) return;
//wxLogTrace("OnChangeDoc %d %d - %d", di.document_id, di.revision_id, filter);

self->m_source_win_id = filter;
self->m_editorCtrl = (EditorCtrl*)data;
const doc_id di = self->m_editorCtrl->GetDocID();
self->SetDocument(di);
}

Expand All @@ -665,18 +693,7 @@ void DocHistory::OnDocUpdated(DocHistory* self, void* data, int WXUNUSED(filter)
if (!self->m_sourceDoc.IsOk()) return;

const doc_id& di = *(const doc_id*)data;

bool isSameDoc;
cxLOCK_READ(self->m_catalyst)
isSameDoc = catalyst.InSameHistory(di, self->m_sourceDoc);
cxENDLOCK

if (isSameDoc) {
self->ReBuildTree();
self->m_isScrolling = false; // avoid moving old image if scrolling during update
wxClientDC dc(self);
self->DrawLayout(dc);
}
self->HandleDocUpdate(di);
}

// static notification handler
Expand All @@ -700,43 +717,24 @@ void DocHistory::OnDocCommited(DocHistory* self, void* data, int WXUNUSED(filter
if (self->m_sourceDoc.SameDoc(diPair->doc1)) {
self->m_isScrolling = false; // avoid moving old image if scrolling during update
self->SetDocument(diPair->doc2);
/*self->m_sourceDoc = diPair->doc2;
self->ReBuildTree();
self->m_isScrolling = false; // avoid moving old image if scrolling during update
wxClientDC dc(self);
self->DrawLayout(dc);*/
}
else {
self->HandleDocUpdate(diPair->doc2);
}
}

// static notification handler
void DocHistory::OnNewRevision(DocHistory* self, void* data, int WXUNUSED(filter)) {
if (!self->m_sourceDoc.IsOk()) return;
const doc_id* const di = (doc_id*)data;
wxASSERT(di->IsDraft());

bool inSame;
cxLOCK_READ(self->m_catalyst)
inSame = catalyst.InSameHistory(self->m_sourceDoc, *di);
cxENDLOCK

if (inSame) {
self->SetDocument(*di);
}
const doc_id& di = *(const doc_id*)data;
self->HandleDocUpdate(di);
}

// static notification handler
void DocHistory::OnUpdateRevision(DocHistory* self, void* data, int WXUNUSED(filter)) {
if (!self->m_sourceDoc.IsOk()) return;
const doc_id* const di = (doc_id*)data;
wxASSERT(di->IsDraft());

bool inSame;
cxLOCK_READ(self->m_catalyst)
inSame = catalyst.InSameHistory(self->m_sourceDoc, *di);
cxENDLOCK

if (inSame) {
self->SetDocument(*di);
}
const doc_id& di = *(const doc_id*)data;
self->HandleDocUpdate(di);
}
6 changes: 5 additions & 1 deletion src/DocHistory.h
Expand Up @@ -24,6 +24,7 @@
class VersionTree;
class VersionTreeEvent;
class Timeline;
class EditorCtrl;

class DocHistory : public wxControl {
public:
Expand All @@ -38,6 +39,7 @@ class DocHistory : public wxControl {
void MakeItemVisible(unsigned int item_id);
void DrawLayout(wxDC& dc);
void AddChildren(int parent_pos, const doc_id& doc, const doc_id& sel_doc, const Catalyst& catalyst);
void HandleDocUpdate(const doc_id& di);

// Event handlers
void OnPaint(wxPaintEvent& event);
Expand All @@ -56,6 +58,7 @@ class DocHistory : public wxControl {
DECLARE_EVENT_TABLE();

// Notifier handlers
static void OnClosePage(DocHistory* self, void* data, int filter);
static void OnChangeDoc(DocHistory* self, void* data, int filter);
static void OnDocUpdated(DocHistory* self, void* data, int filter);
static void OnDocDeleted(DocHistory* self, void* data, int filter);
Expand All @@ -75,6 +78,7 @@ class DocHistory : public wxControl {
wxTimer m_tooltipTimer;
int m_hotNode;
RevTooltip m_revTooltip;
EditorCtrl* m_editorCtrl;

wxBrush bgBrush;
wxPen linePen;
Expand All @@ -92,7 +96,7 @@ class DocHistory : public wxControl {
int m_document_id;
doc_id m_sourceDoc;
int m_selectedNode;
int m_source_win_id;
const int m_source_win_id;
int m_lineHeight;
int m_treeHeight;
int m_scrollPos;
Expand Down
2 changes: 1 addition & 1 deletion src/EditorBundlePanel.cpp
Expand Up @@ -173,7 +173,7 @@ const char** EditorBundlePanel::RecommendedIcon() const {
return m_editorCtrl->RecommendedIcon();
}

void EditorBundlePanel::SaveSettings(unsigned int i, eSettings& settings) {
void EditorBundlePanel::SaveSettings(unsigned int i, eFrameSettings& settings) {
m_editorCtrl->SaveSettings(i, settings);
}

Expand Down
2 changes: 1 addition & 1 deletion src/EditorBundlePanel.h
Expand Up @@ -46,7 +46,7 @@ class EditorBundlePanel : public wxPanel, public IUpdatePanel, public ITabPage {

virtual EditorCtrl* GetActiveEditor();
virtual const char** RecommendedIcon() const;
virtual void SaveSettings(unsigned int i, eSettings& settings);
virtual void SaveSettings(unsigned int i, eFrameSettings& settings);

private:
void Init();
Expand Down
18 changes: 9 additions & 9 deletions src/EditorCtrl.cpp
Expand Up @@ -107,7 +107,7 @@ unsigned long EditorCtrl::s_ctrlDownTime = 0;
bool EditorCtrl::s_altGrDown = false;

/// Open a page saved from a previous session
EditorCtrl::EditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame, const wxPoint& pos, const wxSize& size) :
EditorCtrl::EditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent, EditorFrame& parentFrame) :
m_catalyst(cw),
m_doc(cw),
dispatcher(cw.GetDispatcher()),
Expand Down Expand Up @@ -144,11 +144,11 @@ EditorCtrl::EditorCtrl(const int page_id, CatalystWrapper& cw, wxBitmap& bitmap,
m_re(NULL),
m_symbolCacheToken(0)
{
Create(parent, wxID_ANY, pos, size, wxNO_BORDER|wxWANTS_CHARS|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE);
Create(parent, wxID_ANY, wxPoint(-100,-100), wxDefaultSize, wxNO_BORDER|wxWANTS_CHARS|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE);
Hide(); // start hidden to avoid flicker
Init();

eSettings& settings = eGetSettings();
eFrameSettings& settings = parentFrame.GetFrameSettings();
RestoreSettings(page_id, settings);
}

Expand Down Expand Up @@ -263,7 +263,7 @@ EditorCtrl::EditorCtrl(CatalystWrapper& cw, wxBitmap& bitmap, wxWindow* parent,
FoldingInvalidate();
}

void EditorCtrl::RestoreSettings(unsigned int page_id, eSettings& settings, unsigned int subid) {
void EditorCtrl::RestoreSettings(unsigned int page_id, eFrameSettings& settings, unsigned int subid) {
wxString mirrorPath;
doc_id di;
int newpos;
Expand All @@ -274,7 +274,7 @@ void EditorCtrl::RestoreSettings(unsigned int page_id, eSettings& settings, unsi

// Retrieve the page info
wxASSERT(0 <= page_id && page_id < (int)settings.GetPageCount());
settings.GetPageSettings(page_id, mirrorPath, di, newpos, topline, syntax, folds, bookmarks, (eSettings::SubPage)subid);
settings.GetPageSettings(page_id, mirrorPath, di, newpos, topline, syntax, folds, bookmarks, (SubPage)subid);

if (eDocumentPath::IsRemotePath(mirrorPath)) {
// If the mirror points to a remote file, we have to download it first.
Expand Down Expand Up @@ -453,11 +453,11 @@ EditorCtrl::~EditorCtrl() {
ClearRemoteInfo();
}

void EditorCtrl::SaveSettings(unsigned int i, eSettings& settings) {
void EditorCtrl::SaveSettings(unsigned int i, eFrameSettings& settings) {
SaveSettings(i, settings, 0);
}

void EditorCtrl::SaveSettings(unsigned int i, eSettings& settings, unsigned int subid) {
void EditorCtrl::SaveSettings(unsigned int i, eFrameSettings& settings, unsigned int subid) {
const wxString& path = GetPath();
const doc_id di = GetDocID();
const int pos = GetPos();
Expand All @@ -466,7 +466,7 @@ void EditorCtrl::SaveSettings(unsigned int i, eSettings& settings, unsigned int
const vector<unsigned int> folds = GetFoldedLines();
const vector<cxBookmark>& bookmarks = GetBookmarks();

settings.SetPageSettings(i, path, di, pos, topline, syntax, folds, bookmarks, (eSettings::SubPage)subid);
settings.SetPageSettings(i, path, di, pos, topline, syntax, folds, bookmarks, (SubPage)subid);
//wxLogDebug(wxT(" %d (%d,%d,%d) pos:%d topline:%d"), i, di.type, di.document_id, di.version_id, pos, topline);
}

Expand Down Expand Up @@ -2933,7 +2933,7 @@ bool EditorCtrl::SetDocument(const doc_id& di, const wxString& path, const Remot

// Notify that we have changed document
const doc_id docId = di; // AdamV: Does this exist just to be on the stack in bug reports?
dispatcher.Notify(wxT("WIN_CHANGEDOC"), this, GetId());
dispatcher.Notify(wxT("WIN_CHANGEDOC"), this, m_parentFrame.GetId());

return true;
}
Expand Down

1 comment on commit 00a68e1

@adamv
Copy link
Contributor

@adamv adamv commented on 00a68e1 Oct 12, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Bundles" menu is only populated in the first window opened.

Please sign in to comment.