Changeset View
Changeset View
Standalone View
Standalone View
shell/projectsourcepage.cpp
Show All 25 Lines | |||||
26 | #include <KMessageBox> | 26 | #include <KMessageBox> | ||
27 | 27 | | |||
28 | #include <interfaces/iprojectprovider.h> | 28 | #include <interfaces/iprojectprovider.h> | ||
29 | 29 | | |||
30 | using namespace KDevelop; | 30 | using namespace KDevelop; | ||
31 | 31 | | |||
32 | static const int FROM_FILESYSTEM_SOURCE_INDEX = 0; | 32 | static const int FROM_FILESYSTEM_SOURCE_INDEX = 0; | ||
33 | 33 | | |||
34 | ProjectSourcePage::ProjectSourcePage(const QUrl& initial, QWidget* parent) | 34 | ProjectSourcePage::ProjectSourcePage(const QUrl& initial, const QUrl& repoUrl, IPlugin* preSelectPlugin, | ||
35 | QWidget* parent) | ||||
mwolff: & placement | |||||
35 | : QWidget(parent) | 36 | : QWidget(parent) | ||
36 | { | 37 | { | ||
37 | m_ui = new Ui::ProjectSourcePage; | 38 | m_ui = new Ui::ProjectSourcePage; | ||
38 | m_ui->setupUi(this); | 39 | m_ui->setupUi(this); | ||
39 | 40 | | |||
40 | m_ui->status->setCloseButtonVisible(false); | 41 | m_ui->status->setCloseButtonVisible(false); | ||
41 | m_ui->status->setMessageType(KMessageWidget::Error); | 42 | m_ui->status->setMessageType(KMessageWidget::Error); | ||
42 | 43 | | |||
43 | m_ui->workingDir->setUrl(initial); | 44 | m_ui->workingDir->setUrl(initial); | ||
44 | m_ui->workingDir->setMode(KFile::Directory); | 45 | m_ui->workingDir->setMode(KFile::Directory); | ||
45 | m_ui->remoteWidget->setLayout(new QVBoxLayout(m_ui->remoteWidget)); | 46 | m_ui->remoteWidget->setLayout(new QVBoxLayout(m_ui->remoteWidget)); | ||
46 | 47 | | |||
47 | m_ui->sources->addItem(QIcon::fromTheme(QStringLiteral("folder")), i18n("From File System")); | 48 | m_ui->sources->addItem(QIcon::fromTheme(QStringLiteral("folder")), i18n("From File System")); | ||
48 | m_plugins.append(nullptr); | 49 | m_plugins.append(nullptr); | ||
49 | 50 | | |||
51 | int preselectIndex = -1; | ||||
50 | IPluginController* pluginManager = ICore::self()->pluginController(); | 52 | IPluginController* pluginManager = ICore::self()->pluginController(); | ||
51 | QList<IPlugin*> plugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IBasicVersionControl") ); | 53 | QList<IPlugin*> plugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IBasicVersionControl") ); | ||
52 | foreach( IPlugin* p, plugins ) | 54 | foreach( IPlugin* p, plugins ) | ||
53 | { | 55 | { | ||
56 | if (p == preSelectPlugin) { | ||||
57 | preselectIndex = m_plugins.count(); | ||||
58 | } | ||||
54 | m_plugins.append(p); | 59 | m_plugins.append(p); | ||
55 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IBasicVersionControl>()->name()); | 60 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IBasicVersionControl>()->name()); | ||
56 | } | 61 | } | ||
57 | 62 | | |||
58 | plugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IProjectProvider") ); | 63 | plugins = pluginManager->allPluginsForExtension( QStringLiteral("org.kdevelop.IProjectProvider") ); | ||
59 | foreach( IPlugin* p, plugins ) | 64 | foreach( IPlugin* p, plugins ) | ||
60 | { | 65 | { | ||
66 | if (p == preSelectPlugin) { | ||||
67 | preselectIndex = m_plugins.count(); | ||||
68 | } | ||||
61 | m_plugins.append(p); | 69 | m_plugins.append(p); | ||
62 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IProjectProvider>()->name()); | 70 | m_ui->sources->addItem(QIcon::fromTheme(pluginManager->pluginInfo(p).iconName()), p->extension<IProjectProvider>()->name()); | ||
63 | } | 71 | } | ||
64 | 72 | | |||
73 | if (preselectIndex == -1) { | ||||
74 | // "From File System" is quite unlikely to be what the user wants, so default to first real plugin... | ||||
mwolff: to *do*? | |||||
This is comment from old code just moved around, but now that I look at it I see a flaw, will fix that one as well. kossebau: This is comment from old code just moved around, but now that I look at it I see a flaw, will… | |||||
75 | const int defaultIndex = (m_plugins.count() > 1) ? 1 : 0; | ||||
76 | KConfigGroup configGroup = KSharedConfig::openConfig()->group("Providers"); | ||||
77 | preselectIndex = configGroup.readEntry("LastProviderIndex", defaultIndex); | ||||
78 | } | ||||
79 | preselectIndex = qBound(0, preselectIndex, m_ui->sources->count() - 1); | ||||
80 | m_ui->sources->setCurrentIndex(preselectIndex); | ||||
81 | setSourceWidget(preselectIndex, repoUrl); | ||||
82 | | ||||
83 | // connect as last step, otherwise KMessageWidget could get both animatedHide() and animatedShow() | ||||
84 | // during setup and due to a bug will ignore any but the first call | ||||
85 | // Patch proposed at https://phabricator.kde.org/D4329 | ||||
65 | connect(m_ui->workingDir, &KUrlRequester::textChanged, this, &ProjectSourcePage::reevaluateCorrection); | 86 | connect(m_ui->workingDir, &KUrlRequester::textChanged, this, &ProjectSourcePage::reevaluateCorrection); | ||
66 | connect(m_ui->sources, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ProjectSourcePage::setSourceIndex); | 87 | connect(m_ui->sources, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ProjectSourcePage::setSourceIndex); | ||
67 | connect(m_ui->get, &QPushButton::clicked, this, &ProjectSourcePage::checkoutVcsProject); | 88 | connect(m_ui->get, &QPushButton::clicked, this, &ProjectSourcePage::checkoutVcsProject); | ||
68 | | ||||
69 | emit isCorrect(false); | | |||
70 | | ||||
71 | setSourceIndex(FROM_FILESYSTEM_SOURCE_INDEX); | | |||
72 | | ||||
73 | const int defaultIndex = m_plugins.isEmpty() ? 0 : 1; // "From File System" is quite unlikely to what you want... | | |||
74 | KConfigGroup configGroup = KSharedConfig::openConfig()->group("Providers"); | | |||
75 | const int lastCurrentIndex = configGroup.readEntry("LastProviderIndex", defaultIndex); | | |||
76 | m_ui->sources->setCurrentIndex(qBound(0, lastCurrentIndex, m_ui->sources->count() - 1)); | | |||
77 | } | 89 | } | ||
78 | 90 | | |||
79 | ProjectSourcePage::~ProjectSourcePage() | 91 | ProjectSourcePage::~ProjectSourcePage() | ||
80 | { | 92 | { | ||
81 | KConfigGroup configGroup = KSharedConfig::openConfig()->group("Providers"); | 93 | KConfigGroup configGroup = KSharedConfig::openConfig()->group("Providers"); | ||
82 | configGroup.writeEntry("LastProviderIndex", m_ui->sources->currentIndex()); | 94 | configGroup.writeEntry("LastProviderIndex", m_ui->sources->currentIndex()); | ||
83 | 95 | | |||
84 | delete m_ui; | 96 | delete m_ui; | ||
85 | } | 97 | } | ||
86 | 98 | | |||
87 | void ProjectSourcePage::setSourceIndex(int index) | 99 | void ProjectSourcePage::setSourceIndex(int index) | ||
88 | { | 100 | { | ||
101 | setSourceWidget(index, QUrl()); | ||||
102 | } | ||||
103 | | ||||
104 | void ProjectSourcePage::setSourceWidget(int index, const QUrl& repoUrl) | ||||
105 | { | ||||
89 | m_locationWidget = nullptr; | 106 | m_locationWidget = nullptr; | ||
90 | m_providerWidget = nullptr; | 107 | m_providerWidget = nullptr; | ||
91 | QLayout* remoteWidgetLayout = m_ui->remoteWidget->layout(); | 108 | QLayout* remoteWidgetLayout = m_ui->remoteWidget->layout(); | ||
92 | QLayoutItem *child; | 109 | QLayoutItem *child; | ||
93 | while ((child = remoteWidgetLayout->takeAt(0)) != nullptr) { | 110 | while ((child = remoteWidgetLayout->takeAt(0)) != nullptr) { | ||
94 | delete child->widget(); | 111 | delete child->widget(); | ||
95 | delete child; | 112 | delete child; | ||
96 | } | 113 | } | ||
97 | 114 | | |||
98 | IBasicVersionControl* vcIface = vcsPerIndex(index); | 115 | IBasicVersionControl* vcIface = vcsPerIndex(index); | ||
99 | IProjectProvider* providerIface; | 116 | IProjectProvider* providerIface; | ||
100 | bool found=false; | 117 | bool found=false; | ||
101 | if(vcIface) { | 118 | if(vcIface) { | ||
102 | found=true; | 119 | found=true; | ||
103 | m_locationWidget=vcIface->vcsLocation(m_ui->sourceBox); | 120 | m_locationWidget=vcIface->vcsLocation(m_ui->sourceBox); | ||
104 | connect(m_locationWidget, &VcsLocationWidget::changed, this, &ProjectSourcePage::locationChanged); | 121 | connect(m_locationWidget, &VcsLocationWidget::changed, this, &ProjectSourcePage::locationChanged); | ||
105 | 122 | | |||
123 | // set after connect, to trigger handler | ||||
124 | if (!repoUrl.isEmpty()) { | ||||
125 | m_locationWidget->setLocation(repoUrl); | ||||
126 | } | ||||
106 | remoteWidgetLayout->addWidget(m_locationWidget); | 127 | remoteWidgetLayout->addWidget(m_locationWidget); | ||
107 | } else { | 128 | } else { | ||
108 | providerIface = providerPerIndex(index); | 129 | providerIface = providerPerIndex(index); | ||
109 | if(providerIface) { | 130 | if(providerIface) { | ||
110 | found=true; | 131 | found=true; | ||
111 | m_providerWidget=providerIface->providerWidget(m_ui->sourceBox); | 132 | m_providerWidget=providerIface->providerWidget(m_ui->sourceBox); | ||
112 | connect(m_providerWidget, &IProjectProviderWidget::changed, this, &ProjectSourcePage::projectChanged); | 133 | connect(m_providerWidget, &IProjectProviderWidget::changed, this, &ProjectSourcePage::projectChanged); | ||
113 | 134 | | |||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Line(s) | |||||
266 | void ProjectSourcePage::setStatus(const QString& message) | 287 | void ProjectSourcePage::setStatus(const QString& message) | ||
267 | { | 288 | { | ||
268 | m_ui->status->setText(message); | 289 | m_ui->status->setText(message); | ||
269 | m_ui->status->animatedShow(); | 290 | m_ui->status->animatedShow(); | ||
270 | } | 291 | } | ||
271 | 292 | | |||
272 | void ProjectSourcePage::clearStatus() | 293 | void ProjectSourcePage::clearStatus() | ||
273 | { | 294 | { | ||
295 | // workaround for KMessageWidget bug: | ||||
296 | // animatedHide will not explicitely hide the widget if it is not yet shown, | ||||
297 | // so if show() is called on the parent later, the KMessageWidget | ||||
298 | // Patch proposed at https://phabricator.kde.org/D4329 | ||||
299 | if (!m_ui->status->isVisible()) { | ||||
300 | m_ui->status->hide(); | ||||
301 | } else { | ||||
274 | m_ui->status->animatedHide(); | 302 | m_ui->status->animatedHide(); | ||
275 | } | 303 | } | ||
304 | } | ||||
276 | 305 | | |||
277 | QUrl ProjectSourcePage::workingDir() const | 306 | QUrl ProjectSourcePage::workingDir() const | ||
278 | { | 307 | { | ||
279 | return m_ui->workingDir->url(); | 308 | return m_ui->workingDir->url(); | ||
280 | } | 309 | } |
& placement