Mon, 15 Jul 2013 13:50:12 +0300
Made the pointer to current file a private member of an anonymous shell class, thus getting accessors
src/addObjectDialog.cpp | file | annotate | diff | comparison | revisions | |
src/bbox.cpp | file | annotate | diff | comparison | revisions | |
src/common.h | file | annotate | diff | comparison | revisions | |
src/extprogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/history.cpp | file | annotate | diff | comparison | revisions | |
src/ldtypes.cpp | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions |
--- a/src/addObjectDialog.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/addObjectDialog.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -397,7 +397,7 @@ if (newObject) { ulong idx = g_win->getInsertionPoint (); - g_curfile->insertObj (idx, obj); + currentFile()->insertObj (idx, obj); } g_win->fullRefresh ();
--- a/src/bbox.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/bbox.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -36,10 +36,10 @@ { reset(); - if( !g_curfile ) + if( !currentFile() ) return; - for( LDObject* obj : g_curfile->objs() ) + for( LDObject* obj : currentFile()->objs() ) calcObject( obj ); }
--- a/src/common.h Sat Jul 13 21:21:33 2013 +0300 +++ b/src/common.h Mon Jul 15 13:50:12 2013 +0300 @@ -272,10 +272,6 @@ extern const vertex g_origin; // ----------------------------------------------------------------------------- -// Pointer to the OpenFile which is currently being edited by the user. -extern LDOpenFile* g_curfile; - -// ----------------------------------------------------------------------------- // Pointer to the bounding box. extern bbox g_BBox;
--- a/src/extprogs.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/extprogs.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -160,7 +160,7 @@ void writeColorGroup (const short colnum, str fname) { vector<LDObject*> objects; - for (LDObject* obj : *g_curfile) { + for (LDObject* obj : *currentFile()) { if (obj->isColored() == false || obj->color() != colnum) continue; @@ -257,7 +257,7 @@ continue; } - g_curfile->addObject (obj); + currentFile()->addObject (obj); g_win->sel() << obj; }
--- a/src/file.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/file.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -153,10 +153,10 @@ relpath.replace ("\\", "/"); #endif // WIN32 - if (g_curfile) { + if (currentFile()) { // First, try find the file in the current model's file path. We want a file // in the immediate vicinity of the current model to override stock LDraw stuff. - str partpath = fmt ("%1" DIRSLASH "%2", dirname (g_curfile->name ()), relpath); + str partpath = fmt ("%1" DIRSLASH "%2", dirname (currentFile()->name ()), relpath); if (f->open (partpath, File::Read)) { return f; @@ -333,12 +333,12 @@ if (!f) return null; - LDOpenFile* oldLoad = g_curfile; + LDOpenFile* oldLoad = currentFile(); LDOpenFile* load = new LDOpenFile; load->setName (path); if (g_loadingMainFile) { - g_curfile = load; + setCurrentFile (load); g_win->R()->setFile (load); } @@ -348,7 +348,7 @@ if (!ok) { if (g_loadingMainFile) { - g_curfile = oldLoad; + setCurrentFile (oldLoad); g_win->R()->setFile (oldLoad); } @@ -387,7 +387,7 @@ // If we don't have a file path yet, we have to ask the user for one. if (name().length() == 0) { str newpath = QFileDialog::getSaveFileName (g_win, "Save As", - g_curfile->name(), "LDraw files (*.dat *.ldr)"); + currentFile()->name(), "LDraw files (*.dat *.ldr)"); if (newpath.length() == 0) return false; @@ -431,7 +431,7 @@ // Clear the array g_loadedFiles.clear(); - g_curfile = null; + setCurrentFile (null); g_win->R()->setFile (null); g_win->fullRefresh(); @@ -448,7 +448,7 @@ f->setName (""); f->setImplicit (false); g_loadedFiles << f; - g_curfile = f; + setCurrentFile (f); g_BBox.reset(); g_win->R()->setFile (f); @@ -513,7 +513,7 @@ } file->setImplicit (false); - g_curfile = file; + setCurrentFile (file); // Recalculate the bounding box g_BBox.calculate(); @@ -773,14 +773,14 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void reloadAllSubfiles () { - if (!g_curfile) + if (!currentFile()) return; g_loadedFiles.clear(); - g_loadedFiles << g_curfile; + g_loadedFiles << currentFile(); // Go through all objects in the current file and reload the subfiles - for (LDObject* obj : g_curfile->objs()) { + for (LDObject* obj : currentFile()->objs()) { if (obj->getType() == LDObject::Subfile) { LDSubfileObject* ref = static_cast<LDSubfileObject*> (obj); LDOpenFile* fileInfo = getFile (ref->fileInfo()->name()); @@ -811,7 +811,7 @@ if (obj->getType() == LDObject::Vertex) PROP_NAME (vertices) << obj; - if (this == g_curfile) + if (this == currentFile()) g_BBox.calcObject (obj); return numObjs() - 1; @@ -824,7 +824,7 @@ m_history.add (new AddHistory (pos, obj)); m_objs.insert (pos, obj); - if (this == g_curfile) + if (this == currentFile()) g_BBox.calcObject (obj); } @@ -837,7 +837,7 @@ m_objs.erase (idx); // Update the bounding box - if (this == g_curfile) + if (this == currentFile()) g_BBox.calculate (); } @@ -880,7 +880,7 @@ // ============================================================================= // Find out which files are unused and close them. void LDOpenFile::closeUnused () { - vector<LDOpenFile*> filesUsed = getFilesUsed (g_curfile); + vector<LDOpenFile*> filesUsed = getFilesUsed (currentFile()); // Anything that's explicitly opened must not be closed for (LDOpenFile* file : g_loadedFiles) @@ -916,9 +916,40 @@ return m_objs[pos]; } +LDObject* LDOpenFile::obj (ulong pos) const { + return object (pos); +} + +ulong LDOpenFile::numObjs() const { + return m_objs.size(); +} + LDOpenFile& LDOpenFile::operator<< (vector<LDObject*> objs) { for (LDObject* obj : objs) m_objs << obj; return *this; +} + +// ============================================================================= +class { +public: + LDOpenFile* currentFile() { + return m_curfile; + } + + void setCurrentFile (LDOpenFile* f) { + m_curfile = f; + } + +private: + LDOpenFile* m_curfile; +} g_currentFile; + +LDOpenFile* currentFile() { + return g_currentFile.currentFile(); +} + +void setCurrentFile (LDOpenFile* f) { + g_currentFile.setCurrentFile (f); } \ No newline at end of file
--- a/src/file.h Sat Jul 13 21:21:33 2013 +0300 +++ b/src/file.h Mon Jul 15 13:50:12 2013 +0300 @@ -46,7 +46,8 @@ // A file is implicit when they are opened automatically for caching purposes // and are hidden from the user. User-opened files are explicit (not implicit). // ============================================================================= -class LDOpenFile { +class LDOpenFile : public QObject { + Q_OBJECT PROPERTY (str, name, setName) PROPERTY (bool, implicit, setImplicit) READ_PROPERTY (vector<LDObject*>, objs, setObjects) @@ -62,27 +63,14 @@ LDOpenFile(); ~LDOpenFile(); - // Saves this file to disk. - bool save (str zPath = ""); - - // Perform safety checks. Do this before closing any files! - bool safeToClose(); - - // Adds an object to this file at the end of the file. - ulong addObject (LDObject* obj); - - // Deletes the given object from the object chain. - void forgetObject (LDObject* obj); - + ulong addObject (LDObject* obj); // Adds an object to this file at the end of the file. + void forgetObject (LDObject* obj); // Deletes the given object from the object chain. + void insertObj (const ulong pos, LDObject* obj); + ulong numObjs() const; LDObject* object (ulong pos) const; - LDObject* obj (ulong pos) const { - return object (pos); - } - - void insertObj (const ulong pos, LDObject* obj); - ulong numObjs() const { - return m_objs.size(); - } + LDObject* obj (ulong pos) const; + bool save (str path = ""); // Saves this file to disk. + bool safeToClose(); // Perform safety checks. Do this before closing any files! void setObject (ulong idx, LDObject* obj); LDOpenFile& operator<< (LDObject* obj) { @@ -173,6 +161,8 @@ void addRecentFile (str path); str basename (str path); str dirname (str path); +LDOpenFile* currentFile(); +void setCurrentFile (LDOpenFile* f); // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -207,5 +197,6 @@ void workDone(); }; -#endif // FILE_H -// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4; +void changeCurrentFile (LDOpenFile* f); + +#endif // FILE_H \ No newline at end of file
--- a/src/gui.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/gui.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -489,21 +489,21 @@ str title = fmt (APPNAME " %1", fullVersionString()); // Append our current file if we have one - if (g_curfile) { - if (g_curfile->name ().length () > 0) - title += fmt (": %1", basename (g_curfile->name ())); + if (currentFile()) { + if (currentFile()->name ().length () > 0) + title += fmt (": %1", basename (currentFile()->name ())); else title += fmt (": <anonymous>"); - if (g_curfile->numObjs () > 0 && - g_curfile->obj (0)->getType () == LDObject::Comment) + if (currentFile()->numObjs () > 0 && + currentFile()->obj (0)->getType () == LDObject::Comment) { // Append title - LDCommentObject* comm = static_cast<LDCommentObject*> (g_curfile->obj (0)); + LDCommentObject* comm = static_cast<LDCommentObject*> (currentFile()->obj (0)); title += fmt (": %1", comm->text); } - if (g_curfile->history ().pos () != g_curfile->savePos ()) + if (currentFile()->history ().pos () != currentFile()->savePos ()) title += '*'; } @@ -519,7 +519,7 @@ void ForgeWindow::slot_action () { // Open the history so we can record the edits done during this action. if( sender() != ACTION( undo ) && sender() != ACTION( redo ) && sender() != ACTION( open )) - g_curfile->openHistory (); + currentFile()->openHistory (); // Get the action that triggered this slot. QAction* qAct = static_cast<QAction*> (sender ()); @@ -545,7 +545,7 @@ // We have the meta, now call the handler. (*meta->handler) (); - g_curfile->closeHistory (); + currentFile()->closeHistory (); } // ============================================================================= @@ -562,7 +562,7 @@ // Delete the objects that were being selected for( LDObject * obj : selCopy ) { - g_curfile->forgetObject( obj ); + currentFile()->forgetObject( obj ); ++num; delete obj; } @@ -575,7 +575,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::buildObjList () { - if (!g_curfile) + if (!currentFile()) return; // Lock the selection while we do this so that refreshing the object list @@ -588,7 +588,7 @@ m_objList->clear (); - for (LDObject* obj : g_curfile->objs ()) { + for (LDObject* obj : currentFile()->objs ()) { str descr; switch (obj->getType ()) { @@ -701,7 +701,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::slot_selectionChanged () { - if (g_bSelectionLocked == true || g_curfile == null) + if (g_bSelectionLocked == true || currentFile() == null) return; /* @@ -724,7 +724,7 @@ m_sel.clear (); const QList<QListWidgetItem*> items = m_objList->selectedItems (); - for (LDObject* obj : g_curfile->objs ()) + for (LDObject* obj : currentFile()->objs ()) for (QListWidgetItem* item : items) { if (item == obj->qObjListEntry) { m_sel << obj; @@ -756,7 +756,7 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void ForgeWindow::slot_quickColor () { - g_curfile->openHistory (); + currentFile()->openHistory (); QToolButton* button = static_cast<QToolButton*> (sender ()); LDColor* col = null; @@ -780,7 +780,7 @@ } fullRefresh (); - g_curfile->closeHistory (); + currentFile()->closeHistory (); } // ============================================================================= @@ -789,11 +789,11 @@ ulong ForgeWindow::getInsertionPoint () { if (m_sel.size () > 0) { // If we have a selection, put the item after it. - return (m_sel[m_sel.size() - 1]->getIndex (g_curfile)) + 1; + return (m_sel[m_sel.size() - 1]->getIndex (currentFile())) + 1; } // Otherwise place the object at the end. - return g_curfile->numObjs (); + return currentFile()->numObjs (); } // ============================================================================= @@ -815,7 +815,7 @@ void ForgeWindow::updateSelection () { g_bSelectionLocked = true; - for (LDObject* obj : g_curfile->objs ()) + for (LDObject* obj : currentFile()->objs ()) obj->setSelected (false); m_objList->clearSelection (); @@ -937,7 +937,7 @@ // ============================================================================= void ForgeWindow::deleteObjVector (vector<LDObject*> objs) { for (LDObject* obj : objs) { - g_curfile->forgetObject (obj); + currentFile()->forgetObject (obj); delete obj; } } @@ -945,7 +945,7 @@ // ============================================================================= void ForgeWindow::deleteByColor (const short colnum) { vector<LDObject*> objs; - for (LDObject* obj : g_curfile->objs ()) { + for (LDObject* obj : currentFile()->objs ()) { if (!obj->isColored () || obj->color () != colnum) continue; @@ -974,7 +974,7 @@ void ForgeWindow::slot_editObject (QListWidgetItem* listitem) { LDObject* obj = null; - for (LDObject* it : *g_curfile) { + for (LDObject* it : *currentFile()) { if (it->qObjListEntry == listitem) { obj = it; break; @@ -1012,7 +1012,7 @@ if (path.length () == 0 || saveAs) { path = QFileDialog::getSaveFileName (g_win, tr ("Save As"), - g_curfile->name (), tr ("LDraw files (*.dat *.ldr)")); + currentFile()->name (), tr ("LDraw files (*.dat *.ldr)")); if (path.length () == 0) { // User didn't give a file name. This happens if the user cancelled @@ -1024,7 +1024,7 @@ if (f->save (path)) { f->setName (path); - if (f == g_curfile) + if (f == currentFile()) g_win->updateTitle (); log ("Saved to %1.", path); @@ -1124,7 +1124,7 @@ void makeColorSelector (QComboBox* box) { std::map<short, ulong> counts; - for (LDObject* obj : g_curfile->objs ()) { + for (LDObject* obj : currentFile()->objs ()) { if (!obj->isColored ()) continue;
--- a/src/gui_actions.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/gui_actions.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -66,17 +66,17 @@ ui.rb_license_nonca->isChecked() ? NonCALicense : ""; - *g_curfile << new LDCommentObject (ui.le_title->text()); - *g_curfile << new LDCommentObject ("Name: <untitled>.dat" ); - *g_curfile << new LDCommentObject (fmt ("Author: %1", ui.le_author->text())); - *g_curfile << new LDCommentObject (fmt ("!LDRAW_ORG Unofficial_Part")); + *currentFile() << new LDCommentObject (ui.le_title->text()); + *currentFile() << new LDCommentObject ("Name: <untitled>.dat" ); + *currentFile() << new LDCommentObject (fmt ("Author: %1", ui.le_author->text())); + *currentFile() << new LDCommentObject (fmt ("!LDRAW_ORG Unofficial_Part")); if (license != "") - *g_curfile << new LDCommentObject (license); + *currentFile() << new LDCommentObject (license); - *g_curfile << new LDEmptyObject; - *g_curfile << new LDBFCObject (BFCType); - *g_curfile << new LDEmptyObject; + *currentFile() << new LDEmptyObject; + *currentFile() << new LDBFCObject (BFCType); + *currentFile() << new LDEmptyObject; g_win->fullRefresh(); } @@ -102,7 +102,7 @@ // ============================================================================= MAKE_ACTION (save, "&Save", "file-save", "Save the part model.", CTRL (S)) { - g_win->save (g_curfile, false); + g_win->save (currentFile(), false); } // ============================================================================= @@ -110,7 +110,7 @@ // ============================================================================= MAKE_ACTION (saveAs, "Save &As", "file-save-as", "Save the part model to a specific file.", CTRL_SHIFT (S)) { - g_win->save (g_curfile, true); + g_win->save (currentFile(), true); } // ============================================================================= @@ -204,7 +204,7 @@ MAKE_ACTION (selectAll, "Select All", "select-all", "Selects all objects.", CTRL (A)) { g_win->sel().clear(); - for (LDObject* obj : g_curfile->objs()) + for (LDObject* obj : currentFile()->objs()) g_win->sel() << obj; g_win->updateSelection(); @@ -220,7 +220,7 @@ return; // no consensus on color g_win->sel().clear(); - for (LDObject* obj : g_curfile->objs()) + for (LDObject* obj : currentFile()->objs()) if (obj->color() == colnum) g_win->sel() << obj; @@ -252,7 +252,7 @@ } g_win->sel().clear(); - for (LDObject* obj : g_curfile->objs()) { + for (LDObject* obj : currentFile()->objs()) { if (obj->getType() != type) continue; @@ -312,7 +312,7 @@ g_win->sel().clear(); for (LDObject* obj : objs) { - g_curfile->insertObj (idx, obj); + currentFile()->insertObj (idx, obj); g_win->sel() << obj; idx++; @@ -373,7 +373,7 @@ for (str line : str (te_edit->toPlainText()).split ("\n")) { LDObject* obj = parseLine (line); - g_curfile->insertObj (idx, obj); + currentFile()->insertObj (idx, obj); g_win->sel() << obj; idx++; } @@ -390,7 +390,7 @@ uchar* imgdata = g_win->R()->screencap (w, h); QImage img = imageFromScreencap (imgdata, w, h); - str root = basename (g_curfile->name()); + str root = basename (currentFile()->name()); if (root.right (4) == ".dat") root.chop (4);
--- a/src/gui_editactions.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/gui_editactions.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -90,7 +90,7 @@ for (str line : clipboardText.split ("\n")) { LDObject* pasted = parseLine (line); - g_curfile->insertObj (idx++, pasted); + currentFile()->insertObj (idx++, pasted); g_win->sel() << pasted; g_win->R()->compileObject (pasted); ++num; @@ -118,7 +118,7 @@ for (LDObject* obj : sel) { // Get the index of the subfile so we know where to insert the // inlined contents. - long idx = obj->getIndex (g_curfile); + long idx = obj->getIndex (currentFile()); if (idx == -1) continue; @@ -136,12 +136,12 @@ delete inlineobj; LDObject* newobj = parseLine (line); - g_curfile->insertObj (idx++, newobj); + currentFile()->insertObj (idx++, newobj); g_win->sel() << newobj; } // Delete the subfile now as it's been inlined. - g_curfile->forgetObject (obj); + currentFile()->forgetObject (obj); delete obj; } @@ -170,7 +170,7 @@ continue; // Find the index of this quad - long index = obj->getIndex (g_curfile); + long index = obj->getIndex (currentFile()); if (index == -1) return; @@ -179,8 +179,8 @@ // Replace the quad with the first triangle and add the second triangle // after the first one. - g_curfile->setObject (index, triangles[0]); - g_curfile->insertObj (index + 1, triangles[1]); + currentFile()->setObject (index, triangles[0]); + currentFile()->insertObj (index + 1, triangles[1]); // Delete this quad now, it has been split. delete obj; @@ -289,10 +289,10 @@ } for (short i = 0; i < numLines; ++i) { - ulong idx = obj->getIndex (g_curfile) + i + 1; + ulong idx = obj->getIndex (currentFile()) + i + 1; lines[i]->setColor (edgecolor); - g_curfile->insertObj (idx, lines[i]); + currentFile()->insertObj (idx, lines[i]); g_win->R()->compileObject (lines[i]); } @@ -315,14 +315,14 @@ if (obj->vertices() < 2) continue; - ulong idx = obj->getIndex (g_curfile); + ulong idx = obj->getIndex (currentFile()); for (short i = 0; i < obj->vertices(); ++i) { LDVertexObject* vert = new LDVertexObject; vert->pos = obj->getVertex (i); vert->setColor (obj->color()); - g_curfile->insertObj (++idx, vert); + currentFile()->insertObj (++idx, vert); g_win->R()->compileObject (vert); ++num; } @@ -353,11 +353,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (undo, "Undo", "undo", "Undo a step.", CTRL (Z)) { - g_curfile->undo(); + currentFile()->undo(); } MAKE_ACTION (redo, "Redo", "redo", "Redo a step.", CTRL_SHIFT (Z)) { - g_curfile->redo(); + currentFile()->redo(); } // ============================================================================= @@ -663,7 +663,7 @@ // ================================================================================================= static bool isColorUsed (short colnum) { - for (LDObject* obj : g_curfile->objs()) + for (LDObject* obj : currentFile()->objs()) if (obj->isColored() && obj->color() == colnum) return true;
--- a/src/history.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/history.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -164,14 +164,14 @@ // ============================================================================= void EditHistory::undo() const { - LDObject* obj = g_curfile->object (index()); + LDObject* obj = currentFile()->object (index()); LDObject* newobj = parseLine (oldCode()); obj->replace (newobj); g_win->R()->compileObject (newobj); } void EditHistory::redo() const { - LDObject* obj = g_curfile->object (index()); + LDObject* obj = currentFile()->object (index()); LDObject* newobj = parseLine (newCode()); obj->replace (newobj); g_win->R()->compileObject (newobj);
--- a/src/ldtypes.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/ldtypes.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -190,11 +190,11 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::replace (LDObject* other) { - long idx = getIndex (g_curfile); + long idx = getIndex (currentFile()); assert (idx != -1); // Replace the instance of the old object with the new object - g_curfile->setObject (idx, other); + currentFile()->setObject (idx, other); // Remove the old object delete this; @@ -204,14 +204,14 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void LDObject::swap (LDObject* other) { - for (LDObject*& obj : *g_curfile) { + for (LDObject*& obj : *currentFile()) { if (obj == this) obj = other; elif (obj == other) obj = this; } - g_curfile->addToHistory (new SwapHistory (id(), other->id())); + currentFile()->addToHistory (new SwapHistory (id(), other->id())); } LDLineObject::LDLineObject (vertex v1, vertex v2) { @@ -352,10 +352,10 @@ for (long i = start; i != end; i += incr) { LDObject* obj = objs[i]; - const long idx = obj->getIndex (g_curfile), + const long idx = obj->getIndex (currentFile()), target = idx + (up ? -1 : 1); - if ((up && idx == 0) || (!up && idx == (long) (g_curfile->objs().size() - 1))) { + if ((up && idx == 0) || (!up && idx == (long) (currentFile()->objs().size() - 1))) { // One of the objects hit the extrema. If this happens, this should be the first // object to be iterated on. Thus, nothing has changed yet and it's safe to just // abort the entire operation. @@ -364,9 +364,9 @@ } objsToCompile << obj; - objsToCompile << g_curfile->obj (target); + objsToCompile << currentFile()->obj (target); - obj->swap (g_curfile->obj (target)); + obj->swap (currentFile()->obj (target)); } objsToCompile.makeUnique(); @@ -436,24 +436,24 @@ // ============================================================================= LDObject* LDObject::next() const { - long idx = getIndex (g_curfile); + long idx = getIndex (currentFile()); assert (idx != -1); - if (idx == (long) g_curfile->numObjs() - 1) + if (idx == (long) currentFile()->numObjs() - 1) return null; - return g_curfile->obj (idx + 1); + return currentFile()->obj (idx + 1); } // ============================================================================= LDObject* LDObject::prev() const { - long idx = getIndex (g_curfile); + long idx = getIndex (currentFile()); assert (idx != -1); if (idx == 0) return null; - return g_curfile->obj (idx - 1); + return currentFile()->obj (idx - 1); } // ============================================================================= @@ -551,14 +551,14 @@ // flipped but I don't have a method for checking flatness yet. // Food for thought... - ulong idx = getIndex (g_curfile); + ulong idx = getIndex (currentFile()); if (idx > 0) { LDBFCObject* bfc = dynamic_cast<LDBFCObject*> (prev()); if (bfc && bfc->type == LDBFCObject::InvertNext) { // This is prefixed with an invertnext, thus remove it. - g_curfile->forgetObject (bfc); + currentFile()->forgetObject (bfc); delete bfc; return; } @@ -566,7 +566,7 @@ // Not inverted, thus prefix it with a new invertnext. LDBFCObject* bfc = new LDBFCObject (LDBFCObject::InvertNext); - g_curfile->insertObj (idx, bfc); + currentFile()->insertObj (idx, bfc); } static void invertLine (LDObject* line) { @@ -627,12 +627,12 @@ template<class T> void changeProperty (LDObject* obj, T* ptr, const T& val) { long idx; - if ((idx = obj->getIndex (g_curfile)) != -1) { + if ((idx = obj->getIndex (currentFile())) != -1) { str before = obj->raw(); *ptr = val; str after = obj->raw(); - g_curfile->addToHistory (new EditHistory (idx, before, after)); + currentFile()->addToHistory (new EditHistory (idx, before, after)); } else *ptr = val; }
--- a/src/main.cpp Sat Jul 13 21:21:33 2013 +0300 +++ b/src/main.cpp Mon Jul 15 13:50:12 2013 +0300 @@ -31,7 +31,6 @@ #include "primitives.h" vector<LDOpenFile*> g_loadedFiles; -LDOpenFile* g_curfile = null; ForgeWindow* g_win = null; bbox g_BBox; const QApplication* g_app = null; @@ -62,7 +61,7 @@ int main (int argc, char* argv[]) { const QApplication app (argc, argv); g_app = &app; - g_curfile = null; + setCurrentFile (null); // Load or create the configuration if (!config::load ()) {