/
manager.cpp
1318 lines (1139 loc) · 32.6 KB
/
manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
manager.cpp
Переключение между несколькими file panels, viewers, editors, dialogs
*/
/*
Copyright © 1996 Eugene Roshal
Copyright © 2000 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "headers.hpp"
#pragma hdrstop
#include "manager.hpp"
#include "keys.hpp"
#include "window.hpp"
#include "vmenu2.hpp"
#include "filepanels.hpp"
#include "panel.hpp"
#include "cmdline.hpp"
#include "ctrlobj.hpp"
#include "syslog.hpp"
#include "interf.hpp"
#include "keyboard.hpp"
#include "grabber.hpp"
#include "message.hpp"
#include "config.hpp"
#include "plist.hpp"
#include "pathmix.hpp"
#include "strmix.hpp"
#include "exitcode.hpp"
#include "scrbuf.hpp"
#include "DlgGuid.hpp"
#include "plugins.hpp"
#include "language.hpp"
#include "desktop.hpp"
#include "keybar.hpp"
#include "fileedit.hpp"
#include "scrsaver.hpp"
long Manager::CurrentWindowType=-1;
bool Manager::window_comparer::operator()(window_ptr_ref lhs, window_ptr_ref rhs) const
{
return lhs->ID() < rhs->ID();
}
void Manager::Key::Fill(unsigned int Key)
{
m_FarKey = Key;
m_EventFilled = KeyToInputRecord(m_FarKey, &m_Event);
assert(m_EventFilled);
}
Manager::Key::Key(int Key): m_Event(), m_FarKey(), m_EventFilled(false)
{
Fill(Key);
}
bool Manager::Key::IsReal(void)const
{
return m_FarKey!=KEY_IDLE && m_Event.EventType!=0;
}
Manager::Key& Manager::Key::operator=(unsigned int Key)
{
Fill(Key);
return *this;
}
Manager::Key& Manager::Key::operator&=(unsigned int Key)
{
assert(m_EventFilled);
Fill(m_FarKey&Key);
return *this;
}
static int CASHook(const Manager::Key& key)
{
if (key.IsEvent())
{
const KEY_EVENT_RECORD& rec=key.Event().Event.KeyEvent;
if (rec.bKeyDown)
{
switch (rec.wVirtualKeyCode)
{
case VK_SHIFT:
case VK_MENU:
case VK_CONTROL:
{
const auto
maskLeft=LEFT_CTRL_PRESSED|LEFT_ALT_PRESSED|SHIFT_PRESSED,
maskRight=RIGHT_CTRL_PRESSED|RIGHT_ALT_PRESSED|SHIFT_PRESSED;
const auto state = rec.dwControlKeyState;
const auto wait = [](DWORD mask)
{
for (;;)
{
INPUT_RECORD rec;
if (PeekInputRecord(&rec,true))
{
GetInputRecord(&rec,true,true);
if ((rec.Event.KeyEvent.dwControlKeyState&mask) != mask)
break;
}
Sleep(1);
}
};
const auto
case1 = Global->Opt->CASRule&1 && (state&maskLeft) == maskLeft,
case2 = Global->Opt->CASRule&2 && (state&maskRight) == maskRight;
if (case1 || case2)
{
const auto maskCurrent = case1?maskLeft:maskRight;
const auto currentWindow = Global->WindowManager->GetCurrentWindow();
if (currentWindow->CanFastHide())
{
int isPanelFocus=currentWindow->GetType() == windowtype_panels;
if (isPanelFocus)
{
const auto LeftVisible = Global->CtrlObject->Cp()->LeftPanel()->IsVisible();
const auto RightVisible = Global->CtrlObject->Cp()->RightPanel()->IsVisible();
const auto CmdLineVisible = Global->CtrlObject->CmdLine()->IsVisible();
const auto KeyBarVisible = Global->CtrlObject->Cp()->GetKeybar().IsVisible();
Manager::ShowBackground();
Global->CtrlObject->Cp()->LeftPanel()->HideButKeepSaveScreen();
Global->CtrlObject->Cp()->RightPanel()->HideButKeepSaveScreen();
switch (Global->Opt->PanelCtrlAltShiftRule)
{
case 0:
if (CmdLineVisible)
Global->CtrlObject->CmdLine()->Show();
if (KeyBarVisible)
Global->CtrlObject->Cp()->GetKeybar().Show();
break;
case 1:
if (KeyBarVisible)
Global->CtrlObject->Cp()->GetKeybar().Show();
break;
}
wait(maskCurrent);
if (LeftVisible) Global->CtrlObject->Cp()->LeftPanel()->Show();
if (RightVisible) Global->CtrlObject->Cp()->RightPanel()->Show();
if (CmdLineVisible) Global->CtrlObject->CmdLine()->Show();
if (KeyBarVisible) Global->CtrlObject->Cp()->GetKeybar().Show();
}
else
{
Global->WindowManager->ImmediateHide();
wait(maskCurrent);
}
Global->WindowManager->RefreshWindow();
}
return TRUE;
}
break;
}
}
}
}
return FALSE;
}
static void RegisterCASHook(Manager& WindowManager)
{
static bool registered = false;
if (!registered)
{
WindowManager.AddGlobalKeyHandler(CASHook);
registered = true;
}
}
Manager::Manager():
m_currentWindow(nullptr),
EndLoop(false),
ModalExitCode(-1),
StartManager(false)
{
m_windows.reserve(1024);
m_modalWindows.reserve(1024);
RegisterCASHook(*this);
}
Manager::~Manager()
{
}
/* $ 29.12.2000 IS
Аналог CloseAll, но разрешает продолжение полноценной работы в фаре,
если пользователь продолжил редактировать файл.
Возвращает TRUE, если все закрыли и можно выходить из фара.
*/
BOOL Manager::ExitAll()
{
_MANAGER(CleverSysLog clv(L"Manager::ExitAll()"));
// BUGBUG don't use iterators here, may be invalidated by DeleteCommit()
for(size_t i = m_modalWindows.size(); i; --i)
{
if (i - 1 >= m_modalWindows.size())
continue;
const auto CurrentWindow = m_modalWindows[i - 1];
if (!CurrentWindow->GetCanLoseFocus(TRUE))
{
const auto PrevWindowCount = m_modalWindows.size();
CurrentWindow->ProcessKey(Manager::Key(KEY_ESC));
Commit();
if (PrevWindowCount == m_modalWindows.size())
{
return FALSE;
}
}
}
// BUGBUG don't use iterators here, may be invalidated by DeleteCommit()
for(size_t i = m_windows.size(); i; --i)
{
if (i - 1 >= m_windows.size())
continue;
const auto CurrentWindow = m_windows[i - 1];
if (!CurrentWindow->GetCanLoseFocus(TRUE))
{
ActivateWindow(CurrentWindow);
Commit();
const auto PrevWindoowCount = m_windows.size();
CurrentWindow->ProcessKey(Manager::Key(KEY_ESC));
Commit();
if (PrevWindoowCount == m_windows.size())
{
return FALSE;
}
}
}
return TRUE;
}
void Manager::RefreshAll()
{
if (!m_windows.empty())
{
RefreshWindow(m_windows.front());
}
}
void Manager::CloseAll()
{
_MANAGER(CleverSysLog clv(L"Manager::CloseAll()"));
while(!m_modalWindows.empty())
{
DeleteWindow(m_modalWindows.back());
Commit();
}
while(!m_windows.empty())
{
DeleteWindow(m_windows.back());
Commit();
}
m_windows.clear();
}
void Manager::PushWindow(window_ptr_ref Param, window_callback Callback)
{
m_Queue.emplace([=]{ (this->*Callback)(Param); });
}
void Manager::CheckAndPushWindow(window_ptr_ref Param, window_callback Callback)
{
//assert(Param);
if (Param&&!Param->IsDeleting()) PushWindow(Param,Callback);
}
void Manager::CallbackWindow(const std::function<void(void)>& Callback)
{
m_Queue.emplace(Callback);
}
void Manager::InsertWindow(window_ptr_ref Inserted)
{
_MANAGER(CleverSysLog clv(L"Manager::InsertWindow(window *Inserted, int Index)"));
_MANAGER(SysLog(L"Inserted=%p, Index=%i",Inserted, Index));
CheckAndPushWindow(Inserted,&Manager::InsertCommit);
}
void Manager::DeleteWindow(window_ptr_ref Deleted)
{
_MANAGER(CleverSysLog clv(L"Manager::DeleteWindow(window *Deleted)"));
_MANAGER(SysLog(L"Deleted=%p",Deleted));
const auto& Window=Deleted?Deleted:m_currentWindow;
assert(Window);
CheckAndPushWindow(Window,&Manager::DeleteCommit);
Window->SetDeleting();
}
void Manager::RedeleteWindow(window_ptr_ref Deleted)
{
m_Queue.emplace(nullptr);
PushWindow(Deleted,&Manager::DeleteCommit);
}
void Manager::ExecuteNonModal(window_ptr_ref NonModal)
{
_MANAGER(CleverSysLog clv(L"Manager::ExecuteNonModal ()"));
if (!NonModal) return;
for (;;)
{
Commit();
if (m_currentWindow!=NonModal || EndLoop)
{
break;
}
ProcessMainLoop();
}
}
void Manager::ExecuteModal(window_ptr_ref Executed)
{
_MANAGER(CleverSysLog clv(L"Manager::ExecuteModal (window *Executed)"));
_MANAGER(SysLog(L"Executed=%p",Executed));
bool stop=false;
auto& stop_ref=m_Executed[Executed];
if (stop_ref) return;
stop_ref=&stop;
const auto OriginalStartManager = StartManager;
StartManager = true;
for (;;)
{
Commit();
if (stop)
{
break;
}
ProcessMainLoop();
}
StartManager = OriginalStartManager;
return;// GetModalExitCode();
}
int Manager::GetModalExitCode() const
{
return ModalExitCode;
}
/* $ 11.10.2001 IS
Подсчитать количество окон с указанным именем.
*/
int Manager::CountWindowsWithName(const string& Name, BOOL IgnoreCase)
{
typedef int (*CompareFunction)(const string&, const string&);
CompareFunction CaseSenitive = StrCmp, CaseInsensitive = StrCmpI;
CompareFunction CmpFunction = IgnoreCase? CaseInsensitive : CaseSenitive;
string strType, strCurName;
return std::count_if(CONST_RANGE(m_windows, i)
{
i->GetTypeAndName(strType, strCurName);
return !CmpFunction(Name, strCurName);
});
}
/*!
\return Возвращает nullptr если нажат "отказ" или если нажато текущее окно.
Другими словами, если немодальное окно не поменялось.
Если же поменялось, то тогда функция должна возвратить
указатель на предыдущее окно.
*/
window_ptr Manager::WindowMenu()
{
/* $ 28.04.2002 KM
Флаг для определения того, что меню переключения
экранов уже активировано.
*/
static int AlreadyShown=FALSE;
if (AlreadyShown)
return nullptr;
int ExitCode, CheckCanLoseFocus=m_currentWindow->GetCanLoseFocus();
{
const auto ModalMenu = VMenu2::create(MSG(MScreensTitle), nullptr, 0, ScrY - 4);
ModalMenu->SetHelp(L"ScrSwitch");
ModalMenu->SetMenuFlags(VMENU_WRAPMODE);
ModalMenu->SetPosition(-1,-1,0,0);
ModalMenu->SetId(ScreensSwitchId);
size_t n = 0;
const auto windows = GetSortedWindows();
std::for_each(CONST_RANGE(windows, i)
{
string strType, strName, strNumText;
i->GetTypeAndName(strType, strName);
MenuItemEx ModalMenuItem;
if (n < 10)
strNumText = string_format(L"&%1. ", n);
else if (n < 36)
strNumText = string_format(L"&%1. ", wchar_t(L'A' + n - 10));
else
strNumText = L"& ";
//TruncPathStr(strName,ScrX-24);
ReplaceStrings(strName, L"&", L"&&");
/* добавляется "*" если файл изменен */
ModalMenuItem.strName = str_printf(L"%s%-10.10s %c %s", strNumText.data(), strType.data(),(i->IsFileModified()?L'*':L' '), strName.data());
const auto tmp = i.get();
ModalMenuItem.UserData = tmp;
ModalMenuItem.SetSelect(i==m_windows.back());
ModalMenu->AddItem(ModalMenuItem);
++n;
});
AlreadyShown=TRUE;
ExitCode=ModalMenu->Run();
AlreadyShown=FALSE;
if (CheckCanLoseFocus)
{
if (ExitCode>=0)
{
const auto ActivatedWindow = *ModalMenu->GetUserDataPtr<window*>(ExitCode);
ActivateWindow(ActivatedWindow->shared_from_this());
return (ActivatedWindow == m_currentWindow.get() || !m_currentWindow->GetCanLoseFocus())? nullptr : m_currentWindow;
}
}
}
return nullptr;
}
int Manager::GetWindowCountByType(int Type)
{
return std::count_if(CONST_RANGE(m_windows, i)
{
return !i->IsDeleting() && i->GetExitCode() != XC_QUIT && i->GetType() == Type;
});
}
/*$ 11.05.2001 OT Теперь можно искать файл не только по полному имени, но и отдельно - путь, отдельно имя */
window_ptr Manager::FindWindowByFile(int ModalType,const string& FileName, const wchar_t *Dir)
{
string strBufFileName;
string strFullFileName = FileName;
if (Dir)
{
strBufFileName = Dir;
AddEndSlash(strBufFileName);
strBufFileName += FileName;
strFullFileName = strBufFileName;
}
const auto ItemIterator = std::find_if(CONST_RANGE(m_windows, i)
{
string strType, strName;
// Mantis#0000469 - получать Name будем только при совпадении ModalType
if (!i->IsDeleting() && i->GetType() == ModalType)
{
i->GetTypeAndName(strType, strName);
if (!StrCmpI(strName, strFullFileName))
return true;
}
return false;
});
return ItemIterator == m_windows.cend()? nullptr : *ItemIterator;
}
bool Manager::ShowBackground()
{
Global->CtrlObject->Desktop->Show();
return true;
}
void Manager::ActivateWindow(window_ptr_ref Activated)
{
_MANAGER(CleverSysLog clv(L"Manager::ActivateWindow(window *Activated)"));
_MANAGER(SysLog(L"Activated=%i",Activated));
if (Activated) CheckAndPushWindow(Activated,&Manager::ActivateCommit);
}
void Manager::SwitchWindow(DirectionType Direction)
{
const auto windows = GetSortedWindows();
auto pos = windows.find(m_windows.back());
const auto process = [&, this]()
{
if (Direction==Manager::NextWindow)
{
++pos;
if (pos==windows.end()) pos = windows.begin();
}
else if (Direction==Manager::PreviousWindow)
{
if (pos==windows.begin()) pos=windows.end();
--pos;
}
};
process();
// For now we don't want to switch to the desktop window with Ctrl-[Shift-]Tab
if (std::dynamic_pointer_cast<desktop>(*pos))
process();
ActivateWindow(*pos);
}
void Manager::RefreshWindow(window_ptr_ref Refreshed)
{
_MANAGER(CleverSysLog clv(L"Manager::RefreshWindow(window *Refreshed)"));
_MANAGER(SysLog(L"Refreshed=%p",Refreshed));
CheckAndPushWindow(Refreshed?Refreshed:m_currentWindow,&Manager::RefreshCommit);
}
void Manager::ExecuteWindow(window_ptr_ref Executed)
{
_MANAGER(CleverSysLog clv(L"Manager::ExecuteWindow(window *Executed)"));
_MANAGER(SysLog(L"Executed=%p",Executed));
CheckAndPushWindow(Executed,&Manager::ExecuteCommit);
}
void Manager::ReplaceWindow(window_ptr_ref Old, window_ptr_ref New)
{
m_Queue.emplace([=]{ ReplaceCommit(Old, New); });
}
void Manager::SubmergeWindow(window_ptr_ref Window)
{
CheckAndPushWindow(Window, &Manager::SubmergeCommit);
}
void Manager::SwitchToPanels()
{
_MANAGER(CleverSysLog clv(L"Manager::SwitchToPanels()"));
if (!Global->OnlyEditorViewerUsed)
{
const auto PanelsWindow = std::find_if(ALL_CONST_RANGE(m_windows), [](const auto& item) { return std::dynamic_pointer_cast<FilePanels>(item) != nullptr; });
if (PanelsWindow != m_windows.cend())
{
ActivateWindow(*PanelsWindow);
}
}
}
bool Manager::HaveAnyWindow() const
{
return !m_windows.empty() || !m_Queue.empty() || m_currentWindow;
}
bool Manager::OnlyDesktop() const
{
return m_windows.size() == 1 && m_Queue.empty();
}
bool Manager::HaveAnyMessage() const
{
return !m_Queue.empty();
}
void Manager::EnterMainLoop()
{
Global->WaitInFastFind=0;
StartManager = true;
for (;;)
{
Commit();
if (EndLoop || (!HaveAnyWindow() || OnlyDesktop()))
{
break;
}
ProcessMainLoop();
}
}
void Manager::ProcessMainLoop()
{
if ( m_currentWindow && !m_currentWindow->ProcessEvents() )
{
ProcessKey(Manager::Key(KEY_IDLE));
}
else
{
// Mantis#0000073: Не работает автоскролинг в QView
Global->WaitInMainLoop=IsPanelsActive(true);
//WaitInFastFind++;
INPUT_RECORD rec;
int Key=GetInputRecord(&rec);
//WaitInFastFind--;
Global->WaitInMainLoop=FALSE;
if (EndLoop)
return;
if (rec.EventType==MOUSE_EVENT && !(Key==KEY_MSWHEEL_UP || Key==KEY_MSWHEEL_DOWN || Key==KEY_MSWHEEL_RIGHT || Key==KEY_MSWHEEL_LEFT))
{
// используем копию структуры, т.к. LastInputRecord может внезапно измениться во время выполнения ProcessMouse
MOUSE_EVENT_RECORD mer=rec.Event.MouseEvent;
ProcessMouse(&mer);
}
else
ProcessKey(Manager::Key(Key, rec));
}
if(IsPanelsActive())
{
if(!Global->PluginPanelsCount)
{
Global->CtrlObject->Plugins->RefreshPluginsList();
}
}
}
void Manager::ExitMainLoop(int Ask)
{
if (Global->CloseFAR)
{
Global->CloseFARMenu=TRUE;
};
if (!Ask || !Global->Opt->Confirm.Exit || Message(0, MSG(MQuit),
make_vector<string>(MSG(MAskQuit)),
make_vector<string>(MSG(MYes), MSG(MNo)),
nullptr, nullptr, &FarAskQuitId) == Message::first_button)
{
/* $ 29.12.2000 IS
+ Проверяем, сохранены ли все измененные файлы. Если нет, то не выходим
из фара.
*/
if (ExitAll() || Global->CloseFAR)
{
const auto cp = Global->CtrlObject->Cp();
if (!cp || (!cp->LeftPanel()->ProcessPluginEvent(FE_CLOSE, nullptr) && !cp->RightPanel()->ProcessPluginEvent(FE_CLOSE, nullptr)))
EndLoop=true;
}
else
{
Global->CloseFARMenu=FALSE;
}
}
}
void Manager::AddGlobalKeyHandler(const std::function<int(const Key&)>& Handler)
{
m_GlobalKeyHandlers.emplace_back(Handler);
}
int Manager::ProcessKey(Key key)
{
if (m_currentWindow)
{
/*** БЛОК ПРИВИЛЕГИРОВАННЫХ КЛАВИШ ! ***/
/*** КОТОРЫЕ НЕЛЬЗЯ НАМАКРОСИТЬ ***/
switch (key())
{
case KEY_ALT|KEY_NUMPAD0:
case KEY_RALT|KEY_NUMPAD0:
case KEY_ALTINS:
case KEY_RALTINS:
{
RunGraber();
return TRUE;
}
case KEY_CONSOLE_BUFFER_RESIZE:
Sleep(1);
ResizeAllWindows();
return TRUE;
}
/*** А вот здесь - все остальное! ***/
if (!Global->IsProcessAssignMacroKey)
{
if (std::any_of(CONST_RANGE(m_GlobalKeyHandlers, i) { return i(key); }))
{
return TRUE;
}
switch (key())
{
case KEY_CTRLW:
case KEY_RCTRLW:
ShowProcessList();
return TRUE;
case KEY_F11:
{
int WindowType = Global->WindowManager->GetCurrentWindow()->GetType();
static int reentry=0;
if(!reentry && (WindowType == windowtype_dialog || WindowType == windowtype_menu))
{
++reentry;
int r=m_currentWindow->ProcessKey(key);
--reentry;
return r;
}
PluginsMenu();
Global->WindowManager->RefreshWindow();
//_MANAGER(SysLog(-1));
return TRUE;
}
case KEY_ALTF9:
case KEY_RALTF9:
{
//_MANAGER(SysLog(1,"Manager::ProcessKey, KEY_ALTF9 pressed..."));
Sleep(1);
SetVideoMode();
Sleep(1);
/* В процессе исполнения Alt-F9 (в нормальном режиме) в очередь
консоли попадает WINDOW_BUFFER_SIZE_EVENT, формируется в
ChangeVideoMode().
В режиме исполнения макросов ЭТО не происходит по вполне понятным
причинам.
*/
if (Global->CtrlObject->Macro.IsExecuting())
{
int PScrX=ScrX;
int PScrY=ScrY;
Sleep(1);
GetVideoMode(CurSize);
if (PScrX+1 == CurSize.X && PScrY+1 == CurSize.Y)
{
//_MANAGER(SysLog(-1,"GetInputRecord(WINDOW_BUFFER_SIZE_EVENT); return KEY_NONE"));
return TRUE;
}
else
{
PrevScrX=PScrX;
PrevScrY=PScrY;
//_MANAGER(SysLog(-1,"GetInputRecord(WINDOW_BUFFER_SIZE_EVENT); return KEY_CONSOLE_BUFFER_RESIZE"));
Global->WindowManager->ResizeAllWindows();
return TRUE;
}
}
//_MANAGER(SysLog(-1));
return TRUE;
}
case KEY_F12:
{
if (!std::dynamic_pointer_cast<Modal>(Global->WindowManager->GetCurrentWindow()))
{
WindowMenu();
//_MANAGER(SysLog(-1));
return TRUE;
}
break; // отдадим F12 дальше по цепочке
}
case KEY_CTRLTAB:
case KEY_RCTRLTAB:
case KEY_CTRLSHIFTTAB:
case KEY_RCTRLSHIFTTAB:
if (m_currentWindow->GetCanLoseFocus())
{
SwitchWindow((key()==KEY_CTRLTAB||key()==KEY_RCTRLTAB)?NextWindow:PreviousWindow);
}
else
break;
_MANAGER(SysLog(-1));
return TRUE;
}
}
m_currentWindow->UpdateKeyBar();
m_currentWindow->ProcessKey(key);
}
_MANAGER(SysLog(-1));
return FALSE;
}
static bool FilterMouseMoveNoise(const MOUSE_EVENT_RECORD* MouseEvent)
{
static COORD LastPosition = {};
if (MouseEvent->dwEventFlags == MOUSE_MOVED && LastPosition.X == MouseEvent->dwMousePosition.X && LastPosition.Y == MouseEvent->dwMousePosition.Y)
{
return false;
}
LastPosition = MouseEvent->dwMousePosition;
return true;
}
int Manager::ProcessMouse(const MOUSE_EVENT_RECORD *MouseEvent)
{
int ret=FALSE;
if (!MouseEvent->dwMousePosition.Y && MouseEvent->dwMousePosition.X == ScrX)
{
if (Global->Opt->ScreenSaver && !(MouseEvent->dwButtonState & 3))
{
ScreenSaver();
return TRUE;
}
}
if (m_currentWindow && FilterMouseMoveNoise(MouseEvent))
ret=m_currentWindow->ProcessMouse(MouseEvent);
_MANAGER(SysLog(-1));
return ret;
}
void Manager::PluginsMenu() const
{
_MANAGER(SysLog(1));
int curType = m_currentWindow->GetType();
if (curType == windowtype_panels || curType == windowtype_editor || curType == windowtype_viewer || curType == windowtype_dialog || curType == windowtype_menu)
{
/* 02.01.2002 IS
! Вывод правильной помощи по Shift-F1 в меню плагинов в редакторе/viewer-е/диалоге
! Если на панели QVIEW или INFO открыт файл, то считаем, что это
полноценный viewer и запускаем с соответствующим параметром плагины
*/
if (curType==windowtype_panels)
{
const auto pType = Global->CtrlObject->Cp()->ActivePanel()->GetType();
if (pType == panel_type::QVIEW_PANEL || pType == panel_type::INFO_PANEL)
{
string strType, strCurFileName;
Global->CtrlObject->Cp()->GetTypeAndName(strType, strCurFileName);
if (!strCurFileName.empty())
{
// интересуют только обычные файлы
if (os::fs::is_file(strCurFileName))
curType=windowtype_viewer;
}
}
}
// в редакторе, viewer-е или диалоге покажем свою помощь по Shift-F1
const wchar_t *Topic=curType==windowtype_editor?L"Editor":
curType==windowtype_viewer?L"Viewer":
curType==windowtype_dialog?L"Dialog":nullptr;
Global->CtrlObject->Plugins->CommandsMenu(curType,0,Topic);
}
_MANAGER(SysLog(-1));
}
bool Manager::IsPanelsActive(bool and_not_qview) const
{
if (!m_windows.empty() && m_currentWindow)
{
const auto fp = std::dynamic_pointer_cast<FilePanels>(m_currentWindow);
return fp && (!and_not_qview || fp->ActivePanel()->GetType() != panel_type::QVIEW_PANEL);
}
else
{
return false;
}
}
window_ptr Manager::GetWindow(size_t Index) const
{
if (Index >= m_windows.size() || m_windows.empty())
{
return nullptr;
}
return m_windows[Index];
}
int Manager::IndexOfStack(window_ptr_ref Window)
{
const auto ItemIterator = std::find(ALL_CONST_RANGE(m_modalWindows), Window);
return ItemIterator != m_modalWindows.cend()? ItemIterator - m_modalWindows.cbegin() : -1;
}
int Manager::IndexOf(window_ptr_ref Window)
{
const auto ItemIterator = std::find(ALL_CONST_RANGE(m_windows), Window);
return ItemIterator != m_windows.cend() ? ItemIterator - m_windows.cbegin() : -1;
}
void Manager::Commit(void)
{
_MANAGER(CleverSysLog clv(L"Manager::Commit()"));
_MANAGER(ManagerClass_Dump(L"ManagerClass"));
while (!m_Queue.empty())
{
const auto Handler = std::move(m_Queue.front());
m_Queue.pop();
if (!Handler)
break;
Handler();
}
}
void Manager::InsertCommit(window_ptr_ref Param)
{
_MANAGER(CleverSysLog clv(L"Manager::InsertCommit()"));
_MANAGER(SysLog(L"InsertedWindow=%p",Param));
if (Param && AddWindow(Param))
{
m_windows.emplace_back(Param);
ActivateCommit(Param);
}
}
void Manager::DeleteCommit(window_ptr_ref Param)
{
_MANAGER(CleverSysLog clv(L"Manager::DeleteCommit()"));
_MANAGER(SysLog(L"DeletedWindow=%p",Param));
if (!Param)
return;
if (Param->IsPinned())
{
RedeleteWindow(Param);
return;
}
if (m_currentWindow==Param) DeactivateCommit(Param);
Param->OnDestroy();
int ModalIndex=IndexOfStack(Param);
int WindowIndex=IndexOf(Param);
assert(!(-1!=ModalIndex&&-1!=WindowIndex));
const auto ClearCurrentWindow = [this]
{
m_currentWindow = nullptr;
InterlockedExchange(&CurrentWindowType,-1);
};
if (ModalIndex!=-1)
{
m_modalWindows.erase(m_modalWindows.begin() + ModalIndex);
if (m_currentWindow==Param)
{
if (!m_modalWindows.empty())
{
const auto PtrCopy = m_modalWindows.back();
ActivateCommit(PtrCopy);
}
else if (!m_windows.empty())
{
const auto PtrCopy = m_windows.back();
ActivateCommit(PtrCopy);
}