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  void on_textbuf_change();
47 
48  sigc::signal1<bool, DTree::iterator> content_execute;
49  sigc::signal1<bool, DTree::iterator> content_changed;
50  sigc::signal3<bool, std::string, int, DTree::iterator> content_insert;
51  sigc::signal3<bool, int, int, DTree::iterator> content_erase;
52  sigc::signal1<bool, DTree::iterator> cell_got_focus;
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 
68 
69  bool handle_button_press(GdkEventButton *);
70 
76 
77  void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
78 
83 
84  void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
85 
88 
89  void update_buffer();
90 
93 
94  void slice_cell(std::string& before, std::string& after);
95 
100 
101  Glib::RefPtr<Gtk::TextBuffer> buffer;
102 
104 
105  private:
106  void init(const Prefs& prefs);
107 
108  void highlight_python();
109  void highlight_latex();
110 
111  sigc::connection hl_conn; // Connection holding the syntax highlighting signal
112  };
113 
114  }
DocumentThread.hh
cadabra::CodeInput
Definition: CodeInput.hh:18
cadabra::CodeInput::exp_input_tv::exp_input_tv
exp_input_tv(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale)
Definition: CodeInput.cc:24
cadabra::CodeInput::disable_highlighting
void disable_highlighting()
Definition: CodeInput.cc:494
cadabra::CodeInput::exp_input_tv::cell_got_focus
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition: CodeInput.hh:52
cadabra::CodeInput::edit
exp_input_tv edit
Definition: CodeInput.hh:103
cadabra::CodeInput::exp_input_tv::on_focus_in_event
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition: CodeInput.cc:648
cadabra::CodeInput::exp_input_tv::on_textbuf_change
void on_textbuf_change()
Definition: CodeInput.cc:550
cadabra::CodeInput::exp_input_tv::CodeInput
friend CodeInput
Definition: CodeInput.hh:54
cadabra::CodeInput::exp_input_tv::on_key_press_event
virtual bool on_key_press_event(GdkEventKey *) override
Definition: CodeInput.cc:507
cadabra::CodeInput::exp_input_tv::shift_enter_pressed
void shift_enter_pressed()
Definition: CodeInput.cc:541
cadabra::CodeInput::exp_input_tv::content_insert
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition: CodeInput.hh:50
cadabra::CodeInput::exp_input_tv::datacell
DTree::iterator datacell
Definition: CodeInput.hh:58
cadabra::CodeInput::handle_button_press
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition: CodeInput.cc:555
cadabra::CodeInput::handle_insert
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:673
cadabra::CodeInput::highlight_latex
void highlight_latex()
Definition: CodeInput.cc:348
cadabra::CodeInput::exp_input_tv::content_changed
sigc::signal1< bool, DTree::iterator > content_changed
Definition: CodeInput.hh:49
cadabra::DocumentThread::Prefs
Definition: DocumentThread.hh:94
cadabra::CodeInput::enable_highlighting
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Definition: CodeInput.cc:447
DataCell.hh
cadabra::CodeInput::exp_input_tv::scale_
double scale_
Definition: CodeInput.hh:57
cadabra::CodeInput::exp_input_tv::content_erase
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition: CodeInput.hh:51
cadabra::CodeInput::buffer
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition: CodeInput.hh:101
cadabra::CodeInput::set_font_size
void set_font_size(int num)
Set the font size, 0 being default, negative smaller, positive larger.
Definition: CodeInput.cc:703
cadabra
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:80
cadabra::CodeInput::highlight_python
void highlight_python()
Definition: CodeInput.cc:119
cadabra::CodeInput::exp_input_tv::on_show
virtual void on_show() override
Definition: CodeInput.cc:654
cadabra::DataCell::CellType
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition: DataCell.hh:34
cadabra::CodeInput::slice_cell
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:694
cadabra::CodeInput::exp_input_tv::content_execute
sigc::signal1< bool, DTree::iterator > content_execute
Definition: CodeInput.hh:48
cadabra::CodeInput::exp_input_tv
The actual text widget used by CodeInput.
Definition: CodeInput.hh:37
cadabra::CodeInput::exp_input_tv::on_draw
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition: CodeInput.cc:598
cadabra::CodeInput::hl_conn
sigc::connection hl_conn
Definition: CodeInput.hh:111
cadabra::CodeInput::update_buffer
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition: CodeInput.cc:660
cadabra::CodeInput::init
void init(const Prefs &prefs)
Definition: CodeInput.cc:53
cadabra::CodeInput::CodeInput
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
cadabra::CodeInput::handle_erase
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition: CodeInput.cc:685