void MainWindow::addRecentFiles( QSettings& settings , const QString& group, const QString& pfx, const QString& value, const QString& key ) { std::vector< QString > list; getRecentFiles( settings, group, pfx, list, key ); boost::filesystem::path path = boost::filesystem::path( value.toStdWString() ).generic_wstring(); auto it = std::remove_if( list.begin(), list.end(), [path] ( const QString& a ){ return path == a.toStdWString(); } ); if ( it != list.end() ) list.erase( it, list.end() ); settings.beginGroup( group ); settings.beginWriteArray( pfx ); settings.setArrayIndex( 0 ); settings.setValue( key, QString::fromStdWString( path.generic_wstring() ) ); for ( size_t i = 0; i < list.size() && i < 7; ++i ) { settings.setArrayIndex( int(i + 1) ); settings.setValue( key, list[ i ] ); } settings.endArray(); settings.endGroup(); }
void MainWindow::onInitialUpdate( std::shared_ptr< QSettings >& settings ) { settings_ = settings; std::string filename = settings->fileName().toStdString(); std::vector< QString > list; getRecentFiles( "Stylesheets", "DIRS", list, "DIR" ); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::handleOpenFile ); connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::handleSaveTemplateAs ); connect(ui->actionApply, &QAction::triggered, this, &MainWindow::handleApplyStylesheet ); }
void RecentFiles::updateRecentFiles(QSettings &settings) { int numOfRecentFiles = settings.value(recentFileCount, QVariant(4)).toInt(); QStringList MyRecentFileList = settings.value(recentFileListId).toStringList(); purgeMissingFilesFromList(MyRecentFileList); settings.setValue(recentFileListId, QVariant(MyRecentFileList)); // If there are no recent files, then the menu item (that would show the list) // should not be visible. if (m_recentMenuTriggeredAction) { if (numOfRecentFiles == 0) { m_recentMenuTriggeredAction->setVisible(false); } else { m_recentMenuTriggeredAction->setVisible(true); } } for (int j = 0; j < MaxRecentFiles; ++j) { if (j < MyRecentFileList.count() && j < numOfRecentFiles) { QString text = strippedName(MyRecentFileList[j]); m_recentFileActions[j]->setText(text); m_recentFileActions[j]->setData(MyRecentFileList[j]); m_recentFileActions[j]->setObjectName(sanitizedFileName(text)); m_recentFileActions[j]->setVisible(true); } else { m_recentFileActions[j]->setVisible(false); } } for (int j = numOfRecentFiles; j < MyRecentFileList.count(); j++) m_recentFileActions[j]->setVisible(false); getRecentFiles(); }
void MainWindow::getRecentFiles( const QString& group, const QString& pfx, std::vector<QString>& list, const QString& key ) const { getRecentFiles( *settings_, group, pfx, list, key ); }
int App::run() { #ifdef ENABLE_UPDATER app::CheckUpdateThreadLauncher checkUpdate; #endif // Initialize GUI interface if (isGui()) { View* view; Editor* editor; PRINTF("GUI mode\n"); // Setup the GUI screen jmouse_set_cursor(JI_CURSOR_NORMAL); gui::Manager::getDefault()->invalidate(); // Load main window top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window")); box_menubar = top_window->findChild("menubar"); box_editors = top_window->findChild("editor"); box_colorbar = top_window->findChild("colorbar"); box_toolbar = top_window->findChild("toolbar"); box_statusbar = top_window->findChild("statusbar"); box_tabsbar = top_window->findChild("tabsbar"); menubar = new MenuBar(); statusbar = new StatusBar(); colorbar = new ColorBar(box_colorbar->getAlign()); toolbar = toolbar_new(); tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate()); view = new EditorView(EditorView::CurrentEditorMode); editor = create_new_editor(); // configure all widgets to expansives menubar->setExpansive(true); statusbar->setExpansive(true); colorbar->setExpansive(true); toolbar->setExpansive(true); tabsbar->setExpansive(true); view->setExpansive(true); /* prepare the first editor */ view->attachToView(editor); /* setup the menus */ menubar->setMenu(get_root_menu()); /* start text of status bar */ app_default_statusbar_message(); /* add the widgets in the boxes */ if (box_menubar) box_menubar->addChild(menubar); if (box_editors) box_editors->addChild(view); if (box_colorbar) box_colorbar->addChild(colorbar); if (box_toolbar) box_toolbar->addChild(toolbar); if (box_statusbar) box_statusbar->addChild(statusbar); if (box_tabsbar) box_tabsbar->addChild(tabsbar); /* prepare the window */ top_window->remap_window(); // Create the list of tabs app_rebuild_documents_tabs(); app_rebuild_recent_list(); // Set current editor set_current_editor(editor); // Open the window top_window->open_window(); // Redraw the whole screen. gui::Manager::getDefault()->invalidate(); } /* set background mode for non-GUI modes */ /* if (!(ase_mode & MODE_GUI)) */ /* set_display_switch_mode(SWITCH_BACKAMNESIA); */ set_display_switch_mode(SWITCH_BACKGROUND); // procress options PRINTF("Processing options...\n"); ASSERT(m_checkArgs != NULL); { Console console; for (CheckArgs::iterator it = m_checkArgs->begin(); it != m_checkArgs->end(); ++it) { CheckArgs::Option* option = *it; switch (option->type()) { case CheckArgs::Option::OpenSprite: { // Load the sprite Document* document = load_document(option->data().c_str()); if (!document) { if (!isGui()) console.printf("Error loading file \"%s\"\n", option->data().c_str()); } else { // Mount and select the sprite UIContext* context = UIContext::instance(); context->addDocument(document); context->setActiveDocument(document); if (isGui()) { // Show it set_document_in_more_reliable_editor(context->getFirstDocument()); // Recent file getRecentFiles()->addRecentFile(option->data().c_str()); } } break; } } } delete m_checkArgs; m_checkArgs = NULL; } // Run the GUI if (isGui()) { // Support to drop files from Windows explorer install_drop_files(); #ifdef ENABLE_UPDATER // Launch the thread to check for updates. checkUpdate.launch(); #endif // Run the GUI main message loop gui_run(); // Uninstall support to drop files uninstall_drop_files(); // Remove the root-menu from the menu-bar (because the rootmenu // module should destroy it). menubar->setMenu(NULL); // Delete all editors first because they used signals from other // widgets (e.g. color bar). delete box_editors; // Destroy mini-editor. exit_module_editors(); // Destroy the top-window delete top_window; top_window = NULL; } return 0; }