Skip to content

Commit 57d0a1f

Browse files
committed
Reorganized code
1 parent 27a876b commit 57d0a1f

12 files changed

Lines changed: 2221 additions & 222 deletions

deb.out

Lines changed: 2025 additions & 0 deletions
Large diffs are not rendered by default.

include/text-editor/ScintillaView.hpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

include/text-editor/editor.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
#include <text-editor/app.hpp>
3+
#include <tvision/tv.h>
4+
#include <scintilla.h>
5+
#include <scintilla/tscintilla.h>
6+
#include <set>
7+
8+
struct EditorObserver{
9+
public:
10+
virtual void editorUpdate() = 0;
11+
};
12+
13+
struct Editor : turbo::TScintillaParent{
14+
15+
public:
16+
Editor();
17+
void setSize(const TPoint& size);
18+
void paint(TDrawSurface& surface, TRect area);
19+
void handleEvent(TEvent &event);
20+
//observers
21+
void addObserver(EditorObserver* observer);
22+
void removeObserver(EditorObserver* observer);
23+
24+
//interface TScintillaParent
25+
virtual TPoint getEditorSize() noexcept;
26+
virtual void invalidate(TRect area) noexcept;
27+
virtual void handleNotification(const SCNotification &scn);
28+
virtual void setVerticalScrollPos(int delta, int limit) noexcept;
29+
virtual void setHorizontalScrollPos(int delta, int limit) noexcept;
30+
31+
private:
32+
void updateAll();
33+
34+
private:
35+
turbo::TScintilla scintilla;
36+
TPoint size = {0, 0};
37+
std::set<EditorObserver*> observers;
38+
};

include/text-editor/editorView.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
#define Uses_TSurfaceView
3+
#include <text-editor/app.hpp>
4+
#include <tvision/tv.h>
5+
#include <scintilla.h>
6+
#include <text-editor/editor.hpp>
7+
8+
struct EditorView : TSurfaceView, EditorObserver{
9+
10+
public:
11+
EditorView(const TRect& bounds) noexcept;
12+
void resize(const TRect& bounds) noexcept;
13+
void paint();
14+
void attachEditor(Editor* newEditor);
15+
virtual void editorUpdate();
16+
17+
private:
18+
TDrawSurface drawSurface;//maybe this should be moved to editor?
19+
Editor* editor = nullptr; //non-owning
20+
};
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
2-
// Copyright (c) 2025 Piotr Białek
3-
// Copyright (c) 2025 Mateusz Rajs
4-
// Copyright (c) 2025 Mikołaj Rams
5-
// Copyright (c) 2025 Antoni Długosz
6-
//
7-
// Licensed under the MIT license
8-
1+
#pragma once
92
#include <text-editor/app.hpp>
10-
#include <tvision/tv.h>
3+
#include <text-editor/editorView.hpp>
4+
#include <text-editor/editor.hpp>
115

12-
struct EditWindow : TEditWindow {
6+
struct EditorWindow : TWindow{
137

14-
EditWindow(const TRect &rect, TStringView view, int val) noexcept;
8+
public:
9+
EditorWindow(const TRect& bounds, TStringView aTitle, short aNumber)noexcept;
1510

1611
void handleEvent(TEvent &event) override;
1712

18-
private:
19-
// last modification this editor made to the file
20-
time_t open_time;
21-
};
13+
virtual void changeBounds(const TRect& bounds);
2214

15+
private:
16+
TRect viewBounds(const TRect& bounds);
17+
18+
public:
19+
time_t open_time;
20+
private:
21+
EditorView view;
22+
Editor editor; //potentially multiple editors in the future
23+
};

include/text-editor/scintillaEditorWindow.hpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

source/text-editor/ScintillaView.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

source/text-editor/app.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include <text-editor/editorWindow.hpp>
1717
#include <text-editor/explorerWindow.hpp>
1818
#include <text-editor/terminal.hpp>
19-
#include <text-editor/scintillaEditorWindow.hpp>
19+
// #include <text-editor/scintillaEditorWindow.hpp>
20+
#include <text-editor/editorWindow.hpp>
2021
#include <tvision/tv.h>
2122

