Skip to content

Commit

Permalink
Tail plugin: the tail panel can now detach from the output notebook i…
Browse files Browse the repository at this point in the history
…nto a separatea frame
  • Loading branch information
Eran Ifrah committed Nov 7, 2016
1 parent 3174cec commit 70ecdd1
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 565 deletions.
Binary file modified Runtime/codelite-bitmaps.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions Tail/Tail.project
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<File Name="tail.cpp"/>
<File Name="TailPanel.h"/>
<File Name="TailPanel.cpp"/>
<File Name="TailFrame.h"/>
<File Name="TailFrame.cpp"/>
</VirtualDirectory>
<VirtualDirectory Name="include">
<File Name="tail.h"/>
Expand Down
17 changes: 17 additions & 0 deletions Tail/TailFrame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "TailFrame.h"
#include "tail.h"

TailFrame::TailFrame(wxWindow* parent, Tail* plugin)
: TailFrameBase(parent)
, m_plugin(plugin)
{
}

TailFrame::~TailFrame() {}

void TailFrame::OnClose(wxCloseEvent& event)
{
m_plugin->CallAfter(&Tail::DockTailWindow);
m_plugin->m_view = NULL;
event.Skip();
}
16 changes: 16 additions & 0 deletions Tail/TailFrame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TAILFRAME_H
#define TAILFRAME_H
#include "TailUI.h"

class Tail;
class TailFrame : public TailFrameBase
{
Tail* m_plugin;

public:
TailFrame(wxWindow* parent, Tail* plugin);
virtual ~TailFrame();
protected:
virtual void OnClose(wxCloseEvent& event);
};
#endif // TAILFRAME_H
18 changes: 17 additions & 1 deletion Tail/TailPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
#include "lexer_configuration.h"
#include "ColoursAndFontsManager.h"
#include "cl_config.h"
#include "tail.h"

TailPanel::TailPanel(wxWindow* parent)
TailPanel::TailPanel(wxWindow* parent, Tail* plugin)
: TailPanelBase(parent)
, m_lastPos(0)
, m_plugin(plugin)
, m_isDetached(false)
{
m_fileWatcher.reset(new clFileSystemWatcher());
m_fileWatcher->SetOwner(this);
Bind(wxEVT_FILE_MODIFIED, &TailPanel::OnFileModified, this);

wxCommandEvent dummy;
OnThemeChanged(dummy);
EventNotifier::Get()->Bind(wxEVT_CL_THEME_CHANGED, &TailPanel::OnThemeChanged, this);
}

Expand Down Expand Up @@ -78,6 +84,7 @@ void TailPanel::OnThemeChanged(wxCommandEvent& event)
lexer->Apply(m_stc);
}
}

void TailPanel::OnClear(wxCommandEvent& event)
{
m_stc->SetReadOnly(false);
Expand Down Expand Up @@ -149,3 +156,12 @@ void TailPanel::OnOpenRecentItem(wxCommandEvent& event)
DoOpen(filepath);
m_recentItemsMap.clear();
}

void TailPanel::OnDetachWindow(wxCommandEvent& event)
{
wxUnusedVar(event);
m_plugin->CallAfter(&Tail::DetachTailWindow);
m_isDetached = true;
}

void TailPanel::OnDetachWindowUI(wxUpdateUIEvent& event) { event.Enable(!m_isDetached); }
10 changes: 9 additions & 1 deletion Tail/TailPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
#include "clEditorEditEventsHandler.h"
#include <map>

class Tail;
class TailPanel : public TailPanelBase
{
clFileSystemWatcher::Ptr_t m_fileWatcher;
wxFileName m_file;
size_t m_lastPos;
clEditEventsHandler::Ptr_t m_editEvents;
std::map<int, wxString> m_recentItemsMap;
Tail* m_plugin;
bool m_isDetached;

protected:
virtual void OnDetachWindow(wxCommandEvent& event);
virtual void OnDetachWindowUI(wxUpdateUIEvent& event);
virtual void OnOpen(wxAuiToolBarEvent& event);
virtual void OnClear(wxCommandEvent& event);
virtual void OnClearUI(wxUpdateUIEvent& event);
Expand All @@ -32,9 +37,12 @@ class TailPanel : public TailPanelBase
void DoPrepareRecentItemsMenu(wxMenu& menu);

public:
TailPanel(wxWindow* parent);
TailPanel(wxWindow* parent, Tail* plugin);
virtual ~TailPanel();

void SetIsDetached(bool isDetached) { this->m_isDetached = isDetached; }
bool IsDetached() const { return m_isDetached; }

protected:
virtual void OnPause(wxCommandEvent& event);
virtual void OnPauseUI(wxUpdateUIEvent& event);
Expand Down
53 changes: 50 additions & 3 deletions Tail/TailUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ TailPanelBase::TailPanelBase(wxWindow* parent, wxWindowID id, const wxPoint& pos
m_auibar->AddSeparator();

m_auibar->AddTool(ID_TAIL_CLEAR, _("Clear"), wxXmlResource::Get()->LoadBitmap(wxT("16-clear")), wxNullBitmap, wxITEM_NORMAL, _("Clear"), wxT(""), NULL);

m_auibar->AddStretchSpacer(1);

m_auibar->AddTool(ID_TAIL_DETACH, _("Open in a separate window"), wxXmlResource::Get()->LoadBitmap(wxT("16-windows")), wxNullBitmap, wxITEM_NORMAL, _("Open in a separate window"), _("Open in a separate window"), NULL);
m_auibar->Realize();

m_stc = new wxStyledTextCtrl(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
Expand All @@ -67,9 +71,8 @@ TailPanelBase::TailPanelBase(wxWindow* parent, wxWindowID id, const wxPoint& pos
m_stc->SetMarginSensitive(2, true);

// Configure the line numbers margin
int m_stc_PixelWidth = 4 + 5 *m_stc->TextWidth(wxSTC_STYLE_LINENUMBER, wxT("9"));
m_stc->SetMarginType(0, wxSTC_MARGIN_NUMBER);
m_stc->SetMarginWidth(0,m_stc_PixelWidth);
m_stc->SetMarginWidth(0,0);

// Configure the line symbol margin
m_stc->SetMarginType(3, wxSTC_MARGIN_FORE);
Expand Down Expand Up @@ -104,6 +107,8 @@ TailPanelBase::TailPanelBase(wxWindow* parent, wxWindowID id, const wxPoint& pos
this->Connect(ID_TAIL_PLAY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnPlayUI), NULL, this);
this->Connect(ID_TAIL_CLEAR, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(TailPanelBase::OnClear), NULL, this);
this->Connect(ID_TAIL_CLEAR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnClearUI), NULL, this);
this->Connect(ID_TAIL_DETACH, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(TailPanelBase::OnDetachWindow), NULL, this);
this->Connect(ID_TAIL_DETACH, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnDetachWindowUI), NULL, this);

this->Connect(wxID_ANY, wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler(TailPanelBase::ShowAuiToolMenu), NULL, this);
}
Expand All @@ -119,6 +124,8 @@ TailPanelBase::~TailPanelBase()
this->Disconnect(ID_TAIL_PLAY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnPlayUI), NULL, this);
this->Disconnect(ID_TAIL_CLEAR, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(TailPanelBase::OnClear), NULL, this);
this->Disconnect(ID_TAIL_CLEAR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnClearUI), NULL, this);
this->Disconnect(ID_TAIL_DETACH, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(TailPanelBase::OnDetachWindow), NULL, this);
this->Disconnect(ID_TAIL_DETACH, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(TailPanelBase::OnDetachWindowUI), NULL, this);

