-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathned_embed.cpp
More file actions
345 lines (281 loc) · 9.29 KB
/
ned_embed.cpp
File metadata and controls
345 lines (281 loc) · 9.29 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/*
File: ned_embed.cpp
Description: Implementation of the embeddable NED editor wrapper.
*/
// Include GLEW first to avoid conflicts
#include <GL/glew.h>
#include "ned_embed.h"
#include "ai/ai_agent.h"
#include "ai/ai_agent.h" // Ensure AI agent is included
#include "editor/editor.h"
#include "editor/editor_bookmarks.h"
#include "files/file_finder.h"
#include "files/file_tree.h"
#include "files/files.h"
#include "shaders/shader_manager.h"
#include "shaders/shader_types.h"
#include "util/font.h"
#include "util/init.h"
#include "util/keybinds.h"
#include "util/render.h"
#include "util/settings.h"
#include "util/splitter.h"
#include "util/terminal.h"
#include "util/welcome.h"
#include "util/window_resize.h"
// Include global variable declarations
#include "globals.h"
#include <algorithm> // for std::max
// Stub for macOS-specific function that's not needed in the embedded version
extern "C" void updateMacOSWindowProperties(float opacity, bool blurEnabled)
{
// This function is not needed for the embedded app
(void)opacity;
(void)blurEnabled;
}
// Global variables are now defined in globals.cpp
// Constants
constexpr float kAgentSplitterWidth = 6.0f;
NedEmbed::NedEmbed()
: settings(nullptr), splitter(nullptr), windowResize(nullptr), showSidebar(true),
showAgentPane(false), showLineNumbers(true), showWelcome(true), isEmbedded(true),
initialized(false)
{
// Auto-initialize when constructed
initialize();
}
NedEmbed::~NedEmbed() { cleanup(); }
bool NedEmbed::initialize()
{
if (initialized)
{
return true;
}
if (!initializeComponents())
{
return false;
}
initialized = true;
return true;
}
bool NedEmbed::initializeComponents()
{
// Initialize settings
settings = &gSettings;
// Initialize splitter
splitter = new Splitter();
// Initialize window resize (without GLFW window)
windowResize = new WindowResize();
// Initialize settings and configuration
gSettings.loadSettings();
if (gKeybinds.loadKeybinds())
{
std::cout << "Initial keybinds loaded successfully." << std::endl;
}
// Load UI settings
Splitter::loadSidebarSettings();
Splitter::loadAgentPaneSettings();
Splitter::adjustAgentSplitPosition();
// Initialize fonts
gFont.initialize();
// Initialize file explorer
gFileExplorer.loadIcons();
// Configure ImGui to only allow window movement from title bar
// This prevents accidental window movement when clicking/dragging in content areas
ImGuiIO &io = ImGui::GetIO();
io.ConfigWindowsMoveFromTitleBarOnly = true;
// Apply initial background color settings to ImGui style
// This ensures the background color is set correctly on startup
ImGuiStyle &style = ImGui::GetStyle();
// Set the child window background color (for editor panes, file explorer, etc.)
// Use a proper alpha value (1.0) instead of the settings alpha which might be 0
style.Colors[ImGuiCol_ChildBg] =
ImVec4(gSettings.getSettings()["backgroundColor"][0].get<float>(),
gSettings.getSettings()["backgroundColor"][1].get<float>(),
gSettings.getSettings()["backgroundColor"][2].get<float>(),
1.0f); // Use full alpha for child windows
// Also set the main window background color for popups and settings windows
// but use a slightly different alpha to distinguish from child windows
style.Colors[ImGuiCol_WindowBg] =
ImVec4(gSettings.getSettings()["backgroundColor"][0].get<float>(),
gSettings.getSettings()["backgroundColor"][1].get<float>(),
gSettings.getSettings()["backgroundColor"][2].get<float>(),
0.95f); // Slightly transparent for main windows
// Set scrollbar background to transparent for embedded mode on startup
style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0, 0, 0, 0); // Transparent track
return true;
}
void NedEmbed::render()
{
if (!initialized || !settings || !splitter || !windowResize)
{
return;
}
// Get the available content region size automatically
ImVec2 contentSize = ImGui::GetContentRegionAvail();
float width = contentSize.x;
float height = contentSize.y;
// Handle input
handleInput();
// Handle file dialog (this is what was missing!)
if (gFileExplorer.handleFileDialog())
{
// If a folder was selected, hide the welcome screen
if (showWelcome)
{
showWelcome = false;
}
}
// Set up the editor area - this is the key part where we extract from
// Render::renderMainWindow()
ImGui::PushFont(gFont.currentFont);
float padding = ImGui::GetStyle().WindowPadding.x;
float availableWidth =
width - padding * 3 - (showAgentPane ? kAgentSplitterWidth : 0.0f);
// Force agent pane to be hidden in embedded mode
Splitter::showAgentPane = false;
// Check if welcome screen should be shown (like in standalone app)
if (showWelcome)
{
// Welcome screen takes over the entire window when visible
// Set the welcome screen's embedded flag based on our embedded state
gWelcome.setEmbedded(isEmbedded);
gWelcome.render();
// Add a dummy item to satisfy ImGui's boundary requirements ONLY in embedded mode
if (isEmbedded)
{
ImGui::Dummy(ImVec2(0, 0));
}
// Make sure we pop the font before returning to avoid font stack issues
ImGui::PopFont();
return; // Don't render editor when welcome screen is visible
}
if (Splitter::showSidebar)
{
// Render with sidebar: File Explorer + Editor (no agent pane)
float leftSplit = settings->getSplitPos();
// Ensure minimum widths and prevent negative values
float minWidth = 50.0f; // Minimum width for any component
float explorerWidth = std::max(availableWidth * leftSplit, minWidth);
float editorWidth =
std::max(availableWidth - explorerWidth - (padding * 2), minWidth);
// Render File Explorer
renderFileExplorer(explorerWidth);
ImGui::SameLine(0, 0);
// Render left splitter (only when sidebar is visible)
renderSplitter(padding, availableWidth);
ImGui::SameLine(0, 0);
// Render Editor
renderEditor(editorWidth);
} else
{
// No sidebar: just editor (no agent pane)
float editorWidth = availableWidth + 5.0f; // Full width for editor
renderEditor(editorWidth);
}
// Render additional components that are called in the standalone app's renderFrame
// These are crucial for settings popup, notifications, and keybinds
// Check if terminal should be rendered (like in standalone app)
if (gTerminal.isTerminalVisible())
{
// Terminal takes over the editor area when visible
// Set the terminal's embedded flag based on our embedded state
gTerminal.setEmbedded(isEmbedded);
// Don't pop the font here - let the terminal handle its own font management
gTerminal.render();
// Don't return early - allow settings window to render even when terminal is visible
}
// Always render settings and other UI components, regardless of terminal visibility
// Set embedded flag for settings to constrain popup to editor pane
gSettings.setEmbedded(true);
gSettings.renderSettingsWindow();
gSettings.setEmbedded(false); // Reset for standalone app
// Set embedded flag for FileFinder to constrain it to editor pane
gFileFinder.setEmbedded(true);
gSettings.renderNotification("");
gKeybinds.checkKeybindsFile();
ImGui::PopFont();
}
void NedEmbed::renderEditor(float editorWidth)
{
// Use the existing editor render function
gEditor.renderEditor(gFont.currentFont, editorWidth);
}
void NedEmbed::renderFileExplorer(float explorerWidth)
{
// Use the existing file explorer render function
gFileExplorer.renderFileExplorer(explorerWidth);
}
void NedEmbed::renderAgentPane(float agentWidth)
{
// Use the existing AI agent render function
gAIAgent.render(agentWidth, gFont.largeFont);
}
void NedEmbed::renderSplitter(float padding, float availableWidth)
{
// Use the existing splitter render function
splitter->renderSplitter(padding, availableWidth);
}
void NedEmbed::setShowSidebar(bool show) { showSidebar = show; }
void NedEmbed::setShowAgentPane(bool show) { showAgentPane = show; }
void NedEmbed::setShowLineNumbers(bool show) { showLineNumbers = show; }
void NedEmbed::setShowWelcome(bool show) { showWelcome = show; }
void NedEmbed::handleInput()
{
// Check if the editor pane is focused before processing keybinds
// This prevents keybinds from being processed when the app pane is not focused
bool isEditorPaneFocused =
ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows);
// Only process keybinds if the editor pane is focused
if (isEditorPaneFocused)
{
// Handle keyboard shortcuts (like in standalone app)
if (gKeybinds.handleKeyboardShortcuts())
{
// Mark for redraw if needed
}
}
}
void NedEmbed::checkForFontReload()
{
if (!initialized || !settings)
{
return;
}
// Handle font reloading automatically (like in standalone app)
// First check for settings changes to detect font size changes
gSettings.setEmbedded(true);
bool needFontReload = false;
bool needsRedraw = false;
int framesToRender = 0;
float lastOpacity = 0.0f;
bool lastBlurEnabled = false;
gSettings.handleSettingsChanges(
needFontReload,
needsRedraw,
framesToRender,
[](bool enabled) { /* shader not used in embedded mode */ },
lastOpacity,
lastBlurEnabled);
// Handle font reloading BEFORE ImGui frame starts
if (needFontReload)
{
gFont.handleFontReloadWithFrameUpdates();
}
}
void NedEmbed::cleanup() { cleanupComponents(); }
void NedEmbed::cleanupComponents()
{
if (splitter)
{
delete splitter;
splitter = nullptr;
}
if (windowResize)
{
delete windowResize;
windowResize = nullptr;
}
settings = nullptr;
initialized = false;
}