2223
App::App(int argc, char **argv)
@@ -184,7 +185,7 @@ auto App::newEditor(std::optional<char *> path) -> void {
184185
rect.b.y -= 12;
185186
rect.a.x += (m_explorer->visible() ? m_explorer->size.x : 0);
186187
// auto *editor = new EditWindow(rect, path.value_or(nullptr), wnNoNumber);
187-
auto *editor = new ScintillaEditWindow(rect, path.value_or(nullptr), wnNoNumber);
188+
auto *editor = new EditorWindow(rect, path.value_or(nullptr), wnNoNumber);
188189
deskTop->insert(editor);
189190
}
190191

source/text-editor/editor.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <text-editor/editor.hpp>
2+
#include <iostream>
3+
4+
Editor::Editor(){
5+
scintilla.setParent(this);
6+
//configure margins
7+
turbo::call(scintilla, SCI_SETMARGINS, 0, 0);
8+
9+
// Indentation
10+
turbo::call(scintilla, SCI_SETUSETABS, false, 0U);
11+
turbo::call(scintilla, SCI_SETINDENT, 4, 0U);
12+
turbo::call(scintilla, SCI_SETTABWIDTH, 4, 0U);
13+
turbo::call(scintilla, SCI_SETTABINDENTS, true, 0U);
14+
turbo::call(scintilla, SCI_SETBACKSPACEUNINDENTS, true, 0U);
15+
}
16+
17+
void Editor::setSize(const TPoint& size){
18+
this->size = size;
19+
}
20+
21+
void Editor::paint(TDrawSurface& surface, TRect area){
22+
turbo::paint(scintilla, surface, area);
23+
}
24+
25+
void Editor::handleEvent(TEvent& event){
26+
if(event.what == evKeyboard){
27+
turbo::handleKeyDown(scintilla, event.keyDown);
28+
}
29+
//TODO: handle mouse events
30+
}
31+
32+
void Editor::addObserver(EditorObserver* observer){
33+
observers.insert(observer);
34+
}
35+
36+
void Editor::removeObserver(EditorObserver* observer){
37+
observers.erase(observer);
38+
}
39+
40+
TPoint Editor::getEditorSize(){
41+
return size;
42+
}
43+
44+
void Editor::invalidate(TRect area){
45+
// may be useful later for understanding scintilla events
46+
std::cerr << "invalidate " << area.a.x << " " << area.a.y << " " << area.b.x << " " << area.b.y << "\n";
47+
updateAll();
48+
}
49+
50+
void Editor::handleNotification(const SCNotification &scn){
51+
std::cerr << "handleNotification\n";
52+
// updateAll();
53+
}
54+
55+
void Editor::setVerticalScrollPos(int delta, int limit){
56+
std::cerr << "setVerticalScrollPos " << delta << " " << limit << "\n";
57+
updateAll();
58+
}
59+
60+
void Editor::setHorizontalScrollPos(int delta, int limit){
61+
std::cerr << "setHorizontalScrollPos " << delta << " " << limit << "\n";
62+
updateAll();
63+
}
64+
65+
void Editor::updateAll(){
66+
for(auto observer : observers)observer->editorUpdate();
67+
}

source/text-editor/editorView.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <text-editor/editorView.hpp>
2+
3+
EditorView::EditorView(const TRect& bounds) : TSurfaceView(bounds){
4+
surface = &drawSurface;
5+
drawSurface.resize(bounds.b - bounds.a);
6+
}
7+
8+
void EditorView::resize(const TRect& bounds){
9+
drawSurface.resize(bounds.b - bounds.a);
10+
if(editor){
11+
editor->setSize(bounds.b - bounds.a);
12+
}
13+
TSurfaceView::setBounds(bounds);
14+
paint();
15+
draw();
16+
}
17+
18+
void EditorView::paint(){
19+
if(editor){
20+
editor->paint(drawSurface, TRect({0, 0}, size));
21+
}
22+
}
23+
24+
void EditorView::attachEditor(Editor* newEditor){
25+
if(editor){
26+
editor->removeObserver(this);
27+
}
28+
editor = newEditor;
29+
editor->setSize(size);
30+
editor->addObserver(this);
31+
paint();
32+
draw();
33+
}
34+
35+
void EditorView::editorUpdate(){
36+
paint();
37+
draw();
38+
}

0 commit comments

Comments
 (0)