MCPcopy Create free account
hub / github.com/dail8859/NotepadNext / addEditor

Method addEditor

src/DockedEditor.cpp:152–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152void DockedEditor::addEditor(ScintillaNext *editor)
153{
154 qInfo(Q_FUNC_INFO);
155
156 Q_ASSERT(editor != Q_NULLPTR);
157
158 if (currentEditor == Q_NULLPTR) {
159 currentEditor = editor;
160 }
161
162 // Create the dock widget for the editor
163 ads::CDockWidget *dockWidget = dockManager->createDockWidget(editor->getName());
164
165 // Disable elide, elided file names not readable when lots of files opened
166 dockWidget->tabWidget()->setElideMode(Qt::ElideNone);
167
168 // We need a unique object name. Can't use the name or file path so use a uuid
169 dockWidget->setObjectName(QUuid::createUuid().toString());
170
171 dockWidget->setWidget(editor);
172 dockWidget->setFeature(ads::CDockWidget::DockWidgetFeature::DockWidgetDeleteOnClose, true);
173 dockWidget->setFeature(ads::CDockWidget::DockWidgetFeature::CustomCloseHandling, true);
174 dockWidget->setFeature(ads::CDockWidget::DockWidgetFeature::DockWidgetFloatable, false);
175
176 dockWidget->tabWidget()->setContextMenuPolicy(Qt::CustomContextMenu);
177 connect(dockWidget->tabWidget(), &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
178 Q_UNUSED(pos)
179
180 emit contextMenuRequestedForEditor(editor);
181 });
182
183 // Set the tooltip based on the buffer
184 if (editor->isFile()) {
185 dockWidget->tabWidget()->setToolTip(editor->getFilePath());
186 }
187 else {
188 dockWidget->tabWidget()->setToolTip(editor->getName());
189 }
190
191 // Set the icon
192 if (editor->readOnly()) {
193 dockWidget->tabWidget()->setIcon(QIcon(":/icons/readonly.png"));
194 }
195 else {
196 dockWidget->tabWidget()->setIcon(QIcon(editor->canSaveToDisk() ? ":/icons/unsaved.png" : ":/icons/saved.png"));
197 connect(editor, &ScintillaNext::savePointChanged, dockWidget, [=](bool dirty) {
198 Q_UNUSED(dirty)
199 const bool actuallyDirty = editor->canSaveToDisk();
200 const QString iconPath = actuallyDirty ? ":/icons/unsaved.png" : ":/icons/saved.png";
201 dockWidget->tabWidget()->setIcon(QIcon(iconPath));
202 });
203 }
204
205 connect(editor, &ScintillaNext::closed, dockWidget, &ads::CDockWidget::closeDockWidget);
206 connect(editor, &ScintillaNext::closed, this, [=]() { emit editorClosed(editor); });
207 connect(editor, &ScintillaNext::renamed, this, [=]() { editorRenamed(editor); });
208
209 connect(dockWidget, &ads::CDockWidget::closeRequested, this, &DockedEditor::dockWidgetCloseRequested);

Callers

nothing calls this directly

Calls 5

toStringMethod · 0.80
isFileMethod · 0.80
getFilePathMethod · 0.80
canSaveToDiskMethod · 0.80
getNameMethod · 0.45

Tested by

no test coverage detected