Skip to content

Commit

Permalink
Support multiple files in a single drag
Browse files Browse the repository at this point in the history
  • Loading branch information
RMichelsen committed Nov 20, 2020
1 parent 99a3dfb commit 07725aa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,11 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} return 0;
case WM_DROPFILES: {
char file_to_open[MAX_PATH];
DragQueryFileA(reinterpret_cast<HDROP>(wparam), 0, file_to_open, MAX_PATH);
NvimOpenFile(context->nvim, file_to_open);
uint32_t num_files = DragQueryFileA(reinterpret_cast<HDROP>(wparam), 0xFFFFFFFF, file_to_open, MAX_PATH);
for(int i = 0; i < num_files; ++i) {
DragQueryFileA(reinterpret_cast<HDROP>(wparam), i, file_to_open, MAX_PATH);
NvimOpenFile(context->nvim, file_to_open);
}
} return 0;
}

Expand Down

5 comments on commit 07725aa

@imbear
Copy link

@imbear imbear commented on 07725aa Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use unicode api better:

		wchar_t file_to_open[MAX_PATH];
		char file_to_open_u8[MAX_PATH];
		uint32_t num_files = DragQueryFileW(reinterpret_cast<HDROP>(wparam), 0xFFFFFFFF, NULL, MAX_PATH);
		for(int i = 0; i < num_files; ++i) {
			DragQueryFileW(reinterpret_cast<HDROP>(wparam), i, file_to_open, MAX_PATH);
			int bytes = WideCharToMultiByte(CP_UTF8, 0, file_to_open, -1, NULL, 0, NULL, NULL);
			WideCharToMultiByte(CP_UTF8, 0, file_to_open, -1, file_to_open_u8, bytes, NULL, NULL);
			NvimOpenFile(context->nvim, file_to_open_u8);
		}

@RMichelsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since nvim takes a utf8 string I don't see the benefits of this? I think the Win32 API does the utf8 conversion itself when you call the old DragQueryFileA version?

@imbear
Copy link

@imbear imbear commented on 07725aa Nov 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run nvy under win10 home chinese version.

By DragQueryFileA, a chinese file name(for example "文本文档.txt") will make NvimOpenFile open file failed.

nvy

@RMichelsen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see, did you compile and see if it works with the WideCharToMultiByte transformation you mentioned?

@imbear
Copy link

@imbear imbear commented on 07725aa Nov 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebuild nvy as I mentioned, it seemed work well.

Please sign in to comment.