forked from brzozi/harbour-commander
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hc.prg
2957 lines (2181 loc) · 90.6 KB
/
hc.prg
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
/* Copyright 2017-2019 Rafał Jopek ( rafaljopek at hotmail com ) */
/* Harbour Commander */
#include "box.ch"
#include "directry.ch"
#include "fileio.ch"
#include "hbgtinfo.ch"
#include "inkey.ch"
#include "setcurs.ch"
#define DIR_PREFIX( v ) iif( "D" $ v[ F_ATTR ], "A", "B" )
#if defined( __PLATFORM__WINDOWS )
#define OSUPPER( x ) Upper( x )
#else
#define OSUPPER( x ) ( x )
#endif
#define _nTop 1
#define _nLeft 2
#define _nBottom 3
#define _nRight 4
#define _cCurrentDir 5
#define _aDirectory 6
#define _nRowBar 7
#define _nRowNo 8
#define _cComdLine 9
#define _nComdCol 10
#define _nComdColNo 11
#define _nIdPanel 12
#define _nWinHndl 13
#define _nElements 13
STATIC aConfig
#define _nElementConfig 6
#define _aStackWindow 1
#define _nMaxRow 2 // here save MaxRow() of physical screen
#define _nMaxCol 3 // here save MaxCol() of physical screen
#define nCmdHndl 4 // handle of window for cmd
#define aCmdHist 5 // command's history
#define nBBarHndl 6 // handle of window for bottom bar
/* FError() */
#define MEANING 2
#define F_STATUS 6 /* select file, directory */
#define FXO_SHARELOCK 0x4000 /* emulate DOS SH_DENY* mode in POSIX OS */
STATIC aWinStack
#define nWinSession 1
#define GetSession aWinStack[ nWinSession ]
#define GetPanels aWinStack[ GetSession ]
#define GetPanelActive aWinStack[ GetSession, GetPanels[ idPanelActive ] ]
#define SetPanelActive( xId ) GetPanels[ idPanelActive ] := xId
#define IsPanelActive( xId ) iif( GetPanelActive[ _nIdPanel ] == xId, .T., .F. )
STATIC aPanels // array of panels and id of active panel
#define idPanelLeft 1
#define idPanelRight 2
#define idPanelActive 3 // Active panel { 1 - left, 2 - right }
PROCEDURE Main()
Set( _SET_DATEFORMAT, "yyyy-mm-dd" )
Set( _SET_SCOREBOARD, .F. )
Set( _SET_EVENTMASK, hb_bitOr( INKEY_KEYBOARD, HB_INKEY_GTEVENT, INKEY_ALL ) )
Set( _SET_INSERT, .T. )
/* Setup input CP of the translation */
hb_cdpSelect( "UTF8EX" )
hb_gtInfo( HB_GTI_COMPATBUFFER, .F. )
hb_gtInfo( HB_GTI_BOXCP, hb_cdpSelect() )
/* Configure terminal and OS codepage */
hb_SetTermCP( hb_cdpTerm() )
Set( _SET_OSCODEPAGE, hb_cdpOS() )
Set( _SET_DBCODEPAGE, "EN" )
hb_gtInfo( HB_GTI_RESIZEMODE, HB_GTI_RESIZEMODE_ROWS )
hb_gtInfo( HB_GTI_WINTITLE, "Harbour Commander" )
/* restore configuration*/
aConfig := hb_deserialize( hb_memoread( "hc.cfg" ) )
IF ! HB_ISARRAY( aConfig )
ConfigInit()
/* add new sessins to windows stack */
IF !hb_IsArray( aWinStack )
aWinStack := {}
/* in first element we save active session number, initial is 2 (should be greater then 1) */
AAdd( aWinStack, 2 )
/* next elements of aWinStack is array( 3 ), { left panel, right panel , active panel (default: left) } */
AAdd( aWinStack, { PanelInit( idPanelLeft ), PanelInit( idPanelRight ), idPanelLeft } )
ENDIF
aConfig[ _aStackWindow ] := aWinStack
ELSE
aWinStack := aConfig[ _aStackWindow ]
ENDIF
aConfig[ _nMaxRow ] := MaxRow()
aConfig[ _nMaxCol ] := MaxCol()
Prompt()
hb_Scroll()
SetPos( 0, 0 )
RETURN
STATIC PROCEDURE ConfigInit()
aConfig := Array( _nElementConfig )
aConfig[ _aStackWindow ] := {}
aConfig[ _nMaxRow ] := NIL
aConfig[ _nMaxCol ] := NIL
aConfig[ nCmdHndl ] := NIL
aConfig[ aCmdHist ] := {}
aConfig[ nBBarHndl ] := NIL
RETURN
STATIC FUNCTION PanelInit( IdPanel )
LOCAL aInit
aInit := Array( _nElements )
aInit[ _nTop ] := 0
aInit[ _nLeft ] := 0
aInit[ _nBottom ] := 0
aInit[ _nRight ] := 0
aInit[ _cCurrentDir ] := hb_cwd() /* hb_cwd () returns the full current working directory containing the disk and final path separator */
aInit[ _aDirectory ] := {}
aInit[ _nRowBar ] := 1
aInit[ _nRowNo ] := 0
aInit[ _cComdLine ] := ""
aInit[ _nComdCol ] := 0
aInit[ _nComdColNo ] := 0
aInit[ _nIdPanel ] := IdPanel
aInit[ _nWinHndl ] := NIL // handle to window
RETURN aInit
STATIC PROCEDURE FetchData()
PanelFetchList( GetPanels[ idPanelLeft ] )
PanelFetchList( GetPanels[ idPanelRight ] )
AutoSize()
RETURN
STATIC PROCEDURE PanelFetchList( aPanel )
LOCAL i, nPos, a2Dot, aDots := { ".", ".." }, iDot
CheckDirExists( @aPanel[ _cCurrentDir ] )
aPanel[ _aDirectory ] := hb_vfDirectory( aPanel[ _cCurrentDir ], "HSD" )
/* Add .T. to each element of the array. */
FOR i := 1 TO Len( aPanel[ _aDirectory ] ) // ? na AEval()
AAdd( aPanel[ _aDirectory ][ i ], .T. )
NEXT
FOR EACH iDot in aDots
IF ( nPos := AScan( aPanel[ _aDirectory ], {| x | x[ F_NAME ] == iDot } ) ) > 0
IF iDot:__enumIndex == 2
a2Dot := aPanel[ _aDirectory ][ nPos ]
ENDIF
hb_ADel( aPanel[ _aDirectory ], nPos, .T. )
ENDIF
NEXT
ASort( aPanel[ _aDirectory ],,, {| x, y | DIR_PREFIX( x ) + OSUPPER( x[ F_NAME ] ) < DIR_PREFIX( y ) + OSUPPER( y[ F_NAME ] ) } )
IF HB_ISARRAY( a2Dot )
hb_AIns( aPanel[ _aDirectory ], 1, a2Dot, .T. )
ENDIF
RETURN
STATIC PROCEDURE CheckDirExists( cDir )
LOCAL nPs
WHILE ! hb_DirExists( cDir )
nPs := hb_Rat( hb_ps(), cDir,, iif( Right( cDir, 1 ) == hb_ps(), Len( cDir ) - 1, NIL ) )
cDir := SubStr( cDir, 1, nPs )
CheckDirExists( @cDir )
END
RETURN
STATIC PROCEDURE AutoSize()
Resize( GetPanels[ idPanelLeft ], 0, 0, aConfig[ _nMaxRow ] - 2, aConfig[ _nMaxCol ] / 2 )
Resize( GetPanels[ idPanelRight ], 0, aConfig[ _nMaxCol ] / 2 + 1, aConfig[ _nMaxRow ] - 2, aConfig[ _nMaxCol ] )
RETURN
STATIC PROCEDURE Resize( aPanel, nTop, nLeft, nBottom, nRight )
aPanel[ _nTop ] := nTop
aPanel[ _nLeft ] := nLeft
aPanel[ _nBottom ] := nBottom
aPanel[ _nRight ] := nRight
RETURN
STATIC PROCEDURE Prompt()
LOCAL lContinue := .T.
LOCAL nMaxRow := 0, nMaxCol := 0
LOCAL nKey, nKeyStd
LOCAL nPos
LOCAL cFileName
LOCAL pHandle
LOCAL nMRow, nMCol
LOCAL nCol
LOCAL cSpaces
LOCAL nErrorCode
LOCAL cNewDrive
LOCAL i
LOCAL lCtrlO := .F.
LOCAL _nPanelActive := 0
LOCAL _nPanelRowBar := 0
#if defined( __PLATFORM__WINDOWS )
// optimized, PLATFORM_LINUX ?
#else
LOCAL result := ""
LOCAL ctuxCmd := "xdg-open "
LOCAL cTerminal := ""
#endif
/*
Ok, now fetch the data
*/
FetchData()
DO WHILE lContinue
DispBegin()
IF ( GetPanels[ idPanelLeft ][ _nWinHndl ] == NIL .OR. GetPanels[ idPanelRight ][ _nWinHndl ] == NIL ) .OR.;
_nPanelActive != GetPanels[ idPanelActive ] .OR.;
_nPanelRowBar != GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
IF _nPanelActive != GetPanels[ idPanelActive ]
_nPanelActive := GetPanels[ idPanelActive ]
ENDIF
IF _nPanelRowBar != GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
_nPanelRowBar := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
ENDIF
AutoSize()
PanelDisplay( GetPanels[ idPanelLeft ] )
PanelDisplay( GetPanels[ idPanelRight ] )
BottomBar()
nMaxRow := MaxRow()
nMaxCol := MaxCol()
ENDIF
ComdLineDisplay( )
DispEnd()
WSelect( aConfig[ nCmdHndl ] )
SetCursor( SC_NORMAL )
nKey := Inkey( 0 )
nKeyStd := hb_keyStd( nKey )
SWITCH nKeyStd
CASE K_ESC
IF ! Empty( GetPanelActive[ _cComdLine ] )
GetPanelActive[ _cComdLine ] := ""
GetPanelActive[ _nComdCol ] := 0
ComdLineDisplay( )
ELSE
lContinue := .F.
/* save configuration on exit*/
GetPanels[ idPanelLeft ][ _nWinHndl ] := NIL
GetPanels[ idPanelRight ][ _nWinHndl ] := NIL
aConfig[ _aStackWindow ] := aWinStack
aConfig[ nCmdHndl ] := NIL
aConfig[ nBBarHndl ] := NIL
hb_MemoWrit( StartUpPath() + "hc.cfg", hb_Serialize( aConfig ) )
ENDIF
EXIT
CASE K_ENTER
nPos := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
IF Empty( GetPanelActive[ _cComdLine ] )
/* if we stand on a file */
IF At( "D", GetPanelActive[ _aDirectory ][ nPos ][ F_ATTR ] ) == 0
#if defined( __PLATFORM__WINDOWS )
hb_run( Chr( 34 ) + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + Chr( 34 ) )
#else
IF hb_vfExists( "/usr/bin/nautilus" )
cTerminal = "gnome-terminal"
ELSEIF hb_vfExists( "/usr/bin/thunar" )
cTerminal = "xfce4-terminal"
ELSEIF hb_vfExists( "/usr/bin/pcmanfm" )
cTerminal = "lxterminal"
ELSEIF hb_vfExists( "/usr/bin/caja" )
cTerminal = "mate-terminal"
ELSEIF hb_vfExists( "/usr/bin/dolphin" )
cTerminal = "konsole"
ENDIF
hb_processRun( "sh -c 'file " + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + "'" + Chr( 34 ),, @result )
IF At( "ELF", result ) > 0
ctuxCmd = ""
ELSEIF At( "script", result ) > 0
ctuxCmd = cterminal + " -x "
ENDIF
hb_run( ctuxCmd + Chr( 34 ) + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + Chr( 34 ) )
#endif
ELSE
ChangeDir( GetPanelActive )
ENDIF
ELSE
// hb_Scroll()
// hb_processRun( GetPanelActive[ _cComdLine ] )
hb_processRun( getEnv( "COMSPEC" ) + " /c start " + GetPanelActive[ _cComdLine ] )
AAdd( aConfig[ aCmdHist ], GetPanelActive[ _cComdLine ] )
GetPanelActive[ _cComdLine ] := ""
// Inkey( 0 )
// nMaxRow := 0
GetPanelActive[ _nComdCol ] := 0
PanelRefresh( GetPanelActive )
ENDIF
EXIT
CASE K_TAB
IF ! lCtrlO
IF IsPanelActive( idPanelLeft )
SetPanelActive( idPanelRight )
GetPanelActive[ _cComdLine ] := GetPanels[ idPanelLeft, _cComdLine ]
GetPanelActive[ _nComdCol ] := GetPanels[ idPanelLeft, _nComdCol ]
GetPanels[ idPanelLeft, _cComdLine ] := ""
GetPanels[ idPanelLeft, _nComdCol ] := 0
ELSE
SetPanelActive( idPanelLeft )
GetPanelActive[ _cComdLine ] := GetPanels[ idPanelRight, _cComdLine ]
GetPanelActive[ _nComdCol ] := GetPanels[ idPanelRight, _nComdCol ]
GetPanels[ idPanelRight, _cComdLine ] := ""
GetPanels[ idPanelRight, _nComdCol ] := 0
ENDIF
ShowSession()
ENDIF
EXIT
CASE HB_K_RESIZE
WClose( GetPanels[ idPanelLeft, _nWinHndl ] )
GetPanels[ idPanelLeft, _nWinHndl ] := NIL
WClose( GetPanels[ idPanelRight, _nWinHndl ] )
GetPanels[ idPanelRight, _nWinHndl ] := NIL
WClose( aConfig[ nCmdHndl ] )
aConfig[ nCmdHndl ] := NIL
WClose( aConfig[ nBBarHndl ] )
aConfig[ nBBarHndl ] := NIL
WSelect( 0 )
aConfig[ _nMaxRow ] := MaxRow()
aConfig[ _nMaxCol ] := MaxCol()
CASE K_MOUSEMOVE
DispBegin()
nMRow := MRow()
nCol := Int( nMaxCol / 10 ) + 1
BottomBar()
IF nMRow > nMaxRow - 1
cSpaces := Space( nCol - 8 )
SWITCH Int( MCol() / nCol ) + 1
CASE 1 ; hb_DispOutAt( nMRow, 2, "Help " + cSpaces, 0xb0 ) ; EXIT
CASE 2 ; hb_DispOutAt( nMRow, nCol + 2, "Menu " + cSpaces, 0xb0 ) ; EXIT
CASE 3 ; hb_DispOutAt( nMRow, nCol * 2 + 2, "View " + cSpaces, 0xb0 ) ; EXIT
CASE 4 ; hb_DispOutAt( nMRow, nCol * 3 + 2, "Edit " + cSpaces, 0xb0 ) ; EXIT
CASE 5 ; hb_DispOutAt( nMRow, nCol * 4 + 2, "Copy " + cSpaces, 0xb0 ) ; EXIT
CASE 6 ; hb_DispOutAt( nMRow, nCol * 5 + 2, "RenMov" + cSpaces, 0xb0 ) ; EXIT
CASE 7 ; hb_DispOutAt( nMRow, nCol * 6 + 2, "MkDir " + cSpaces, 0xb0 ) ; EXIT
CASE 8 ; hb_DispOutAt( nMRow, nCol * 7 + 2, "Delete" + cSpaces, 0xb0 ) ; EXIT
CASE 9 ; hb_DispOutAt( nMRow, nCol * 8 + 2, "PullDn" + cSpaces, 0xb0 ) ; EXIT
CASE 10 ; hb_DispOutAt( nMRow, nCol * 9 + 2, "Quit " + cSpaces, 0xb0 ) ; EXIT
ENDSWITCH
ENDIF
DispEnd()
EXIT
CASE K_LDBLCLK
IF ! lCtrlO
nPos := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
/* if we stand on a file */
IF At( "D", GetPanelActive[ _aDirectory ][ nPos ][ F_ATTR ] ) == 0
#if defined( __PLATFORM__WINDOWS )
hb_run( Chr( 34 ) + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + Chr( 34 ) )
#else
IF hb_vfExists( "/usr/bin/nautilus" )
cTerminal = "gnome-terminal"
ELSEIF hb_vfExists( "/usr/bin/thunar" )
cTerminal = "xfce4-terminal"
ELSEIF hb_vfExists( "/usr/bin/pcmanfm" )
cTerminal = "lxterminal"
ELSEIF hb_vfExists( "/usr/bin/caja" )
cTerminal = "mate-terminal"
ELSEIF hb_vfExists( "/usr/bin/dolphin" )
cTerminal = "konsole"
ENDIF
hb_processRun( "sh -c 'file " + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + "'" + Chr( 34 ),, @result )
IF At( "ELF", result ) > 0
ctuxCmd = ""
ELSEIF At( "script", result ) > 0
ctuxCmd = cterminal + " -x "
ENDIF
hb_run( ctuxCmd + Chr( 34 ) + GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] + Chr( 34 ) )
#endif
ELSE
ChangeDir( GetPanelActive )
ENDIF
ENDIF
EXIT
CASE K_RBUTTONDOWN
IF ! lCtrlO
nMRow := MRow()
nMCol := MCol()
IF nMRow > 0 .AND. nMRow < MaxRow() - 1 .AND. nMCol < Int( MaxCol() / 2 ) + 1
GetPanelActive := aPanels[ idPanelLeft ]
IF nMRow <= Len( GetPanelActive[ _aDirectory ] )
GetPanelActive[ _nRowBar ] := nMRow
ENDIF
ENDIF
IF nMRow > 0 .AND. nMRow < MaxRow() - 1 .AND. nMCol > Int( MaxCol() / 2 )
GetPanelActive := aPanels[ idPanelRight ]
IF nMRow <= Len( GetPanelActive[ _aDirectory ] )
GetPanelActive[ _nRowBar ] := nMRow
ENDIF
ENDIF
nPos := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
IF GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] != ".." // ?
/* Marking the deletion status of the current item in the table */
IF GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ]
GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ] := .F.
ELSE
/* return the delete status of the current item in the array */
GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ] := .T.
ENDIF
ENDIF
PanelDisplay( GetPanels[ idPanelLeft ] )
PanelDisplay( GetPanels[ idPanelRight ] )
ENDIF
EXIT
CASE K_LBUTTONDOWN
IF ! lCtrlO
nMRow := MRow()
nMCol := MCol()
IF nMRow > 0 .AND. nMRow < MaxRow() - 1 .AND. nMCol < Int( MaxCol() / 2 ) + 1
GetPanelActive := aPanels[ idPanelLeft ]
IF nMRow <= Len( GetPanelActive[ _aDirectory ] )
GetPanelActive[ _nRowBar ] := nMRow
ENDIF
ENDIF
IF nMRow > 0 .AND. nMRow < MaxRow() - 1 .AND. nMCol > Int( MaxCol() / 2 )
GetPanelActive := aPanels[ idPanelRight ]
IF nMRow <= Len( GetPanelActive[ _aDirectory ] )
GetPanelActive[ _nRowBar ] := nMRow
ENDIF
ENDIF
/* BottomBar */
nCol := Int( nMaxCol / 10 ) + 1
IF nMRow > nMaxRow - 1
SWITCH Int( MCol() / nCol ) + 1
CASE 1 ; FunctionKey_F1() ; EXIT
CASE 2 ; FunctionKey_F2() ; EXIT
CASE 3 ; FunctionKey_F3( GetPanelActive ) ; EXIT
CASE 4 ; FunctionKey_F4( GetPanelActive ) ; EXIT
CASE 5 ; FunctionKey_F5( GetPanelActive ) ; EXIT
CASE 6 ; FunctionKey_F6( GetPanelActive ) ; EXIT
CASE 7 ; FunctionKey_F7( GetPanelActive ) ; EXIT
CASE 8 ; FunctionKey_F8( GetPanelActive ) ; EXIT
CASE 9 ; EXIT
CASE 10
IF HC_Alert( "The Harbour Commander", "Do you want to quit the Harbour Commander?", { "Yes", "No!" }, 0x8f ) == 1
lContinue := .F.
ENDIF
EXIT
ENDSWITCH
ENDIF
PanelDisplay( GetPanels[ idPanelLeft ] )
PanelDisplay( GetPanels[ idPanelRight ] )
ENDIF
EXIT
CASE K_MWFORWARD
IF GetPanelActive[ _nRowBar ] > 1
--GetPanelActive[ _nRowBar ]
ELSE
IF GetPanelActive[ _nRowNo ] >= 1
--GetPanelActive[ _nRowNo ]
ENDIF
ENDIF
EXIT
CASE K_MWBACKWARD
IF GetPanelActive[ _nRowBar ] < GetPanelActive[ _nBottom ] - 1 .AND. GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowBar ]
ELSE
IF GetPanelActive[ _nRowNo ] + GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowNo ]
ENDIF
ENDIF
EXIT
CASE K_UP
IF ! lCtrlO
IF GetPanelActive[ _nRowBar ] > 1
--GetPanelActive[ _nRowBar ]
ELSE
IF GetPanelActive[ _nRowNo ] >= 1
--GetPanelActive[ _nRowNo ]
ENDIF
ENDIF
ENDIF
EXIT
CASE K_DOWN
IF ! lCtrlO
IF GetPanelActive[ _nRowBar ] < GetPanelActive[ _nBottom ] - 1 .AND. GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowBar ]
ELSE
IF GetPanelActive[ _nRowNo ] + GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowNo ]
ENDIF
ENDIF
ENDIF
EXIT
CASE K_LEFT
IF ! lCtrlO
IF GetPanelActive[ _nComdCol ] > 0
GetPanelActive[ _nComdCol ]--
ELSE
IF GetPanelActive[ _nComdColNo ] >= 1
GetPanelActive[ _nComdColNo ]--
ENDIF
ENDIF
ENDIF
EXIT
CASE K_RIGHT
IF ! lCtrlO
IF GetPanelActive[ _nComdCol ] < nMaxCol - Len( GetPanelActive[ _cCurrentDir ] ) .AND. GetPanelActive[ _nComdCol ] < Len( GetPanelActive[ _cComdLine ] )
GetPanelActive[ _nComdCol ]++
ELSE
IF GetPanelActive[ _nComdColNo ] + GetPanelActive[ _nComdCol ] < Len( GetPanelActive[ _cComdLine ] )
GetPanelActive[ _nComdColNo ]++
ENDIF
ENDIF
ENDIF
EXIT
CASE K_HOME
IF ! lCtrlO
GetPanelActive[ _nComdCol ] := 0
ENDIF
EXIT
CASE K_END
IF ! lCtrlO
GetPanelActive[ _nComdCol ] := Len( GetPanelActive[ _cComdLine ] )
ENDIF
EXIT
CASE K_PGUP
IF ! lCtrlO
IF GetPanelActive[ _nRowBar ] <= 1
IF GetPanelActive[ _nRowNo ] - nMaxRow >= 0
GetPanelActive[ _nRowNo ] -= nMaxRow
ENDIF
ENDIF
GetPanelActive[ _nRowBar ] := 1
ENDIF
EXIT
CASE K_PGDN
IF ! lCtrlO
IF GetPanelActive[ _nRowBar ] >= nMaxRow - 3
IF GetPanelActive[ _nRowNo ] + nMaxRow <= Len( GetPanelActive[ _aDirectory ] )
GetPanelActive[ _nRowNo ] += nMaxRow
ENDIF
ENDIF
GetPanelActive[ _nRowBar ] := Min( nMaxRow - 3, Len( GetPanelActive[ _aDirectory ] ) - GetPanelActive[ _nRowNo ] )
ENDIF
EXIT
CASE K_INS
IF ! lCtrlO
nPos := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
IF GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ] != ".." // ?
/* Marking the deletion status of the current item in the table */
IF GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ]
GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ] := .F.
ELSE
/* return the delete status of the current item in the array */
GetPanelActive[ _aDirectory ][ nPos ][ F_STATUS ] := .T.
ENDIF
IF GetPanelActive[ _nRowBar ] < GetPanelActive[ _nBottom ] - 1 .AND. GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowBar ]
ELSE
IF GetPanelActive[ _nRowNo ] + GetPanelActive[ _nRowBar ] <= Len( GetPanelActive[ _aDirectory ] ) - 1
++GetPanelActive[ _nRowNo ]
ENDIF
ENDIF
ENDIF
ENDIF
EXIT
CASE K_DEL
IF GetPanelActive[ _nComdCol ] >= 0
GetPanelActive[ _cComdLine ] := Stuff( GetPanelActive[ _cComdLine ], GetPanelActive[ _nComdCol ] + 1, 1, "" )
ENDIF
EXIT
CASE K_BS
IF GetPanelActive[ _nComdCol ] > 0
GetPanelActive[ _cComdLine ] := Stuff( GetPanelActive[ _cComdLine ], GetPanelActive[ _nComdCol ], 1, "" )
GetPanelActive[ _nComdCol ]--
ENDIF
EXIT
CASE K_CTRL_O
IF ! lCtrlO
lCtrlO := .T.
WClose( aConfig[ nCmdHndl ] )
WSelect( 0 )
SetColor( "N" )
aConfig[ nCmdHndl ] := WOpen( 0, 0, MaxRow() - 1, MaxCol(), .T. )
ELSE
lCtrlO := .F.
WClose( aConfig[ nCmdHndl ] )
aConfig[ nCmdHndl ] := NIL
ShowSession()
ENDIF
EXIT
CASE K_F1
FunctionKey_F1()
EXIT
CASE K_F2
FunctionKey_F2()
EXIT
CASE K_F3
IF ! lCtrlO
FunctionKey_F3( GetPanelActive )
ENDIF
EXIT
CASE K_F4
IF ! lCtrlO
FunctionKey_F4( GetPanelActive )
ENDIF
EXIT
CASE K_F5
IF ! lCtrlO
FunctionKey_F5( GetPanelActive )
ENDIF
EXIT
CASE K_F6
IF ! lCtrlO
FunctionKey_F6( GetPanelActive )
ENDIF
EXIT
CASE K_F7
IF ! lCtrlO
FunctionKey_F7( GetPanelActive )
ENDIF
EXIT
CASE K_F8
IF ! lCtrlO
FunctionKey_F8( GetPanelActive )
ENDIF
EXIT
CASE K_F9
IF ! lCtrlO
FunctionKey_F9( )
ENDIF
EXIT
CASE K_F10
lContinue := .F.
EXIT
#if defined( __PLATFORM__WINDOWS )
CASE K_ALT_F1
IF ! lCtrlO
/* change directory to the left panel mount point,
the last parameter sets the dialog: NIL center, 0x0 to the left and 0x1 to the right
AllDrives () returns an array */
IF ( cNewDrive := HC_Alert( "Drive letter", "Choose left drive:", AllDrives(), 0x8a, 0x0 ) ) != 0
hb_CurDrive( AllDrives()[ cNewDrive ] )
PanelFetchList( aPanels[ idPanelLeft ], hb_cwd() )
PanelDisplay( aPanels[ idPanelLeft ] )
ENDIF
ENDIF
EXIT
CASE K_ALT_F2
IF ! lCtrlO
/* change directory to the right panel mount point,
the last parameter sets the dialog: NIL center, 0x0 to the left and 0x1 to the right
AllDrives () returns an array */
IF ( cNewDrive := HC_Alert( "Drive letter", "Choose right drive:", AllDrives(), 0x8a, 0x1 ) ) != 0
hb_CurDrive( AllDrives()[ cNewDrive ] )
PanelFetchList( aPanels[ idPanelRight ], hb_cwd() )
PanelDisplay( aPanels[ idPanelRight ] )
ENDIF
ENDIF
EXIT
#endif
CASE K_SH_F4
IF ! lCtrlO
nPos := GetPanelActive[ _nRowBar ] + GetPanelActive[ _nRowNo ]
/* if we stand on a file */
IF At( "D", GetPanelActive[ _aDirectory ][ nPos ][ F_ATTR ] ) == 0
IF HB_ISSTRING( cFileName := MsgBox( "Create file.", GetPanelActive[ _cCurrentDir ] + GetPanelActive[ _aDirectory ][ nPos ][ F_NAME ], { "Yes", "No!" } ) )
IF hb_vfExists( cFileName )
HCEdit( cFileName, .T. )
ELSE
IF ( pHandle := hb_vfOpen( cFileName, FO_CREAT + FO_TRUNC + FO_WRITE ) ) != NIL
IF ! hb_vfClose( pHandle )
IF ( nErrorCode := AScan( FileError(), {| x | x[ 1 ] == FError() } ) ) > 0
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + FileError()[ nErrorCode ][ MEANING ] )
ELSE
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + hb_ntos( FError() ) )
ENDIF
ENDIF
PanelRefresh( GetPanelActive )
ELSE
IF ( nErrorCode := AScan( FileError(), {| x | x[ 1 ] == FError() } ) ) > 0
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + FileError()[ nErrorCode ][ MEANING ] )
ELSE
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + hb_ntos( FError() ) )
ENDIF
ENDIF
ENDIF
ENDIF
ELSE
/* if we stand on the catalog */
IF HB_ISSTRING( cFileName := MsgBox( "Create file.", NIL, { "Yes", "No!" } ) )
IF ( pHandle := hb_vfOpen( GetPanelActive[ _cCurrentDir ] + cFileName, FO_CREAT + FO_TRUNC + FO_WRITE ) ) != NIL
IF ! hb_vfClose( pHandle )
IF ( nErrorCode := AScan( FileError(), {| x | x[ 1 ] == FError() } ) ) > 0
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + FileError()[ nErrorCode ][ MEANING ] )
ELSE
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + hb_ntos( FError() ) )
ENDIF
ENDIF
PanelRefresh( GetPanelActive, cFileName )
ELSE
IF ( nErrorCode := AScan( FileError(), {| x | x[ 1 ] == FError() } ) ) > 0
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + FileError()[ nErrorCode ][ MEANING ] )
ELSE
HC_Alert( "Error", "Test for errors after a binary file operation.;Cannot make file, error:;" + hb_ntos( FError() ) )
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
EXIT
CASE 43 /* select a group of files. */
IF ! lCtrlO
FOR i := 1 TO Len( GetPanelActive[ _aDirectory ] )
IF GetPanelActive[ _aDirectory ][ i ][ F_NAME ] != ".."
GetPanelActive[ _aDirectory ][ i ][ F_STATUS ] := .F.
ENDIF
NEXT
ENDIF
EXIT
CASE 95 /* Unselect a group of files. */
IF ! lCtrlO
FOR i := 1 TO Len( GetPanelActive[ _aDirectory ] )
IF GetPanelActive[ _aDirectory ][ i ][ F_NAME ] != ".."
GetPanelActive[ _aDirectory ][ i ][ F_STATUS ] := .T.
ENDIF
NEXT
ENDIF
EXIT
OTHERWISE
IF ( nKeyStd >= 32 .AND. nKeyStd <= 126 ) .OR. ( nKeyStd >= 160 .AND. nKeyStd <= 255 ) .OR. ! hb_keyChar( nKeyStd ) == ""
GetPanelActive[ _cComdLine ] := Stuff( GetPanelActive[ _cComdLine ], GetPanelActive[ _nComdCol ] + GetPanelActive[ _nComdColNo ] + 1, 0, hb_keyChar( nKeyStd ) )
IF GetPanelActive[ _nComdCol ] < nMaxCol - Len( GetPanelActive[ _cCurrentDir ] )
GetPanelActive[ _nComdCol ]++
ELSE
GetPanelActive[ _nComdColNo ]++
ENDIF
ENDIF
ENDSWITCH
ENDDO
RETURN
STATIC PROCEDURE FunctionKey_F1()
LOCAL cAddr := "https://github.com/omm/harbour-commander/issues/new"
LOCAL cStdOut, cOutErr
IF HC_Alert( "Report an error", ;
"Creating an issue;" + ;
";Issues can be used to keep track of bugs, enhancements, or;" + ;
"other requests.;" + ;
";Any GitHub user can create an issue in a public repository;" + ;
"where issues have not been disabled.;" + ;
";You can open a new issue based on code from an existing pull;" + ;
"request.;", ;
{ "Click New issue." } ) == 1
#if defined( __PLATFORM__WINDOWS )
hb_processRun( "start " + cAddr,, @cStdOut, @cOuterr )
hb_alert( cStdOut + hb_eol() + "and" + hb_eol() + cOutErr )
//hb_run( "start " + cAddr )
#else
hb_run( "xdg-open " + cAddr )
#endif
ENDIF
RETURN
STATIC PROCEDURE FunctionKey_F2()
HC_MenuF2()
RETURN