File: editorframe.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (142 lines) | stat: -rw-r--r-- 5,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 Eran Ifrah
// file name            : editorframe.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "bookmark_manager.h"
#include "cl_editor.h"
#include "editorframe.h"
#include "event_notifier.h"
#include "mainbook.h"
#include "manager.h"
#include "my_menu_bar.h"
#include "plugin.h"
#include "quickfindbar.h"
#include <wx/msgdlg.h>
#include <wx/xrc/xmlres.h>
#include "frame.h"
#include "clThemeUpdater.h"

class clThemeUpdater;
wxDEFINE_EVENT(wxEVT_DETACHED_EDITOR_CLOSED, clCommandEvent);

EditorFrame::EditorFrame(wxWindow* parent, clEditor* editor, size_t notebookStyle)
    : EditorFrameBase(parent)
    , m_editor(editor)
{
    m_editor->Reparent(m_mainPanel);
    m_mainPanel->GetSizer()->Add(editor, 1, wxEXPAND);
    clThemeUpdater::Get().RegisterWindow(m_mainPanel);
    
    // Notebook::RemovePage hides the detached tab
    if(!editor->IsShown()) { editor->Show(); }

    // Set a find control for this editor
    m_findBar = new QuickFindBar(m_mainPanel);
    m_findBar->SetEditor(editor);
    m_mainPanel->GetSizer()->Add(m_findBar, 0, wxEXPAND | wxALL, 0);
    m_findBar->Hide();
    m_toolbar->SetDropdownMenu(XRCID("toggle_bookmark"), BookmarkManager::Get().CreateBookmarksSubmenu(NULL));
    
    m_toolbar->SetMiniToolBar(false);
    m_toolbar->AddTool(XRCID("file-save"), _("Save"), clGetManager()->GetStdIcons()->LoadBitmap("file_save"));
    m_toolbar->AddTool(XRCID("file-close"), _("Close"), clGetManager()->GetStdIcons()->LoadBitmap("file_close"));
    m_toolbar->AddTool(XRCID("reload_file"), _("Reload"), clGetManager()->GetStdIcons()->LoadBitmap("file_reload"));
    m_toolbar->AddTool(XRCID("show-find-bar"), _("Find"), clGetManager()->GetStdIcons()->LoadBitmap("cscope"));
    m_toolbar->AddSpacer();
    m_toolbar->AddTool(wxID_UNDO, _("Undo"), clGetManager()->GetStdIcons()->LoadBitmap("undo"));
    m_toolbar->AddTool(wxID_REDO, _("Redo"), clGetManager()->GetStdIcons()->LoadBitmap("redo"));
    m_toolbar->Realize();

    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnSave, this, XRCID("file-save"));
    m_toolbar->Bind(wxEVT_UPDATE_UI, &EditorFrame::OnSaveUI, this, XRCID("file-save"));
    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnClose, this, XRCID("file-close"));
    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnEdit, this, wxID_UNDO);
    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnEdit, this, wxID_REDO);
    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnFind, this, XRCID("show-find-bar"));
    m_toolbar->Bind(wxEVT_TOOL, &EditorFrame::OnReload, this, XRCID("reload_file"));
    
    m_mainPanel->Layout();
    SetTitle(editor->GetFileName().GetFullPath());
    SetSize(600, 600);
    CentreOnScreen();
}

EditorFrame::~EditorFrame() { DoCloseEditor(m_editor); }

void EditorFrame::OnClose(wxCommandEvent& event)
{
    wxUnusedVar(event);
    Destroy();
}

void EditorFrame::OnCloseUI(wxUpdateUIEvent& event) { event.Enable(true); }

void EditorFrame::OnFind(wxCommandEvent& event)
{
    if(!m_findBar->IsShown()) {
        m_findBar->Show();
        m_mainPanel->GetSizer()->Layout();
    }
}

void EditorFrame::OnFindUI(wxUpdateUIEvent& event) { event.Enable(true); }

void EditorFrame::OnCloseWindow(wxCloseEvent& event) { event.Skip(); }

void EditorFrame::DoCloseEditor(clEditor* editor)
{
    clCommandEvent evntInternalClosed(wxEVT_DETACHED_EDITOR_CLOSED);
    evntInternalClosed.SetClientData((IEditor*)editor);
    evntInternalClosed.SetFileName(editor->GetFileName().GetFullPath());
    EventNotifier::Get()->ProcessEvent(evntInternalClosed);

    // Send the traditional plugin event notifying that this editor is about to be destroyed
    wxCommandEvent eventClose(wxEVT_EDITOR_CLOSING);
    eventClose.SetClientData((IEditor*)editor);
    EventNotifier::Get()->ProcessEvent(eventClose);
}

void EditorFrame::OnEdit(wxCommandEvent& event) { m_editor->OnMenuCommand(event); }

void EditorFrame::OnSave(wxCommandEvent& event)
{
    m_editor->SaveFile();
    SetTitle(m_editor->GetFileName().GetFullPath());
}

void EditorFrame::OnSaveUI(wxUpdateUIEvent& event) { event.Enable(m_editor && m_editor->GetModify()); }

void EditorFrame::OnUndo(wxCommandEvent& event) { m_editor->GetCtrl()->Undo(); }

void EditorFrame::OnRedo(wxCommandEvent& event) { m_editor->GetCtrl()->Redo(); }

void EditorFrame::OnUndoUI(wxUpdateUIEvent& event) { event.Enable(m_editor && m_editor->CanUndo()); }

void EditorFrame::OnRedoUI(wxUpdateUIEvent& event) { event.Enable(m_editor && m_editor->CanRedo()); }

void EditorFrame::OnReload(wxCommandEvent& event)
{
    wxUnusedVar(event);
    m_editor->ReloadFromDisk();
}