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