Add icon and drop file event

This commit is contained in:
Krzosa Karol
2024-08-08 10:49:13 +02:00
parent 28a9656db1
commit ad2efab7c8
8 changed files with 54 additions and 13 deletions

View File

@@ -153,10 +153,15 @@ int CompileTextEditor() {
// cmd.add("opengl32.lib gdi32.lib winmm.lib shell32.lib user32.lib msvcrt.lib /NODEFAULTLIB:LIBCMT"); // cmd.add("opengl32.lib gdi32.lib winmm.lib shell32.lib user32.lib msvcrt.lib /NODEFAULTLIB:LIBCMT");
For2(lib, libs) For(lib.link) cmd.add(it); For2(lib, libs) For(lib.link) cmd.add(it);
For(libs) For2(o, it.objects) cmd.add(o); For(libs) For2(o, it.objects) cmd.add(o);
cmd.add("icon.res");
OS_DeleteFile("te.pdb"); OS_DeleteFile("te.pdb");
// For(cmd) IO_Printf("%.*s\n", S8_Expand(it)); // For(cmd) IO_Printf("%.*s\n", S8_Expand(it));
if (!OS_FileExists("icon.res")) {
OS_CopyFile("../data/icon.ico", "icon.ico", true);
OS_CopyFile("../data/icon.rc", "icon.rc", true);
Run("rc icon.rc");
}
result += Run(cmd); result += Run(cmd);
return result; return result;
} }

BIN
data/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

1
data/icon.rc Normal file
View File

@@ -0,0 +1 @@
id ICON "icon.ico"

View File

