File list is populated now..

Mon, 15 Jul 2013 20:45:26 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 15 Jul 2013 20:45:26 +0300
changeset 383
10e60ae9ed58
parent 382
c1642530ea35
child 384
f4622b79133d

File list is populated now..

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.h file | annotate | diff | comparison | revisions
--- a/src/file.cpp	Mon Jul 15 19:30:16 2013 +0300
+++ b/src/file.cpp	Mon Jul 15 20:45:26 2013 +0300
@@ -38,6 +38,8 @@
 static const int g_MaxRecentFiles = 5;
 static bool g_aborted = false;
 
+DEFINE_PROPERTY (QListWidgetItem*, LDOpenFile, listItem, setListItem)
+
 // =============================================================================
 namespace LDPaths {
 	static str pathError;
@@ -92,6 +94,7 @@
 LDOpenFile::LDOpenFile() {
 	setImplicit (true);
 	setSavePos (-1);
+	setListItem (null);
 	m_history.setFile (this);
 }
 
@@ -374,7 +377,7 @@
 	setlocale (LC_ALL, "C");
 	
 	// If we have unsaved changes, warn and give the option of saving.
-	if (!implicit() && history().pos() != savePos()) {
+	if (hasUnsavedChanges()) {
 		str message = fmt ("There are unsaved changes to %1. Should it be saved?",
 						   (name().length() > 0) ? name() : "<anonymous>");
 		
@@ -916,6 +919,10 @@
 	return *this;
 }
 
+bool LDOpenFile::hasUnsavedChanges() const {
+	return !implicit() && history().pos() != savePos();
+}
+
 // =============================================================================
 class {
 public:
@@ -925,6 +932,9 @@
 	
 	void setCurrentFile (LDOpenFile* f) {
 		m_curfile = f;
+		
+		if (g_win)
+			g_win->updateFileList();
 	}
 	
 private:
--- a/src/file.h	Mon Jul 15 19:30:16 2013 +0300
+++ b/src/file.h	Mon Jul 15 20:45:26 2013 +0300
@@ -48,13 +48,14 @@
 // =============================================================================
 class LDOpenFile : public QObject {
 	Q_OBJECT
+	READ_PROPERTY (vector<LDObject*>, objs, setObjects)
+	READ_PROPERTY (History, history, setHistory)
+	READ_PROPERTY (vector<LDObject*>, vertices, setVertices)
 	PROPERTY (str, name, setName)
 	PROPERTY (bool, implicit, setImplicit)
-	READ_PROPERTY (vector<LDObject*>, objs, setObjects)
 	PROPERTY (vector<LDObject*>, cache, setCache)
 	PROPERTY (long, savePos, setSavePos)
-	READ_PROPERTY (History, history, setHistory)
-	READ_PROPERTY (vector<LDObject*>, vertices, setVertices)
+	DECLARE_PROPERTY (QListWidgetItem*, listItem, setListItem)
 	
 public:
 	typedef vector<LDObject*>::it it;
@@ -63,14 +64,15 @@
 	LDOpenFile();
 	~LDOpenFile();
 	
-	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.
+	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.
+	bool hasUnsavedChanges() const;                  // Does this file have unsaved changes?
 	void insertObj (const ulong pos, LDObject* obj);
 	ulong numObjs() const;
 	LDObject* object (ulong pos) const;
 	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!
+	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) {
--- a/src/gui.cpp	Mon Jul 15 19:30:16 2013 +0300
+++ b/src/gui.cpp	Mon Jul 15 20:45:26 2013 +0300
@@ -136,6 +136,7 @@
 	
 	// Close the history now.
 	currentFile()->closeHistory();
+	updateFileListItem (currentFile());
 }
 
 // =============================================================================
@@ -846,6 +847,35 @@
 #define act(N) QAction* ForgeWindow::action##N() { return ui->action##N; }
 #include "actions.h"
 
+void ForgeWindow::updateFileList() {
+	ui->fileList->clear();
+	
+	for (LDOpenFile* f : g_loadedFiles) {
+		if (f->implicit())
+			continue;
+		
+		ui->fileList->addItem ("");
+		QListWidgetItem* item = ui->fileList->item (ui->fileList->count() - 1);
+		f->setListItem (item);
+		
+		updateFileListItem (f);
+	}
+}
+
+void ForgeWindow::updateFileListItem (LDOpenFile* f) {
+	str name;
+	if (f->name() == "")
+		name = "<anonymous>";
+	else
+		name = basename (f->name());
+	
+	if (f == currentFile())
+		ui->fileList->setCurrentItem (f->listItem());
+	
+	f->listItem()->setText (name);
+	f->listItem()->setIcon (f->hasUnsavedChanges() ? getIcon ("file-save") : QIcon());
+}
+
 QImage imageFromScreencap (uchar* data, ushort w, ushort h) {
 	// GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well.
 	return QImage (data, w, h, QImage::Format_ARGB32).rgbSwapped().mirrored();
--- a/src/gui.h	Mon Jul 15 19:30:16 2013 +0300
+++ b/src/gui.h	Mon Jul 15 20:45:26 2013 +0300
@@ -40,15 +40,15 @@
 // Stuff for dialogs
 #define IMPLEMENT_DIALOG_BUTTONS \
 	bbx_buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel); \
-	connect (bbx_buttons, SIGNAL (accepted ()), this, SLOT (accept ())); \
-	connect (bbx_buttons, SIGNAL (rejected ()), this, SLOT (reject ())); \
+	connect (bbx_buttons, SIGNAL (accepted()), this, SLOT (accept())); \
+	connect (bbx_buttons, SIGNAL (rejected()), this, SLOT (reject())); \
 
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 #define DEFINE_ACTION(NAME, DEFSHORTCUT) \
 	cfg (keyseq, key_##NAME, DEFSHORTCUT); \
-	void actiondef_##NAME ()
+	void actiondef_##NAME()
 
 #define ACTION(N) g_win->action##N()
 
@@ -88,28 +88,30 @@
 	Q_OBJECT
 	
 public:
-	ForgeWindow ();
-	void buildObjList ();
-	void updateTitle ();
-	void fullRefresh ();
-	void refresh ();
-	ulong getInsertionPoint ();
-	void updateToolBars ();
-	void updateRecentFilesMenu ();
-	void updateSelection ();
-	void updateGridToolBar ();
-	void updateEditModeActions ();
+	ForgeWindow();
+	void buildObjList();
+	void updateTitle();
+	void fullRefresh();
+	void refresh();
+	ulong getInsertionPoint();
+	void updateToolBars();
+	void updateRecentFilesMenu();
+	void updateSelection();
+	void updateGridToolBar();
+	void updateEditModeActions();
+	void updateFileList();
+	void updateFileListItem (LDOpenFile* f);
 	bool isSelected (LDObject* obj);
 	short getSelectedColor();
-	LDObject::Type uniformSelectedType ();
-	void scrollToSelection ();
+	LDObject::Type uniformSelectedType();
+	void scrollToSelection();
 	void spawnContextMenu (const QPoint pos);
 	void deleteObjVector (vector< LDObject* > objs);
-	int deleteSelection ();
+	int deleteSelection();
 	void deleteByColor (const short int colnum);
 	void save (LDOpenFile* f, bool saveAs);
-	GLRenderer* R () { return m_renderer; }
-	vector<LDObject*>& sel () { return m_sel; }
+	GLRenderer* R() { return m_renderer; }
+	vector<LDObject*>& sel() { return m_sel; }
 	void setQuickColorMeta (vector<quickColor>& quickColorMeta) {
 		m_colorMeta = quickColorMeta;
 	}
@@ -123,7 +125,7 @@
 public slots:
 	void primitiveLoaderStart (ulong max);
 	void primitiveLoaderUpdate (ulong prog);
-	void primitiveLoaderEnd ();
+	void primitiveLoaderEnd();
 	void clearSelection();
 	void slot_action();
 	
@@ -141,14 +143,14 @@
 	MessageManager* m_msglog;
 	Ui_LDForgeUI* ui;
 	
-	void invokeAction (QAction* act, void (*func) ());
+	void invokeAction (QAction* act, void (*func)());
 	
 
 private slots:
-	void slot_selectionChanged ();
-	void slot_recentFile ();
-	void slot_quickColor ();
-	void slot_lastSecondCleanup ();
+	void slot_selectionChanged();
+	void slot_recentFile();
+	void slot_quickColor();
+	void slot_lastSecondCleanup();
 	void slot_editObject (QListWidgetItem* listitem);
 };
 
@@ -163,14 +165,14 @@
 // -----------------------------------------------------------------------------
 // Other GUI-related stuff not directly part of ForgeWindow:
 QPixmap getIcon (str iconName);
-vector<quickColor> parseQuickColorMeta ();
+vector<quickColor> parseQuickColorMeta();
 bool confirm (str title, str msg);
 bool confirm (str msg);
 void critical (str msg);
 QIcon makeColorIcon (LDColor* colinfo, const ushort size);
 void makeColorSelector (QComboBox* box);
 QDialogButtonBox* makeButtonBox (QDialog& dlg);
-CheckBoxGroup* makeAxesBox ();
+CheckBoxGroup* makeAxesBox();
 QImage imageFromScreencap (uchar* data, ushort w, ushort h);
 
 // =============================================================================

mercurial