SetActiveView
This commit is contained in:
@@ -713,6 +713,11 @@ CircularArray<T> MakeCircularArray(Allocator allocator, int size) {
|
||||
|
||||
template <class T>
|
||||
void Add(CircularArray<T> *arr, T item) {
|
||||
if (arr->cap == 0) {
|
||||
arr->allocator = GetSystemAllocator();
|
||||
arr->cap = 128;
|
||||
arr->data = AllocArray(arr->allocator, T, arr->cap);
|
||||
}
|
||||
int idx = arr->write;
|
||||
arr->write = (arr->write + 1) % arr->cap;
|
||||
if (arr->write == 0) arr->buffer_is_full = 1;
|
||||
|
||||
@@ -84,8 +84,8 @@ int LuaOpenBigBuffer(lua_State *L) {
|
||||
// @todo: ViewOpenBuffer - new or old view for specified buffer
|
||||
Buffer *buffer = CreateBuffer(GetSystemAllocator(), "big", 2500000 * 4);
|
||||
LoadBigTextAndBigLine(buffer);
|
||||
View *view = CreateView(buffer->id);
|
||||
window->active_view = view->id;
|
||||
View *view = CreateView(buffer->id);
|
||||
SetActiveView(window, view->id);
|
||||
|
||||
SetActiveWindow(window->id);
|
||||
return 0;
|
||||
|
||||
@@ -108,6 +108,11 @@ bool SetActiveWindow(WindowID window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetActiveView(Window *window, ViewID view_id) {
|
||||
window->active_view = view_id;
|
||||
Add(&window->view_history, view_id);
|
||||
}
|
||||
|
||||
Window *GetWindowWithView(ViewID view_id) {
|
||||
ForItem(window, Windows) {
|
||||
if (window.active_view.id == view_id.id) {
|
||||
@@ -218,14 +223,14 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
|
||||
|
||||
View *view = FindViewWithBufferName(name);
|
||||
if (!view) {
|
||||
View *result = OpenBufferView(name);
|
||||
new_parent_window->active_view = result->id;
|
||||
View *result = OpenBufferView(name);
|
||||
SetActiveView(new_parent_window, result->id);
|
||||
return result;
|
||||
}
|
||||
|
||||
Window *window = GetWindowWithView(view->id);
|
||||
if (!window) {
|
||||
new_parent_window->active_view = view->id;
|
||||
SetActiveView(new_parent_window, view->id);
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -236,6 +241,6 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
|
||||
return result;
|
||||
}
|
||||
|
||||
new_parent_window->active_view = view->id;
|
||||
SetActiveView(new_parent_window, view->id);
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,9 @@ struct View {
|
||||
};
|
||||
|
||||
struct Window {
|
||||
WindowID id;
|
||||
ViewID active_view;
|
||||
WindowID id;
|
||||
ViewID active_view;
|
||||
CircularArray<ViewID> view_history;
|
||||
|
||||
Rect2I total_rect;
|
||||
Rect2I scrollbar_rect;
|
||||
|
||||
@@ -16,14 +16,15 @@ void InitWindows(View *null_view) {
|
||||
LoadTextA(b);
|
||||
LoadUnicode(b);
|
||||
w->active_view = v->id;
|
||||
SetActiveView(w, v->id);
|
||||
}
|
||||
|
||||
{
|
||||
Window *w = CreateWindow();
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*console*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
Window *w = CreateWindow();
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*console*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
SetActiveView(w, v->id);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -36,7 +37,8 @@ void InitWindows(View *null_view) {
|
||||
buffer->no_history = true;
|
||||
View *view = CreateView(buffer->id);
|
||||
window->active_view = view->id;
|
||||
DebugWindowID = window->id;
|
||||
SetActiveView(window, view->id);
|
||||
DebugWindowID = window->id;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -49,7 +51,8 @@ void InitWindows(View *null_view) {
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
InfoBarWindowID = w->id;
|
||||
SetActiveView(w, v->id);
|
||||
InfoBarWindowID = w->id;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -64,7 +67,7 @@ void InitWindows(View *null_view) {
|
||||
w->deactivate_on_escape = true;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*commands*");
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
SetActiveView(w, v->id);
|
||||
|
||||
CommandWindowID = w->id;
|
||||
Command_EvalLua(v, L"list_buffers()");
|
||||
@@ -80,7 +83,7 @@ void InitWindows(View *null_view) {
|
||||
w->deactivate_on_escape = true;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*search*");
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
SetActiveView(w, v->id);
|
||||
|
||||
SearchWindowID = w->id;
|
||||
}
|
||||
@@ -96,7 +99,7 @@ void InitWindows(View *null_view) {
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*popup*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
w->active_view = v->id;
|
||||
SetActiveView(w, v->id);
|
||||
|
||||
PopupWindowID = w->id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user