Thu, 11 Apr 2013 17:15:01 +0300
Recent files are now remembered and displayed in a submenu
colors.cpp | file | annotate | diff | comparison | revisions | |
config.cpp | file | annotate | diff | comparison | revisions | |
file.cpp | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
gui_actions.cpp | file | annotate | diff | comparison | revisions | |
icons/clips/clock-medium.png | file | annotate | diff | comparison | revisions | |
icons/clips/clock-small.png | file | annotate | diff | comparison | revisions | |
icons/open-recent.png | file | annotate | diff | comparison | revisions |
--- a/colors.cpp Thu Apr 11 02:26:14 2013 +0300 +++ b/colors.cpp Thu Apr 11 17:15:01 2013 +0300 @@ -29,6 +29,8 @@ if (g_bColorsInit) return; + printf ("%s: initializing color information.\n", __func__); + // Always make sure there's 16 and 24 available. They're special like that. color* maincolor = new color; maincolor->zColorString = "#AAAAAA";
--- a/config.cpp Thu Apr 11 02:26:14 2013 +0300 +++ b/config.cpp Thu Apr 11 17:15:01 2013 +0300 @@ -65,6 +65,8 @@ // ============================================================================= // Load the configuration from file bool config::load () { + printf ("config::load: loading configuration file.\n"); + // Locale must be disabled for atof setlocale (LC_NUMERIC, "C");
--- a/file.cpp Thu Apr 11 02:26:14 2013 +0300 +++ b/file.cpp Thu Apr 11 17:15:01 2013 +0300 @@ -17,7 +17,7 @@ */ #include <vector> - +#include <stdio.h> #include "common.h" #include "config.h" #include "file.h" @@ -26,6 +26,7 @@ #include "gui.h" cfg (str, io_ldpath, ""); +cfg (str, io_recentfiles, ""); // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -198,6 +199,37 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +void addRecentFile (str zPath) { + long lPos = io_recentfiles.value.first (zPath); + + // If this file already is in the list, pop it out. + if (lPos != -1) { + if (~io_recentfiles.value == ~zPath) + return; // only recent file - do nothing + + // Pop it out. + str zFront = io_recentfiles.value.substr (0, lPos); + str zBack = io_recentfiles.value.substr (lPos + ~zPath + 1, -1); + io_recentfiles.value = zFront + zBack; + } + + // If there's too many recent files, drop one out. + while (io_recentfiles.value.count ('@') > 3) + io_recentfiles.value = io_recentfiles.value.substr (io_recentfiles.value.first ("@") + 1, -1); + + // Add the file + if (~io_recentfiles.value > 0) + io_recentfiles.value += "@"; + + io_recentfiles += zPath; + + config::save (); + g_ForgeWindow->updateRecentFilesMenu (); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= void openMainFile (str zPath) { closeAll (); @@ -213,6 +245,9 @@ // Rebuild the object tree view now. g_ForgeWindow->refresh (); + + // Add it to the recent files list. + addRecentFile (zPath); } // =============================================================================
--- a/gui.cpp Thu Apr 11 02:26:14 2013 +0300 +++ b/gui.cpp Thu Apr 11 17:15:01 2013 +0300 @@ -68,6 +68,7 @@ cfg (bool, lv_colorize, true); cfg (int, gui_toolbar_iconsize, 24); +extern_cfg (str, io_recentfiles); // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -138,66 +139,90 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -#define ADD_MENU_ITEM(MENU, ACT) q##MENU##Menu->addAction (ACTION_NAME (ACT)); - void ForgeWindow::createMenus () { + qRecentFilesMenu = new QMenu (tr ("Open &Recent")); + qRecentFilesMenu->setIcon (getIcon ("open-recent")); + updateRecentFilesMenu (); + // File menu qFileMenu = menuBar ()->addMenu (tr ("&File")); - ADD_MENU_ITEM (File, newFile) // New - ADD_MENU_ITEM (File, open) // Open - ADD_MENU_ITEM (File, save) // Save - ADD_MENU_ITEM (File, saveAs) // Save As - qFileMenu->addSeparator (); // ------- - ADD_MENU_ITEM (File, settings) // Settings - qFileMenu->addSeparator (); // ------- - ADD_MENU_ITEM (File, exit) // Exit + qFileMenu->addAction (ACTION_NAME (newFile)); // New + qFileMenu->addAction (ACTION_NAME (open)); // Open + qFileMenu->addMenu (qRecentFilesMenu); // Open Recent + qFileMenu->addAction (ACTION_NAME (save)); // Save + qFileMenu->addAction (ACTION_NAME (saveAs)); // Save As + qFileMenu->addSeparator (); // ------- + qFileMenu->addAction (ACTION_NAME (settings)); // Settings + qFileMenu->addSeparator (); // ------- + qFileMenu->addAction (ACTION_NAME (exit)); // Exit // Insert menu qInsertMenu = menuBar ()->addMenu (tr ("&Insert")); - ADD_MENU_ITEM (Insert, newSubfile) // New Subfile - ADD_MENU_ITEM (Insert, newLine) // New Line - ADD_MENU_ITEM (Insert, newTriangle) // New Triangle - ADD_MENU_ITEM (Insert, newQuad) // New Quad - ADD_MENU_ITEM (Insert, newCondLine) // New Conditional Line - ADD_MENU_ITEM (Insert, newComment) // New Comment - ADD_MENU_ITEM (Insert, newVertex) // New Vertex + qInsertMenu->addAction (ACTION_NAME (newSubfile)); // New Subfile + qInsertMenu->addAction (ACTION_NAME (newLine)); // New Line + qInsertMenu->addAction (ACTION_NAME (newTriangle)); // New Triangle + qInsertMenu->addAction (ACTION_NAME (newQuad)); // New Quad + qInsertMenu->addAction (ACTION_NAME (newCondLine)); // New Conditional Line + qInsertMenu->addAction (ACTION_NAME (newComment)); // New Comment + qInsertMenu->addAction (ACTION_NAME (newVertex)); // New Vertex // Edit menu qEditMenu = menuBar ()->addMenu (tr ("&Edit")); - ADD_MENU_ITEM (Edit, undo) // Undo - ADD_MENU_ITEM (Edit, redo) // Redo - qEditMenu->addSeparator (); // ----- - ADD_MENU_ITEM (Edit, cut) // Cut - ADD_MENU_ITEM (Edit, copy) // Copy - ADD_MENU_ITEM (Edit, paste) // Paste - ADD_MENU_ITEM (Edit, del) // Delete - qEditMenu->addSeparator (); // ----- - ADD_MENU_ITEM (Edit, moveUp) // Move Up - ADD_MENU_ITEM (Edit, moveDown) // Move Down - qEditMenu->addSeparator (); // ----- - ADD_MENU_ITEM (Edit, setColor) // Set Color - ADD_MENU_ITEM (Edit, inlineContents) // Inline - ADD_MENU_ITEM (Edit, deepInline) // Deep Inline - ADD_MENU_ITEM (Edit, splitQuads) // Split Quads - ADD_MENU_ITEM (Edit, setContents) // Set Contents - ADD_MENU_ITEM (Edit, makeBorders) // Make Borders + qEditMenu->addAction (ACTION_NAME (undo)); // Undo + qEditMenu->addAction (ACTION_NAME (redo)); // Redo + qEditMenu->addSeparator (); // ----- + qEditMenu->addAction (ACTION_NAME (cut)); // Cut + qEditMenu->addAction (ACTION_NAME (copy)); // Copy + qEditMenu->addAction (ACTION_NAME (paste)); // Paste + qEditMenu->addAction (ACTION_NAME (del)); // Delete + qEditMenu->addSeparator (); // ----- + qEditMenu->addAction (ACTION_NAME (moveUp)); // Move Up + qEditMenu->addAction (ACTION_NAME (moveDown)); // Move Down + qEditMenu->addSeparator (); // ----- + qEditMenu->addAction (ACTION_NAME (setColor)); // Set Color + qEditMenu->addAction (ACTION_NAME (inlineContents)); // Inline + qEditMenu->addAction (ACTION_NAME (deepInline)); // Deep Inline + qEditMenu->addAction (ACTION_NAME (splitQuads)); // Split Quads + qEditMenu->addAction (ACTION_NAME (setContents)); // Set Contents + qEditMenu->addAction (ACTION_NAME (makeBorders)); // Make Borders // Control menu qControlMenu = menuBar ()->addMenu (tr ("&Control")); - ADD_MENU_ITEM (Control, showHistory) // Show History + qControlMenu->addAction (ACTION_NAME (showHistory)); // Show History #ifndef RELEASE // Debug menu qDebugMenu = menuBar ()->addMenu (tr ("&Debug")); - ADD_MENU_ITEM (Debug, addTestQuad) // Add Test Quad + qDebugMenu->addAction (ACTION_NAME (addTestQuad)); // Add Test Quad #endif // RELEASE // Help menu qHelpMenu = menuBar ()->addMenu (tr ("&Help")); - ADD_MENU_ITEM (Help, help) // Help - qHelpMenu->addSeparator (); // ----- - ADD_MENU_ITEM (Help, about) // About - ADD_MENU_ITEM (Help, aboutQt) // About Qt + qHelpMenu->addAction (ACTION_NAME (help)); // Help + qHelpMenu->addSeparator (); // ----- + qHelpMenu->addAction (ACTION_NAME (about)); // About + qHelpMenu->addAction (ACTION_NAME (aboutQt)); // About Qt +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= +void ForgeWindow::updateRecentFilesMenu () { + // First, clear any items in the recent files menu + for (QAction* qRecent : qaRecentFiles) + delete qRecent; + qaRecentFiles.clear (); + + std::vector<str> zaFiles = io_recentfiles.value / "@"; + for (long i = zaFiles.size() - 1; i >= 0; --i) { + str zFile = zaFiles[i]; + + QAction* qRecent = new QAction (getIcon ("open-recent"), zFile, this); + + connect (qRecent, SIGNAL (triggered ()), this, SLOT (slot_recentFile ())); + qRecentFilesMenu->addAction (qRecent); + qaRecentFiles.push_back (qRecent); + } } // ============================================================================= @@ -479,6 +504,14 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= +void ForgeWindow::slot_recentFile () { + QAction* qAct = static_cast<QAction*> (sender ()); + openMainFile (qAct->text ()); +} + +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= ulong ForgeWindow::getInsertionPoint () { ulong ulIndex;
--- a/gui.h Thu Apr 11 02:26:14 2013 +0300 +++ b/gui.h Thu Apr 11 17:15:01 2013 +0300 @@ -100,6 +100,8 @@ QTreeWidget* qObjList; QTextEdit* qMessageLog; QMenu* qFileMenu, *qEditMenu, *qInsertMenu, *qHelpMenu, *qControlMenu; + QMenu* qRecentFilesMenu; + std::vector<QAction*> qaRecentFiles; #ifndef RELEASE QMenu* qDebugMenu; @@ -118,6 +120,7 @@ ulong getInsertionPoint (); void deleteSelection (vector<ulong>* ulapIndices, std::vector<LDObject*>* papObjects); void updateToolBars (); + void updateRecentFilesMenu (); private: void createMenuActions (); @@ -128,6 +131,7 @@ private slots: void slot_selectionChanged (); void slot_action (); + void slot_recentFile (); }; // -----------------------------------------------------------------------------
--- a/gui_actions.cpp Thu Apr 11 02:26:14 2013 +0300 +++ b/gui_actions.cpp Thu Apr 11 17:15:01 2013 +0300 @@ -82,7 +82,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -ACTION (settings, "Settings", "settings", "Edit the settings of " APPNAME_DISPLAY ".", (0)) { +ACTION (settings, "Settin&gs", "settings", "Edit the settings of " APPNAME_DISPLAY ".", (0)) { ConfigDialog::staticDialog (g_ForgeWindow); }