Improving window/view/buffer management
This commit is contained in:
@@ -226,26 +226,3 @@ void HandleGlobalCommands() {
|
|||||||
SetActiveWindow({2});
|
SetActiveWindow({2});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
|
||||||
For(order) {
|
|
||||||
Window *window = &Windows[it];
|
|
||||||
View *view = GetActiveView(window);
|
|
||||||
|
|
||||||
Vec2 mouse = GetMousePosition();
|
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
|
||||||
if (mouse_in_window) {
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
|
||||||
SetActiveWindow(window->id);
|
|
||||||
}
|
|
||||||
if (LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
|
||||||
if (IsKeyDown(KEY_F1)) {
|
|
||||||
view->scroll.x -= (Int)(GetMouseWheelMove() * 48);
|
|
||||||
} else {
|
|
||||||
view->scroll.y -= (Int)(GetMouseWheelMove() * 48);
|
|
||||||
}
|
|
||||||
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -507,4 +507,27 @@ void HandleWindowBindings(Window *window) {
|
|||||||
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
||||||
view.scroll.x = ClampBottom(view.scroll.x, (Int)0);
|
view.scroll.x = ClampBottom(view.scroll.x, (Int)0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
||||||
|
For(order) {
|
||||||
|
Window *window = &Windows[it];
|
||||||
|
View *view = GetActiveView(window);
|
||||||
|
|
||||||
|
Vec2 mouse = GetMousePosition();
|
||||||
|
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
||||||
|
if (mouse_in_window) {
|
||||||
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
|
SetActiveWindow(window->id);
|
||||||
|
}
|
||||||
|
if (LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
||||||
|
if (IsKeyDown(KEY_F1)) {
|
||||||
|
view->scroll.x -= (Int)(GetMouseWheelMove() * 48);
|
||||||
|
} else {
|
||||||
|
view->scroll.y -= (Int)(GetMouseWheelMove() * 48);
|
||||||
|
}
|
||||||
|
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ lua_State *LuaState = NULL;
|
|||||||
int LuaOpenFile(lua_State *L) {
|
int LuaOpenFile(lua_State *L) {
|
||||||
const char *text = luaL_checkstring(L, 1);
|
const char *text = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
View *view = ViewOpenFile(text);
|
|
||||||
Window *window = GetWindow(LastActiveWindow);
|
Window *window = GetWindow(LastActiveWindow);
|
||||||
AddView(window, view->id);
|
View *view = ViewOpenFile(window, text);
|
||||||
window->active_view = view->id;
|
|
||||||
SetActiveWindow(window->id);
|
SetActiveWindow(window->id);
|
||||||
return 0; // number of results
|
return 0; // number of results
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ inline View *GetView(ViewID id) {
|
|||||||
return &Views[0];
|
return &Views[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool IsNull(Buffer *buffer) { return buffer->id.id == NullBufferID.id; }
|
inline bool IsNull(Buffer *buffer) { return buffer->id.id == NullBufferID.id; }
|
||||||
|
|
||||||
void SetActiveWindow(WindowID window);
|
|
||||||
inline bool IsActive(Window *window) { return window->id.id == ActiveWindow.id; }
|
inline bool IsActive(Window *window) { return window->id.id == ActiveWindow.id; }
|
||||||
inline bool IsActive(Window *window, View *view) { return window->active_view.id == view->id.id; }
|
inline bool IsActive(Window *window, View *view) { return window->active_view.id == view->id.id; }
|
||||||
inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); }
|
inline Window *GetActiveWindow() { return GetWindow(ActiveWindow); }
|
||||||
@@ -145,40 +143,50 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
View *ViewOpenFile(String name) {
|
View *_WindowOpenViewAndBuffer(Window *window, String name, bool set_active = true) {
|
||||||
// if there is no view for this file, create one
|
Buffer *buffer = BufferOpenFile(name);
|
||||||
View *view = FindViewWithBufferName(name);
|
if (IsNull(buffer)) Assert(0); // @todo
|
||||||
if (!view) {
|
View *view = CreateView(buffer->id);
|
||||||
Buffer *buffer = BufferOpenFile(name);
|
Add(&window->views, view->id);
|
||||||
if (IsNull(buffer)) Assert(0); // @todo
|
if (set_active) window->active_view = view->id;
|
||||||
view = CreateView(buffer->id);
|
return view;
|
||||||
return view;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If there is a buffer and view for this file then figure out
|
void UnlinkView(Window *window, ViewID view) {
|
||||||
// if we need another view or can we reuse
|
|
||||||
Window *window = FindParentWindow(view->id);
|
|
||||||
if (!window) {
|
|
||||||
Buffer *buffer = BufferOpenFile(name);
|
|
||||||
if (IsNull(buffer)) Assert(0); // @todo
|
|
||||||
view = CreateView(buffer->id);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new view, 2 view into same buffer at the same time
|
|
||||||
if (window->active_view.id == view->id.id) {
|
|
||||||
Buffer *buffer = BufferOpenFile(name);
|
|
||||||
if (IsNull(buffer)) Assert(0); // @todo
|
|
||||||
view = CreateView(buffer->id);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unlink and reuse
|
|
||||||
For(window->views) {
|
For(window->views) {
|
||||||
if (it.id == view->id.id) {
|
if (it.id == view.id) {
|
||||||
UnorderedRemove(&window->views, it);
|
UnorderedRemove(&window->views, it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Assert(window->active_view.id != view.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
View *ViewOpenFile(Window *new_parent_window, String name) {
|
||||||
|
For(new_parent_window->views) {
|
||||||
|
View *it_view = GetView(it);
|
||||||
|
Buffer *it_buffer = GetBuffer(it_view->buffer_id);
|
||||||
|
if (it_buffer->name == name) {
|
||||||
|
new_parent_window->active_view = it;
|
||||||
|
return it_view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
View *view = FindViewWithBufferName(name);
|
||||||
|
if (!view) return _WindowOpenViewAndBuffer(new_parent_window, name);
|
||||||
|
|
||||||
|
Window *window = FindParentWindow(view->id);
|
||||||
|
if (!window) {
|
||||||
|
Add(&new_parent_window->views, view->id);
|
||||||
|
new_parent_window->active_view = view->id;
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool view_actively_used = window->active_view.id == view->id.id;
|
||||||
|
if (view_actively_used) return _WindowOpenViewAndBuffer(new_parent_window, name);
|
||||||
|
|
||||||
|
UnlinkView(window, view->id);
|
||||||
|
Add(&new_parent_window->views, view->id);
|
||||||
|
new_parent_window->active_view = view->id;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
#include "buffer_multi_cursor.cpp"
|
#include "buffer_multi_cursor.cpp"
|
||||||
#include "buffer_history.cpp"
|
#include "buffer_history.cpp"
|
||||||
#include "buffer_test_load.cpp"
|
#include "buffer_test_load.cpp"
|
||||||
#include "management.cpp"
|
|
||||||
|
|
||||||
|
#include "management.cpp"
|
||||||
#include "commands.cpp"
|
#include "commands.cpp"
|
||||||
#include "commands_clipboard.cpp"
|
#include "commands_clipboard.cpp"
|
||||||
#include "commands_window.cpp"
|
#include "commands_window.cpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user