Ignore:
Timestamp:
May 4, 2016, 12:54:09 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Acronyms management is not done in Acronyms window. List in main window is just for viewing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r18 r19  
    1616
    1717  TFormMain = class(TForm)
    18     AAcronymAdd: TAction;
    19     AAcronymModify: TAction;
    20     AAcronymRemove: TAction;
    21     AAcronymRemoveAll: TAction;
    2218    AShowAcronyms: TAction;
    2319    AShowCategories: TAction;
     
    3430    CheckBoxExactMath: TCheckBox;
    3531    CoolTranslator1: TCoolTranslator;
     32    ImageList1: TImageList;
    3633    LastOpenedList1: TLastOpenedList;
    3734    ListViewAcronyms: TListView;
     
    5653    MenuItem2: TMenuItem;
    5754    MenuItem3: TMenuItem;
    58     MenuItem4: TMenuItem;
    59     MenuItem5: TMenuItem;
    60     MenuItem6: TMenuItem;
    61     MenuItem7: TMenuItem;
    6255    MenuItem8: TMenuItem;
    6356    MenuItem9: TMenuItem;
    6457    OpenDialog1: TOpenDialog;
    6558    PersistentForm1: TPersistentForm;
    66     PopupMenuAcronym: TPopupMenu;
    6759    PopupMenuTryIcon: TPopupMenu;
    6860    SaveDialog1: TSaveDialog;
    6961    TrayIcon1: TTrayIcon;
    70     procedure AAcronymAddExecute(Sender: TObject);
    71     procedure AAcronymModifyExecute(Sender: TObject);
    72     procedure AAcronymRemoveAllExecute(Sender: TObject);
    73     procedure AAcronymRemoveExecute(Sender: TObject);
    7462    procedure AExitExecute(Sender: TObject);
    7563    procedure AFileCloseExecute(Sender: TObject);
     
    9280    procedure LastOpenedList1Change(Sender: TObject);
    9381    procedure ListViewAcronymsData(Sender: TObject; Item: TListItem);
    94     procedure ListViewAcronymsDblClick(Sender: TObject);
    95     procedure ListViewAcronymsKeyPress(Sender: TObject; var Key: char);
    9682    procedure ListViewAcronymsSelectItem(Sender: TObject; Item: TListItem;
    9783      Selected: Boolean);
     
    10288  private
    10389    FAlwaysOnTop: Boolean;
    104     function CompareStrings(Strings1, Strings2: TStrings): Boolean;
    105     procedure SetAlwaysOnTop(AValue: Boolean);
    106   private
    10790    RegistryContext: TRegistryContext;
    10891    ProjectClosed: Boolean;
     92    procedure SetAlwaysOnTop(AValue: Boolean);
    10993    procedure FilterList(List: TListObject);
    11094    procedure OpenRecentClick(Sender: TObject);
     
    11599  public
    116100    AcronymDb: TAcronymDb;
     101    function CompareStrings(Strings1, Strings2: TStrings): Boolean;
    117102    property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
    118103  end;
     
    132117  SAppExit = 'Application exit';
    133118  SAppExitQuery = 'Acronyms were modified. Do you want to save them to file before exit?';
    134   SRemoveAllAcronyms = 'Remove all acronyms';
    135   SRemoveAllAcronymsQuery = 'Do you want to remove all acronyms?';
    136   SRemoveAcronym = 'Remove acronym';
    137   SRemoveAcronymQuery = 'Do you want to remove selected acronym?';
    138119
    139120const
     
    243224end;
    244225
    245 procedure TFormMain.AAcronymModifyExecute(Sender: TObject);
    246 var
    247   TempEntry: TAcronymEntry;
    248   TempCategories: TStringList;
    249   Meaning: TAcronymMeaning;
    250   I: Integer;
    251 begin
    252   if Assigned(ListViewAcronyms.Selected) then
    253   with TAcronymMeaning(ListViewAcronyms.Selected.Data) do begin
    254     TempEntry := TAcronymEntry.Create;
    255     TempEntry.Name := Acronym.Name;
    256     TempEntry.Meaning := Name;
    257     TempEntry.Description := Description;
    258     Categories.AssignToStrings(TempEntry.Categories);
    259     TempCategories := TStringList.Create;
    260     TempCategories.Assign(TempEntry.Categories);
    261     FormAcronym.Load(TempEntry);
    262     if FormAcronym.ShowModal = mrOk then begin
    263       FormAcronym.Save(TempEntry);
    264       if (TempEntry.Name <> Acronym.Name) or
    265       (TempEntry.Meaning <> Name) or
    266       (TempEntry.Description <> Description) or
    267       not CompareStrings(TempEntry.Categories, TempCategories) then begin
    268         // TODO: Update item inplace if possible
    269         AcronymDb.RemoveAcronym(Acronym.Name, Name);
    270         Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
    271         Meaning.Description := TempEntry.Description;
    272         Meaning.Categories.AssignFromStrings(TempEntry.Categories);
    273         for I := 0 to Meaning.Categories.Count - 1 do
    274           TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
    275         UpdateAcronymsList;
    276         UpdateInterface;
    277       end;
    278     end;
    279     TempEntry.Free;
    280     TempCategories.Free;
    281   end;
    282 end;
    283 
    284 procedure TFormMain.AAcronymRemoveAllExecute(Sender: TObject);
    285 begin
    286   if MessageDlg(SRemoveAllAcronyms, SRemoveAllAcronymsQuery,
    287   TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
    288     AcronymDb.Acronyms.Clear;
    289     AcronymDb.Modified := True;
    290     UpdateAcronymsList;
    291     UpdateInterface;
    292   end;
    293 end;
    294 
    295 procedure TFormMain.AAcronymRemoveExecute(Sender: TObject);
    296 begin
    297   if Assigned(ListViewAcronyms.Selected) then begin
    298     if MessageDlg(SRemoveAcronym, SRemoveAcronymQuery,
    299     TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
    300       AcronymDb.RemoveAcronym(TAcronymMeaning(ListViewAcronyms.Selected.Data).Acronym.Name,
    301         TAcronymMeaning(ListViewAcronyms.Selected.Data).Name);
    302       UpdateAcronymsList;
    303       UpdateInterface;
    304     end;
    305   end;
    306 end;
    307 
    308 procedure TFormMain.AAcronymAddExecute(Sender: TObject);
    309 var
    310   TempEntry: TAcronymEntry;
    311   Meaning: TAcronymMeaning;
    312   I: Integer;
    313 begin
    314   TempEntry := TAcronymEntry.Create;
    315   TempEntry.Name := '';
    316   TempEntry.Meaning := '';
    317   TempEntry.Description := '';
    318   FormAcronym.Load(TempEntry);
    319   if FormAcronym.ShowModal = mrOk then begin
    320     FormAcronym.Save(TempEntry);
    321     Meaning := AcronymDb.AddAcronym(TempEntry.Name, TempEntry.Meaning);
    322     Meaning.Description := TempEntry.Description;
    323     Meaning.Categories.AssignFromStrings(TempEntry.Categories);
    324     for I := 0 to Meaning.Categories.Count - 1 do
    325       TAcronymCategory(Meaning.Categories.Items[I]).AcronymMeanings.Add(Meaning);
    326     UpdateAcronymsList;
    327     UpdateInterface;
    328   end;
    329   TempEntry.Free;
    330 end;
    331 
    332226procedure TFormMain.AImportExecute(Sender: TObject);
    333227begin
     
    397291    Item.SubItems.Add(Categories.GetString);
    398292  end;
    399 end;
    400 
    401 procedure TFormMain.ListViewAcronymsDblClick(Sender: TObject);
    402 begin
    403   AAcronymModify.Execute;
    404 end;
    405 
    406 procedure TFormMain.ListViewAcronymsKeyPress(Sender: TObject; var Key: char);
    407 begin
    408293end;
    409294
     
    528413begin
    529414  ListViewAcronyms.Enabled := Assigned(AcronymDb);
    530   AAcronymRemove.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected);
    531   AAcronymModify.Enabled := Assigned(AcronymDb) and Assigned(ListViewAcronyms.Selected);
    532   AAcronymAdd.Enabled := Assigned(AcronymDb);
    533   AAcronymRemoveAll.Enabled := Assigned(AcronymDb) and (AcronymDb.Acronyms.Count > 0);
    534415  AFileClose.Enabled := Assigned(AcronymDb);
    535416  AFileSave.Enabled := Assigned(AcronymDb) and AcronymDb.Modified;
Note: See TracChangeset for help on using the changeset viewer.