Fixed OS X crash when trying to load recent map
authorinsilmaril
Thu, 16 Nov 2006 13:43:06 +0000
changeset 401f364b13047ba
parent 400 4bdeec4f279e
child 402 ae11bca6bbd8
Fixed OS X crash when trying to load recent map
mainwindow.cpp
mainwindow.h
mapeditor.cpp
tex/vym.changelog
version.h
     1.1 --- a/mainwindow.cpp	Thu Nov 16 10:07:12 2006 +0000
     1.2 +++ b/mainwindow.cpp	Thu Nov 16 13:43:06 2006 +0000
     1.3 @@ -130,8 +130,6 @@
     1.4  		settings.setValue( p,s);
     1.5  
     1.6  	
     1.7 -	maxLastMaps=9;
     1.8 -
     1.9  	// Create tab widget which holds the maps
    1.10  	tabWidget= new QTabWidget (this);
    1.11  	connect( tabWidget, SIGNAL( currentChanged( QWidget * ) ), 
    1.12 @@ -190,17 +188,6 @@
    1.13  	settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() );
    1.14  	settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() );
    1.15  
    1.16 -	QString s;
    1.17 -	int maps=lastMaps.count();
    1.18 -	settings.setValue( "/lastMaps/number",maps );
    1.19 -	for (int i=1;i<=maps;i++)
    1.20 -	{
    1.21 -		s=QString("/lastMaps/map-%1").arg(i);
    1.22 -		if (!s.isEmpty() && i<=maxLastMaps) 
    1.23 -			settings.setValue (s, lastMaps.at(i-1));
    1.24 -	}
    1.25 -
    1.26 -
    1.27  	// To make the texteditor save its settings, call the destructor
    1.28  	delete (textEditor);
    1.29  
    1.30 @@ -1526,45 +1513,33 @@
    1.31  	actionFormatBackColor->addTo( canvasContextMenu );
    1.32  
    1.33  	// Menu for last opened files
    1.34 -	// Read settings initially
    1.35 -	QString s;
    1.36 -	int j=settings.readNumEntry( "/lastMaps/number",0);
    1.37 -	for (int i=1;i<=j;i++)
    1.38 +	// Create actions
    1.39 +	for (int i = 0; i < MaxRecentFiles; ++i) 
    1.40  	{
    1.41 -		s=settings.value(QString("/lastMaps/map-%1").arg(i),"").toString();
    1.42 -		if (!s.isEmpty() && j<=maxLastMaps) 
    1.43 -			lastMaps.append(s);
    1.44 -	}
    1.45 -	setupLastMapsMenu();
    1.46 -	connect( fileLastMapsMenu, SIGNAL( triggered(QAction *) ), this, SLOT( fileLoadLast(QAction*) ) );
    1.47 +        recentFileActs[i] = new QAction(this);
    1.48 +        recentFileActs[i]->setVisible(false);
    1.49 +        fileLastMapsMenu->addAction(recentFileActs[i]);
    1.50 +        connect(recentFileActs[i], SIGNAL(triggered()),
    1.51 +                this, SLOT(fileLoadRecent()));
    1.52 +    }
    1.53 +	setupRecentMapsMenu();
    1.54  }
    1.55  
    1.56 -void Main::setupLastMapsMenu()
    1.57 +void Main::setupRecentMapsMenu()
    1.58  {
    1.59 -	// Remove double entries
    1.60 -	QStringList::Iterator it=lastMaps.begin();
    1.61 -	QStringList::Iterator jt;
    1.62 -	while (it!=lastMaps.end() )
    1.63 -	{
    1.64 -		jt=it;
    1.65 -		++jt;
    1.66 -		while (jt!=lastMaps.end() )
    1.67 -		{
    1.68 -			if (*it == *jt)		
    1.69 -				jt=lastMaps.remove(jt);
    1.70 -			else	
    1.71 -				jt++;
    1.72 -		}
    1.73 -		it++;
    1.74 -	}	
    1.75 -
    1.76 -	// Limit length of list to maxLastMaps
    1.77 -	while ((int)(lastMaps.count()) > maxLastMaps) lastMaps.pop_back();
    1.78 -	
    1.79 -	// build Menu from lastMaps string list
    1.80 -	fileLastMapsMenu->clear();
    1.81 -	for (it = lastMaps.begin(); it != lastMaps.end(); ++it ) 
    1.82 -		fileLastMapsMenu->addAction (*it );
    1.83 +    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
    1.84 +
    1.85 +    int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
    1.86 +
    1.87 +    for (int i = 0; i < numRecentFiles; ++i) {
    1.88 +        //QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
    1.89 +        QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
    1.90 +        recentFileActs[i]->setText(text);
    1.91 +        recentFileActs[i]->setData(files[i]);
    1.92 +        recentFileActs[i]->setVisible(true);
    1.93 +    }
    1.94 +    for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
    1.95 +        recentFileActs[j]->setVisible(false);
    1.96  }
    1.97  
    1.98  void Main::hideEvent (QHideEvent * )
    1.99 @@ -1853,8 +1828,7 @@
   1.100  				{
   1.101  					// Only append to lastMaps if not loaded from a tmpDir
   1.102  					// e.g. imported bookmarks are in a tmpDir
   1.103 -					lastMaps.prepend(me->getFilePath() );
   1.104 -					setupLastMapsMenu();
   1.105 +					addRecentMap(me->getFilePath() );
   1.106  				}
   1.107  				actionFilePrint->setEnabled (true);
   1.108  			}	
   1.109 @@ -1911,9 +1885,25 @@
   1.110  	fileLoad (NewMap);
   1.111  }
   1.112  
   1.113 -void Main::fileLoadLast(QAction *a)
   1.114 +void Main::fileLoadRecent()
   1.115  {
   1.116 -	fileLoad(lastMaps.at(fileLastMapsMenu->actions().indexOf(a)) ,NewMap);
   1.117 +    QAction *action = qobject_cast<QAction *>(sender());
   1.118 +    if (action)
   1.119 +        fileLoad (action->data().toString(), NewMap);
   1.120 +}
   1.121 +
   1.122 +void Main::addRecentMap (const QString &fileName)
   1.123 +{
   1.124 +
   1.125 +    QStringList files = settings.value("/mainwindow/recentFileList").toStringList();
   1.126 +    files.removeAll(fileName);
   1.127 +    files.prepend(fileName);
   1.128 +    while (files.size() > MaxRecentFiles)
   1.129 +        files.removeLast();
   1.130 +
   1.131 +    settings.setValue("/mainwindow/recentFileList", files);
   1.132 +
   1.133 +	setupRecentMapsMenu();
   1.134  }
   1.135  
   1.136  void Main::fileSave(const SaveMode &savemode)
   1.137 @@ -2024,8 +2014,7 @@
   1.138  		statusBar()->message( 
   1.139  			tr("Saved  %1").arg(me->getFilePath()), 
   1.140  			statusbarTime );
   1.141 -		lastMaps.prepend(me->getFilePath() );
   1.142 -		setupLastMapsMenu();
   1.143 +		addRecentMap (me->getFilePath() );
   1.144  	} else		
   1.145  		statusBar()->message( 
   1.146  			tr("Couldn't save ").arg(me->getFilePath()), 
     2.1 --- a/mainwindow.h	Thu Nov 16 10:07:12 2006 +0000
     2.2 +++ b/mainwindow.h	Thu Nov 16 13:43:06 2006 +0000
     2.3 @@ -39,7 +39,7 @@
     2.4      void setupTestActions();
     2.5      void setupHelpActions();
     2.6      void setupContextMenus();
     2.7 -	void setupLastMapsMenu();
     2.8 +	void setupRecentMapsMenu();
     2.9  	void hideEvent (QHideEvent * );
    2.10  	void showEvent (QShowEvent * );
    2.11  	bool reallyWriteDirectory(const QString&);
    2.12 @@ -53,7 +53,8 @@
    2.13      ErrorCode fileLoad(QString ,const LoadMode &);
    2.14      void fileLoad(const LoadMode &);
    2.15      void fileLoad();
    2.16 -	void fileLoadLast(QAction *);
    2.17 +	void fileLoadRecent();
    2.18 +	void addRecentMap (const QString &);
    2.19      void fileSave(const SaveMode & );
    2.20      void fileSave();
    2.21      void fileSaveAs(const SaveMode &);
    2.22 @@ -183,8 +184,6 @@
    2.23  private:
    2.24  	QTabWidget *tabWidget;
    2.25  	FindWindow *findWindow;
    2.26 -	QStringList lastMaps;
    2.27 -	int maxLastMaps;
    2.28  	QProcess *procBrowser;
    2.29  
    2.30  	QStringList imageTypes;
    2.31 @@ -196,6 +195,10 @@
    2.32  
    2.33  	QColor currentColor;
    2.34  
    2.35 +	QMenu *recentFilesMenu;
    2.36 +	enum { MaxRecentFiles = 9 };
    2.37 +    QAction *recentFileActs[MaxRecentFiles];
    2.38 +
    2.39  	QAction* actionFileSave;
    2.40  	QAction* actionFilePrint;
    2.41  	QAction* actionEditUndo;
     3.1 --- a/mapeditor.cpp	Thu Nov 16 10:07:12 2006 +0000
     3.2 +++ b/mapeditor.cpp	Thu Nov 16 13:43:06 2006 +0000
     3.3 @@ -40,11 +40,7 @@
     3.4  extern QMenu* branchXLinksContextMenuEdit;
     3.5  extern QMenu* branchXLinksContextMenuFollow;
     3.6  extern QMenu* floatimageContextMenu;
     3.7 -extern QMenu* saveImageFormatMenu;
     3.8  extern QMenu* canvasContextMenu;
     3.9 -extern QMenu* lastMapsMenu;
    3.10 -extern QMenu* importMenu;
    3.11 -extern QMenu* exportMenu;
    3.12  
    3.13  
    3.14  extern Settings settings;
     4.1 --- a/tex/vym.changelog	Thu Nov 16 10:07:12 2006 +0000
     4.2 +++ b/tex/vym.changelog	Thu Nov 16 13:43:06 2006 +0000
     4.3 @@ -1,3 +1,8 @@
     4.4 +-------------------------------------------------------------------
     4.5 +Thu Nov 16 14:41:44 CET 2006 - uwedr
     4.6 +
     4.7 +- Bugfix: New recent file handling, fixes crash on Mac OS X 
     4.8 +
     4.9  -------------------------------------------------------------------
    4.10  Tue Nov 14 10:00:12 CET 2006 - uwedr
    4.11  
     5.1 --- a/version.h	Thu Nov 16 10:07:12 2006 +0000
     5.2 +++ b/version.h	Thu Nov 16 13:43:06 2006 +0000
     5.3 @@ -5,7 +5,7 @@
     5.4  
     5.5  #define __VYM "VYM"
     5.6  #define __VYM_VERSION "1.8.59"
     5.7 -#define __BUILD_DATE "November 14, 2006"
     5.8 +#define __BUILD_DATE "November 16, 2006"
     5.9  
    5.10  
    5.11  bool checkVersion(const QString &);