KoMo2  1.0.0
A modern ARM emulator GUI.
TerminalModel.cpp
Go to the documentation of this file.
1 
11 #include <atkmm/relationset.h>
12 #include <iostream>
13 #include "../views/TerminalView.h"
14 #include "KoMo2Model.h"
15 
22  : Model(parent), view(view) {
23  view->setModel(this);
25 }
26 
32  switch (newState) {
33  default:
34  break;
35  }
36 }
37 
42  getView()->getTextView()->get_buffer()->set_text("");
43 }
44 
50 const bool TerminalModel::handleKeyPress(const GdkEventKey* const e) {
51  // Do not override key presses if not in focus
52  if (not isFocused()) {
53  return false;
54  }
55 
56  // If tab or right arrow pressed, give clear button focus
57  if (e->keyval == GDK_KEY_Tab || e->keyval == GDK_KEY_Right) {
58  getView()->getClearButton()->grab_focus();
59  }
60  // If escape or up arrow pressed, give scroll view focus
61  else if (e->keyval == GDK_KEY_Escape || e->keyval == GDK_KEY_Up) {
62  getView()->getTextView()->grab_focus();
63  }
64  // Else send key press to Jimulator if running or paused
65  else if (Model::getJimulatorState() == JimulatorState::PAUSED ||
66  Model::getJimulatorState() == JimulatorState::RUNNING) {
68  }
69 
70  return true;
71 }
72 
78 void TerminalModel::appendTextToTextView(std::string text) {
79  if (text == "") {
80  return;
81  }
82 
83  auto* const view = getView()->getTextView();
84 
85  // Append text to the buffer, reset the buffer
86  auto buff = view->get_buffer();
87  buff->insert(buff->end(), text);
88  view->set_buffer(buff);
89 
90  // Scroll to the bottom of the scroll bar
91  buff = view->get_buffer();
92  view->scroll_to(buff->create_mark(buff->end(), false));
93 }
94 
99 const std::string TerminalModel::readJimulator() const {
101 }
102 
109  return getView()->getInputBox()->is_focus();
110 }
111 
112 // ! Getters and setters
113 
119  return view;
120 }
Gtk::Entry *const getInputBox()
Returns a constant pointer to the input box.
TerminalView *const getView() const
Gets a pointer to the view object.
void onClearClick()
Handles the clear button being clicked.
JimulatorState getJimulatorState() const
Return the jimulatorState member object.
Definition: Model.cpp:75
Gtk::Button *const getClearButton()
Returns a constant pointer to the clear button.
void setModel(TerminalModel *const val)
Sets the model member.
const std::string readJimulator() const
Reads for any data from Jimulator.
JimulatorState
Describe the 5 states of Jimulator.
Definition: Model.h:19
Gtk::TextView *const getTextView()
Returns a constant pointer to the output box.
void setButtonListener(Gtk::Button *const button, const T1 b, const T2 c)
Connect any button to any member function of.
Definition: Model.h:52
void appendTextToTextView(std::string text)
Appends a string to the current text view of the terminal, and scroll to the bottom of the terminal...
A file containing the definition of the KoMo2Model class.
virtual void changeJimulatorState(const JimulatorState newState) override
Handles the internal state of Jimulator being changed.
The superclass for all other Model classes. Uses a pure virtual function, so is abastract. Keeps KoMo2Model as a friend so it alone can call setJimulatorState. This class provides basic data that are needed by all other.
Definition: Model.h:35
const bool sendTerminalInputToJimulator(const unsigned int val)
Sends terminal information to Jimulator.
Definition: kcmd.cpp:499
virtual const bool handleKeyPress(const GdkEventKey *const e) override
Handles any key press events.
TerminalView *const view
The view this model represents.
Definition: TerminalModel.h:38
const bool isFocused()
Returns whether or not the input box has focus or not.
The logical model of the entire application. All other models should be member variables of this mode...
Definition: KoMo2Model.h:34
The GUI element which encapsulates the "clear" button, the output text box, and the input text box at...
Definition: TerminalView.h:25
TerminalModel(TerminalView *const view, KoMo2Model *const parent)
Construct a new TerminalModel::TerminalModel object.
const std::string getJimulatorTerminalMessages()
Reads for messages from Jimulator, to display in the terminal output.
Definition: kcmd.cpp:470