filelist.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. Const
  2. DefCompare : TGtkCListCompareFunc = Nil;
  3. Function FileCompareFunc(List:PGtkCList; Row1,Row2 : PGtkCListRow) : Longint; Cdecl;
  4. Var
  5. SC : Longint;
  6. begin
  7. SC:=List^.sort_column;
  8. If SC in [2,3] then
  9. begin
  10. SC:=SC-2;
  11. Result:=PLongint(Row1^.Data)[SC]-PLongint(Row2^.Data)[SC];
  12. end
  13. Else
  14. Result:=DefCompare(List,Row1,Row2);
  15. end;
  16. Procedure DestroySortData(FSD : Pointer);cdecl;
  17. begin
  18. FreeMem(FSD);
  19. end;
  20. Procedure AddFileToList(List : PGtkCList; Info : TSearchRec);
  21. Var
  22. Texts : Array[1..6] of AnsiString;
  23. FSD : PLongint;
  24. I : longint;
  25. begin
  26. Texts[1]:=ExtractFileName(Info.Name);
  27. Texts[2]:=ExtractFileExt(Info.Name);
  28. Texts[3]:=FileSizeToString(Info.Size);
  29. Texts[4]:=DateTimeToStr(FileDateToDateTime(Info.Time));
  30. Texts[5]:=FileAttrsToString(Info.Attr);
  31. Texts[6]:='';
  32. i:=gtk_clist_append(List,@Texts[1]);
  33. FSD:=GetMem(2*SizeOf(Longint));
  34. FSD[0]:=Info.Size;
  35. FSD[1]:=Info.Time;
  36. gtk_clist_set_row_data_full (List,I,FSD,@DestroySortData);
  37. end;
  38. Function FillList(List : PGtkCList; Const Dir,Mask : String) : Integer;
  39. Var
  40. Info : TSearchRec;
  41. Size : Int64;
  42. I : longint;
  43. begin
  44. Result:=0;
  45. Size:=0;
  46. gtk_clist_freeze(List);
  47. Try
  48. gtk_clist_clear(List);
  49. If FindFirst (AddTrailingSeparator(Dir)+Mask,faAnyFile,Info)=0 then
  50. Repeat
  51. Inc(Size,Info.Size);
  52. AddFileToList(List,Info);
  53. Inc(Result);
  54. Until FindNext(Info)<>0;
  55. FindClose(info);
  56. finally
  57. For I:=0 to 4 do
  58. gtk_clist_set_column_width(List,i,gtk_clist_optimal_column_width(List,i));
  59. gtk_clist_thaw(List)
  60. end;
  61. end;
  62. Procedure ShowPopup(Widget : PGtkWidget; Event : PGdkEventButton; Window : PMainWindow);cdecl;
  63. begin
  64. if (event^.thetype=GDK_BUTTON_PRESS) and (event^.button=3) then
  65. begin
  66. gtk_menu_popup(Window^.PMFiles,Nil,Nil,Nil,NIl,3,event^.time);
  67. end;
  68. end;
  69. Procedure FileColumnClick(List : PGtkCList;Column:gint; Window : PMainWindow);cdecl;
  70. Var
  71. I : longint;
  72. NS : TGtkSortType;
  73. begin
  74. If Column<>List^.sort_column Then
  75. begin
  76. gtk_clist_set_sort_type(List,GTK_SORT_ASCENDING);
  77. gtk_clist_set_sort_column(list,Column);
  78. end
  79. else
  80. begin
  81. If (List^.Sort_type=GTK_SORT_ASCENDING) Then
  82. NS:=GTK_SORT_DESCENDING
  83. else
  84. NS:=GTK_SORT_ASCENDING;
  85. gtk_clist_set_sort_type(List,NS);
  86. end;
  87. gtk_clist_sort(list);
  88. end;
  89. Function NewFileList(MainWindow : PMainWindow) : PGtkClist;
  90. Const
  91. Titles : Array[1..6] of pchar = ('Name','ext','Size','Date','Attributes','');
  92. begin
  93. MainWindow^.ListScrollWindow:=PGtkScrolledWindow(gtk_scrolled_window_new(Nil,Nil));
  94. gtk_scrolled_window_set_policy(MainWindow^.ListScrollWindow,
  95. GTK_POLICY_AUTOMATIC,
  96. GTK_POLICY_AUTOMATIC);
  97. Result:=PGtkClist(Gtk_Clist_New_with_titles(6,@Titles));
  98. gtk_signal_connect(PgtkObject(Result),'button_press_event',TGtkSignalFunc(@ShowPopup),MainWindow);
  99. gtk_signal_connect(PgtkObject(Result),'click_column',TGtkSignalFunc(@FileColumnClick),MainWindow);
  100. gtk_Container_add(PGTKContainer(MainWindow^.ListScrollWindow),PGtkWidget(Result));
  101. gtk_clist_set_shadow_type(Result,GTK_SHADOW_ETCHED_OUT);
  102. gtk_clist_set_column_justification(result,2,GTK_JUSTIFY_RIGHT);
  103. gtk_clist_set_selection_mode(Result,GTK_SELECTION_MULTIPLE);
  104. gtk_clist_set_auto_sort(Result,True);
  105. If DefCompare=Nil then
  106. DefCompare:=Result^.compare;
  107. gtk_clist_set_compare_func(Result,TGtkCListCompareFunc(@FileCompareFunc));
  108. end;
  109. Procedure ToggleFileListTitles(Sender : PGtkCheckMenuItem;Window : PMainWindow);cdecl;
  110. begin
  111. If active(Sender^)=0 then
  112. gtk_clist_column_titles_show(Window^.FileList)
  113. else
  114. gtk_clist_column_titles_hide(Window^.FileList)
  115. end;
  116. Procedure ToggleFileListColumns(Sender : PGtkCheckMenuItem;Window : PMainWindow);cdecl;
  117. Var Col : Longint;
  118. begin
  119. With Window^ do
  120. If Sender=MIShowExt Then
  121. Col:=1
  122. else if Sender=MiShowSize Then
  123. Col:=2
  124. else if Sender=MIShowDate then
  125. Col:=3
  126. else
  127. Col:=4;
  128. gtk_clist_set_column_visibility(Window^.FileList,Col,(Active(Sender^)=0));
  129. end;
  130. Procedure GetFileSelection (List : PGtkClist; Selection : TStrings);
  131. Var
  132. SList : PGList;
  133. Index : Longint;
  134. P : PChar;
  135. begin
  136. Selection.Clear;
  137. Slist:=List^.Selection;
  138. While SList<>nil do
  139. begin
  140. Index:=Longint(SList^.Data);
  141. gtk_clist_get_text(List,Index,0,@p);
  142. Selection.Add(StrPas(p));
  143. SList:=g_list_next(SList);
  144. end;
  145. end;
  146. Function GetFileFirstSelection (List : PGtkClist) : String;
  147. Var
  148. SList : PGList;
  149. Index : Longint;
  150. P : PChar;
  151. begin
  152. REsult:='';
  153. Slist:=List^.Selection;
  154. If SList<>nil then
  155. begin
  156. Index:=Longint(SList^.Data);
  157. gtk_clist_get_text(List,Index,0,@p);
  158. Result:=StrPas(p);
  159. end;
  160. end;
  161. Function GetFileSelectionCount (List : PGtkClist) : Longint;
  162. Var
  163. SList : PGList;
  164. begin
  165. Slist:=List^.Selection;
  166. Result:=0;
  167. While SList<>nil do
  168. begin
  169. Inc(Result);
  170. SList:=g_list_next(SList);
  171. end;
  172. end;
  173. Procedure RefreshFileView(Window : PMainWindow);
  174. begin
  175. With Window^ do
  176. FillList(FileList,FDir,FMask);
  177. end;