Fri, 15 Mar 2013 21:53:50 +0200
Set window title dynamically based on filename
bbox.cpp | file | annotate | diff | comparison | revisions | |
common.h | file | annotate | diff | comparison | revisions | |
gui.cpp | file | annotate | diff | comparison | revisions | |
gui.h | file | annotate | diff | comparison | revisions | |
io.cpp | file | annotate | diff | comparison | revisions | |
io.h | file | annotate | diff | comparison | revisions | |
moc_draw.cpp | file | annotate | diff | comparison | revisions | |
moc_gui.cpp | file | annotate | diff | comparison | revisions | |
model.cpp | file | annotate | diff | comparison | revisions |
--- a/bbox.cpp Fri Mar 15 21:08:22 2013 +0200 +++ b/bbox.cpp Fri Mar 15 21:53:50 2013 +0200 @@ -1,6 +1,7 @@ #include "common.h" #include "bbox.h" #include "ldtypes.h" +#include "io.h" void bbox::calculate () { if (!g_CurrentFile)
--- a/common.h Fri Mar 15 21:08:22 2013 +0200 +++ b/common.h Fri Mar 15 21:53:50 2013 +0200 @@ -28,6 +28,7 @@ class LDForgeWindow; class LDObject; class bbox; +class OpenFile; // ============================================================================= // vertex (v) @@ -63,11 +64,6 @@ }; // ============================================================================= -typedef struct { - str filename; - vector<LDObject*> objects; -} OpenFile; - // Plural expression #define PLURAL(n) ((n != 1) ? "s" : "")
--- a/gui.cpp Fri Mar 15 21:08:22 2013 +0200 +++ b/gui.cpp Fri Mar 15 21:53:50 2013 +0200 @@ -31,7 +31,7 @@ createMenus (); createToolbars (); - setWindowTitle (APPNAME_DISPLAY " v" VERSION_STRING); + setTitle (); setMinimumSize (320, 200); resize (800, 600); } @@ -158,6 +158,25 @@ addToolBar (qEditToolBar); } +void LDForgeWindow::setTitle () { + str zTitle = APPNAME_DISPLAY " v" VERSION_STRING; + + // Append our current file if we have one + if (g_CurrentFile) { + zTitle.appendformat (": %s", basename (g_CurrentFile->zFileName.chars())); + + if (g_CurrentFile->objects.size() > 0 && + g_CurrentFile->objects[0]->getType() == OBJ_Comment) + { + // Append title + LDComment* comm = static_cast<LDComment*> (g_CurrentFile->objects[0]); + zTitle.appendformat (":%s", comm->zText.chars()); + } + } + + setWindowTitle (zTitle.chars()); +} + void LDForgeWindow::slot_new () { printf ("new file\n");
--- a/gui.h Fri Mar 15 21:08:22 2013 +0200 +++ b/gui.h Fri Mar 15 21:53:50 2013 +0200 @@ -37,6 +37,7 @@ LDForgeWindow (); void buildObjList (); + void setTitle (); private: void createMenuActions ();
--- a/io.cpp Fri Mar 15 21:08:22 2013 +0200 +++ b/io.cpp Fri Mar 15 21:53:50 2013 +0200 @@ -17,7 +17,7 @@ for (uint i = 0; i < g_LoadedFiles.size(); i++) { file = g_LoadedFiles[i]; - if (!file->filename.icompare (name)) + if (!file->zFileName.icompare (name)) return file; } @@ -38,7 +38,7 @@ } OpenFile* load = new OpenFile; - load->filename = path; + load->zFileName = path; vector<str> lines; @@ -67,6 +67,7 @@ // Rebuild the object tree view now. g_qWindow->buildObjList (); + g_qWindow->setTitle (); return g_CurrentFile; } @@ -86,7 +87,6 @@ char c = zLine[0]; vector<str> tokens = zLine / " "; - printf ("line: %s\n", zLine.chars()); switch (c - '0') { case 0: @@ -94,7 +94,6 @@ // Comment LDComment* obj = new LDComment; obj->zText = zLine.substr (1, -1); - printf ("\t-> comment (%s)\n", obj->zText.chars()); return obj; }
--- a/io.h Fri Mar 15 21:08:22 2013 +0200 +++ b/io.h Fri Mar 15 21:53:50 2013 +0200 @@ -5,6 +5,12 @@ #include "ldtypes.h" #include "str.h" +class OpenFile { +public: + str zFileName, zTitle; + vector<LDObject*> objects; +}; + // PROTOTYPES OpenFile* IO_FindLoadedFile (str name); OpenFile* IO_OpenLDrawFile (str path);
--- a/moc_draw.cpp Fri Mar 15 21:08:22 2013 +0200 +++ b/moc_draw.cpp Fri Mar 15 21:53:50 2013 +0200 @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'draw.h' ** -** Created: Fri Mar 15 18:10:06 2013 +** Created: Fri Mar 15 21:46:30 2013 ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.3) ** ** WARNING! All changes made in this file will be lost!
--- a/moc_gui.cpp Fri Mar 15 21:08:22 2013 +0200 +++ b/moc_gui.cpp Fri Mar 15 21:53:50 2013 +0200 @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'gui.h' ** -** Created: Fri Mar 15 19:46:05 2013 +** Created: Fri Mar 15 21:46:32 2013 ** by: The Qt Meta Object Compiler version 63 (Qt 4.8.3) ** ** WARNING! All changes made in this file will be lost!