AS_NAMESPACE_START EditorTabs::EditorTabs(QWidget *parent) : QTabWidget(parent), _finder(nullptr) { _connections << connect(parent, SIGNAL(editCopy()), this, SLOT(onEditCopy())); _connections << connect(parent, SIGNAL(editCut()), this, SLOT(onEditCut())); _connections << connect(parent, SIGNAL(editFind()), this, SLOT(onEditFind())); _connections << connect(parent, SIGNAL(editGoto()), this, SLOT(onEditGoto())); _connections << connect(parent, SIGNAL(editPaste()), this, SLOT(onEditPaste())); _connections << connect(parent, SIGNAL(editRedo()), this, SLOT(onEditRedo())); _connections << connect(parent, SIGNAL(editReplace()), this, SLOT(onEditReplace())); _connections << connect(parent, SIGNAL(editUndo()), this, SLOT(onEditUndo())); _connections << connect(parent, SIGNAL(fileClose()), this, SLOT(onFileClose())); _connections << connect(parent, SIGNAL(fileCloseAll()), this, SLOT(onFileCloseAll())); _connections << connect(parent, SIGNAL(fileOpen(QString)), this, SLOT(onFileOpen(QString))); _connections << connect(parent, SIGNAL(fileSave()), this, SLOT(onFileSave())); _connections << connect(parent, SIGNAL(fileSaveAll()), this, SLOT(onFileSaveAll())); _connections << connect(this, &QTabWidget::tabCloseRequested, this, &EditorTabs::onTabCloseRequested); _connections << connect(tabBar(), &QTabBar::tabMoved, this, &EditorTabs::onTabMoved); _connections << connect(this, &EditorTabs::currentChanged, this, &EditorTabs::onCurrentChanged); _connections << connect(this, SIGNAL(fileChanged(QString)), parent, SLOT(onFileChanged(QString))); _connections << connect(this, SIGNAL(fileSaved(QString)), parent, SLOT(onFileSaved(QString))); setMovable(true); setTabsClosable(true); }
void CodeDownloader::save(QByteArray bytes) { if (output_filename.isEmpty()) { qWarning("CodeDownloader::save: output filename is empty"); emit saveFailed(output_filename); return; } QFile file(output_filename); if (!file.open(QIODevice::WriteOnly)) { qWarning("CodeDownloader::save: could not open %s for writing", output_filename.toUtf8().constData()); emit saveFailed(output_filename); return; } file.write(bytes); file.close(); QString version; QRegExp rx("Version: ([\\d,-]+)"); if (rx.indexIn(bytes)) { version = rx.cap(1); qDebug("CodeDownloader::save: version: %s", version.toLatin1().constData()); } emit fileSaved(output_filename, version); }
/** * Called when a document has completed loading. * Determines the file's properties and refreshes the tag list of the editor * window. * This slot is connected to the completed() signal of the document object. * The signal is emitted when a new file is opened, or when a modified file is * saved. */ void EditorPage::slotFileOpened() { QFileInfo fi(m_pDoc->url().path()); // Get file information m_sName = fi.fileName(); m_bWritable = fi.isWritable(); // Set read/write or read-only mode m_pDoc->setReadWrite(!Config().getReadOnlyMode() && m_bWritable); // Refresh the tag list m_pCtagsList->clear(); m_ctags.run(m_pDoc->url().path()); // Check if this is a modified file that has just been saved if (m_bModified) emit fileSaved(m_pDoc->url().path(), m_bNewFile); // Notify that the document has loaded m_bOpen = true; m_bModified = false; emit fileOpened(this, m_pDoc->url().path()); // Set initial position of the cursor m_nLine = 0; slotCursorPosChange(); // This is no longer a new file m_bNewFile = false; }
HTMLPreview::HTMLPreview(MainWindow *parent) : QWidget(parent), ui(new Ui::HTMLPreview) { mParent = parent; ui->setupUi(this); ui->refreshFrom->addItem(tr("Current File")); ui->refreshFrom->addItem(tr("URL")); ui->refreshWhen->addItem(tr("As You Type")); ui->refreshWhen->addItem(tr("After Save")); ui->refreshWhen->addItem(tr("Manually")); #ifdef Q_OS_MAC ui->refreshButton->setMinimumHeight(32); #endif connect(gDispatcher, SIGNAL(selectFile(BaseFile*)), this, SLOT(fileSelected(BaseFile*))); connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(manualRefresh())); Editor *current = mParent->getCurrentEditor(); if(current) { BaseFile *file = current->getFile(); QTextDocument *doc = file->getTextDocument(); connect(file, SIGNAL(unsavedStatusChanged()), this, SLOT(fileSaved())); connect(doc, SIGNAL(contentsChanged()), this, SLOT(fileChanged())); manualRefresh(); } }
void FileEditorContent::fileWasChanged( bool modified ) { if( modified ) emit fileModified(); else emit fileSaved(); }
bool Editor::saveFile(const QUrl &targetUrl) { QUrl url(targetUrl); bool result = false; if (url.isEmpty() && currentUrl().isEmpty()) { result = saveFileAs(); } else { if (url.isEmpty()) url = currentUrl(); QTemporaryFile tmp; // only used for network export tmp.setAutoRemove(false); tmp.open(); QString filename = url.isLocalFile() ? url.toLocalFile() : tmp.fileName(); QSaveFile *savefile = new QSaveFile(filename); if (savefile->open(QIODevice::WriteOnly)) { QTextStream outputStream(savefile); // store commands in their generic @(...) notation format, to be translatable when reopened // this allows sharing of scripts written in different languages Tokenizer tokenizer; tokenizer.initialize(editor->document()->toPlainText()); const QStringList localizedLooks(Translator::instance()->allLocalizedLooks()); QString unstranslated; Token* t; bool pendingEOL = false; // to avoid writing a final EOL token while ((t = tokenizer.getToken())->type() != Token::EndOfInput) { if (pendingEOL) { unstranslated.append('\n'); pendingEOL = false; } if (localizedLooks.contains(t->look())) { QString defaultLook(Translator::instance()->defaultLook(t->look())); unstranslated.append(QString("@(%1)").arg(defaultLook)); } else { if (t->type() == Token::EndOfLine) pendingEOL = true; else unstranslated.append(t->look()); } } outputStream << KTURTLE_MAGIC_1_0 << '\n'; outputStream << unstranslated; outputStream.flush(); savefile->commit(); // check for error here? } delete savefile; if (!url.isLocalFile()) { KIO::StoredTransferJob *job = KIO::storedPut(savefile, url, -1, 0); if(job->exec()){ setCurrentUrl(url); editor->document()->setModified(false); // MainWindow will add us to the recent file list emit fileSaved(url); result = true; // fix GUI for saveAs and saveExamples. TODO: check 5 lines above } } } return result; }
void FileDownloaderHandler::downloadComplete(QString fileName, QString path) { m_mutex.lock(); --m_outstandingDownloads; qDebug() << "fileSaved: " << fileName; emit fileSaved(fileName,path); //To Database startNewDownload(); m_mutex.unlock(); }
void HTMLPreview::fileSelected(BaseFile *file) { if(!file) return; QTextDocument *doc = file->getTextDocument(); connect(file, SIGNAL(unsavedStatusChanged()), this, SLOT(fileSaved())); connect(doc, SIGNAL(contentsChanged()), this, SLOT(fileChanged())); }
void Persistance::open(){ bool wannaOpen = true; close(); //TODO: get if he choosed to not do anything (Cancel) and set wannaOpen false if(wannaOpen){ QString title = "Choose a Poses File to be Opened"; QString filesType = "RAgent Config File (*.rnc)";\ QString folder = QSettings().value(SETTING_NAME_ID_FILE_PATH).toString(); QString path = QFileDialog::getOpenFileName(this, title, folder, filesType); if(path.isEmpty()){ return; } //caching the last path QSettings * settings = new QSettings(); settings->setValue(SETTING_NAME_ID_FILE_PATH, path); settings->sync(); delete settings; this->filePath = path; this->fileOpened = true; /////// READ FILE QFile file(this->filePath); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << "ERROR: file not save."; showMessage("Error: Could not acces to the file. The document has not been read."); return; } QTextStream in(&file); model->getPoses()->clear(); while (!in.atEnd()){ QString line = in.readLine(); model->getPoses()->addItem(line); } file.close(); //////// END READ FILE qDebug() << "OPEN:" << filePath; this->getController()->showStatusState(filePath); this->modelEdited = false; emit fileSaved(true); }else{ } }
void FileDownloaderHandler::startNewDownload() { if(m_outstandingDownloads < 1 && !m_fileDownloaderQueue.isEmpty()) { QThread* thread = new QThread(); FileDownloader* fd = new FileDownloader(); fd->moveToThread(thread); thread->start(); connect(this, SIGNAL(startDownload(QString,QString,QString)), fd, SLOT(downloadFile(QString,QString,QString))); connect(fd, SIGNAL(fileSaved(QString, QString)), this, SLOT(downloadComplete(QString, QString))); connect(fd, SIGNAL(fileSaved(QString, QString)), thread, SLOT(quit())); connect(thread, &QThread::finished, thread, &QThread::deleteLater); FileInfoStruct fis = m_fileDownloaderQueue.dequeue(); // QString currentBaseUrl = fis.currentBaseUrl; // QString fileName = fis.fileName; // QString savePath = fis.savePath; qDebug() << fis.fileName; emit startDownload(fis.currentBaseUrl, fis.fileName, fis.savePath); m_outstandingDownloads++; } }
void CachedImage::saveToFile(const QString& filename) { if (!_available) return; if (filename.isEmpty()) return; auto pathTo = QString("%1/Taaasty/") .arg(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); QDir dirTo; dirTo.mkpath(pathTo); auto to = QString("%1%2%3%4") .arg(pathTo) .arg(filename) .arg(_extension.isEmpty() ? QString() : ".") .arg(_extension); if (QFile::exists(to))// && !QFile::remove(to)) { qDebug() << "File exists" << to; emit Tasty::instance()->error(0, QString("Файл уже существует:\n%1").arg(to)); emit savingError(); return; } if (!QFile::copy(_path(), to)) { qDebug() << "Error copying" << to; emit Tasty::instance()->error(0, QString("Не удалось сохранить изображение в %1").arg(to)); emit savingError(); return; } emit Tasty::instance()->info(QString("Изображение сохранено в %1").arg(to)); emit fileSaved(); }
void Persistance::save(){ if(!fileOpened){ QString title = "Save as.."; QString filesType = "RAgent Config File (*.rnc)";\ QString folder = QSettings().value(SETTING_NAME_ID_FILE_PATH).toString(); QString path = QFileDialog::getSaveFileName(this, title, folder, filesType); if(path.isEmpty()){ qDebug() << "choosed no file to save"; return; } // what if the users did not specify a suffix...? QFileInfo finfo(path); if (finfo.suffix().isEmpty()){ path += QString(".rnc"); } //caching the last path QSettings * settings = new QSettings(); settings->setValue(SETTING_NAME_ID_FILE_PATH, path); settings->sync(); delete settings; this->filePath = path; this->getController()->showStatusState(filePath); this->fileOpened = true; } this->writeFile(this->filePath); this->modelEdited = false; emit fileSaved(true); qDebug() << "FILE SAVED: " << filePath; getController()->showStatusMessage("File Saved!"); }
void EditorTabs::onFileSave(const int i) { QWidget *w = widget(i); Coder *c; if (w && (c = dynamic_cast<Coder *>(w))) { QString p = w->property(TAB_PROPERTY_PATH).toString(); QFileInfo fi(p); if (fi.exists() || fi.isFile()) { QFile f(p); if (f.open(QIODevice::Text | QIODevice::Truncate | QIODevice::WriteOnly)) { QTextStream s(&f); s.setGenerateByteOrderMark(false); s.setCodec(ENCODING_DEFAULT); s << c->toPlainText(); f.close(); } emit fileSaved(p); } } }
void Persistance::editingPerformed(){ this->modelEdited = true; emit fileSaved(false); }
GPXLab::GPXLab(const QString &fileName, QWidget *parent) : QMainWindow(parent), ui(new Ui::GPXLab), closing(false) { // setup UI ui->setupUi(this); // create GPX_model wrapper gpxmw = new GPX_wrapper(appName); connect(gpxmw, SIGNAL(fileLoaded()), this, SLOT(fileLoaded())); connect(gpxmw, SIGNAL(fileSaved()), this, SLOT(fileSaved())); connect(gpxmw, SIGNAL(modelCleared()), this, SLOT(modelCleared())); connect(gpxmw, SIGNAL(modelPropertiesChanged()), this, SLOT(modelPropertiesChanged())); connect(gpxmw, SIGNAL(modelMetadataChanged()), this, SLOT(modelMetadataChanged())); connect(gpxmw, SIGNAL(trackMetadataChanged(int)), this, SLOT(trackMetadataChanged(int))); connect(gpxmw, SIGNAL(trackInserted(int, const GPX_trkType&)), this, SLOT(trackInserted(int, const GPX_trkType&))); connect(gpxmw, SIGNAL(trackDeleted(int)), this, SLOT(trackDeleted(int))); connect(gpxmw, SIGNAL(trackMovedUp(int)), this, SLOT(trackMovedUp(int))); connect(gpxmw, SIGNAL(trackMovedDown(int)), this, SLOT(trackMovedDown(int))); connect(gpxmw, SIGNAL(trackSplited(int)), this, SLOT(trackSplited(int))); connect(gpxmw, SIGNAL(trackCombined(int)), this, SLOT(trackCombined(int))); connect(gpxmw, SIGNAL(trackTimeShifted(int, long)), this, SLOT(trackTimeShifted(int, long))); connect(gpxmw, SIGNAL(trackSelectionChanged(int, int, int, const GPX_wptType*)), this, SLOT(trackSelectionChanged(int, int, int, const GPX_wptType*))); connect(gpxmw, SIGNAL(pointEdited(int, int, int, GPX_wrapper::TrackPointProperty)), this, SLOT(pointEdited(int, int, int, GPX_wrapper::TrackPointProperty))); connect(gpxmw, SIGNAL(pointInserted(int, int, int, const GPX_wptType&)), this, SLOT(pointInserted(int, int, int, const GPX_wptType&))); connect(gpxmw, SIGNAL(pointDeleted(int, int, int)), this, SLOT(pointDeleted(int, int, int))); connect(gpxmw, SIGNAL(pointSelectionChanged(int, const GPX_wptType*)), this, SLOT(pointSelectionChanged(int, const GPX_wptType*))); // set window title setMainWindowTitle(); // load settings settings = new Settings(this); settings->load(); ui->actionFollow_Item->setChecked(settings->getValue("FollowItem").toBool()); ui->actionShow_Only_Selected_Track->setChecked(settings->getValue("ShowOnlySelectedItem").toBool()); // undo stack undoStack = new QUndoStack(this); undoStack->setUndoLimit(settings->undoLimit); QAction *undoAction = undoStack->createUndoAction(this, tr("&Undo")); undoAction->setShortcuts(QKeySequence::Undo); undoAction->setIcon(QIcon(":/images/undo.png")); QAction *redoAction = undoStack->createRedoAction(this, tr("&Redo")); redoAction->setShortcuts(QKeySequence::Redo); redoAction->setIcon(QIcon(":/images/redo.png")); connect(undoStack, SIGNAL(indexChanged(int)), this, SLOT(setMainWindowTitle())); // tree widget connect(ui->treeTracks, SIGNAL(itemDoubleClicked(QTreeWidgetItem* , int)), this, SLOT(tree_doubleClicked(QTreeWidgetItem*, int))); // map widget ui->mapWidget->init(gpxmw, undoStack, settings->doPersistentCaching, settings->cachePath); ui->mapWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->mapWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(map_showContextMenu(const QPoint&))); connect(ui->mapWidget, SIGNAL(viewChanged(const QPointF&, int)), this, SLOT(map_viewChanged(const QPointF&, int))); // calendar widget ui->calendarWidget->init(gpxmw); // table widget ui->tableWidgetPoints->init(gpxmw, undoStack); connect(settings, SIGNAL(settingsChanged(bool)), ui->tableWidgetPoints, SLOT(settingsChanged(bool))); // diagram widget ui->diagramWidget->addAction(ui->dockWidgetDiagrams->toggleViewAction()); ui->diagramWidget->init(gpxmw); // status bar widgets lblCoordinates = new QLabel(); statusBar()->addWidget(lblCoordinates); lblStatus = new QLabel(); statusBar()->addWidget(lblStatus); // zoom slider widget zoomSlider = new QSlider(Qt::Horizontal, this); zoomSlider->setMinimumWidth(10); zoomSlider->setMaximumWidth(100); zoomSlider->setMinimum(0); zoomSlider->setMaximum(0); ui->mainToolBar->insertWidget(ui->actionMapZoom, zoomSlider); connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(zoom_valueChanged(int))); // build recent files action actionOpenRecentFile = new QAction*[settings->maxRecentFiles]; for (int i = 0; i < settings->maxRecentFiles; ++i) { actionOpenRecentFile[i] = new QAction(this); actionOpenRecentFile[i]->setVisible(false); connect(actionOpenRecentFile[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); ui->menuFile->insertAction(ui->actionExit, actionOpenRecentFile[i]); } ui->menuFile->insertSeparator(ui->actionExit); updateRecentFiles(); // menu edit ui->menuEdit->addAction(undoAction); ui->menuEdit->addAction(redoAction); // menu view ui->menuView->addAction(ui->dockWidgetFile->toggleViewAction()); ui->menuView->addAction(ui->dockWidgetTracks->toggleViewAction()); ui->menuView->addAction(ui->dockWidgetDiagrams->toggleViewAction()); ui->menuView->addAction(ui->dockWidgetPoints->toggleViewAction()); ui->menuView->addAction(ui->mainToolBar->toggleViewAction()); ui->menuView->addSeparator(); ui->menuView->addAction(ui->actionRestore_Default_View); // install event filters for dock widgets to catch resize events ui->dockWidgetFile->installEventFilter(this); ui->dockWidgetTracks->installEventFilter(this); ui->dockWidgetDiagrams->installEventFilter(this); ui->dockWidgetPoints->installEventFilter(this); // dock file ui->dockWidgetFile->addAction(ui->dockWidgetFile->toggleViewAction()); ui->dockWidgetFile->addAction(ui->actionEdit_File_Properties); // dock tracks ui->dockWidgetTracks->addAction(ui->dockWidgetTracks->toggleViewAction()); ui->dockWidgetTracks->addAction(ui->actionEdit_Track_Properties); ui->dockWidgetTracks->addAction(ui->actionGetAltitudeFromSRTM); ui->dockWidgetTracks->addAction(ui->actionSetStartTime); // dock diagram ui->dockWidgetDiagrams->addActions(ui->diagramWidget->actions()); // dock points ui->dockWidgetPoints->addAction(ui->dockWidgetPoints->toggleViewAction()); ui->dockWidgetPoints->addAction(ui->actionInsert_Point); ui->dockWidgetPoints->addAction(ui->actionDelete_Point); // default context menu addActions(ui->menuView->actions()); // connect signals for track and point selection connect(ui->diagramWidget, SIGNAL(selectionChanged(time_t)), this, SLOT(diagram_selectionChanged(time_t))); connect(ui->mapWidget, SIGNAL(selectionChanged(int, int, double, double)), this, SLOT(map_selectionChanged(int, int, double, double))); connect(ui->mapWidget, SIGNAL(selectionChanged(int)), this, SLOT(map_selectionChanged(int))); connect(ui->tableWidgetPoints, SIGNAL(selectionChanged(int)), this, SLOT(table_selectionChanged(int))); connect(ui->treeTracks, SIGNAL(itemSelectionChanged()), this, SLOT(tree_selectionChanged())); connect(ui->calendarWidget, SIGNAL(selectionChanged(int)), this, SLOT(cal_selectionChanged(int))); // disable actions updateActions(false); // open file if any passed as argument if (!fileName.isEmpty()) { openFile(fileName); } }
void EditorBase::save() { setModified(false); emit fileSaved(m_filePath); }