Cadabra
Computer algebra system for field theory problems
CodeInput.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "DataCell.hh"
5 #include "DocumentThread.hh"
6 #include <gtkmm/box.h>
7 #include <gtkmm/textview.h>
8 #include <gtkmm/separator.h>
9 #include <json/json.h>
10 
11 namespace cadabra {
12 
17 
18  class CodeInput : public Gtk::VBox {
19  public:
26 
27  CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, const Prefs& prefs);
28 
32 
33  CodeInput(DTree::iterator, const std::string&, double scale, const Prefs& prefs);
34 
36 
37  class exp_input_tv : public Gtk::TextView {
38  public:
39  exp_input_tv(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale);
40  virtual bool on_key_press_event(GdkEventKey*) override;
41  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
42  virtual bool on_focus_in_event(GdkEventFocus *) override;
43  virtual void on_show() override;
44 
45  void shift_enter_pressed();
46 
47  sigc::signal1<bool, DTree::iterator> content_execute;
48  sigc::signal2<bool, std::string, DTree::iterator> content_changed;
49  sigc::signal3<bool, std::string, int, DTree::iterator> content_insert;
50  sigc::signal3<bool, int, int, DTree::iterator> content_erase;
51  sigc::signal1<bool, DTree::iterator> cell_got_focus;
52 
53  friend CodeInput;
54 
55  private:
56  double scale_;
57  DTree::iterator datacell;
58  };
59 
61 
62  void set_font_size(int num);
63  void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
64  void disable_highlighting();
65 
67 
68  bool handle_button_press(GdkEventButton *);
69 
75 
76  void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
77 
82 
83  void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
84 
87 
88  void update_buffer();
89 
92 
93  void slice_cell(std::string& before, std::string& after);
94 
99 
100  Glib::RefPtr<Gtk::TextBuffer> buffer;
101 
103 
104  private:
105  void init(const Prefs& prefs);
106 
107  void tag_by_regex(const std::string& regex_str, const std::string& tag, std::string& text);
108  void highlight_python();
109  void highlight_latex();
110 
111  sigc::connection hl_conn; // Connection holding the syntax highlighting signal
112  };
113 
114 }
sigc::signal1< bool, DTree::iterator > content_execute
Definition: CodeInput.hh:47
void init(const Prefs &prefs)
Definition: CodeInput.cc:52
CodeInput(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale, const Prefs &prefs)
Initialise with existing TextBuffer and a pointer to the Datacell corresponding to this CodeInput wid...
Definition: CodeInput.cc:39
void tag_by_regex(const std::string &regex_str, const std::string &tag, std::string &text)
Definition: CodeInput.cc:114
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition: CodeInput.cc:429
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition: CodeInput.hh:50
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition: CodeInput.hh:51
exp_input_tv edit
Definition: CodeInput.hh:102
virtual void on_show() override
Definition: CodeInput.cc:401
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition: CodeInput.cc:395
sigc::signal2< bool, std::string, DTree::iterator > content_changed
Definition: CodeInput.hh:48
The actual text widget used by CodeInput.
Definition: CodeInput.hh:37
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition: CodeInput.hh:49
friend CodeInput
Definition: CodeInput.hh:53
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition: CodeInput.cc:306
Definition: DocumentThread.hh:94
void handle_insert(const Gtk::TextIter &pos, const Glib::ustring &text, int bytes)
Handle an insert event, which can consist of one or more inserted characters.
Definition: CodeInput.cc:420
void highlight_latex()
Definition: CodeInput.cc:193
exp_input_tv(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale)
Definition: CodeInput.cc:25
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition: CodeInput.cc:349
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Algorithm.cc:1030
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Definition: CodeInput.cc:211
void shift_enter_pressed()
Definition: CodeInput.cc:297
A text cell editor widget with support for editing Python and LaTeX.
Definition: CodeInput.hh:18
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition: CodeInput.hh:100
void set_font_size(int num)
Set the font size, 0 being default, negative smaller, positive larger.
Definition: CodeInput.cc:445
void highlight_python()
Definition: CodeInput.cc:134
virtual bool on_key_press_event(GdkEventKey *) override
Definition: CodeInput.cc:263
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition: DataCell.hh:34
DTree::iterator datacell
Definition: CodeInput.hh:57
void slice_cell(std::string &before, std::string &after)
Return two strings corresponding to the text before and after the current cursor position.
Definition: CodeInput.cc:436
sigc::connection hl_conn
Definition: CodeInput.hh:111
void disable_highlighting()
Definition: CodeInput.cc:250
double scale_
Definition: CodeInput.hh:56
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition: CodeInput.cc:407