2008-08-27 14:17:04 +00:00
|
|
|
|
unit uViewDocumentos;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
2008-08-27 16:48:20 +00:00
|
|
|
|
Dialogs, uViewBase, cxControls,
|
2008-08-27 14:17:04 +00:00
|
|
|
|
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);
|
2008-08-27 16:15:43 +00:00
|
|
|
|
procedure actActualizarServidorExecute(Sender: TObject);
|
2008-08-27 14:17:04 +00:00
|
|
|
|
procedure CustomViewCreate(Sender: TObject);
|
|
|
|
|
|
procedure CustomViewDestroy(Sender: TObject);
|
2008-08-27 16:15:43 +00:00
|
|
|
|
|
2008-08-27 14:17:04 +00:00
|
|
|
|
private
|
|
|
|
|
|
FDirectorio: Variant;
|
|
|
|
|
|
function GetDirectorio: Variant;
|
|
|
|
|
|
function DarFicherosSeleccionados: TStringList;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
|
2008-08-27 14:17:04 +00:00
|
|
|
|
protected
|
2008-08-27 16:15:43 +00:00
|
|
|
|
FListaFicheros: TStringList;
|
|
|
|
|
|
property Directorio: Variant read GetDirectorio;
|
|
|
|
|
|
|
|
|
|
|
|
//Son los metodos que se sobreescribiran en la vista hija
|
2008-08-27 14:17:04 +00:00
|
|
|
|
procedure Sincronizar; virtual; abstract;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
function RecuperarFicheroServidor(const NombreFichero: String; const DirectorioDestino: String): Boolean; virtual; abstract;
|
|
|
|
|
|
procedure RefrescarVisualizador; virtual;
|
|
|
|
|
|
|
2008-08-27 14:17:04 +00:00
|
|
|
|
public
|
2008-08-27 16:15:43 +00:00
|
|
|
|
property ListaFicheros: TStringList read FListaFicheros;
|
|
|
|
|
|
|
2008-08-27 14:17:04 +00:00
|
|
|
|
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;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
ANombreFichero : String;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
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
|
2008-08-27 16:15:43 +00:00
|
|
|
|
ANombreFichero := openDialog.Files.Strings[i];
|
|
|
|
|
|
if Length(ANombreFichero) > 0 then
|
|
|
|
|
|
CopiarFichero(ANombreFichero, (Directorio + ExtractFileName(ANombreFichero)));
|
2008-08-27 14:17:04 +00:00
|
|
|
|
|
|
|
|
|
|
//Lo a<>adimos a la lista de documentos local
|
2008-08-27 16:15:43 +00:00
|
|
|
|
FListaFicheros.Add(ExtractFileName(ANombreFichero))
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
|
openDialog.Free;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
//Now, We compact the process memory:
|
|
|
|
|
|
SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF);
|
|
|
|
|
|
RefrescarVisualizador;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrViewDocumentos.actEliminarExecute(Sender: TObject);
|
|
|
|
|
|
var
|
|
|
|
|
|
i, j: Integer;
|
|
|
|
|
|
FicherosSeleccionados: TStringList;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
ANombreFichero: String;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
FicherosSeleccionados := DarFicherosSeleccionados;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
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);
|
2008-08-27 14:17:04 +00:00
|
|
|
|
|
2008-08-27 16:15:43 +00:00
|
|
|
|
//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;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrViewDocumentos.actEliminarTodoExecute(Sender: TObject);
|
|
|
|
|
|
begin
|
2008-08-27 16:15:43 +00:00
|
|
|
|
Deltree(Directorio, True);
|
|
|
|
|
|
FListaFicheros.Clear;
|
|
|
|
|
|
FDirectorio := Null;
|
|
|
|
|
|
RefrescarVisualizador;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrViewDocumentos.actModificarExecute(Sender: TObject);
|
|
|
|
|
|
var
|
|
|
|
|
|
i: Integer;
|
|
|
|
|
|
FicherosSeleccionados: TStringList;
|
|
|
|
|
|
begin
|
|
|
|
|
|
FicherosSeleccionados := DarFicherosSeleccionados;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
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;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrViewDocumentos.CustomViewCreate(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
FDirectorio := Null;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
FListaFicheros := Nil;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TfrViewDocumentos.CustomViewDestroy(Sender: TObject);
|
|
|
|
|
|
begin
|
|
|
|
|
|
FDirectorio := Null;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
FreeAndNil(FListaFicheros);
|
2008-08-27 14:17:04 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
2008-08-27 16:15:43 +00:00
|
|
|
|
procedure TfrViewDocumentos.RefrescarVisualizador;
|
2008-08-27 14:17:04 +00:00
|
|
|
|
begin
|
|
|
|
|
|
ListaDocumentos.Clear;
|
2008-08-27 16:15:43 +00:00
|
|
|
|
ListaDocumentos.Items.AddStrings(FListaFicheros);
|
2008-08-27 14:17:04 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|