forked from santaclose/ImGuiColorTextEdit
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy patheditor.h
More file actions
159 lines (128 loc) · 3.71 KB
/
Copy patheditor.h
File metadata and controls
159 lines (128 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// TextEditor - A syntax highlighting text editor for ImGui
// Copyright (c) 2024-2026 Johan A. Goossens. All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
//
// Include files
//
#include <algorithm>
#include <functional>
#include <string>
#include "../TextEditor.h"
#include "../TextDiff.h"
#include "../extras/LspBridge.h"
#include "../extras/Notifications.h"
#include "../extras/TrieAutoComplete.h"
//
// Editor
//
class Editor {
public:
// constructor
Editor();
// file related functions
void newFile();
void openFile();
void openFile(const std::string& path);
void saveFile();
// manage program exit
void tryToQuit();
inline bool isDone() const { return done; }
// render the editor
void render();
// debugging support
inline void setDebugInformation(std::function<std::string()> callback) { getBackendDebugInformation = callback; }
private:
// private functions
void renderMenuBar();
void renderStatusBar();
void showDiff();
void showFileOpen();
void showSaveFileAs();
void showConfirmClose(std::function<void()> callback);
void showConfirmQuit();
void showError(const std::string& message);
void showAddSquiggle();
void showClearSquiggles();
void renderDiff();
void renderFileOpen();
void renderSaveAs();
void renderConfirmClose();
void renderConfirmQuit();
void renderConfirmError();
void renderAddSquiggle();
void renderClearSquiggle();
void renderDebugInformation();
inline bool isDirty() const { return editor.GetUndoIndex() != version; }
inline bool isSavable() const { return isDirty() && filename != "untitled"; }
// properties
std::string originalText;
TextEditor editor;
TextDiff diff;
std::string filename;
size_t version;
bool done = false;
bool popup = true;
std::string errorMessage;
std::function<void()> onConfirmClose;
TextEditor::LineBreakConfig lineBreakConfig;
float fontSize = 17.0f;
inline void resetFontSize() { fontSize = 17.0f; }
inline void increaseFontSize() { fontSize = std::clamp(fontSize + 1.0f, 8.0f, 24.0f); }
inline void decreaseFontSize() { fontSize = std::clamp(fontSize - 1.0f, 8.0f, 24.0f); }
inline void setDarkPalette() {
ImGui::StyleColorsDark();
editor.SetPalette(editor.GetDarkPalette());
diff.SetPalette(editor.GetDarkPalette());
}
inline void setLightPalette() {
ImGui::StyleColorsLight();
editor.SetPalette(editor.GetLightPalette());
diff.SetPalette(editor.GetLightPalette());
}
void setLanguage(const TextEditor::Language* language);
void setLanguageByName(const std::string& name);
void setLanguageByExtention(const std::string& filename);
// examples
void toggleNavigationMode();
void toggleTrieAutoComplete();
void toggleLspBridge();
void toggleShowWordAtMouse();
void toggleLineMarkers();
void toggleLineDecorator();
void toggleContextMenus();
void toggleLineBreak();
void clearSquiggles();
bool demoTrieAutoComplete = false;
bool demoLspBridge = false;
bool showWordAtMouse = false;
bool showLineMarkers = false;
bool showLineDecorator = false;
bool showContextMenus = false;
bool enableUnicodeLineBreakAlgorithm = false;
bool showDebugInformation = false;
TrieAutoComplete trieAutoComplete;
LspBridge lsp;
static constexpr int lspOptions = LspBridge::autocomplete | LspBridge::showHoverHelp;
std::function<std::string()> getBackendDebugInformation;
size_t squiggleType = 1;
ImColor squiggleColor{1.0f, 0.2f, 0.0f, 0.8f};
char squiggleToolTip[128] = {};
// notification system
Notifications notifications;
// editor state
enum class State {
edit,
diff,
newFile,
openFile,
saveFileAs,
confirmClose,
confirmQuit,
confirmError,
addSquiggle,
clearSquiggles
} state = State::edit;
};