1 |
/* |
2 |
Copyright (c) 2014-2020 Christian Schoenebeck |
3 |
|
4 |
This file is part of "gigedit" and released under the terms of the |
5 |
GNU General Public License version 2. |
6 |
*/ |
7 |
|
8 |
#ifndef GIGEDIT_SCRIPTEDITOR_H |
9 |
#define GIGEDIT_SCRIPTEDITOR_H |
10 |
|
11 |
#ifdef LIBGIG_HEADER_FILE |
12 |
# include LIBGIG_HEADER_FILE(gig.h) |
13 |
#else |
14 |
# include <gig.h> |
15 |
#endif |
16 |
|
17 |
#ifdef GTKMM_HEADER_FILE |
18 |
# include GTKMM_HEADER_FILE(gtkmm.h) |
19 |
#else |
20 |
# include <gtkmm.h> |
21 |
#endif |
22 |
#if HAVE_CONFIG_H |
23 |
# include <config.h> |
24 |
#endif |
25 |
#include "compat.h" |
26 |
|
27 |
#if USE_GTKMM_BUILDER |
28 |
# include <gtkmm/builder.h> |
29 |
#else |
30 |
# include <gtkmm/uimanager.h> // deprecated in gtkmm >= 3.21.4 |
31 |
#endif |
32 |
|
33 |
#if USE_GLIB_ACTION |
34 |
# include <giomm/simpleactiongroup.h> |
35 |
#else |
36 |
# include <gtkmm/actiongroup.h> |
37 |
#endif |
38 |
|
39 |
#include "ManagedWindow.h" |
40 |
|
41 |
// Should we use a very simple (and buggy) local NKSP syntax parser, or should |
42 |
// we rather use the full featured NKSP syntax highlighting backend from |
43 |
// liblinuxsampler for syntax highlighting of this text editor? |
44 |
#if HAVE_LINUXSAMPLER |
45 |
# define USE_LS_SCRIPTVM 1 |
46 |
#endif |
47 |
|
48 |
#if USE_LS_SCRIPTVM |
49 |
# ifdef LIBLINUXSAMPLER_HEADER_FILE |
50 |
# include LIBLINUXSAMPLER_HEADER_FILE(scriptvm/ScriptVM.h) |
51 |
# include LIBLINUXSAMPLER_HEADER_FILE(scriptvm/ScriptVMFactory.h) |
52 |
# include LIBLINUXSAMPLER_HEADER_FILE(common/optional.h) |
53 |
# else |
54 |
# include <linuxsampler/scriptvm/ScriptVM.h> |
55 |
# include <linuxsampler/scriptvm/ScriptVMFactory.h> |
56 |
# include <linuxsampler/common/optional.h> |
57 |
# endif |
58 |
#endif |
59 |
|
60 |
class ScriptEditor : public ManagedWindow { |
61 |
public: |
62 |
ScriptEditor(); |
63 |
~ScriptEditor(); |
64 |
void setScript(gig::Script* script); |
65 |
|
66 |
sigc::signal<void, gig::Script*> signal_script_to_be_changed; |
67 |
sigc::signal<void, gig::Script*> signal_script_changed; |
68 |
|
69 |
// implementation for abstract methods of interface class "ManagedWindow" |
70 |
virtual Settings::Property<int>* windowSettingX() { return &Settings::singleton()->scriptEditorWindowX; } |
71 |
virtual Settings::Property<int>* windowSettingY() { return &Settings::singleton()->scriptEditorWindowY; } |
72 |
virtual Settings::Property<int>* windowSettingWidth() { return &Settings::singleton()->scriptEditorWindowW; } |
73 |
virtual Settings::Property<int>* windowSettingHeight() { return &Settings::singleton()->scriptEditorWindowH; } |
74 |
|
75 |
protected: |
76 |
VBox m_vbox; |
77 |
HBox m_footerHBox; |
78 |
HBox m_statusHBox; |
79 |
HButtonBox m_buttonBox; |
80 |
Gtk::ScrolledWindow m_scrolledWindow; |
81 |
HBox m_textViewHBox; |
82 |
Glib::RefPtr<Gtk::TextBuffer> m_lineNrBuffer; |
83 |
Glib::RefPtr<Gtk::TextBuffer> m_textBuffer; |
84 |
Glib::RefPtr<Gtk::TextBuffer::TagTable> m_tagTable; |
85 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_keywordTag; |
86 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_eventTag; |
87 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_variableTag; |
88 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_functionTag; |
89 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_numberTag; |
90 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_stringTag; |
91 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_patchTag; |
92 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_commentTag; |
93 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_preprocTag; |
94 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_errorTag; |
95 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_warningTag; |
96 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_preprocCommentTag; |
97 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_lineNrTag; |
98 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_metricTag; |
99 |
Glib::RefPtr<Gtk::TextBuffer::Tag> m_stdUnitTag; |
100 |
Gtk::TextView m_lineNrView; |
101 |
Gtk::TextView m_lineNrTextViewSpacer; |
102 |
Gtk::TextView m_textView; |
103 |
Gtk::Image m_statusImage; |
104 |
Gtk::Label m_statusLabel; |
105 |
Gtk::Button m_applyButton; |
106 |
Gtk::Button m_cancelButton; |
107 |
|
108 |
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 20) |
109 |
Glib::RefPtr<Gtk::CssProvider> m_css; |
110 |
#endif |
111 |
|
112 |
Glib::RefPtr<Gdk::Pixbuf> m_warningIcon; |
113 |
Glib::RefPtr<Gdk::Pixbuf> m_errorIcon; |
114 |
Glib::RefPtr<Gdk::Pixbuf> m_successIcon; |
115 |
|
116 |
#if USE_GLIB_ACTION |
117 |
Glib::RefPtr<Gio::SimpleActionGroup> m_actionGroup; |
118 |
#else |
119 |
Glib::RefPtr<Gtk::ActionGroup> m_actionGroup; |
120 |
#endif |
121 |
#if USE_GTKMM_BUILDER |
122 |
Glib::RefPtr<Gtk::Builder> m_uiManager; |
123 |
#else |
124 |
Glib::RefPtr<Gtk::UIManager> m_uiManager; |
125 |
#endif |
126 |
|
127 |
gig::Script* m_script; |
128 |
#if USE_LS_SCRIPTVM |
129 |
LinuxSampler::ScriptVM* m_vm; |
130 |
std::vector<LinuxSampler::ParserIssue> m_issues; |
131 |
std::vector<LinuxSampler::ParserIssue> m_errors; |
132 |
std::vector<LinuxSampler::ParserIssue> m_warnings; |
133 |
std::vector<LinuxSampler::CodeBlock> m_preprocComments; |
134 |
#endif |
135 |
|
136 |
bool isModified() const; |
137 |
void onButtonCancel(); |
138 |
void onButtonApply(); |
139 |
void onWindowHide(); |
140 |
void onTextInserted(const Gtk::TextBuffer::iterator& it, const Glib::ustring& txt, int length); |
141 |
void onTextErased(const Gtk::TextBuffer::iterator& itStart, const Gtk::TextBuffer::iterator& itEnd); |
142 |
void onModifiedChanged(); |
143 |
#if USE_LS_SCRIPTVM |
144 |
void updateSyntaxHighlightingByVM(); |
145 |
void updateParserIssuesByVM(); |
146 |
LinuxSampler::ScriptVM* GetScriptVM(); |
147 |
void updateIssueTooltip(GdkEventMotion* e); |
148 |
void updateStatusBar(); |
149 |
#endif |
150 |
bool on_motion_notify_event(GdkEventMotion* e); |
151 |
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 |
152 |
bool onWindowDelete(Gdk::Event& e); |
153 |
#endif |
154 |
bool onWindowDeleteP(GdkEventAny* e); |
155 |
void onMenuChangeFontSize(); |
156 |
int currentFontSize() const; |
157 |
void setFontSize(int size, bool save); |
158 |
void updateLineNumbers(); |
159 |
}; |
160 |
|
161 |
#endif // GIGEDIT_SCRIPTEDITOR_H |