1 parent
1dd6d75596
commit
293c5fd47e
7 files changed
+72
-1
No files matched your search
@@ -636,6 +636,8 @@ struct RemoteTextFile
|
||||
|
||||
class TextWindow;
|
||||
std::map<HWND,std::shared_ptr<TextWindow>> textWindows;
|
||||
std::vector<HWND> textWindowOrder;
|
||||
HWND filesOwner{};
|
||||
bool textOwnerClosed=false;
|
||||
constexpr ULONG_PTR openDocumentQuery=0x4B534644;
|
||||
|
||||
@@ -812,6 +814,7 @@ private:
|
||||
static constexpr UINT previewFailed = WM_APP + 2;
|
||||
static constexpr UINT openPreviewLink = WM_APP + 3;
|
||||
static constexpr UINT previewRendered = WM_APP + 4;
|
||||
static constexpr UINT cycleWindow = WM_APP + 5;
|
||||
|
||||
LRESULT send(UINT message, WPARAM wparam = 0, LPARAM lparam = 0) const
|
||||
{
|
||||
@@ -1471,6 +1474,11 @@ void TextWindow::updatePreview()
|
||||
{
|
||||
const bool ctrl=(GetKeyState(VK_CONTROL)&0x8000)!=0;
|
||||
const bool alt=(GetKeyState(VK_MENU)&0x8000)!=0;
|
||||
if(ctrl && !alt && key==VK_TAB)
|
||||
{
|
||||
PostMessageW(window,cycleWindow,0,0);
|
||||
return true;
|
||||
}
|
||||
if(key==VK_BROWSER_BACK || key==VK_BROWSER_FORWARD || (alt && (key==VK_LEFT || key==VK_RIGHT)))
|
||||
{
|
||||
PostMessageW(window,WM_COMMAND,key==VK_LEFT || key==VK_BROWSER_BACK?historyBack:historyForward,0);
|
||||
@@ -1590,6 +1598,11 @@ void TextWindow::previewMessage(const std::wstring &value)
|
||||
}
|
||||
const auto message=nlohmann::json::parse(utf8(value));
|
||||
const auto action=message.at("action").get<std::string>();
|
||||
if(action=="cycle")
|
||||
{
|
||||
PostMessageW(window,cycleWindow,0,0);
|
||||
return;
|
||||
}
|
||||
if(action=="failed")
|
||||
{
|
||||
PostMessageW(window,previewFailed,0,0);
|
||||
@@ -2030,6 +2043,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
|
||||
const auto &state=*static_cast<const std::shared_ptr<TextWindow> *>(create->lpCreateParams);
|
||||
state->window=window;
|
||||
textWindows.emplace(window,state);
|
||||
textWindowOrder.push_back(window);
|
||||
}
|
||||
const auto found=textWindows.find(window);
|
||||
if(found==textWindows.end()) return DefWindowProcW(window,message,wparam,lparam);
|
||||
@@ -2105,6 +2119,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
|
||||
return 0;
|
||||
}
|
||||
case WM_SETFOCUS: self->focusContent(); return 0;
|
||||
case cycleWindow: cycleTextWindows(window); return 0;
|
||||
case WM_KEYDOWN:
|
||||
if(self->previewWanted && !self->previewVisible)
|
||||
{
|
||||
@@ -2181,6 +2196,7 @@ LRESULT CALLBACK TextWindow::procedure(HWND window, UINT message, WPARAM wparam,
|
||||
case WM_NCDESTROY:
|
||||
self->window=nullptr;
|
||||
textWindows.erase(window);
|
||||
std::erase(textWindowOrder,window);
|
||||
if(textOwnerClosed && textWindows.empty()) PostQuitMessage(0);
|
||||
break;
|
||||
}
|
||||
@@ -2296,10 +2312,29 @@ void showFarHistory(HWND dialog,int fieldId,const std::vector<FarHistoryEntry> &
|
||||
|
||||
void textWindowOwnerClosed()
|
||||
{
|
||||
filesOwner=nullptr;
|
||||
textOwnerClosed=true;
|
||||
if(textWindows.empty()) PostQuitMessage(0);
|
||||
}
|
||||
|
||||
bool cycleTextWindows(HWND current)
|
||||
{
|
||||
if(!current || (current!=filesOwner && !textWindows.contains(current))) return false;
|
||||
std::vector<HWND> windows;
|
||||
if(filesOwner && IsWindowVisible(filesOwner)) windows.push_back(filesOwner);
|
||||
for(const auto window:textWindowOrder)
|
||||
if(IsWindowVisible(window)) windows.push_back(window);
|
||||
if(windows.size()<2) return false;
|
||||
const auto from=std::find(windows.begin(),windows.end(),current);
|
||||
if(from==windows.end()) return false;
|
||||
auto to=std::next(from);
|
||||
if(to==windows.end()) to=windows.begin();
|
||||
if(IsIconic(*to)) ShowWindow(*to,SW_RESTORE);
|
||||
SetForegroundWindow(*to);
|
||||
if(*to!=filesOwner) SendMessageW(*to,WM_SETFOCUS,0,0);
|
||||
return true;
|
||||
}
|
||||
|
||||
HWND findOpenDocument(const std::filesystem::path &path,const lan::FilesPeer *peer)
|
||||
{
|
||||
const auto identity=documentIdentity(path,peer?peer->id:"");
|
||||
@@ -2331,6 +2366,7 @@ void openTextWindow(HWND owner,const std::filesystem::path &path,bool edit,TextD
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!textWindows.contains(owner)) filesOwner=owner;
|
||||
std::error_code error;
|
||||
const auto identity=peer?path.lexically_normal():std::filesystem::weakly_canonical(path,error);
|
||||
const auto &original=error?path:identity;
|
||||
|
||||
Reference in new issue
Block a user