339 lines
11 KiB
ObjectPascal
339 lines
11 KiB
ObjectPascal
|
|
unit uViewDocumentos;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, uViewBase, cxControls,
|
|||
|
|
cxContainer, ActnList, TB2Item, TBX, TB2Dock, TB2Toolbar, StdCtrls,
|
|||
|
|
FileCtrl, cxGraphics, cxCustomData, cxStyles, cxInplaceContainer,
|
|||
|
|
cxTextEdit, ComCtrls, ImgList, PngImageList;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TfrViewDocumentos = class(TfrViewBase)
|
|||
|
|
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;
|
|||
|
|
ListView1: TListView;
|
|||
|
|
LargeImagesBrowser: TPngImageList;
|
|||
|
|
SmallImagesBrowser: TPngImageList;
|
|||
|
|
TBXSeparatorItem1: TTBXSeparatorItem;
|
|||
|
|
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);
|
|||
|
|
procedure actModificarUpdate(Sender: TObject);
|
|||
|
|
procedure actEliminarUpdate(Sender: TObject);
|
|||
|
|
procedure actEliminarTodoUpdate(Sender: TObject);
|
|||
|
|
procedure ListView1DblClick(Sender: TObject);
|
|||
|
|
|
|||
|
|
private
|
|||
|
|
FDirectorio: Variant;
|
|||
|
|
function GetDirectorio: Variant;
|
|||
|
|
function DarFicherosSeleccionados: TStringList;
|
|||
|
|
function AsignarImagen(ANombreFichero: String): Integer;
|
|||
|
|
|
|||
|
|
protected
|
|||
|
|
FHayModificaciones: Boolean;
|
|||
|
|
FListaFicheros: TStringList;
|
|||
|
|
property Directorio: Variant read GetDirectorio;
|
|||
|
|
property ListaFicheros: TStringList read FListaFicheros write FListaFicheros;
|
|||
|
|
|
|||
|
|
function GetModified: Boolean; override;
|
|||
|
|
procedure SetModified(const Value : Boolean); override;
|
|||
|
|
|
|||
|
|
//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;
|
|||
|
|
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;
|
|||
|
|
ANombreSeleccionado : String;
|
|||
|
|
BCopiar: Boolean;
|
|||
|
|
i, j : 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
|
|||
|
|
ANombreSeleccionado := openDialog.Files.Strings[i];
|
|||
|
|
if Length(ANombreSeleccionado) > 0 then
|
|||
|
|
begin
|
|||
|
|
BCopiar := True;
|
|||
|
|
ANombreFichero := ExtractFileName(ANombreSeleccionado);
|
|||
|
|
if FListaFicheros.Find(ANombreFichero, j) then
|
|||
|
|
begin
|
|||
|
|
ANombreFichero := 'Copia de ' + ANombreFichero;
|
|||
|
|
BCopiar := (Application.MessageBox(PChar('Ya existe un archivo con ese nombre, <20>Desea a<>adirlo con el nombre ' + ANombreFichero + '?'), 'Atenci<63>n', MB_YESNO) = IDYES);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
if BCopiar then
|
|||
|
|
begin
|
|||
|
|
CopiarFichero(ANombreSeleccionado, (Directorio + ANombreFichero));
|
|||
|
|
//Lo a<>adimos a la lista de documentos local
|
|||
|
|
FListaFicheros.Add(ANombreFichero);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
finally
|
|||
|
|
openDialog.Free;
|
|||
|
|
//Now, We compact the process memory:
|
|||
|
|
SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF);
|
|||
|
|
RefrescarVisualizador;
|
|||
|
|
FHayModificaciones := True;
|
|||
|
|
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<61> 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;
|
|||
|
|
FHayModificaciones := True;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.actEliminarTodoExecute(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
if DirectoryExists(Directorio) then
|
|||
|
|
Deltree(Directorio, True);
|
|||
|
|
FListaFicheros.Clear;
|
|||
|
|
FDirectorio := Null;
|
|||
|
|
RefrescarVisualizador;
|
|||
|
|
FHayModificaciones := True;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.actEliminarTodoUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := (ListView1.Items.Count > 0)
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.actEliminarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := Assigned(ListView1.ItemFocused);
|
|||
|
|
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);
|
|||
|
|
FHayModificaciones := True;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.actModificarUpdate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
(Sender as TAction).Enabled := Assigned(ListView1.ItemFocused);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TfrViewDocumentos.AsignarImagen(ANombreFichero: String): Integer;
|
|||
|
|
begin
|
|||
|
|
Result := -1;
|
|||
|
|
|
|||
|
|
if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.txt')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.ini')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.sql') then
|
|||
|
|
Result := 1
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.pdf') then
|
|||
|
|
Result := 3
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.doc')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.rtf') then
|
|||
|
|
Result := 2
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.ppt')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.pps')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.ppa') then
|
|||
|
|
Result := 7
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.mdb')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.adp')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.mde')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.ade')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.mda') then
|
|||
|
|
Result := 5
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.xls')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.xl')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.xlt')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.xla')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.xlc') then
|
|||
|
|
Result := 4
|
|||
|
|
|
|||
|
|
else if (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.png')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.tif')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.pict')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.pct')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.bmp')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.gif')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.jpg')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.jpeg')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.jpe')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.png')
|
|||
|
|
or (LOWERCASE(ExtractFileExt(ANombreFichero)) = '.tiff') then
|
|||
|
|
Result := 6
|
|||
|
|
|
|||
|
|
else Result := 0;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.CustomViewCreate(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FDirectorio := Null;
|
|||
|
|
FListaFicheros := Nil;
|
|||
|
|
FHayModificaciones:= False;
|
|||
|
|
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 ListView1.Items.Count - 1 do
|
|||
|
|
begin
|
|||
|
|
if ListView1.Items[i].Selected then
|
|||
|
|
Result.Add(Directorio + ListView1.Items[i].Caption);
|
|||
|
|
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;
|
|||
|
|
|
|||
|
|
function TfrViewDocumentos.GetModified: Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := FHayModificaciones;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.ListView1DblClick(Sender: TObject);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
if Assigned(ListView1.ItemFocused) then
|
|||
|
|
actModificar.Execute;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.RefrescarVisualizador;
|
|||
|
|
var
|
|||
|
|
i: Integer;
|
|||
|
|
AItem: TListItem;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
ListView1.Clear;
|
|||
|
|
for i := 0 to FListaFicheros.Count - 1 do
|
|||
|
|
begin
|
|||
|
|
AItem := ListView1.Items.Add;
|
|||
|
|
AItem.Caption := FListaFicheros.Strings[i];
|
|||
|
|
AItem.ImageIndex := AsignarImagen(FListaFicheros.Strings[i]);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TfrViewDocumentos.SetModified(const Value: Boolean);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
FHayModificaciones := Value;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|