frmprops.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. Unit frmprops;
  2. {$mode objfpc}
  3. Interface
  4. uses glib,gdk,gtk,sysutils;
  5. Const
  6. NrTableLines = 8;
  7. CheckBoxLineStart = 5;
  8. Type
  9. TFilePropertiesDialog = Record
  10. Window : PgtkDialog;
  11. Table : PGtkTable;
  12. OkButton : PGtkButton;
  13. Labels : Array[0..1,0..NrTableLines] of PGtkLabel;
  14. CheckBoxes : Array[CheckBoxLineStart..NrTableLines] of PgtkCheckButton;
  15. end;
  16. PFilePropertiesDialog = ^TFilePropertiesDialog;
  17. Function NewFilePropertiesDialog(FileName : String) : PFilePropertiesDialog;
  18. Procedure ShowFilePropertiesDialog(Dialog : PFilePropertiesDialog);
  19. Implementation
  20. uses Futils;
  21. Const
  22. SPropsTitle : PChar = 'File properties';
  23. SOk : PChar = ' OK ';
  24. SFile = ' File.';
  25. LabelTexts : Array[0..NrTableLines] of Pchar = (
  26. 'Name',
  27. 'Directory',
  28. 'Type',
  29. 'Size',
  30. 'Date',
  31. 'Attributes',
  32. '',
  33. '',
  34. ''
  35. );
  36. CheckBoxTexts : Array[CheckBoxLineStart..NrTableLines] of Pchar = (
  37. 'Read-only',
  38. 'Archive',
  39. 'Hidden',
  40. 'System'
  41. );
  42. procedure DestroyPropDialog(Widget : PGtkWidget; Dlg : PFilePropertiesDialog);cdecl;
  43. begin
  44. Dispose(Dlg);
  45. end;
  46. Function NewFilePropertiesDialog(FileName : String) : PFilePropertiesDialog;
  47. Const
  48. CheckAttrs : Array [CheckBoxLineStart..NrTableLines] of Integer
  49. = (faReadOnly,faArchive,faHidden,faSysFile);
  50. Var
  51. Info : TSearchRec;
  52. I : Longint;
  53. begin
  54. Result:=New(PFilePropertiesDialog);
  55. With Result^ do
  56. begin
  57. Window:=PgtkDialog(gtk_dialog_new);
  58. gtk_window_set_title(PgtkWindow(Window),SPropsTitle);
  59. gtk_window_set_modal(PgtkWindow(Window),True);
  60. gtk_window_set_policy(PgtkWindow(Window),0,0,0);
  61. gtk_window_set_position(PGtkWindow(Window),GTK_WIN_POS_CENTER);
  62. OkButton:=PGtkButton(gtk_button_new_with_label(SOK));
  63. gtk_box_pack_start(PgtkBox(Window^.action_area),PGtkWidget(Okbutton),False,False,5);
  64. gtk_window_set_focus(PGtkWindow(Window),PGtkWidget(OkButton));
  65. gtk_widget_show(PGtkWidget(OkButton));
  66. Table:=PgtkTable(gtk_table_new(NrTableLines+1,2,TRUE));
  67. gtk_box_pack_start(PGtkBox(Window^.vbox),PGtkWidget(Table),True,True,10);
  68. For I:=0 to NrTableLines do
  69. begin
  70. Labels[0,i]:=PGtkLabel(gtk_label_new(LabelTexts[i]));
  71. gtk_label_set_justify(Labels[0,I],GTK_JUSTIFY_RIGHT);
  72. gtk_table_attach_defaults(Table,PgtkWidget(Labels[0,I]),0,1,I,I+1);
  73. end;
  74. For I:=0 to CheckboxLineStart-1 do
  75. begin
  76. Labels[1,i]:=PGtkLabel(gtk_label_new(''));
  77. gtk_label_set_justify(Labels[1,I],GTK_JUSTIFY_LEFT);
  78. gtk_table_attach_defaults(Table,PgtkWidget(Labels[1,I]),1,2,I,I+1);
  79. end;
  80. For I:=CheckboxLineStart to NrTableLines do
  81. begin
  82. checkBoxes[i]:=PgtkCheckButton(gtk_check_button_new_with_label(CheckBoxTexts[I]));
  83. gtk_widget_set_state(PGtKWidget(CheckBoxes[i]),GTK_STATE_INSENSITIVE);
  84. gtk_table_attach_defaults(Table,PgtkWidget(CheckBoxes[i]),1,2,I,I+1);
  85. end;
  86. gtk_label_set_text(Labels[1,0],PChar(ExtractFileName(FileName)));
  87. gtk_label_set_text(Labels[1,1],PChar(ExtractFilePath(FileName)));
  88. gtk_label_set_text(Labels[1,2],PChar(ExtractFileExt(FileName)+SFile));
  89. If FindFirst(FileName,faAnyFile,Info)=0 Then
  90. begin
  91. gtk_label_set_text(Labels[1,3],PChar(FileSizeToString(Info.Size)));
  92. gtk_label_set_text(Labels[1,4],PChar(DateTimeToStr(FileDateToDateTime(Info.Time))));
  93. For I:=CheckboxLineStart to NrTableLines do
  94. If (CheckAttrs[i] and Info.Attr)=CheckAttrs[i] then
  95. gtk_toggle_button_set_active(PgtkToggleButton(CheckBoxes[I]),True);
  96. FindClose(Info);
  97. end;
  98. gtk_signal_connect(PGtkObject(Window),'destroy',
  99. TGTKSignalFunc(@DestroyPropDialog),Result);
  100. gtk_signal_connect_object(PgtkObject(OKButton),'clicked',
  101. GTK_SIGNAL_FUNC(@gtk_widget_destroy),
  102. PGTKOBJECT(Window));
  103. end;
  104. end;
  105. Procedure ShowFilePropertiesDialog(Dialog : PFilePropertiesDialog);
  106. begin
  107. gtk_widget_show_all(PgtkWidget(Dialog^.Window));
  108. end;
  109. end.