Skip to content

Commit

Permalink
添加第1项为路径名字
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnux committed Nov 16, 2022
1 parent 223a855 commit b73e176
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@
```
(pop-select/popup-shell-menu PATH X Y)
```
PATH即路径,目录/文件都可以,X、Y即屏幕座标,如何都是0,那么会在当前鼠标指针位置弹出。
我是拿来配合dired使用
PATH即路径,目录/文件都可以,X、Y即屏幕座标,如何都是0,那么会在当前鼠标指针位置弹出。额外添加第1项为路径的文件名。
TODO: 点击空白处目前不会消失。
8 changes: 8 additions & 0 deletions src/ShellMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.h>
#include <commctrl.h>
#include "shellmenu.h"
#include <Shlwapi.h>

//-----------------------------------------------------------------------------
// Name: CShellMenu
Expand Down Expand Up @@ -70,6 +71,10 @@ CShellMenu::CShellMenu(HWND hWndDialog,int SpecialFolderCSIDL,BOOL bFolderBackgr
//-----------------------------------------------------------------------------
CShellMenu::CShellMenu(HWND hWndDialog,TCHAR* FileOrDirectoryPath)
{
name_ = FileOrDirectoryPath;
std::wstring temp = PathFindFileNameW(name_.c_str());
name_.swap(temp);

this->CommonConstructor(hWndDialog);
this->bFillMenuSuccess=this->FillMenu(FileOrDirectoryPath);
}
Expand Down Expand Up @@ -471,6 +476,9 @@ BOOL CShellMenu::Show(int x,int y)
// add window subclassing
this->SubClassWindowProc();

InsertMenu(this->hPopUpMenu, 0, 0x0400|0x800, 2, 0);
InsertMenu(this->hPopUpMenu, 0, 0x0400|0x002, 1, name_.c_str());

// show popupmenu
CmdId=(UINT)::TrackPopupMenuEx(this->hPopUpMenu,TPM_LEFTALIGN|TPM_RETURNCMD,x,y,this->hWndDialog,NULL);

Expand Down
2 changes: 2 additions & 0 deletions src/ShellMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#pragma warning (pop)
#include <shlobj.h>
#include <commctrl.h>
#include <string> // atlstr.h不行,rust编译也看不到错误
#pragma comment (lib,"comctl32.lib")

#define CShellMenu_idCmdFirst 0xF000// Cmd must be on WORD see CMINVOKECOMMANDINFO.lpVerb
Expand All @@ -48,6 +49,7 @@ class CShellMenu
IContextMenu* pContextMenu;
IContextMenu2* pContextMenu2;
IContextMenu3* pContextMenu3;
std::wstring name_;

void CommonConstructor(HWND hWndDialog);
BOOL SubClassWindowProc();
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn ensure_all_window_dark_mode() -> Result<usize> {
}

#[defun]
fn popup_shell_menu(path: String, x: usize, y: usize) -> Result<usize> {
fn popup_shell_menu(path: String, x: i32, y: i32) -> Result<usize> {
if let Err(e) = crate::shellmenu::pop_shell_menu(path, x, y) {
let es = format!("popup_shell_menu error: {}", e);
let esw = to_wstring(&es);
Expand Down
4 changes: 2 additions & 2 deletions src/shellmenu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern "C" {
fn PopupShellMenu(h: winapi::shared::windef::HWND, path: LPCWSTR, x: i32, y: i32);
}

pub fn pop_shell_menu(path: String, x: usize, y: usize) -> Result<(), NwgError> {
pub fn pop_shell_menu(path: String, x: i32, y: i32) -> Result<(), NwgError> {
// use winapi::um::winuser::GetForegroundWindow;
// let h = GetForegroundWindow();
// 测试发现SetWindowSubclass跨线程不会成功,因为emacs module的运行线程不是gui线程。所以这里需要跟ctrl+tab那样的处理机制。
Expand All @@ -26,7 +26,7 @@ pub fn pop_shell_menu(path: String, x: usize, y: usize) -> Result<(), NwgError>
if msg == (WM_USER + 1) {
unsafe {
let p = crate::to_wstring(&path);
PopupShellMenu(hwnd, p.as_ptr(), x as i32, y as i32);
PopupShellMenu(hwnd, p.as_ptr(), x, y);
}
nwg::stop_thread_dispatch();
}
Expand Down

0 comments on commit b73e176

Please sign in to comment.