Commits

tariq  committed ba1fb70

menu item (de)activation for selection modes of group/entry view

git-svn-id: https://keepassx.svn.sourceforge.net/svnroot/keepassx/trunk@10b624d157-de02-0410-bad0-e51aec6abb33

  • Participants
  • Parent commits 1920e80

Comments (0)

Files changed (3)

File src/forms/MainWindow.ui

     <addaction name="separator" />
     <addaction name="EditPasswordToClipboardAction" />
     <addaction name="EditUsernameToClipboardAction" />
-    <addaction name="ActionOpenUrl" />
+    <addaction name="OpenUrlAction" />
     <addaction name="EditSaveAttachmentAction" />
     <addaction name="separator" />
     <addaction name="EditNewEntryAction" />
     <string>Benutzername in Zwischenablage kopieren</string>
    </property>
   </action>
-  <action name="ActionOpenUrl" >
+  <action name="OpenUrlAction" >
    <property name="text" >
     <string>URL öffnen</string>
    </property>

File src/mainwindow.cpp

 	   SLOT(OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
    connect(EntryView,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,
 	   SLOT(OnEntryItemDoubleClicked(QTreeWidgetItem*,int)));
+   connect(EntryView,SIGNAL(itemSelectionChanged()), this, SLOT(OnEntrySelectionChanged()));
+   connect(GroupView,SIGNAL(itemSelectionChanged()), this, SLOT(OnGroupSelectionChanged()));
 }
 
 void KeepassMainWindow::setupToolbar(){
 FileCloseAction->setEnabled(IsOpen);
 FileSettingsAction->setEnabled(IsOpen);
 FileChangeKeyAction->setEnabled(IsOpen);
+EditSearchAction->setEnabled(IsOpen);
 GroupView->setEnabled(IsOpen);
 EntryView->setEnabled(IsOpen);
+if(!IsOpen){
+    EditNewGroupAction->setEnabled(false);
+    EditEditGroupAction->setEnabled(false);
+    EditDeleteGroupAction->setEnabled(false);
+    EditPasswordToClipboardAction->setEnabled(false);
+    EditUsernameToClipboardAction->setEnabled(false);
+    OpenUrlAction->setEnabled(false);
+    EditSaveAttachmentAction->setEnabled(false);
+    EditNewEntryAction->setEnabled(false);
+    EditEditEntryAction->setEnabled(false);
+    EditCloneEntryAction->setEnabled(false);
+    EditDeleteEntryAction->setEnabled(false);
+    EditGroupSearchAction->setEnabled(false);
+}
+else{
+    OnGroupSelectionChanged();
+    OnEntrySelectionChanged();
+}
+
 }
 
 void KeepassMainWindow::editEntry(CEntry* pEntry){
 FileSaveAction->setEnabled(mod);
 }
 
+void KeepassMainWindow::setStateGroupSelected(SelectionState s){
+GroupSelection=s;
+switch(GroupSelection){
+ case NONE:
+    EditNewGroupAction->setEnabled(true);
+    EditEditGroupAction->setEnabled(false);
+    EditDeleteGroupAction->setEnabled(false);
+    EditGroupSearchAction->setEnabled(false);
+    EditNewEntryAction->setEnabled(false);
+    break;
+ case SINGLE:
+    EditNewGroupAction->setEnabled(true);
+    EditEditGroupAction->setEnabled(true);
+    EditDeleteGroupAction->setEnabled(true);
+    EditGroupSearchAction->setEnabled(true);
+    EditNewEntryAction->setEnabled(true);
+    break;
+default: Q_ASSERT(false);
+}
+}
+
+void KeepassMainWindow::setStateEntrySelected(SelectionState s){
+EntrySelection=NONE;
+switch(EntrySelection){
+ case NONE:
+    EditPasswordToClipboardAction->setEnabled(false);
+    EditUsernameToClipboardAction->setEnabled(false);
+    OpenUrlAction->setEnabled(false);
+    EditSaveAttachmentAction->setEnabled(false);
+    EditEditEntryAction->setEnabled(false);
+    EditCloneEntryAction->setEnabled(false);
+    EditCloneEntryAction->setText(trUtf8("Eintrag duplizieren"));
+    EditDeleteEntryAction->setEnabled(false);
+    EditDeleteEntryAction->setText(trUtf8("Eintrag löschen"));
+    break;
+ case SINGLE:
+    EditPasswordToClipboardAction->setEnabled(true);
+    EditUsernameToClipboardAction->setEnabled(true);
+    OpenUrlAction->setEnabled(true);
+    EditSaveAttachmentAction->setEnabled(true);
+    EditEditEntryAction->setEnabled(true);
+    EditCloneEntryAction->setEnabled(true);
+    EditCloneEntryAction->setText(trUtf8("Eintrag duplizieren"));
+    EditDeleteEntryAction->setEnabled(true);
+    EditDeleteEntryAction->setText(trUtf8("Eintrag löschen"));
+    break;
+ case MULTIPLE:
+    EditPasswordToClipboardAction->setEnabled(false);
+    EditUsernameToClipboardAction->setEnabled(false);
+    OpenUrlAction->setEnabled(false);
+    EditSaveAttachmentAction->setEnabled(false);
+    EditEditEntryAction->setEnabled(false);
+    EditCloneEntryAction->setEnabled(true);
+    EditCloneEntryAction->setText(trUtf8("Einträge duplizieren"));
+    EditDeleteEntryAction->setEnabled(true);
+    EditDeleteEntryAction->setText(trUtf8("Einträge löschen"));
+    break;
+ default: Q_ASSERT(false);
+}
+}
 
 bool KeepassMainWindow::OnFileSave(){
 if(db->filename==QString())
 if(column) return;
 if(!config.Columns[0]) return;
 editEntry(static_cast<EntryViewItem*>(item)->pEntry);
+}
+
+void KeepassMainWindow::OnEntrySelectionChanged(){
+if(EntryView->selectedItems().size()==0)
+  setStateEntrySelected(NONE);
+if(EntryView->selectedItems().size()==1)
+  setStateEntrySelected(SINGLE);
+if(EntryView->selectedItems().size()>1)
+  setStateEntrySelected(MULTIPLE);
+
+}
+
+void KeepassMainWindow::OnGroupSelectionChanged(){
+if(GroupView->selectedItems().size()==0)
+  setStateGroupSelected(NONE);
+if(GroupView->selectedItems().size()==1)
+  setStateGroupSelected(SINGLE);
+Q_ASSERT(GroupView->selectedItems().size()<=1);
 }

File src/mainwindow.h

 
 #include "ui_MainWindow.h"
 
-#define NO_ENTRY_SELECTED
+
 
 class KeepassMainWindow : public QMainWindow, public Ui_MainWindow{
 Q_OBJECT
    void OnImportFromKWalletXml();
    void OnCurrentGroupChanged(QTreeWidgetItem*,QTreeWidgetItem*);
    void OnEntryItemDoubleClicked(QTreeWidgetItem* item,int column);
-
+   void OnEntrySelectionChanged();
+   void OnGroupSelectionChanged();
 
 private:
+ enum SelectionState{NONE,SINGLE,MULTIPLE};
+ SelectionState GroupSelection, EntrySelection;
  bool FileOpen;
  bool ModFlag;
  inline void setupToolbar();
  inline void setupConnections();
  void setStateFileOpen(bool);
  void setStateFileModified(bool);
+ void setStateGroupSelected(SelectionState s);
+ void setStateEntrySelected(SelectionState s);
  void openDatabase(QString filename);
  bool closeDatabase();
  void editEntry(CEntry* pEntry);