Add icon and drop file event
This commit is contained in:
@@ -153,10 +153,15 @@ int CompileTextEditor() {
|
||||
// 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);
|
||||
For(libs) For2(o, it.objects) cmd.add(o);
|
||||
cmd.add("icon.res");
|
||||
|
||||
OS_DeleteFile("te.pdb");
|
||||
// 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);
|
||||
return result;
|
||||
}
|
||||
|
||||
BIN
data/icon.ico
Normal file
BIN
data/icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
1
data/icon.rc
Normal file
1
data/icon.rc
Normal file
@@ -0,0 +1 @@
|
||||
id ICON "icon.ico"
|
||||
@@ -17,9 +17,9 @@ enum EventKind {
|
||||
|
||||
EVENT_KEY_PRESS,
|
||||
EVENT_TEXT_INPUT,
|
||||
};
|
||||
|
||||
bool IsMouseEvent(EventKind kind) { return kind >= EVENT_MOUSE_LEFT && kind <= EVENT_MOUSE_MOVE; }
|
||||
EVENT_DROP_FILE,
|
||||
};
|
||||
|
||||
struct Event {
|
||||
EventKind kind;
|
||||
@@ -39,6 +39,8 @@ struct Event {
|
||||
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_LEFT = 1;
|
||||
const int DIR_DOWN = 2;
|
||||
|
||||
@@ -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)) {
|
||||
Command_DuplicateLine(view, DIR_DOWN);
|
||||
} else if (AltShift(SDLK_DOWN)) {
|
||||
@@ -732,7 +736,7 @@ void WindowCommand(Event event, Window *window, View *view) {
|
||||
search = true;
|
||||
}
|
||||
|
||||
if (event.text) {
|
||||
if (event.kind == EVENT_TEXT_INPUT) {
|
||||
Scratch scratch;
|
||||
String string = event.text;
|
||||
String16 string16 = ToString16(scratch, string);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
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() {
|
||||
Scratch scratch;
|
||||
int64_t buffer_size = 4096;
|
||||
|
||||
@@ -82,7 +82,8 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
||||
case SDL_EVENT_TEXT_INPUT: {
|
||||
event.kind = EVENT_TEXT_INPUT;
|
||||
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;
|
||||
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||
@@ -131,6 +132,21 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
||||
// SDL_MouseMotionEvent &b = input_event->motion;
|
||||
} 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: {
|
||||
};
|
||||
}
|
||||
@@ -218,9 +234,13 @@ Array<Event> GetEventsForFrame(Allocator allocator) {
|
||||
#if _WIN32
|
||||
int WinMain(void *hInstance, void *hPrevInstance, const char *lpCmdLine, int nShowCmd)
|
||||
#else
|
||||
int main()
|
||||
int main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
#if _WIN32
|
||||
int argc = __argc;
|
||||
char **argv = __argv;
|
||||
#endif
|
||||
BeginProfiler();
|
||||
|
||||
InitScratch();
|
||||
@@ -291,6 +311,7 @@ int main()
|
||||
}
|
||||
|
||||
SDL_StartTextInput(SDLWindow);
|
||||
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, true);
|
||||
SDL_GL_SetSwapInterval(1); // vsync
|
||||
{
|
||||
float scale = SDL_GetWindowDisplayScale(SDLWindow);
|
||||
@@ -304,6 +325,12 @@ int main()
|
||||
InitLuaConfig();
|
||||
InitWindows();
|
||||
|
||||
for (int i = 1; i < argc; i += 1) {
|
||||
String it = argv[i];
|
||||
Window *window = GetWindow({0});
|
||||
WindowOpenBufferView(window, it);
|
||||
}
|
||||
|
||||
while (AppIsRunning) {
|
||||
FrameID += 1;
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
- 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
|
||||
- if exec is prepended with '!' symbol then run a shell command
|
||||
- try using git grep for search for now, combine with fuzzy search buffer
|
||||
- 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)
|
||||
|
||||
- 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
|
||||
|
||||
- search as a command to execute which is going to be in the title bar
|
||||
|
||||
Reference in New Issue
Block a user