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 
10 namespace cadabra {
11 
16 
17  class CodeInput : public Gtk::VBox {
18  public:
25 
26  CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, const Prefs& prefs);
27 
31 
32  CodeInput(DTree::iterator, const std::string&, double scale, const Prefs& prefs);
33 
35 
36  class exp_input_tv : public Gtk::TextView {
37  public:
38  exp_input_tv(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale);
39  virtual bool on_key_press_event(GdkEventKey*) override;
40  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
41  virtual bool on_focus_in_event(GdkEventFocus *) override;
42  virtual void on_show() override;
43 
44  void shift_enter_pressed();
45  void on_textbuf_change();
46 
47  sigc::signal1<bool, DTree::iterator> content_execute;
48  sigc::signal1<bool, 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  sigc::signal2<bool, DTree::iterator, int> complete_request;
53 
54  friend CodeInput;
55 
56  private:
57  double scale_;
58  DTree::iterator datacell;
59  };
60 
62 
63  void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
64  void disable_highlighting();
65 
66  void relay_cursor_pos(std::function<void(int, int)> callback);
67 
69 
70  bool handle_button_press(GdkEventButton *);
71 
77 
78  void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
79 
84 
85  void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
86 
89 
90  void update_buffer();
91 
94 
95  void slice_cell(std::string& before, std::string& after);
96 
101 
102  Glib::RefPtr<Gtk::TextBuffer> buffer;
103 
105 
106  private:
107  void init(const Prefs& prefs);
108 
109  void highlight_python();
110  void highlight_latex();
111 
112  sigc::connection hl_conn; // Connection holding the syntax highlighting signal
113  };
114 
115  }
The actual text widget used by CodeInput.
Definition: CodeInput.hh:36
virtual bool on_key_press_event(GdkEventKey *) override
Definition: CodeInput.cc:507
DTree::iterator datacell
Definition: CodeInput.hh:58
sigc::signal2< bool, DTree::iterator, int > complete_request
Definition: CodeInput.hh:52
friend CodeInput
Definition: CodeInput.hh:54
void shift_enter_pressed()
Definition: CodeInput.cc:553
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition: CodeInput.cc:657
virtual void on_show() override
Definition: CodeInput.cc:663
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition: CodeInput.hh:50
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition: CodeInput.hh:49
void on_textbuf_change()
Definition: CodeInput.cc:562
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition: CodeInput.cc:607
sigc::signal1< bool, DTree::iterator > content_execute
Definition: CodeInput.hh:47
double scale_
Definition: CodeInput.hh:57
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition: CodeInput.hh:51
sigc::signal1< bool, DTree::iterator > content_changed
Definition: CodeInput.hh:48
exp_input_tv(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale)
Definition: CodeInput.cc:24
A text cell editor widget with support for editing Python and LaTeX.
Definition: CodeInput.hh:17
void highlight_latex()
Definition: CodeInput.cc:338
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition: CodeInput.cc:669
sigc::connection hl_conn
Definition: CodeInput.hh:112
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Set highlighting modes.
Definition: CodeInput.cc:437
void disable_highlighting()
Definition: CodeInput.cc:484
void relay_cursor_pos(std::function< void(int, int)> callback)
Definition: CodeInput.cc:497
exp_input_tv edit
Definition: CodeInput.hh:104
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition: CodeInput.hh:102
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition: CodeInput.cc:694
void init(const Prefs &prefs)
Definition: CodeInput.cc:53
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:682
void highlight_python()
Definition: CodeInput.cc:109
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:40
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:703
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition: CodeInput.cc:567
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition: DataCell.hh:34
Definition: DocumentThread.hh:101
callback
Definition: cadabra2_defaults.py:411
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83
end
Definition: nevaluate.py:22
start
Definition: nevaluate.py:20