std::map<int, wxMenu*>::iterator menuIter = m_dropdownMenus.begin();
for( ; menuIter != m_dropdownMenus.end(); ++menuIter ) {
Expand Down Expand Up @@ -148,4 +155,44 @@ void TailPanelBase::ShowAuiToolMenu(wxAuiToolBarEvent& event)
}
}
}
}
}
TailFrameBase::TailFrameBase(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
: wxFrame(parent, id, title, pos, size, style)
{
if ( !bBitmapLoaded ) {
// We need to initialise the default bitmap handler
wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
wxCB60EInitBitmapResources();
bBitmapLoaded = true;
}

wxBoxSizer* boxSizer37 = new wxBoxSizer(wxVERTICAL);
this->SetSizer(boxSizer37);

SetName(wxT("TailFrameBase"));
SetSize(500,300);
if (GetSizer()) {
GetSizer()->Fit(this);
}
if(GetParent()) {
CentreOnParent(wxBOTH);
} else {
CentreOnScreen(wxBOTH);
}
#if wxVERSION_NUMBER >= 2900
if(!wxPersistenceManager::Get().Find(this)) {
wxPersistenceManager::Get().RegisterAndRestore(this);
} else {
wxPersistenceManager::Get().Restore(this);
}
#endif
// Connect events
this->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(TailFrameBase::OnClose), NULL, this);

}

TailFrameBase::~TailFrameBase()
{
this->Disconnect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(TailFrameBase::OnClose), NULL, this);

}
24 changes: 21 additions & 3 deletions Tail/TailUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <wx/menu.h>
#include <wx/toolbar.h>
#include <wx/stc/stc.h>
#include <wx/frame.h>
#include <wx/iconbndl.h>
#if wxVERSION_NUMBER >= 2900
#include <wx/persist.h>
#include <wx/persist/toplevel.h>
Expand All @@ -42,9 +44,10 @@ class TailPanelBase : public wxPanel
enum {
ID_TAIL_CLEAR = 10001,
ID_TAIL_CLOSE = 10002,
ID_TAIL_OPEN = 10003,
ID_TAIL_PAUSE = 10004,
ID_TAIL_PLAY = 10005,
ID_TAIL_DETACH = 10003,
ID_TAIL_OPEN = 10004,
ID_TAIL_PAUSE = 10005,
ID_TAIL_PLAY = 10006,
};
protected:
wxAuiToolBar* m_auibar;
Expand All @@ -61,6 +64,8 @@ class TailPanelBase : public wxPanel
virtual void OnPlayUI(wxUpdateUIEvent& event) { event.Skip(); }
virtual void OnClear(wxCommandEvent& event) { event.Skip(); }
virtual void OnClearUI(wxUpdateUIEvent& event) { event.Skip(); }
virtual void OnDetachWindow(wxCommandEvent& event) { event.Skip(); }
virtual void OnDetachWindowUI(wxUpdateUIEvent& event) { event.Skip(); }

public:

Expand All @@ -71,4 +76,17 @@ class TailPanelBase : public wxPanel
virtual ~TailPanelBase();
};


class TailFrameBase : public wxFrame
{
protected:

protected:
virtual void OnClose(wxCloseEvent& event) { event.Skip(); }

public:
TailFrameBase(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500,300), long style = wxDEFAULT_FRAME_STYLE|wxFRAME_FLOAT_ON_PARENT);
virtual ~TailFrameBase();
};

#endif
Loading

0 comments on commit 70ecdd1

Please sign in to comment.