Changeset View
Changeset View
Standalone View
Standalone View
plugins/patchreview/patchreviewtoolview.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
46 | 46 | | |||
47 | #ifdef WITH_PURPOSE | 47 | #ifdef WITH_PURPOSE | ||
48 | #include <Purpose/AlternativesModel> | 48 | #include <Purpose/AlternativesModel> | ||
49 | #include <PurposeWidgets/Menu> | 49 | #include <PurposeWidgets/Menu> | ||
50 | #endif | 50 | #endif | ||
51 | 51 | | |||
52 | using namespace KDevelop; | 52 | using namespace KDevelop; | ||
53 | 53 | | |||
54 | class DiffContextMenu : public QObject | ||||
55 | { | ||||
56 | Q_OBJECT | ||||
57 | public: | ||||
58 | DiffContextMenu(PatchReviewPlugin *prPlugin) | ||||
59 | : QObject(dynamic_cast<QObject*>(prPlugin)) | ||||
60 | , m_prPlugin(prPlugin) | ||||
61 | { | ||||
62 | m_contextActions = new QActionGroup(this); | ||||
63 | m_contextActions->setExclusive(true); | ||||
64 | QAction *title = new QAction(i18n("diff context"), m_contextActions); | ||||
65 | title->setEnabled(false); | ||||
66 | m_contextActions->addAction(title); | ||||
67 | for (int i = 1; i <= 5; ++i) { | ||||
68 | addContextAction(i); | ||||
69 | } | ||||
70 | addContextAction(10); | ||||
71 | addContextAction(0); | ||||
72 | } | ||||
73 | | ||||
74 | void addContextAction(int contextLines) | ||||
75 | { | ||||
76 | QAction *action; | ||||
77 | if (contextLines == 0) { | ||||
78 | action = new QAction(i18n("whole file"), m_contextActions); | ||||
79 | } else if (contextLines > 0) { | ||||
80 | action = new QAction(i18n("%1 lines").arg(contextLines), m_contextActions); | ||||
81 | } else { | ||||
82 | return; | ||||
83 | } | ||||
84 | action->setData(contextLines); | ||||
85 | action->setCheckable(true); | ||||
86 | connect(action, &QAction::triggered, this, [action, this]() { | ||||
87 | action->setChecked(true); | ||||
88 | m_prPlugin->forceUpdateWithContext(action->data().toInt()); | ||||
89 | }); | ||||
90 | m_contextActions->addAction(action); | ||||
91 | if (contextLines == 3) { | ||||
92 | m_defaultContextAction = action; | ||||
93 | action->setChecked(true); | ||||
94 | } | ||||
95 | } | ||||
96 | QActionGroup *m_contextActions; | ||||
97 | PatchReviewPlugin *m_prPlugin; | ||||
98 | QAction *m_defaultContextAction; | ||||
99 | }; | ||||
100 | | ||||
54 | class PatchFilesModel : public VcsFileChangesModel | 101 | class PatchFilesModel : public VcsFileChangesModel | ||
55 | { | 102 | { | ||
56 | Q_OBJECT | 103 | Q_OBJECT | ||
57 | public: | 104 | public: | ||
58 | PatchFilesModel( QObject *parent, bool allowSelection ) : VcsFileChangesModel( parent, allowSelection ) { }; | 105 | PatchFilesModel( QObject *parent, bool allowSelection ) : VcsFileChangesModel( parent, allowSelection ) { }; | ||
59 | enum ItemRoles { HunksNumberRole = LastItemRole+1 }; | 106 | enum ItemRoles { HunksNumberRole = LastItemRole+1 }; | ||
60 | 107 | | |||
61 | public slots: | 108 | public slots: | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
121 | } | 168 | } | ||
122 | 169 | | |||
123 | void PatchReviewToolView::startingNewReview() | 170 | void PatchReviewToolView::startingNewReview() | ||
124 | { | 171 | { | ||
125 | m_resetCheckedUrls = true; | 172 | m_resetCheckedUrls = true; | ||
126 | } | 173 | } | ||
127 | 174 | | |||
128 | void PatchReviewToolView::patchChanged() { | 175 | void PatchReviewToolView::patchChanged() { | ||
176 | if(m_resetCheckedUrls) { | ||||
177 | // set the default number of context lines | ||||
178 | m_editPatch.diffContext->setValue(3); | ||||
179 | m_diffContextMenu->m_defaultContextAction->setChecked(true); | ||||
180 | } | ||||
181 | | ||||
129 | fillEditFromPatch(); | 182 | fillEditFromPatch(); | ||
130 | kompareModelChanged(); | 183 | kompareModelChanged(); | ||
131 | 184 | | |||
132 | #ifdef WITH_PURPOSE | 185 | #ifdef WITH_PURPOSE | ||
133 | IPatchSource::Ptr p = m_plugin->patch(); | 186 | IPatchSource::Ptr p = m_plugin->patch(); | ||
134 | if (p) { | 187 | if (p) { | ||
135 | m_exportMenu->model()->setInputData(QJsonObject { | 188 | m_exportMenu->model()->setInputData(QJsonObject { | ||
136 | { QStringLiteral("urls"), QJsonArray { p->file().toString() } }, | 189 | { QStringLiteral("urls"), QJsonArray { p->file().toString() } }, | ||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 293 | #endif | |||
246 | connect( m_editPatch.filesList, &QTreeView::activated , this, &PatchReviewToolView::fileDoubleClicked ); | 299 | connect( m_editPatch.filesList, &QTreeView::activated , this, &PatchReviewToolView::fileDoubleClicked ); | ||
247 | 300 | | |||
248 | connect( m_editPatch.cancelReview, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::cancelReview ); | 301 | connect( m_editPatch.cancelReview, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::cancelReview ); | ||
249 | //connect( m_editPatch.cancelButton, SIGNAL(pressed()), this, SLOT(slotEditCancel()) ); | 302 | //connect( m_editPatch.cancelButton, SIGNAL(pressed()), this, SLOT(slotEditCancel()) ); | ||
250 | 303 | | |||
251 | //connect( this, SIGNAL(finished(int)), this, SLOT(slotEditDialogFinished(int)) ); | 304 | //connect( this, SIGNAL(finished(int)), this, SLOT(slotEditDialogFinished(int)) ); | ||
252 | 305 | | |||
253 | connect( m_editPatch.updateButton, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::forceUpdate ); | 306 | connect( m_editPatch.updateButton, &QPushButton::clicked, m_plugin, &PatchReviewPlugin::forceUpdate ); | ||
307 | m_editPatch.updateButton->setContextMenuPolicy(Qt::ActionsContextMenu); | ||||
308 | m_diffContextMenu = new DiffContextMenu(m_plugin); | ||||
309 | m_editPatch.updateButton->addActions(m_diffContextMenu->m_contextActions->actions()); | ||||
310 | // FIXME: cleanup after deciding on the GUI | ||||
311 | m_editPatch.diffContext->hide(); | ||||
312 | // connect( m_editPatch.diffContext, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), | ||||
313 | // m_plugin, &PatchReviewPlugin::forceUpdateWithContext ); | ||||
254 | 314 | | |||
255 | connect( m_editPatch.testsButton, &QPushButton::clicked, this, &PatchReviewToolView::runTests ); | 315 | connect( m_editPatch.testsButton, &QPushButton::clicked, this, &PatchReviewToolView::runTests ); | ||
256 | 316 | | |||
257 | m_selectAllAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-select-all")), i18n("Select All"), this ); | 317 | m_selectAllAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-select-all")), i18n("Select All"), this ); | ||
258 | connect( m_selectAllAction, &QAction::triggered, this, &PatchReviewToolView::selectAll ); | 318 | connect( m_selectAllAction, &QAction::triggered, this, &PatchReviewToolView::selectAll ); | ||
259 | m_deselectAllAction = new QAction( i18n("Deselect All"), this ); | 319 | m_deselectAllAction = new QAction( i18n("Deselect All"), this ); | ||
260 | connect( m_deselectAllAction, &QAction::triggered, this, &PatchReviewToolView::deselectAll ); | 320 | connect( m_deselectAllAction, &QAction::triggered, this, &PatchReviewToolView::deselectAll ); | ||
261 | } | 321 | } | ||
▲ Show 20 Lines • Show All 341 Lines • Show Last 20 Lines |