예제 #1
0
/* Prompt to delete a local branch and do so. */
void BranchDialog::remove()
{
    QModelIndex selected = selectedIndex();
    Q_ASSERT(selected != m_model->currentBranch()); // otherwise the button would not be enabled!

    QString branchName = m_model->branchName(selected);
    if (branchName.isEmpty())
        return;

    QString message = tr("Would you like to delete the branch '%1'?").arg(branchName);
    bool wasMerged = m_model->branchIsMerged(selected);
    if (!wasMerged)
        message = tr("Would you like to delete the <b>unmerged</b> branch '%1'?").arg(branchName);

    if (QMessageBox::question(this, tr("Delete Branch"), message, QMessageBox::Yes|QMessageBox::No,
                              wasMerged ? QMessageBox::Yes : QMessageBox::No) == QMessageBox::Yes)
        m_model->removeBranch(selected);
}
예제 #2
0
    void BsonTableView::showContextMenu( const QPoint &point )
    {
        QPoint menuPoint = mapToGlobal(point);
        menuPoint.setY(menuPoint.y() + horizontalHeader()->height());
        menuPoint.setX(menuPoint.x() + verticalHeader()->width());

        QModelIndexList indexes = selectedIndexes();
        if (detail::isMultySelection(indexes)) {
            QMenu menu(this);
            _notifier.initMultiSelectionMenu(&menu);
            menu.exec(menuPoint);
        }
        else{
            QModelIndex selectedInd = selectedIndex();
            BsonTreeItem *documentItem = QtUtils::item<BsonTreeItem*>(selectedInd);
            QMenu menu(this);
            _notifier.initMenu(&menu,documentItem);
            menu.exec(menuPoint);
        }
    }
예제 #3
0
    void BsonTableView::onCopyDocument()
    {
        QModelIndex selectedInd = selectedIndex();
        if (!selectedInd.isValid())
            return;

        BsonTableItem *documentItem = QtUtils::item<BsonTableItem*>(selectedInd);
        if(!documentItem)
            return;

        mongo::BSONElement element = documentItem->row(selectedInd.column()).second;

        if (!BsonUtils::isSimpleType(element) && BsonUtils::isUuidType(element))
            return;

        QClipboard *clipboard = QApplication::clipboard();
        std::string res;
        BsonUtils::buildJsonString(element,res,AppRegistry::instance().settingsManager()->uuidEncoding(),AppRegistry::instance().settingsManager()->timeZone());
        clipboard->setText(QtUtils::toQString(res));
    }
bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
{
    // Allow (Shift) F4 and (Ctrl/Shift) Alt/AltGr + Up/Down arrow to pop the menu, matching Firefox.
    bool eventShowsMenu = (!event->altKey() && !event->ctrlKey() && event->keyIdentifier() == "F4")
        || ((event->altGraphKey() || event->altKey()) && (event->keyIdentifier() == "Down" || event->keyIdentifier() == "Up"));
    if (!eventShowsMenu)
        return false;

    // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex,
    // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
    saveLastSelection();
    if (RenderMenuList* menuList = toRenderMenuList(renderer()))
        menuList->showPopup();

    int index = selectedIndex();
    ASSERT(index >= 0);
    ASSERT_WITH_SECURITY_IMPLICATION(index < static_cast<int>(listItems().size()));
    setSelectedIndex(index);
    event->setDefaultHandled();
    return true;
}
예제 #5
0
void BranchDialog::merge()
{
    if (!Core::DocumentManager::saveAllModifiedDocuments())
        return;
    QModelIndex idx = selectedIndex();
    QTC_CHECK(idx != m_model->currentBranch()); // otherwise the button would not be enabled!

    const QString branch = m_model->fullName(idx, true);
    GitClient *client = GitPlugin::instance()->gitClient();
    bool allowFastForward = true;
    if (client->isFastForwardMerge(m_repository, branch)) {
        QMenu popup;
        QAction *fastForward = popup.addAction(tr("Fast-Forward"));
        popup.addAction(tr("No Fast-Forward"));
        QAction *chosen = Utils::execMenuAtWidget(&popup, m_ui->mergeButton);
        if (!chosen)
            return;
        allowFastForward = (chosen == fastForward);
    }
    if (client->beginStashScope(m_repository, QLatin1String("merge"), AllowUnstashed))
        client->synchronousMerge(m_repository, branch, allowFastForward);
}
예제 #6
0
void BranchDialog::add()
{
    QModelIndex trackedIndex = selectedIndex();
    QString trackedBranch = m_model->fullName(trackedIndex);
    if (trackedBranch.isEmpty()) {
        trackedIndex = m_model->currentBranch();
        trackedBranch = m_model->fullName(trackedIndex);
    }
    const bool isLocal = m_model->isLocal(trackedIndex);
    const bool isTag = m_model->isTag(trackedIndex);

    QStringList localNames = m_model->localBranchNames();

    QString suggestedNameBase = trackedBranch.mid(trackedBranch.lastIndexOf(QLatin1Char('/')) + 1);
    QString suggestedName = suggestedNameBase;
    int i = 2;
    while (localNames.contains(suggestedName)) {
        suggestedName = suggestedNameBase + QString::number(i);
        ++i;
    }

    BranchAddDialog branchAddDialog(localNames, true, this);
    branchAddDialog.setBranchName(suggestedName);
    branchAddDialog.setTrackedBranchName(isTag ? QString() : trackedBranch, !isLocal);

    if (branchAddDialog.exec() == QDialog::Accepted) {
        QModelIndex idx = m_model->addBranch(branchAddDialog.branchName(), branchAddDialog.track(), trackedIndex);
        if (!idx.isValid())
            return;
        m_ui->branchView->selectionModel()->select(idx, QItemSelectionModel::Clear
                                                        | QItemSelectionModel::Select
                                                        | QItemSelectionModel::Current);
        m_ui->branchView->scrollTo(idx);
        if (QMessageBox::question(this, tr("Checkout"), tr("Checkout branch?"),
                                  QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
            checkout();
    }
}
예제 #7
0
    void BsonTableView::onViewDocument()
    {
        QModelIndex selectedInd = selectedIndex();
        if (!selectedInd.isValid())
            return;

        BsonTableItem *documentItem = QtUtils::item<BsonTableItem*>(selectedInd);
        if(!documentItem)
            return;

        mongo::BSONObj obj = documentItem->root();

        std::string str = BsonUtils::jsonString(obj, mongo::TenGen, 1, AppRegistry::instance().settingsManager()->uuidEncoding(), AppRegistry::instance().settingsManager()->timeZone());
        const QString &json = QtUtils::toQString(str);

        std::string server = _queryInfo.isNull ? "" : _queryInfo.serverAddress;
        std::string database = _queryInfo.isNull ? "" : _queryInfo.databaseName;
        std::string collection = _queryInfo.isNull ? "" : _queryInfo.collectionName;

        DocumentTextEditor *editor = new DocumentTextEditor(QtUtils::toQString(server),QtUtils::toQString(database), QtUtils::toQString(collection), json, true, this);

        editor->setWindowTitle("View Document");
        editor->show();
    }
예제 #8
0
    void BsonTableView::onDeleteDocument()
    {
        if (_queryInfo.isNull)
            return;

        QModelIndex selectedInd = selectedIndex();
        if (!selectedInd.isValid())
            return;

        BsonTableItem *documentItem = QtUtils::item<BsonTableItem*>(selectedInd);
        if(!documentItem)
            return;

        mongo::BSONObj obj = documentItem->root();
        mongo::BSONElement id = obj.getField("_id");

        if (id.eoo()) {
            QMessageBox::warning(this, "Cannot delete", "Selected document doesn't have _id field. \n"
                "Maybe this is a system document that should be managed in a special way?");
            return;
        }

        mongo::BSONObjBuilder builder;
        builder.append(id);
        mongo::BSONObj bsonQuery = builder.obj();
        mongo::Query query(bsonQuery);

        // Ask user
        int answer = utils::questionDialog(this,"Delete","Document","%1 %2 with id:<br><b>%3</b>?",QtUtils::toQString(id.toString(false)));

        if (answer != QMessageBox::Yes)
            return ;

        _shell->server()->removeDocuments(query, _queryInfo.databaseName, _queryInfo.collectionName);
        _shell->query(0, _queryInfo);
    }
예제 #9
0
QString toBrowserSchemaTableView::objectName()
{
    return selectedIndex(1).data(Qt::EditRole).toString();
}
예제 #10
0
void BranchDialog::setRemoteTracking()
{
    m_model->setRemoteTracking(selectedIndex());
}
예제 #11
0
void BranchDialog::checkout()
{
    if (!Core::DocumentManager::saveAllModifiedDocuments())
        return;
    QModelIndex idx = selectedIndex();

    const QString currentBranch = m_model->fullName(m_model->currentBranch());
    const QString nextBranch = m_model->fullName(idx);
    const QString popMessageStart = QCoreApplication::applicationName() +
            QLatin1String(" ") + nextBranch + QLatin1String("-AutoStash ");

    BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch);
    GitClient *gitClient = GitPlugin::instance()->gitClient();

    if (gitClient->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
        branchCheckoutDialog.foundNoLocalChanges();

    QList<Stash> stashes;
    gitClient->synchronousStashList(m_repository, &stashes);
    foreach (const Stash &stash, stashes) {
        if (stash.message.startsWith(popMessageStart)) {
            branchCheckoutDialog.foundStashForNextBranch();
            break;
        }
    }

    if (!branchCheckoutDialog.hasLocalChanges() &&
        !branchCheckoutDialog.hasStashForNextBranch()) {
        // No local changes and no Auto Stash - no need to open dialog
        m_model->checkoutBranch(idx);
    } else if (branchCheckoutDialog.exec() == QDialog::Accepted) {

        if (branchCheckoutDialog.makeStashOfCurrentBranch()) {
            if (gitClient->synchronousStash(m_repository,
                           currentBranch + QLatin1String("-AutoStash")).isEmpty()) {
                return;
            }
        } else if (branchCheckoutDialog.moveLocalChangesToNextBranch()) {
            if (!gitClient->beginStashScope(m_repository, QLatin1String("Checkout"), NoPrompt))
                return;
        } else if (branchCheckoutDialog.discardLocalChanges()) {
            if (!gitClient->synchronousReset(m_repository))
                return;
        }

        m_model->checkoutBranch(idx);

        QString stashName;
        gitClient->synchronousStashList(m_repository, &stashes);
        foreach (const Stash &stash, stashes) {
            if (stash.message.startsWith(popMessageStart)) {
                stashName = stash.name;
                break;
            }
        }

        if (branchCheckoutDialog.moveLocalChangesToNextBranch())
            gitClient->endStashScope(m_repository);
        else if (branchCheckoutDialog.popStashOfNextBranch())
            gitClient->synchronousStashRestore(m_repository, stashName, true);
    }
    enableButtons();
}
예제 #12
0
void ThemePage::updateSizeComboBox()
{
    // clear the combo box
    sizeComboBox->clear();

    // refill the combo box and adopt its icon size
    QModelIndex selected = selectedIndex();
    int maxIconWidth = 0;
    int maxIconHeight = 0;
    if (selected.isValid())
    {
        const CursorTheme *theme = proxy->theme(selected);
        const QList<int> sizes = theme->availableSizes();
        QIcon m_icon;
        if (sizes.size() > 1)  // only refill the combobox if there is more that 1 size
        {
            int i;
            QList<int> comboBoxList;
            QPixmap m_pixmap;

            // insert the items
            m_pixmap = theme->createIcon(0);
            if (m_pixmap.width() > maxIconWidth)
                maxIconWidth = m_pixmap.width();
            if (m_pixmap.height() > maxIconHeight)
                maxIconHeight = m_pixmap.height();
            sizeComboBox->addItem(
                QIcon(m_pixmap),
                i18nc("@item:inlistbox size", "Resolution dependent"),
                0);
            comboBoxList << 0;
            foreach (i, sizes)
            {
                m_pixmap = theme->createIcon(i);
                if (m_pixmap.width() > maxIconWidth)
                    maxIconWidth = m_pixmap.width();
                if (m_pixmap.height() > maxIconHeight)
                    maxIconHeight = m_pixmap.height();
                sizeComboBox->addItem(QIcon(m_pixmap), QString::number(i), i);
                comboBoxList << i;
            };

            // select an item
            int selectItem = comboBoxList.indexOf(preferredSize);
            if (selectItem < 0)  // preferredSize not available for this theme
            {
                /* Search the value next to preferredSize. The first entry (0)
                   is ignored. (If preferredSize would have been 0, then we
                   would had found it yet. As preferredSize is not 0, we won't
                   default to "automatic size".)*/
                int j;
                int distance;
                int smallestDistance;
                selectItem = 1;
                j = comboBoxList.value(selectItem);
                smallestDistance = j < preferredSize ? preferredSize - j : j - preferredSize;
                for (int i = 2; i < comboBoxList.size(); ++i)
                {
                    j = comboBoxList.value(i);
                    distance = j < preferredSize ? preferredSize - j : j - preferredSize;
                    if (distance < smallestDistance || (distance == smallestDistance && j > preferredSize))
                    {
                        smallestDistance = distance;
                        selectItem = i;
                    };
                }
            };
            sizeComboBox->setCurrentIndex(selectItem);
        };
예제 #13
0
int WMLSelectElement::activeSelectionStartListIndex() const
{
    if (m_data.activeSelectionAnchorIndex() >= 0)
        return m_data.activeSelectionAnchorIndex();
    return optionToListIndex(selectedIndex());
}
예제 #14
0
void MetaListViewPart::removeSelectedItem()
{
    if ( !QtWinePreferences::askBeforeDelete() or KMessageBox::Yes ==
         KMessageBox::questionYesNo(widget(), i18n("Are you sure you want to remove this item?")) )
        model()->removeRow(selectedIndex().row());
}
예제 #15
0
void SelectElement::listBoxDefaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm)
{
    const Vector<Element*>& listItems = data.listItems(element);

    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
        element->focus();

        // Convert to coords relative to the list box if needed.
        MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
        IntPoint localOffset = roundedIntPoint(element->renderer()->absoluteToLocal(mouseEvent->absoluteLocation(), false, true));
        int listIndex = static_cast<RenderListBox*>(element->renderer())->listIndexAtOffset(localOffset.x(), localOffset.y());
        if (listIndex >= 0) {
            // Save the selection so it can be compared to the new selection when dispatching change events during mouseup, or after autoscroll finishes.
            saveLastSelection(data, element);

            data.setActiveSelectionState(true);
            
            bool multiSelectKeyPressed = false;
#if PLATFORM(MAC)
            multiSelectKeyPressed = mouseEvent->metaKey();
#else
            multiSelectKeyPressed = mouseEvent->ctrlKey();
#endif

            bool shiftSelect = data.multiple() && mouseEvent->shiftKey();
            bool multiSelect = data.multiple() && multiSelectKeyPressed && !mouseEvent->shiftKey();

            Element* clickedElement = listItems[listIndex];            
            OptionElement* option = toOptionElement(clickedElement);
            if (option) {
                // Keep track of whether an active selection (like during drag selection), should select or deselect
                if (option->selected() && multiSelectKeyPressed)
                    data.setActiveSelectionState(false);

                if (!data.activeSelectionState())
                    option->setSelectedState(false);
            }
            
            // If we're not in any special multiple selection mode, then deselect all other items, excluding the clicked option.
            // If no option was clicked, then this will deselect all items in the list.
            if (!shiftSelect && !multiSelect)
                deselectItems(data, element, clickedElement);

            // If the anchor hasn't been set, and we're doing a single selection or a shift selection, then initialize the anchor to the first selected index.
            if (data.activeSelectionAnchorIndex() < 0 && !multiSelect)
                setActiveSelectionAnchorIndex(data, element, selectedIndex(data, element));

            // Set the selection state of the clicked option
            if (option && !clickedElement->disabled())
                option->setSelectedState(true);
            
            // If there was no selectedIndex() for the previous initialization, or
            // If we're doing a single selection, or a multiple selection (using cmd or ctrl), then initialize the anchor index to the listIndex that just got clicked.
            if (listIndex >= 0 && (data.activeSelectionAnchorIndex() < 0 || !shiftSelect))
                setActiveSelectionAnchorIndex(data, element, listIndex);
            
            setActiveSelectionEndIndex(data, listIndex);
            updateListBoxSelection(data, element, !multiSelect);

            if (Frame* frame = element->document()->frame())
                frame->eventHandler()->setMouseDownMayStartAutoscroll();

            event->setDefaultHandled();
        }
    } else if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton && element->document()->frame()->eventHandler()->autoscrollRenderer() != element->renderer())
        // This makes sure we fire dispatchFormControlChangeEvent for a single click.  For drag selection, onChange will fire when the autoscroll timer stops.
        listBoxOnChange(data, element);
    else if (event->type() == eventNames().keydownEvent) {
        if (!event->isKeyboardEvent())
            return;
        String keyIdentifier = static_cast<KeyboardEvent*>(event)->keyIdentifier();

        int endIndex = 0;        
        if (data.activeSelectionEndIndex() < 0) {
            // Initialize the end index
            if (keyIdentifier == "Down")
                endIndex = nextSelectableListIndex(data, element, lastSelectedListIndex(data, element));
            else if (keyIdentifier == "Up")
                endIndex = previousSelectableListIndex(data, element, optionToListIndex(data, element, selectedIndex(data, element)));
        } else {
            // Set the end index based on the current end index
            if (keyIdentifier == "Down")
                endIndex = nextSelectableListIndex(data, element, data.activeSelectionEndIndex());
            else if (keyIdentifier == "Up")
                endIndex = previousSelectableListIndex(data, element, data.activeSelectionEndIndex());    
        }
        
        if (keyIdentifier == "Down" || keyIdentifier == "Up") {
            // Save the selection so it can be compared to the new selection when dispatching change events immediately after making the new selection.
            saveLastSelection(data, element);

            ASSERT(endIndex >= 0 && (unsigned) endIndex < listItems.size()); 
            setActiveSelectionEndIndex(data, endIndex);
            
            // If the anchor is unitialized, or if we're going to deselect all other options, then set the anchor index equal to the end index.
            bool deselectOthers = !data.multiple() || !static_cast<KeyboardEvent*>(event)->shiftKey();
            if (data.activeSelectionAnchorIndex() < 0 || deselectOthers) {
                data.setActiveSelectionState(true);
                if (deselectOthers)
                    deselectItems(data, element);
                setActiveSelectionAnchorIndex(data, element, data.activeSelectionEndIndex());
            }

            static_cast<RenderListBox*>(element->renderer())->scrollToRevealElementAtListIndex(endIndex);
            updateListBoxSelection(data, element, deselectOthers);
            listBoxOnChange(data, element);
            event->setDefaultHandled();
        }
    } else if (event->type() == eventNames().keypressEvent) {
        if (!event->isKeyboardEvent())
            return;
        int keyCode = static_cast<KeyboardEvent*>(event)->keyCode();

        if (keyCode == '\r') {
            if (htmlForm)
                htmlForm->submitClick(event);
            event->setDefaultHandled();
            return;
        }
    }
}
예제 #16
0
void SelectElement::menuListDefaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm)
{
#if !ARROW_KEYS_POP_MENU
    UNUSED_PARAM(htmlForm);
#endif

    if (event->type() == eventNames().keydownEvent) {
        if (!element->renderer() || !event->isKeyboardEvent())
            return;

        String keyIdentifier = static_cast<KeyboardEvent*>(event)->keyIdentifier();
        bool handled = false;

#if ARROW_KEYS_POP_MENU
        if (keyIdentifier == "Down" || keyIdentifier == "Up") {
            element->focus();
            // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex,
            // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
            saveLastSelection(data, element);
            if (RenderMenuList* menuList = static_cast<RenderMenuList*>(element->renderer()))
                menuList->showPopup();
            handled = true;
        }
#else
        const Vector<Element*>& listItems = data.listItems(element);
        int size = listItems.size();

        int listIndex = optionToListIndex(data, element, selectedIndex(data, element));
        if (keyIdentifier == "Down" || keyIdentifier == "Right") {
            for (listIndex += 1;
                 listIndex >= 0 && listIndex < size && (listItems[listIndex]->disabled() || !isOptionElement(listItems[listIndex]));
                 ++listIndex) { }
            if (listIndex >= 0 && listIndex < size)
                setSelectedIndex(data, element, listToOptionIndex(data, element, listIndex));
            handled = true;
        } else if (keyIdentifier == "Up" || keyIdentifier == "Left") {
            for (listIndex -= 1;
                 listIndex >= 0 && listIndex < size && (listItems[listIndex]->disabled() || !isOptionElement(listItems[listIndex]));
                 --listIndex) { }
            if (listIndex >= 0 && listIndex < size)
                setSelectedIndex(data, element, listToOptionIndex(data, element, listIndex));
            handled = true;
        }
#endif
        if (handled)
            event->setDefaultHandled();
    }

    // Use key press event here since sending simulated mouse events
    // on key down blocks the proper sending of the key press event.
    if (event->type() == eventNames().keypressEvent) {
        if (!element->renderer() || !event->isKeyboardEvent())
            return;

        int keyCode = static_cast<KeyboardEvent*>(event)->keyCode();
        bool handled = false;

#if SPACE_OR_RETURN_POP_MENU
        if (keyCode == ' ' || keyCode == '\r') {
            element->focus();
            // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex,
            // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
            saveLastSelection(data, element);
            if (RenderMenuList* menuList = static_cast<RenderMenuList*>(element->renderer()))
                menuList->showPopup();
            handled = true;
        }
#elif ARROW_KEYS_POP_MENU
        if (keyCode == ' ') {
            element->focus();
            // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex,
            // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
            saveLastSelection(data, element);
            if (RenderMenuList* menuList = static_cast<RenderMenuList*>(element->renderer()))
                menuList->showPopup();
            handled = true;
        } else if (keyCode == '\r') {
            menuListOnChange(data, element);
            if (htmlForm)
                htmlForm->submitClick(event);
            handled = true;
        }
#else
        int listIndex = optionToListIndex(data, element, selectedIndex(data, element));
        if (keyCode == '\r') {
            // listIndex should already be selected, but this will fire the onchange handler.
            setSelectedIndex(data, element, listToOptionIndex(data, element, listIndex), true, true);
            handled = true;
        }
#endif
        if (handled)
            event->setDefaultHandled();
    }

    if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) {
        element->focus();
        if (RenderMenuList* menuList = static_cast<RenderMenuList*>(element->renderer())) {
            if (menuList->popupIsVisible())
                menuList->hidePopup();
            else {
                // Save the selection so it can be compared to the new selection when we call onChange during setSelectedIndex,
                // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
                saveLastSelection(data, element);
                menuList->showPopup();
            }
        }
        event->setDefaultHandled();
    }
}
예제 #17
0
/*! called from the "setDefault" action */
void MetaListViewPart::setCurrentItemAsDefault()
{
    QModelIndex selectedItem = selectedIndex();
    Q_ASSERT(selectedItem.isValid());
    updateDefaultItemRow(selectedItem.row());
}
예제 #18
0
bool BranchUtils::checkout()
{
    if (!Core::DocumentManager::saveAllModifiedDocuments())
        return false;

    const QModelIndex selected = selectedIndex();
    const QString currentBranch = m_model->fullName(m_model->currentBranch());
    const QString nextBranch = m_model->fullName(selected);
    const QString popMessageStart = QCoreApplication::applicationName() +
            ' ' + nextBranch + "-AutoStash ";

    BranchCheckoutDialog branchCheckoutDialog(m_widget, currentBranch, nextBranch);
    GitClient *client = GitPlugin::client();

    if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
        branchCheckoutDialog.foundNoLocalChanges();

    QList<Stash> stashes;
    client->synchronousStashList(m_repository, &stashes);
    for (const Stash &stash : qAsConst(stashes)) {
        if (stash.message.startsWith(popMessageStart)) {
            branchCheckoutDialog.foundStashForNextBranch();
            break;
        }
    }

    if (!branchCheckoutDialog.hasLocalChanges() &&
        !branchCheckoutDialog.hasStashForNextBranch()) {
        // No local changes and no Auto Stash - no need to open dialog
        m_model->checkoutBranch(selected);
    } else if (branchCheckoutDialog.exec() == QDialog::Accepted) {

        if (branchCheckoutDialog.makeStashOfCurrentBranch()) {
            if (client->synchronousStash(m_repository, currentBranch + "-AutoStash").isEmpty())
                return false;
        } else if (branchCheckoutDialog.moveLocalChangesToNextBranch()) {
            if (!client->beginStashScope(m_repository, "Checkout", NoPrompt))
                return false;
        } else if (branchCheckoutDialog.discardLocalChanges()) {
            if (!client->synchronousReset(m_repository))
                return false;
        }

        m_model->checkoutBranch(selected);

        QString stashName;
        client->synchronousStashList(m_repository, &stashes);
        for (const Stash &stash : qAsConst(stashes)) {
            if (stash.message.startsWith(popMessageStart)) {
                stashName = stash.name;
                break;
            }
        }

        if (branchCheckoutDialog.moveLocalChangesToNextBranch())
            client->endStashScope(m_repository);
        else if (branchCheckoutDialog.popStashOfNextBranch())
            client->synchronousStashRestore(m_repository, stashName, true);
    }

    if (QTC_GUARD(m_branchView))
        m_branchView->selectionModel()->clear();
    return true;
}
void TreeViewComboBox::currentIndexChanged() {
  selectIndex(selectedIndex());
}