@@ -17,9 +17,9 @@ enum EventKind {
EVENT_KEY_PRESS, EVENT_KEY_PRESS,
EVENT_TEXT_INPUT, EVENT_TEXT_INPUT,
};
bool IsMouseEvent(EventKind kind) { return kind >= EVENT_MOUSE_LEFT && kind <= EVENT_MOUSE_MOVE; } EVENT_DROP_FILE,
};
struct Event { struct Event {
EventKind kind; EventKind kind;
@@ -39,6 +39,8 @@ struct Event {
const char *text; const char *text;
}; };
inline bool IsMouseEvent(EventKind kind) { return kind >= EVENT_MOUSE_LEFT && kind <= EVENT_MOUSE_MOVE; }
const int DIR_RIGHT = 0; const int DIR_RIGHT = 0;
const int DIR_LEFT = 1; const int DIR_LEFT = 1;
const int DIR_DOWN = 2; const int DIR_DOWN = 2;

View File

@@ -595,6 +595,10 @@ void WindowCommand(Event event, Window *window, View *view) {
} }
} }
if (event.kind == EVENT_DROP_FILE) {
WindowOpenBufferView(window, event.text);
}
if (CtrlAlt(SDLK_DOWN)) { if (CtrlAlt(SDLK_DOWN)) {
Command_DuplicateLine(view, DIR_DOWN); Command_DuplicateLine(view, DIR_DOWN);
} else if (AltShift(SDLK_DOWN)) { } else if (AltShift(SDLK_DOWN)) {
@@ -732,7 +736,7 @@ void WindowCommand(Event event, Window *window, View *view) {
search = true; search = true;
} }
if (event.text) { if (event.kind == EVENT_TEXT_INPUT) {
Scratch scratch; Scratch scratch;
String string = event.text; String string = event.text;
String16 string16 = ToString16(scratch, string); String16 string16 = ToString16(scratch, string);

View File

@@ -1,5 +1,11 @@
Array<Process> ActiveProcesses = {}; Array<Process> ActiveProcesses = {};
// WARNING: seems that this maybe can't work reliably?
// in case of 'git grep a' it's possible that child process spawns it's own
// child process and then it won't print anything because it won't have
// the appropriate handles. This happens in this case when git grep calls
// 'less' program which errors out and doesn't print anything
// @todo: maybe I should ask someone smarter about this!
void UpdateProcesses() { void UpdateProcesses() {
Scratch scratch; Scratch scratch;
int64_t buffer_size = 4096; int64_t buffer_size = 4096;

View File

@@ -80,9 +80,10 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
} break; } break;
case SDL_EVENT_TEXT_INPUT: { case SDL_EVENT_TEXT_INPUT: {
event.kind = EVENT_TEXT_INPUT; event.kind = EVENT_TEXT_INPUT;
SDL_TextInputEvent &b = input_event->text; SDL_TextInputEvent &b = input_event->text;
event.text = b.text; String string = b.text;
event.text = Copy(Perm, string).data; // @leak: @todo: intern table
} break; } break;
case SDL_EVENT_MOUSE_BUTTON_DOWN: { case SDL_EVENT_MOUSE_BUTTON_DOWN: {
@@ -131,6 +132,21 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
// SDL_MouseMotionEvent &b = input_event->motion; // SDL_MouseMotionEvent &b = input_event->motion;
} break; } break;
case SDL_EVENT_DROP_FILE: {
event.kind = EVENT_DROP_FILE;
SDL_DropEvent &b = input_event->drop;
String string = b.data;
event.text = Copy(Perm, string).data; // @leak
} break;
// SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, true);
// case SDL_EVENT_DROP_TEXT: {
// SDL_DropEvent &b = input_event->drop;
// event.kind = EVENT_DROP_TEXT;
// String string = b.data;
// event.text = Copy(Perm, string).data; // @leak
// } break;
default: { default: {
}; };
} }
@@ -218,9 +234,13 @@ Array<Event> GetEventsForFrame(Allocator allocator) {
#if _WIN32 #if _WIN32
int WinMain(void *hInstance, void *hPrevInstance, const char *lpCmdLine, int nShowCmd) int WinMain(void *hInstance, void *hPrevInstance, const char *lpCmdLine, int nShowCmd)
#else #else
int main() int main(int argc, char **argv)
#endif #endif
{ {
#if _WIN32
int argc = __argc;
char **argv = __argv;
#endif
BeginProfiler(); BeginProfiler();
InitScratch(); InitScratch();
@@ -291,6 +311,7 @@ int main()
} }
SDL_StartTextInput(SDLWindow); SDL_StartTextInput(SDLWindow);
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true);
SDL_GL_SetSwapInterval(1); // vsync SDL_GL_SetSwapInterval(1); // vsync
{ {
float scale = SDL_GetWindowDisplayScale(SDLWindow); float scale = SDL_GetWindowDisplayScale(SDLWindow);
@@ -304,6 +325,12 @@ int main()
InitLuaConfig(); InitLuaConfig();
InitWindows(); InitWindows();
for (int i = 1; i < argc; i += 1) {
String it = argv[i];
Window *window = GetWindow({0});
WindowOpenBufferView(window, it);
}
while (AppIsRunning) { while (AppIsRunning) {
FrameID += 1; FrameID += 1;

View File

@@ -1,15 +1,11 @@
- I guess it's pretty dangerous passing pointers everywhere? - I guess it's pretty dangerous passing pointers everywhere?
- kill process using command in window - text in events aren't we using invalid memory for text? We need an intern table?
- kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433 - kill all processes on exit https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433
- if exec is prepended with '!' symbol then run a shell command - if exec is prepended with '!' symbol then run a shell command
- try using git grep for search for now, combine with fuzzy search buffer - try using git grep for search for now, combine with fuzzy search buffer
- Test stdin writing code - Test stdin writing code
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell) - Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
- open file from cmd
- detach from console when executing the program from the console to make sure that the user won't have to keep the cmd alive
- win32 open file with text editor from desktop
- drag and drop file into the window
- exe icon - exe icon
- search as a command to execute which is going to be in the title bar - search as a command to execute which is going to be in the title bar