diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 681ac0089..8887141e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(keepassx_SOURCES autotype/AutoType.cpp autotype/AutoTypeAction.cpp autotype/ShortcutWidget.cpp + autotype/WindowSelectComboBox.cpp core/AutoTypeAssociations.cpp core/Config.cpp core/Database.cpp @@ -99,6 +100,7 @@ set(keepassx_SOURCES set(keepassx_MOC autotype/AutoType.h autotype/ShortcutWidget.h + autotype/WindowSelectComboBox.h core/AutoTypeAssociations.h core/Config.h core/Database.h diff --git a/src/autotype/WindowSelectComboBox.cpp b/src/autotype/WindowSelectComboBox.cpp new file mode 100644 index 000000000..6c26b7620 --- /dev/null +++ b/src/autotype/WindowSelectComboBox.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2012 Felix Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "WindowSelectComboBox.h" + +#include + +#include "autotype/AutoType.h" + +WindowSelectComboBox::WindowSelectComboBox(QWidget* parent) + : QComboBox(parent) +{ + setEditable(true); + setInsertPolicy(QComboBox::NoInsert); + setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::ComboBox)); + + // first item is always the current content of the line edit + insertItem(0, ""); +} + +void WindowSelectComboBox::refreshWindowList() +{ + model()->setData(model()->index(0, 0), lineEdit()->text()); + + while (count() > 1) { + removeItem(1); + } + insertItems(1, autoType()->windowTitles()); +} + +void WindowSelectComboBox::showPopup() +{ + if (lineEdit()->isReadOnly()) { + return; + } + + refreshWindowList(); + + QComboBox::showPopup(); +} + +QSize WindowSelectComboBox::sizeHint() const +{ + QSize size = lineEdit()->sizeHint(); + size.setHeight(qMax(size.height(), QComboBox::sizeHint().height())); + return size; +} + +QSize WindowSelectComboBox::minimumSizeHint() const +{ + QSize size = lineEdit()->minimumSizeHint(); + size.setHeight(qMax(size.height(), QComboBox::minimumSizeHint().height())); + return size; +} diff --git a/src/autotype/WindowSelectComboBox.h b/src/autotype/WindowSelectComboBox.h new file mode 100644 index 000000000..6fb839ab8 --- /dev/null +++ b/src/autotype/WindowSelectComboBox.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 Felix Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSX_WINDOWSELECTCOMBOBOX_H +#define KEEPASSX_WINDOWSELECTCOMBOBOX_H + +#include + +#include "core/Global.h" + +class WindowSelectComboBox : public QComboBox +{ + Q_OBJECT + +public: + explicit WindowSelectComboBox(QWidget* parent = Q_NULLPTR); + void refreshWindowList(); + + void showPopup() Q_DECL_OVERRIDE; + QSize sizeHint() const Q_DECL_OVERRIDE; + QSize minimumSizeHint() const Q_DECL_OVERRIDE; +}; + +#endif // KEEPASSX_WINDOWSELECTCOMBOBOX_H diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 90dd63134..669395ae9 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -29,7 +29,6 @@ #include #include -#include "autotype/AutoType.h" #include "core/Database.h" #include "core/Entry.h" #include "core/Metadata.h" @@ -280,10 +279,6 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) iconStruct.number = entry->iconNumber(); m_iconsWidget->load(entry->uuid(), m_database, iconStruct); - m_autoTypeUi->windowTitleCombo->clear(); - if (!m_history) { - m_autoTypeUi->windowTitleCombo->insertItems(0, autoType()->windowTitles()); - } m_autoTypeUi->windowTitleCombo->lineEdit()->clear(); m_autoTypeAssoc->copyDataFrom(entry->autoTypeAssociations()); m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled()); @@ -297,6 +292,9 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore) if (m_autoTypeAssoc->size() != 0) { m_autoTypeUi->assocView->setCurrentIndex(m_autoTypeAssocModel->index(0, 0)); } + if (!m_history) { + m_autoTypeUi->windowTitleCombo->refreshWindowList(); + } updateAutoTypeEnabled(); if (!m_history && !restore) { diff --git a/src/gui/entry/EditEntryWidgetAutoType.ui b/src/gui/entry/EditEntryWidgetAutoType.ui index 28e2fe667..c1245e67c 100644 --- a/src/gui/entry/EditEntryWidgetAutoType.ui +++ b/src/gui/entry/EditEntryWidgetAutoType.ui @@ -76,7 +76,7 @@ - + @@ -150,11 +150,7 @@ - - - true - - + @@ -232,6 +228,13 @@ + + + WindowSelectComboBox + QComboBox +
autotype/WindowSelectComboBox.h
+
+