# HG changeset patch # User Santeri Piippo # Date 1375365614 -10800 # Node ID 14bfeed046f31fd751ee9b81e55383e50a0ea6bc # Parent be1824f53c48080e5724456039a167d235ae06f2 Added an option for listing implicit files diff -r be1824f53c48 -r 14bfeed046f3 src/configDialog.cpp --- a/src/configDialog.cpp Thu Aug 01 16:05:31 2013 +0300 +++ b/src/configDialog.cpp Thu Aug 01 17:00:14 2013 +0300 @@ -45,6 +45,7 @@ extern_cfg (str, gui_colortoolbar); extern_cfg (bool, edit_schemanticinline); extern_cfg (bool, gl_blackedges); +extern_cfg (bool, gui_implicitfiles); #define act(N) extern_cfg (keyseq, key_##N); #include "actions.h" @@ -92,7 +93,8 @@ ui->colorizeObjects->setChecked (lv_colorize); ui->colorBFC->setChecked (gl_colorbfc); ui->blackEdges->setChecked (gl_blackedges); - ui->scemanticInlining->setChecked (edit_schemanticinline); + // ui->scemanticInlining->setChecked (edit_schemanticinline); + ui->implicitFiles->setChecked (gui_implicitfiles); } // ============================================================================= @@ -561,10 +563,11 @@ // Apply configuration lv_colorize = dlg.getUI()->colorizeObjects->isChecked(); gl_colorbfc = dlg.getUI()->colorBFC->isChecked(); - edit_schemanticinline = dlg.getUI()->scemanticInlining->isChecked(); + // edit_schemanticinline = dlg.getUI()->scemanticInlining->isChecked(); gl_blackedges = dlg.getUI()->blackEdges->isChecked(); gl_maincolor_alpha = ((double) dlg.getUI()->mainColorAlpha->value()) / 10.0f; gl_linethickness = dlg.getUI()->lineThickness->value(); + gui_implicitfiles = dlg.getUI()->implicitFiles->isChecked(); // Rebuild the quick color toolbar g_win->setQuickColors (dlg.quickColors); @@ -593,6 +596,7 @@ g_win->R()->setBackground(); g_win->fullRefresh(); g_win->updateToolBars(); + g_win->updateFileList(); } } diff -r be1824f53c48 -r 14bfeed046f3 src/file.cpp --- a/src/file.cpp Thu Aug 01 16:05:31 2013 +0300 +++ b/src/file.cpp Thu Aug 01 17:00:14 2013 +0300 @@ -899,7 +899,7 @@ for (LDFile* file : g_loadedFiles) { bool isused = false; - for (LDFile* usedFile : filesUsed) { + for (LDFile* usedFile : filesUsed) { if (file == usedFile) { isused = true; break; @@ -952,7 +952,18 @@ return m_curfile; } +// ============================================================================= +/* Sets the given file as the current one on display. At some point in time this + * was an operation completely unheard of. ;) + * + * FIXME: f can be temporarily null. This probably should not be the case. + */ void LDFile::setCurrent (LDFile* f) { + /* Implicit files were loaded for caching purposes and must never be set + * current. */ + if( f && f->implicit() ) + return; + m_curfile = f; if( g_win && f ) { @@ -960,17 +971,28 @@ g_win->updateFileListItem( f ); g_win->buildObjList(); g_win->R()->setFile( f ); - g_win->R()->update(); + g_win->R()->repaint(); log( "Changed file to %1", f->getShortName()); } } // ============================================================================= +int LDFile::countExplicitFiles() { + int count = 0; + + for( LDFile* f : g_loadedFiles ) + if( f->implicit() == false ) + count++; + + return count; +} + +// ============================================================================= // This little beauty closes the initial file that was open at first when opening // a new file over it. void LDFile::closeInitialFile() { - if (g_loadedFiles.size() == 2 && + if (countExplicitFiles() == 2 && g_loadedFiles[0]->name() == "" && !g_loadedFiles[0]->hasUnsavedChanges()) { diff -r be1824f53c48 -r 14bfeed046f3 src/file.h --- a/src/file.h Thu Aug 01 16:05:31 2013 +0300 +++ b/src/file.h Thu Aug 01 17:00:14 2013 +0300 @@ -128,6 +128,7 @@ static LDFile* current(); static void setCurrent (LDFile* f); static void closeInitialFile(); + static int countExplicitFiles(); str getShortName(); private: diff -r be1824f53c48 -r 14bfeed046f3 src/gui.cpp --- a/src/gui.cpp Thu Aug 01 16:05:31 2013 +0300 +++ b/src/gui.cpp Thu Aug 01 17:00:14 2013 +0300 @@ -53,6 +53,7 @@ cfg (bool, lv_colorize, true); cfg (str, gui_colortoolbar, "16:24:|:1:2:4:14:0:15:|:33:34:36:46"); +cfg (bool, gui_implicitfiles, false); extern_cfg (str, io_recentfiles); extern_cfg (bool, gl_axes); extern_cfg (str, gl_maincolor); @@ -827,11 +828,12 @@ ui->fileList->clear(); for (LDFile* f : g_loadedFiles) { - /* - if (f->implicit()) + /* Don't list implicit files unless explicitly desired. */ + if (f->implicit() && !gui_implicitfiles) continue; - */ + /* Add an item to the list for this file and store a pointer to it in + * the file, so we can find files by the list item. */ ui->fileList->addItem (""); QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1); f->setListItem (item); @@ -842,20 +844,25 @@ void ForgeWindow::updateFileListItem (LDFile* f) { if (f->listItem() == null) { - // We don't have a list item for this file, so the list - // doesn't exist yet. Create it - afterwards this will be - // up to date. + /* We don't have a list item for this file, so the list either doesn't + * exist yet or is out of date. Build the list now. */ updateFileList(); return; } + /* If this is the current file, it also needs to be the selected item on + * the list. */ if (f == LDFile::current()) ui->fileList->setCurrentItem (f->listItem()); + /* If we list implicit files, draw them with a shade of gray to make them + * distinct. */ if (f->implicit()) f->listItem()->setForeground (QColor (96, 96, 96)); f->listItem()->setText (f->getShortName()); + + /* If the file has unsaved changes, draw a little icon next to it to mark that. */ f->listItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon()); } @@ -868,13 +875,21 @@ void ForgeWindow::endAction() { // Close the history now. LDFile::current()->closeHistory(); + + /* Update the list item of the current file - we may need to draw an icon + * now that marks it as having unsaved changes. */ updateFileListItem (LDFile::current()); } +// ============================================================================= +/* A file is selected from the list of files on the left of the screen. Find out + * which file was picked and change to it. + */ void ForgeWindow::changeCurrentFile() { LDFile* f = null; QListWidgetItem* item = ui->fileList->currentItem(); + /* Find the file pointer of the item that was selected. */ for (LDFile* it : g_loadedFiles) { if (it->listItem() == item) { f = it; @@ -882,6 +897,8 @@ } } + /* If we picked the same file we're currently on, we don't need to do + * anything. */ if (!f || f == LDFile::current()) return; diff -r be1824f53c48 -r 14bfeed046f3 src/ui/config.ui --- a/src/ui/config.ui Thu Aug 01 16:05:31 2013 +0300 +++ b/src/ui/config.ui Thu Aug 01 17:00:14 2013 +0300 @@ -7,7 +7,7 @@ 0 0 476 - 358 + 377 @@ -220,15 +220,9 @@ - - - false - - - When inserting objects through inlining, file inserting or through external programs, all non-schemantics (those without actual meaning in the part file like comments and such) are filtered out. - + - Inline scemantic objects only + List implicitly loaded files