"New" command better, GetUniqueBufferName no longer big numbers
This commit is contained in:
@@ -954,6 +954,37 @@ int Lua_Reopen(lua_State *L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void New(Window *window, String name = "") {
|
||||||
|
View *view = GetView(window->active_view);
|
||||||
|
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||||
|
|
||||||
|
Scratch scratch;
|
||||||
|
String dir = GetDir(buffer);
|
||||||
|
if (name != "") {
|
||||||
|
if (!IsAbsolute(name)) {
|
||||||
|
name = Format(scratch, "%.*s/%.*s", FmtString(dir), FmtString(name));
|
||||||
|
}
|
||||||
|
name = GetAbsolutePath(scratch, name);
|
||||||
|
} else {
|
||||||
|
name = GetUniqueBufferName(dir, "new");
|
||||||
|
}
|
||||||
|
WindowOpenBufferView(window, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_New(String name = "") {
|
||||||
|
BSet main = GetActiveMainSet();
|
||||||
|
New(main.window, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Lua_New(lua_State *L) {
|
||||||
|
Scratch scratch;
|
||||||
|
String name = lua_tostring(L, 1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
Command_New(name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Command_ToggleFullscreen() {
|
void Command_ToggleFullscreen() {
|
||||||
if (IsInFullscreen) {
|
if (IsInFullscreen) {
|
||||||
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
|
SDL_SetWindowSize(SDLWindow, FullScreenSizeX, FullScreenSizeY);
|
||||||
|
|||||||
@@ -659,6 +659,9 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CtrlPress(SDLK_N)) {
|
||||||
|
Command_New();
|
||||||
|
}
|
||||||
|
|
||||||
if (CtrlPress(SDLK_S)) {
|
if (CtrlPress(SDLK_S)) {
|
||||||
SaveBuffer(active.buffer);
|
SaveBuffer(active.buffer);
|
||||||
|
|||||||
@@ -30,21 +30,6 @@ int Lua_GetLoadWord(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Lua_New(lua_State *L) {
|
|
||||||
Scratch scratch;
|
|
||||||
String name = luaL_checkstring(L, 1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
BSet main = GetActiveMainSet();
|
|
||||||
if (!IsAbsolute(name)) {
|
|
||||||
String dir = GetDir(main.buffer);
|
|
||||||
name = Format(scratch, "%.*s/%.*s", FmtString(dir), FmtString(name));
|
|
||||||
}
|
|
||||||
WindowOpenBufferView(main.window, name);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Lua_BufferExists(lua_State *L) {
|
int Lua_BufferExists(lua_State *L) {
|
||||||
String string = lua_tostring(L, 1);
|
String string = lua_tostring(L, 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"Print", Lua_Print},
|
{"Print", Lua_Print},
|
||||||
{"Kill", Lua_Kill},
|
{"Kill", Lua_Kill},
|
||||||
{"GetLoadWord", Lua_GetLoadWord},
|
{"GetLoadWord", Lua_GetLoadWord},
|
||||||
{"New", Lua_New},
|
|
||||||
{"BufferExists", Lua_BufferExists},
|
{"BufferExists", Lua_BufferExists},
|
||||||
{"GetSelection", Lua_GetSelection},
|
{"GetSelection", Lua_GetSelection},
|
||||||
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
{"GetEntireBuffer", Lua_GetEntireBuffer},
|
||||||
@@ -20,6 +19,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{"GetBufferNameByID", Lua_GetBufferNameByID},
|
{"GetBufferNameByID", Lua_GetBufferNameByID},
|
||||||
{"Save", Lua_Save},
|
{"Save", Lua_Save},
|
||||||
{"Reopen", Lua_Reopen},
|
{"Reopen", Lua_Reopen},
|
||||||
|
{"New", Lua_New},
|
||||||
{"ToggleFullscreen", Lua_ToggleFullscreen},
|
{"ToggleFullscreen", Lua_ToggleFullscreen},
|
||||||
{"GetCFiles", Lua_GetCFiles},
|
{"GetCFiles", Lua_GetCFiles},
|
||||||
{"C", Lua_C},
|
{"C", Lua_C},
|
||||||
|
|||||||
@@ -49,13 +49,16 @@ Array<String16> SavedClipboardCarets;
|
|||||||
|
|
||||||
|
|
||||||
String GetUniqueBufferName(String working_dir, String prepend_name) {
|
String GetUniqueBufferName(String working_dir, String prepend_name) {
|
||||||
if (UniqueBufferNameSeed.a == 0) {
|
|
||||||
double value = get_time_in_micros();
|
|
||||||
UniqueBufferNameSeed.a = *(uint64_t *)&value;
|
|
||||||
}
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
uint64_t number = GetRandomU64(&UniqueBufferNameSeed);
|
String buffer_name = {};
|
||||||
String buffer_name = Format(scratch, "%.*s/%.*s%llu.log", FmtString(working_dir), FmtString(prepend_name), number);
|
for (int i = 1; i < INT_MAX; i += 1) {
|
||||||
|
buffer_name = Format(scratch, "%.*s/%.*s%d.log", FmtString(working_dir), FmtString(prepend_name), i);
|
||||||
|
buffer_name = GetAbsolutePath(scratch, buffer_name);
|
||||||
|
Buffer *exists = FindBuffer(buffer_name);
|
||||||
|
if (!exists) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
buffer_name = Intern(&GlobalInternTable, buffer_name);
|
buffer_name = Intern(&GlobalInternTable, buffer_name);
|
||||||
return buffer_name;
|
return buffer_name;
|
||||||
}
|
}
|
||||||
@@ -102,7 +105,7 @@ inline Buffer *GetBuffer(BufferID id) {
|
|||||||
return FirstBuffer;
|
return FirstBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Buffer *GetBufferStrict(BufferID id) {
|
inline Buffer *FindBuffer(BufferID id) {
|
||||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||||
if (it->id == id) return it;
|
if (it->id == id) return it;
|
||||||
}
|
}
|
||||||
@@ -116,7 +119,7 @@ inline Buffer *GetBuffer(String name) {
|
|||||||
return FirstBuffer;
|
return FirstBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Buffer *GetBufferStrict(String name) {
|
inline Buffer *FindBuffer(String name) {
|
||||||
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
for (Buffer *it = FirstBuffer; it; it = it->next) {
|
||||||
if (it->name == name) return it;
|
if (it->name == name) return it;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ void Command_Appendf(View *view, const char *fmt, ...);
|
|||||||
Buffer *CreateBuffer(Allocator allocator, String name, Int size = 4096);
|
Buffer *CreateBuffer(Allocator allocator, String name, Int size = 4096);
|
||||||
View *CreateView(BufferID active_buffer);
|
View *CreateView(BufferID active_buffer);
|
||||||
void ReopenBuffer(Buffer *buffer);
|
void ReopenBuffer(Buffer *buffer);
|
||||||
|
inline Buffer *FindBuffer(String name);
|
||||||
|
|
||||||
inline bool operator==(WindowID a, WindowID b) { return a.id == b.id; }
|
inline bool operator==(WindowID a, WindowID b) { return a.id == b.id; }
|
||||||
inline bool operator==(BufferID a, BufferID b) { return a.id == b.id; }
|
inline bool operator==(BufferID a, BufferID b) { return a.id == b.id; }
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
String name = ToString(scratch, buffer_name);
|
String name = ToString(scratch, buffer_name);
|
||||||
if (name != main.buffer->name) {
|
if (name != main.buffer->name) {
|
||||||
name = GetAbsolutePath(scratch, name);
|
name = GetAbsolutePath(scratch, name);
|
||||||
if (GetBufferStrict(name)) {
|
if (FindBuffer(name)) {
|
||||||
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
title.window->title_bar_last_buffer_change_id = title.buffer->change_id;
|
||||||
ReportConsolef("there is already buffer with name: %.*s", FmtString(name));
|
ReportConsolef("there is already buffer with name: %.*s", FmtString(name));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
- LoadWord, EncloseWord configurable?
|
- LoadWord, EncloseWord configurable?
|
||||||
- dump text editor state to file, restore state
|
- dump text editor state to file, restore state
|
||||||
- help menu popup when for example in process buffer, on tile bar buffer and stuff like that
|
- help menu popup when for example in process buffer, on tile bar buffer and stuff like that
|
||||||
- report errors (try showing a window)
|
|
||||||
- proper lister
|
- proper lister
|
||||||
- Setting size of splits
|
- Setting size of splits
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user