Esempio n. 1
0
CloseConfirmDialog::CloseConfirmDialog(
    QList<KTextEditor::Document*>& docs
  , KToggleAction* show_confirmation_action
  , QWidget* const parent
  )
  : QDialog(parent)
  , m_docs(docs)
{
    assert("Documents container expected to be non empty" && !docs.isEmpty());
    setupUi(this);
    
    setWindowTitle(i18nc("@title:window", "Close files confirmation"));
    setModal(true);
    buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
    
    icon->setPixmap(KIconLoader::global()->loadIcon(QStringLiteral("dialog-warning"),KIconLoader::Desktop,KIconLoader::SizeLarge));

    text->setText(
        i18nc("@label:listbox", "You are about to close the following documents:")
    );
    
    QStringList headers;
    headers << i18nc("@title:column", "Document") << i18nc("@title:column", "Location");
    m_docs_tree->setHeaderLabels(headers);
    m_docs_tree->setSelectionMode(QAbstractItemView::SingleSelection);
    m_docs_tree->setRootIsDecorated(false);

    for (int i = 0; i < m_docs.size(); i++)
    {
        new KateDocItem(m_docs[i], m_docs_tree);
    }
    m_docs_tree->header()->setStretchLastSection(false);
    m_docs_tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    m_docs_tree->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);

    m_dont_ask_again->setText(i18nc("option:check", "Do not ask again"));
    // NOTE If we are here, it means that 'Show Confirmation' action is enabled,
    // so not needed to read config...
    assert("Sanity check" && show_confirmation_action->isChecked());
    m_dont_ask_again->setCheckState(Qt::Unchecked);
    connect(m_dont_ask_again, SIGNAL(toggled(bool)), show_confirmation_action, SLOT(toggle()));

    // Update documents list according checkboxes
    connect(this, SIGNAL(accepted()), this, SLOT(updateDocsList()));

    KConfigGroup gcg(KSharedConfig::openConfig(), "kate-close-except-like-CloseConfirmationDialog");
    KWindowConfig::restoreWindowSize(windowHandle(),gcg);                                 // restore dialog geometry from config
}
CloseConfirmDialog::CloseConfirmDialog(
    QList<KTextEditor::Document*>& docs
  , KToggleAction* show_confirmation_action
  , QWidget* const parent
  )
  : KDialog(parent)
  , m_docs(docs)
{
    assert("Documents container expected to be non empty" && !docs.isEmpty());

    setCaption(i18n("Close files confirmation"));
    setButtons(Ok | Cancel);
    setModal(true);
    setDefaultButton(KDialog::Ok);

    KVBox* w = new KVBox(this);
    setMainWidget(w);
    w->setSpacing(KDialog::spacingHint());

    KHBox* lo1 = new KHBox(w);

    // dialog text
    QLabel* icon = new QLabel(lo1);
    icon->setPixmap(DesktopIcon("dialog-warning"));

    QLabel* t = new QLabel(
        i18n(
            "<qt>You are about to close the following documents..."
            "<p>It is last chance to uncheck those you don't want to close ;-)</p></qt>"
          )
      , lo1
      );
    lo1->setStretchFactor(t, 1000);

    // document list
    m_docs_tree = new QTreeWidget(w);
    QStringList headers;
    headers << i18n("Document") << i18n("Location");
    m_docs_tree->setHeaderLabels(headers);
    m_docs_tree->setSelectionMode(QAbstractItemView::SingleSelection);
    m_docs_tree->setRootIsDecorated(false);

    for (int i = 0; i < m_docs.size(); i++)
    {
        new KateDocItem(m_docs[i], m_docs_tree);
    }
    m_docs_tree->header()->setStretchLastSection(false);
    m_docs_tree->header()->setResizeMode(0, QHeaderView::ResizeToContents);
    m_docs_tree->header()->setResizeMode(1, QHeaderView::ResizeToContents);

    m_dont_ask_again = new QCheckBox(i18n("Do not ask again"), w);
    // NOTE If we are here, it means that 'Show Confirmation' action is enabled,
    // so not needed to read config...
    assert("Sanity check" && show_confirmation_action->isChecked());
    m_dont_ask_again->setCheckState(Qt::Checked);
    connect(m_dont_ask_again, SIGNAL(toggled(bool)), show_confirmation_action, SLOT(setChecked(bool)));

    // Update documents list according checkboxes
    connect(this, SIGNAL(accepted()), this, SLOT(updateDocsList()));

    KConfigGroup gcg(KGlobal::config(), "CloseConfirmationDialog");
    restoreDialogSize(gcg);                                 // restore dialog geometry from config
}