📄 umainmodule.pas
字号:
F.ShowModal;
finally
F.Free;
end;
end;
procedure TMainModule.ExportXmiActionExecute(Sender: TObject);
begin
DoXmiFile;
end;
procedure TMainModule.LayoutDiagramActionExecute(Sender: TObject);
begin
Diagram.DoLayout;
end;
procedure TMainModule.ProcessCommandLine;
var
I : integer;
Files : TStringList;
S : string;
DocGenDir : string;
IsDocGen : boolean;
XmiFile : string;
IsXmi : boolean;
procedure InShowHelp;
begin
ShowMessage(
'Syntax: '#9 + ChangeFileExt(ExtractFileName(Application.ExeName),'') + ' [options] [@list] [files...]'#13#10#13#10 +
'Valid options are:'#13#10#13#10+
' -d[path]'#9'Generate documentation to the path specified'#13#10 +
' -a[+/-]'#9'Show associations on generated diagrams on/off'#13#10 +
' -v[0-3]'#9'Visibilty filter for generated diagrams'#13#10 +
' -x[file]'#9'Export model to xmi file')
end;
procedure InOne(S : string);
var
IsAbsolute : boolean;
DirInfo: TSearchRec;
Code,I : integer;
L : TStringList;
begin
if Pos('@',S)=1 then
begin
//File with a list of filenames
L := TStringList.Create;
try
L.LoadFromFile( Copy(S,2,255) );
for I := 0 to L.Count - 1 do
InOne(L[I]);
finally
L.Free;
end;
end;
//Files added on the command line needs their home directory added to searchpaths
IsAbsolute := ( Pos(Copy(S,1,1),'\/')>0 ) or (Copy(S,2,1)=':');
if not IsAbsolute then
S := GetCurrentDir + PathDelim + S;
if LastDelimiter('*?',S)>0 then
begin
//Expand wildcards
Code := FindFirst(S, 0, DirInfo);
while Code = 0 do
begin
Files.Add( ExtractFilePath(S) + DirInfo.Name );
Code := FindNext(DirInfo);
end;
FindClose(DirInfo);
end
else
Files.Add( S );
end;
begin
Files := TStringList.Create;
try
IsDocGen := False;
IsXmi := False;
for I := 1 to ParamCount do
begin
S := ParamStr(I);
if Copy(S,1,2)='-d' then
begin //-d Generate documentation
DocGenDir := Copy(S,3,255);
IsDocGen := True;
end
else if Copy(S,1,2)='-x' then
begin //-x Generate xmi-file
XmiFile := Copy(S,3,255);
IsXmi := True;
end else if Copy(S,1,2)='-a' then
begin //Show associations on/off
Config.DiShowAssoc := Copy(S,3,1)<>'-';
end else if Copy(S,1,2)='-v' then
begin //Visibility filter
Config.DiVisibilityFilter := StrToIntDef(Copy(S,3,1),0 );
end
else if (S='-?') or (S='-help') then
InShowHelp
else if (S='-traceon') then
//ignore
else if (S<>'') and (S[1]='-') then
ShowMessage('Ignoring unknown switch: ' + S)
else if (S<>'') and (S[1]<>'-') then
InOne( ParamStr(I) );
end;
if Files.Count>0 then
LoadProject(Files);
// Do stuff after the model is read in
// the program will exit automatically
if IsDocGen then
DoDocGen(False,DocGenDir);
if IsXmi then
DoXmiFile(XmiFile);
if IsDocGen or IsXmi then
//Delayed exit by using a timer, this is so that all global objects have
//time to initialize (MainForm, MainModule). Otherwise this would be a
//special case exit.
CloseTimer.Enabled := True;
finally
Files.Free;
end;
end;
procedure TMainModule.FileOpenActionExecute(Sender: TObject);
const
// Keep dialog alive between calls so the searchpath is retained
D : TOpenDialog = nil;
var
Ints : TClassList;
Exts : TStringList;
I,J : integer;
AnyFilter,
Filter : string;
begin
Filter := '';
Ints := Integrators.Get(TImportIntegrator);
try
for I := 0 to Ints.Count - 1 do
begin
Exts := TImportIntegratorClass(Ints[I]).GetFileExtensions;
try
for J := 0 to Exts.Count - 1 do
begin
if Filter<>'' then
Filter := Filter + '|';
Filter := Filter + Exts.Values[ Exts.Names[J] ] + ' (*' + Exts.Names[J] + ')|*' + Exts.Names[J];
if AnyFilter<>'' then
AnyFilter := AnyFilter + ';';
AnyFilter := AnyFilter + '*' + Exts.Names[J];
end;
finally
Exts.Free;
end;
end;
finally
Ints.Free;
end;
Filter := 'All types (' + AnyFilter + ')|' + AnyFilter + '|' + Filter;
if not Assigned(D) then
begin
D := TOpenDialog.Create(MainForm);
D.Filter := Filter;
D.Options := D.Options + [ofAllowMultiSelect];
end;
if D.Execute then
LoadProject(D.Files);
end;
procedure TMainModule.ExitActionExecute(Sender: TObject);
begin
Application.MainForm.Close;
end;
procedure TMainModule.DoDocGen(IsPreview : boolean; const DestPath: string = '');
var
Doc : TDocGen;
begin
Screen.Cursor := crHourGlass;
Doc := uDocGen.CreateDocGen(Model);
try
Doc.DestPath := DestPath;
Doc.IsPreview := IsPreview;
Doc.InitFromModel;
finally
Screen.Cursor := crArrow;
Doc.Free;
end;
end;
procedure TMainModule.SettingsActionExecute(Sender: TObject);
var
F : TForm;
begin
F := TSettingsForm.Create(Self);
try
F.ShowModal;
finally
F.Free;
end;
end;
procedure TMainModule.UnhideElementsActionUpdate(Sender: TObject);
begin
UnhideElementsAction.Enabled := Diagram.HasHiddenElements;
end;
procedure TMainModule.UnhideElementsActionExecute(Sender: TObject);
begin
Diagram.UnHideAllElements;
end;
procedure TMainModule.DoXmiFile(const DestFile: string);
var
Xmi : {$IFDEF ARGO_XMI}TXMIExporterArgoUML{$ELSE}TXmiExporter{$ENDIF};
begin
Xmi := {$IFDEF ARGO_XMI}TXMIExporterArgoUML{$ELSE}TXmiExporter{$ENDIF}.Create(Model,Feedback);
try
Screen.Cursor := crHourGlass;
Xmi.InitFromModel;
if DestFile='' then
Xmi.ShowSaveDialog
else
Xmi.SaveTo(DestFile);
finally
Screen.Cursor := crArrow;
Xmi.Free;
end;
end;
procedure TMainModule.RefreshRecentFiles;
var
Items : array of TMenuItem;
M : TMenuItem;
I : integer;
begin
//MAke sure the list never grows beyond 10 items
while RecentFiles.Count>10 do
RecentFiles.Delete(RecentFiles.Count-1);
// Erase old menuitems
while MainForm.ReopenMenuItem.Count>0 do
MainForm.ReopenMenuItem.Items[0].Free;
SetLength(Items,RecentFiles.Count);
for I := 0 to RecentFiles.Count-1 do
begin
M := TMenuItem.Create(MainForm);
M.Caption := '&' + IntToStr(I) + ' ' + RecentFiles[I];
M.OnClick := OnRecentFilesClicked;
M.Tag := I;
Items[I]:= M;
end;
MainForm.ReopenMenuItem.Add(Items);
end;
procedure TMainModule.OnRecentFilesClicked(Sender: TObject);
begin
LoadProject( RecentFiles[ (Sender as TMenuItem).Tag ] );
end;
procedure TMainModule.SaveDiagramActionExecute(Sender: TObject);
const
D : TSaveDialog = nil;
begin
if not Assigned(D) then
begin
D := TSaveDialog.Create(MainForm);
D.InitialDir := ExtractFilePath( Model.ModelRoot.GetConfigFile );
D.Filter := 'PNG files (*.png)|*.gif|WMF files (*.wmf)|*.wmf|All files (*.*)|*.*';
D.Options := D.Options + [ofOverwritePrompt];
end;
if D.Execute then
begin
if ExtractFileExt(D.FileName)='' then
begin
if D.FilterIndex=1 then
D.FileName := ChangeFileExt(D.FileName,'.png')
else D.FileName := ChangeFileExt(D.FileName,'.wmf');
end;
Diagram.SaveAsPicture( D.FileName );
end;
end;
procedure TMainModule.DocGenPreviewActionExecute(Sender: TObject);
begin
DoDocGen(True);
end;
procedure TMainModule.CloseTimerTimer(Sender: TObject);
begin
ExitAction.Execute;
end;
procedure TMainModule.OpenFolderActionExecute(Sender: TObject);
const
F : TOpenFolderForm = nil;
var
L : TStringList;
Ints : TClassList;
Exts : TStringList;
I : integer;
procedure _AddFileNames(Files : TStringList; Path,Ext : string);
var
Sr : TSearchRec;
begin
{$WARN SYMBOL_PLATFORM OFF}
if FindFirst(Path + '\*.*', faReadOnly or faDirectory, Sr)=0 then
begin
repeat
if (Sr.Name<>'.') and (Sr.Name<>'..') then
begin
if (Sr.Attr and faDirectory=faDirectory) then
_AddFileNames(Files,Path + '\' + Sr.Name,Ext)
else
if CompareText(ExtractFileExt(Sr.Name),Ext)=0 then
Files.Add(Path + '\' + Sr.Name);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
{$WARN SYMBOL_PLATFORM ON}
end;
begin
L := TStringList.Create;
Ints := Integrators.Get(TImportIntegrator);
try
if not Assigned(F) then
begin
F := TOpenFolderForm.Create(MainForm);
for I := 0 to Ints.Count - 1 do
begin
Exts := TImportIntegratorClass(Ints[I]).GetFileExtensions;
F.FileTypeCombo.Items.Add( '*' + Exts.Names[0]);
end;
F.FileTypeCombo.ItemIndex := F.FileTypeCombo.Items.Count-1;
end;
if F.ShowModal=mrOk then
begin
_AddFileNames(L,F.PathTreeView.Path, Copy(F.FileTypeCombo.Items[ F.FileTypeCombo.ItemIndex ],2,10) );
if L.Count>0 then
LoadProject(L)
else
ShowMessage('No files found');
end;
finally
L.Free;
Ints.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -