unit uViewDocumentos; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel, dxSkinCoffee, dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinSilver, dxSkinStardust, dxSkinsDefaultPainters, dxSkinValentine, dxSkinXmas2008Blue, cxControls, cxContainer, cxListBox, ActnList, TB2Item, TBX, TB2Dock, TB2Toolbar; type TfrViewDocumentos = class(TfrViewBase) ListaDocumentos: TcxListBox; EditorActionList: TActionList; TBXDock: TTBXDock; tbxMain: TTBXToolbar; TBXItem2: TTBXItem; actAnadir: TAction; actModificar: TAction; actEliminar: TAction; TBXItem1: TTBXItem; TBXItem3: TTBXItem; actEliminarTodo: TAction; TBXItem4: TTBXItem; actActualizarServidor: TAction; TBXItem5: TTBXItem; procedure actAnadirExecute(Sender: TObject); procedure actModificarExecute(Sender: TObject); procedure actEliminarExecute(Sender: TObject); procedure actEliminarTodoExecute(Sender: TObject); procedure actActualizarServidorExecute(Sender: TObject); procedure CustomViewCreate(Sender: TObject); procedure CustomViewDestroy(Sender: TObject); private FDirectorio: Variant; function GetDirectorio: Variant; function DarFicherosSeleccionados: TStringList; protected FListaFicheros: TStringList; property Directorio: Variant read GetDirectorio; //Son los metodos que se sobreescribiran en la vista hija procedure Sincronizar; virtual; abstract; function RecuperarFicheroServidor(const NombreFichero: String; const DirectorioDestino: String): Boolean; virtual; abstract; procedure RefrescarVisualizador; virtual; public property ListaFicheros: TStringList read FListaFicheros; end; var frViewDocumentos: TfrViewDocumentos; implementation {$R *.dfm} uses uSistemaFunc, ShellAPI, uDialogUtils; procedure TfrViewDocumentos.actActualizarServidorExecute(Sender: TObject); begin inherited; Sincronizar; end; procedure TfrViewDocumentos.actAnadirExecute(Sender: TObject); var openDialog : TOpenDialog; ANombreFichero : String; i : Integer; begin openDialog := TOpenDialog.Create(self); try // Set up the starting directory to be the current one // openDialog.InitialDir := GetCurrentDir; // Only allow existing files to be selected // openDialog.Options := [ofFileMustExist]; // Allow multiple files to be selected - of any type openDialog.Options := [ofAllowMultiSelect]; // Allow only .dpr and .pas files to be selected // openDialog.Filter := 'Delphi project files|*.dpr|Delphi pascal files|*.pas'; // Select pascal files as the starting filter type // openDialog.FilterIndex := 2; if openDialog.Execute then begin for i:=0 to openDialog.Files.Count - 1 do begin ANombreFichero := openDialog.Files.Strings[i]; if Length(ANombreFichero) > 0 then CopiarFichero(ANombreFichero, (Directorio + ExtractFileName(ANombreFichero))); //Lo añadimos a la lista de documentos local FListaFicheros.Add(ExtractFileName(ANombreFichero)) end; end; finally openDialog.Free; //Now, We compact the process memory: SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); RefrescarVisualizador; end; end; procedure TfrViewDocumentos.actEliminarExecute(Sender: TObject); var i, j: Integer; FicherosSeleccionados: TStringList; ANombreFichero: String; begin FicherosSeleccionados := DarFicherosSeleccionados; try for i := 0 to FicherosSeleccionados.Count - 1 do begin //Buscamos si existen fisicamente y si es así los eliminamos if FileExists(FicherosSeleccionados.Strings[i]) then if not DeleteFile(FicherosSeleccionados.Strings[i]) then Application.MessageBox('No se pudo borrar el fichero', 'Error', MB_ICONEXCLAMATION); //Lo quitamos de la propiedad donde guardamos lista de documentos ANombreFichero := ExtractFileName(FicherosSeleccionados.Strings[i]); if FListaFicheros.Find(ANombreFichero, j) then FListaFicheros.Delete(j); end; finally FreeAndNil(FicherosSeleccionados); RefrescarVisualizador; end; end; procedure TfrViewDocumentos.actEliminarTodoExecute(Sender: TObject); begin Deltree(Directorio, True); FListaFicheros.Clear; FDirectorio := Null; RefrescarVisualizador; end; procedure TfrViewDocumentos.actModificarExecute(Sender: TObject); var i: Integer; FicherosSeleccionados: TStringList; begin FicherosSeleccionados := DarFicherosSeleccionados; try for i := 0 to FicherosSeleccionados.Count - 1 do if FileExists(FicherosSeleccionados.Strings[i]) then begin if ShellExecute(Handle, nil, pchar(FicherosSeleccionados.Strings[i]), nil, nil, SW_SHOWNORMAL) <= 32 then Application.MessageBox('No se pudo editar el fichero', 'Error', MB_ICONEXCLAMATION); end else begin if not RecuperarFicheroServidor(ExtractFileName(FicherosSeleccionados.Strings[i]), ExtractFilePath(FicherosSeleccionados.Strings[i])) then Application.MessageBox('No se pudo RecuperarFicheroServidor', 'Error', MB_ICONEXCLAMATION); if ShellExecute(Handle, nil, pchar(FicherosSeleccionados.Strings[i]), nil, nil, SW_SHOWNORMAL) <= 32 then Application.MessageBox('No se pudo editar el fichero', 'Error', MB_ICONEXCLAMATION); end; finally FreeAndNil(FicherosSeleccionados) end; end; procedure TfrViewDocumentos.CustomViewCreate(Sender: TObject); begin inherited; FDirectorio := Null; FListaFicheros := Nil; end; procedure TfrViewDocumentos.CustomViewDestroy(Sender: TObject); begin FDirectorio := Null; FreeAndNil(FListaFicheros); inherited; end; function TfrViewDocumentos.DarFicherosSeleccionados: TStringList; var i: Integer; begin Result := TStringList.Create; for i := 0 to ListaDocumentos.Count - 1 do begin if ListaDocumentos.Selected[i] then Result.Add(Directorio + ListaDocumentos.Items[i]); end; end; function TfrViewDocumentos.GetDirectorio: Variant; begin if VarIsNull(FDirectorio) then begin FDirectorio := DarDirectorioTemporal; if not CreateDir(FDirectorio) then raise Exception.Create('ERROR: No se ha podido crear el fichero temporal GetDirectorio'); end; Result := FDirectorio; end; procedure TfrViewDocumentos.RefrescarVisualizador; begin ListaDocumentos.Clear; ListaDocumentos.Items.AddStrings(FListaFicheros); end; end.