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 set_font_size(int num);
64  void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
65  void disable_highlighting();
66 
67  void relay_cursor_pos(std::function<void(int, int)> callback);
68 
70 
71  bool handle_button_press(GdkEventButton *);
72 
78 
79  void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
80 
85 
86  void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
87 
90 
91  void update_buffer();
92 
95 
96  void slice_cell(std::string& before, std::string& after);
97 
102 
103  Glib::RefPtr<Gtk::TextBuffer> buffer;
104 
106 
107  private:
108  void init(const Prefs& prefs);
109 
110  void highlight_python();
111  void highlight_latex();
112 
113  sigc::connection hl_conn; // Connection holding the syntax highlighting signal
114  };
115 
116  }
The actual text widget used by CodeInput.
Definition: CodeInput.hh:36
virtual bool on_key_press_event(GdkEventKey *) override
Definition: CodeInput.cc:517
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:563
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition: CodeInput.cc:670
virtual void on_show() override
Definition: CodeInput.cc:676
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:572
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition: CodeInput.cc:620
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:348
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition: CodeInput.cc:682
sigc::connection hl_conn
Definition: CodeInput.hh:113
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Definition: CodeInput.cc:447
void disable_highlighting()
Definition: CodeInput.cc:494
void set_font_size(int num)
Set the font size, 0 being default, negative smaller, positive larger.
Definition: CodeInput.cc:725
void relay_cursor_pos(std::function< void(int, int)> callback)
Definition: CodeInput.cc:507
exp_input_tv edit
Definition: CodeInput.hh:105
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition: CodeInput.hh:103
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition: CodeInput.cc:707
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:695
void highlight_python()
Definition: CodeInput.cc:119
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:716
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition: CodeInput.cc:577
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:368
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