1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Robert Bieber
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "editorwindow.h"
23 #include "projectmodel.h"
24 #include "ui_editorwindow.h"
25 #include "rbfontcache.h"
26 #include "rbtextcache.h"
27 #include "newprojectdialog.h"
28 #include "projectexporter.h"
30 #include <QDesktopWidget>
31 #include <QFileSystemModel>
33 #include <QFileDialog>
34 #include <QMessageBox>
35 #include <QGraphicsScene>
39 const int EditorWindow::numRecent
= 5;
41 EditorWindow::EditorWindow(QWidget
*parent
) :
42 QMainWindow(parent
), ui(new Ui::EditorWindow
), parseTreeSelection(0)
45 prefs
= new PreferencesDialog(this);
53 EditorWindow::~EditorWindow()
64 RBFontCache::clearCache();
65 RBTextCache::clearCache();
68 void EditorWindow::loadTabFromSkinFile(QString fileName
)
72 /* Checking to see if the file is already open */
73 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
75 TabContent
* current
= dynamic_cast<TabContent
*>
76 (ui
->editorTabs
->widget(i
));
77 if(current
->file() == fileName
)
79 ui
->editorTabs
->setCurrentIndex(i
);
84 /* Adding a new document*/
85 SkinDocument
* doc
= new SkinDocument(parseStatus
, fileName
, project
,
88 ui
->editorTabs
->setCurrentWidget(doc
);
92 void EditorWindow::loadConfigTab(ConfigDocument
* doc
)
94 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
96 TabContent
* current
= dynamic_cast<TabContent
*>
97 (ui
->editorTabs
->widget(i
));
98 if(current
->file() == doc
->file())
100 ui
->editorTabs
->setCurrentIndex(i
);
107 ui
->editorTabs
->setCurrentWidget(doc
);
109 QObject::connect(doc
, SIGNAL(titleChanged(QString
)),
110 this, SLOT(tabTitleChanged(QString
)));
113 void EditorWindow::loadSettings()
118 /* Main Window location */
119 settings
.beginGroup("EditorWindow");
120 QSize size
= settings
.value("size").toSize();
121 QPoint pos
= settings
.value("position").toPoint();
122 QByteArray state
= settings
.value("state").toByteArray();
124 /* Recent docs/projects */
125 recentDocs
= settings
.value("recentDocs", QStringList()).toStringList();
126 recentProjects
= settings
.value("recentProjects",
127 QStringList()).toStringList();
131 if(!(size
.isNull() || pos
.isNull() || state
.isNull()))
140 void EditorWindow::saveSettings()
145 /* Saving window and panel positions */
146 settings
.beginGroup("EditorWindow");
147 settings
.setValue("position", pos());
148 settings
.setValue("size", size());
149 settings
.setValue("state", saveState());
151 /* Saving recent docs/projects */
152 settings
.setValue("recentDocs", recentDocs
);
153 settings
.setValue("recentProjects", recentProjects
);
158 void EditorWindow::setupUI()
160 /* Connecting the tab bar signals */
161 QObject::connect(ui
->editorTabs
, SIGNAL(currentChanged(int)),
162 this, SLOT(shiftTab(int)));
163 QObject::connect(ui
->editorTabs
, SIGNAL(tabCloseRequested(int)),
164 this, SLOT(closeTab(int)));
166 /* Connecting the code gen button */
167 QObject::connect(ui
->fromTree
, SIGNAL(pressed()),
168 this, SLOT(updateCurrent()));
170 /* Connecting the preferences dialog */
171 QObject::connect(ui
->actionPreferences
, SIGNAL(triggered()),
172 prefs
, SLOT(exec()));
174 /* Setting up the parse status label */
175 parseStatus
= new QLabel(this);
176 ui
->statusbar
->addPermanentWidget(parseStatus
);
178 /* Setting the selection for parse tree highlighting initially NULL */
179 parseTreeSelection
= 0;
181 /* Adding the skin viewer */
182 viewer
= new SkinViewer(this);
183 ui
->skinPreviewLayout
->addWidget(viewer
);
185 /* Positioning the device settings dialog */
186 deviceDock
= new QDockWidget(tr("Device Configuration"), this);
187 deviceConfig
= new DeviceState(deviceDock
);
189 deviceDock
->setObjectName("deviceDock");
190 deviceDock
->setWidget(deviceConfig
);
191 deviceDock
->setFloating(true);
192 deviceDock
->move(QPoint(x() + width() / 2, y() + height() / 2));
195 /* Positioning the timer panel */
196 timerDock
= new QDockWidget(tr("Timer"), this);
197 timer
= new SkinTimer(deviceConfig
, timerDock
);
199 timerDock
->setObjectName("timerDock");
200 timerDock
->setWidget(timer
);
201 timerDock
->setFloating(true);
202 timerDock
->move(QPoint(x() + width() / 2, y() + height() / 2));
208 void EditorWindow::setupMenus()
210 /* Adding actions to the toolbar */
211 ui
->toolBar
->addAction(ui
->actionNew_Document
);
212 ui
->toolBar
->addAction(ui
->actionOpen_Document
);
213 ui
->toolBar
->addAction(ui
->actionSave_Document
);
214 ui
->toolBar
->addAction(ui
->actionSave_Document_As
);
216 ui
->toolBar
->addSeparator();
217 ui
->toolBar
->addAction(ui
->actionUndo
);
218 ui
->toolBar
->addAction(ui
->actionRedo
);
220 ui
->toolBar
->addSeparator();
221 ui
->toolBar
->addAction(ui
->actionCut
);
222 ui
->toolBar
->addAction(ui
->actionCopy
);
223 ui
->toolBar
->addAction(ui
->actionPaste
);
225 ui
->toolBar
->addSeparator();
226 ui
->toolBar
->addAction(ui
->actionFind_Replace
);
228 /* Connecting panel show actions */
229 QObject::connect(ui
->actionFile_Panel
, SIGNAL(triggered()),
230 this, SLOT(showPanel()));
231 QObject::connect(ui
->actionDisplay_Panel
, SIGNAL(triggered()),
232 this, SLOT(showPanel()));
233 QObject::connect(ui
->actionPreview_Panel
, SIGNAL(triggered()),
234 this, SLOT(showPanel()));
235 QObject::connect(ui
->actionDevice_Configuration
, SIGNAL(triggered()),
236 deviceDock
, SLOT(show()));
237 QObject::connect(ui
->actionTimer
, SIGNAL(triggered()),
238 timerDock
, SLOT(show()));
240 /* Connecting the document management actions */
241 QObject::connect(ui
->actionNew_Document
, SIGNAL(triggered()),
242 this, SLOT(newTab()));
243 QObject::connect(ui
->actionNew_Project
, SIGNAL(triggered()),
244 this, SLOT(newProject()));
246 QObject::connect(ui
->actionClose_Document
, SIGNAL(triggered()),
247 this, SLOT(closeCurrent()));
248 QObject::connect(ui
->actionClose_Project
, SIGNAL(triggered()),
249 this, SLOT(closeProject()));
251 QObject::connect(ui
->actionSave_Document
, SIGNAL(triggered()),
252 this, SLOT(saveCurrent()));
253 QObject::connect(ui
->actionSave_Document_As
, SIGNAL(triggered()),
254 this, SLOT(saveCurrentAs()));
255 QObject::connect(ui
->actionExport_Project
, SIGNAL(triggered()),
256 this, SLOT(exportProject()));
258 QObject::connect(ui
->actionOpen_Document
, SIGNAL(triggered()),
259 this, SLOT(openFile()));
261 QObject::connect(ui
->actionOpen_Project
, SIGNAL(triggered()),
262 this, SLOT(openProject()));
264 /* Connecting the edit menu */
265 QObject::connect(ui
->actionUndo
, SIGNAL(triggered()),
267 QObject::connect(ui
->actionRedo
, SIGNAL(triggered()),
269 QObject::connect(ui
->actionCut
, SIGNAL(triggered()),
271 QObject::connect(ui
->actionCopy
, SIGNAL(triggered()),
273 QObject::connect(ui
->actionPaste
, SIGNAL(triggered()),
274 this, SLOT(paste()));
275 QObject::connect(ui
->actionFind_Replace
, SIGNAL(triggered()),
276 this, SLOT(findReplace()));
278 /* Adding the recent docs/projects menus */
279 for(int i
= 0; i
< numRecent
; i
++)
281 recentDocsMenu
.append(new QAction(tr("Recent Doc"),
282 ui
->menuRecent_Files
));
283 recentDocsMenu
.last()
284 ->setShortcut(QKeySequence(tr("CTRL+")
285 + QString::number(i
+ 1)));
286 QObject::connect(recentDocsMenu
.last(), SIGNAL(triggered()),
287 this, SLOT(openRecentFile()));
288 ui
->menuRecent_Files
->addAction(recentDocsMenu
.last());
291 recentProjectsMenu
.append(new QAction(tr("Recent Project"),
292 ui
->menuRecent_Projects
));
293 recentProjectsMenu
.last()
294 ->setShortcut(QKeySequence(tr("CTRL+SHIFT+") +
295 QString::number(i
+ 1)));
296 QObject::connect(recentProjectsMenu
.last(), SIGNAL(triggered()),
297 this, SLOT(openRecentProject()));
298 ui
->menuRecent_Projects
->addAction(recentProjectsMenu
.last());
300 refreshRecentMenus();
303 void EditorWindow::addTab(TabContent
*doc
)
305 ui
->editorTabs
->addTab(doc
, doc
->title());
307 /* Connecting to title change events */
308 QObject::connect(doc
, SIGNAL(titleChanged(QString
)),
309 this, SLOT(tabTitleChanged(QString
)));
310 QObject::connect(doc
, SIGNAL(lineChanged(int)),
311 this, SLOT(lineChanged(int)));
313 /* Connecting to settings change events */
314 doc
->connectPrefs(prefs
);
318 void EditorWindow::newTab()
320 SkinDocument
* doc
= new SkinDocument(parseStatus
, project
, deviceConfig
);
322 ui
->editorTabs
->setCurrentWidget(doc
);
325 void EditorWindow::newProject()
327 NewProjectDialog
dialog(this);
328 if(dialog
.exec() == QDialog::Rejected
)
331 /* Assembling the new project if the dialog was accepted */
332 NewProjectDialog::NewProjectInfo info
= dialog
.results();
334 QDir
path(info
.path
);
337 QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
338 " Project directory does not exist"));
342 if(path
.exists(info
.name
))
344 QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
345 " Project directory already exists"));
349 if(!path
.mkdir(info
.name
))
351 QMessageBox::warning(this, tr("Error Creating Project"), tr("Error:"
352 " Project directory not writeable"));
358 /* Making standard directories */
361 path
.mkdir("backdrops");
363 /* Adding the desired wps documents */
368 createFile(path
.filePath(info
.name
+ ".sbs"), tr("# SBS Document\n"));
370 createFile(path
.filePath(info
.name
+ ".wps"), tr("# WPS Document\n"));
372 createFile(path
.filePath(info
.name
+ ".fms"), tr("# FMS Document\n"));
374 createFile(path
.filePath(info
.name
+ ".rsbs"), tr("# RSBS Document\n"));
376 createFile(path
.filePath(info
.name
+ ".rwps"), tr("# RWPS Document\n"));
378 createFile(path
.filePath(info
.name
+ ".rfms"), tr("# RFMS Document\n"));
380 path
.mkdir(info
.name
);
384 /* Adding the config file */
385 path
.mkdir("themes");
388 /* Generating the config file */
389 QString config
= tr("# Config file for ") + info
.name
+ "\n";
390 config
.append("#target: " + info
.target
+ "\n\n");
391 QString wpsBase
= "/.rockbox/wps/";
393 config
.append("sbs: " + wpsBase
+ info
.name
+ ".sbs\n");
395 config
.append("wps: " + wpsBase
+ info
.name
+ ".wps\n");
397 config
.append("fms: " + wpsBase
+ info
.name
+ ".fms\n");
399 config
.append("rsbs: " + wpsBase
+ info
.name
+ ".rsbs\n");
401 config
.append("rwps: " + wpsBase
+ info
.name
+ ".rwps\n");
403 config
.append("rfms: " + wpsBase
+ info
.name
+ ".rfms\n");
406 createFile(path
.filePath(info
.name
+ ".cfg"),
409 /* Opening the new project */
410 loadProjectFile(path
.filePath(info
.name
+ ".cfg"));
413 void EditorWindow::shiftTab(int index
)
415 TabContent
* widget
= dynamic_cast<TabContent
*>
416 (ui
->editorTabs
->currentWidget());
419 ui
->parseTree
->setModel(0);
420 ui
->actionSave_Document
->setEnabled(false);
421 ui
->actionSave_Document_As
->setEnabled(false);
422 ui
->actionClose_Document
->setEnabled(false);
423 ui
->fromTree
->setEnabled(false);
424 ui
->actionUndo
->setEnabled(false);
425 ui
->actionRedo
->setEnabled(false);
426 ui
->actionCut
->setEnabled(false);
427 ui
->actionCopy
->setEnabled(false);
428 ui
->actionPaste
->setEnabled(false);
429 ui
->actionFind_Replace
->setEnabled(false);
430 viewer
->connectSkin(0);
432 else if(widget
->type() == TabContent::Config
)
434 ui
->actionSave_Document
->setEnabled(true);
435 ui
->actionSave_Document_As
->setEnabled(true);
436 ui
->actionClose_Document
->setEnabled(true);
437 ui
->actionUndo
->setEnabled(false);
438 ui
->actionRedo
->setEnabled(false);
439 ui
->actionCut
->setEnabled(false);
440 ui
->actionCopy
->setEnabled(false);
441 ui
->actionPaste
->setEnabled(false);
442 ui
->actionFind_Replace
->setEnabled(false);
443 viewer
->connectSkin(0);
445 else if(widget
->type() == TabContent::Skin
)
447 /* Syncing the tree view and the status bar */
448 SkinDocument
* doc
= dynamic_cast<SkinDocument
*>(widget
);
449 ui
->parseTree
->setModel(doc
->getModel());
450 parseStatus
->setText(doc
->getStatus());
452 ui
->actionSave_Document
->setEnabled(true);
453 ui
->actionSave_Document_As
->setEnabled(true);
454 ui
->actionClose_Document
->setEnabled(true);
455 ui
->fromTree
->setEnabled(true);
457 ui
->actionUndo
->setEnabled(true);
458 ui
->actionRedo
->setEnabled(true);
459 ui
->actionCut
->setEnabled(true);
460 ui
->actionCopy
->setEnabled(true);
461 ui
->actionPaste
->setEnabled(true);
462 ui
->actionFind_Replace
->setEnabled(true);
466 /* Syncing the preview */
467 viewer
->connectSkin(doc
);
472 /* Hiding all the find/replace dialogs */
473 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
474 if(dynamic_cast<TabContent
*>(ui
->editorTabs
->widget(i
))->type() ==
476 dynamic_cast<SkinDocument
*>(ui
->editorTabs
->widget(i
))->hideFind();
480 bool EditorWindow::closeTab(int index
)
482 TabContent
* widget
= dynamic_cast<TabContent
*>
483 (ui
->editorTabs
->widget(index
));
484 if(widget
->requestClose())
486 ui
->editorTabs
->removeTab(index
);
487 widget
->deleteLater();
494 void EditorWindow::closeCurrent()
496 closeTab(ui
->editorTabs
->currentIndex());
499 void EditorWindow::closeProject()
503 project
->deleteLater();
507 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
509 TabContent
* doc
= dynamic_cast<TabContent
*>
510 (ui
->editorTabs
->widget(i
));
511 if(doc
->type() == TabContent::Skin
)
513 dynamic_cast<SkinDocument
*>(doc
)->setProject(project
);
514 if(i
== ui
->editorTabs
->currentIndex())
516 viewer
->connectSkin(dynamic_cast<SkinDocument
*>(doc
));
521 ui
->actionClose_Project
->setEnabled(false);
522 ui
->actionExport_Project
->setEnabled(false);
525 void EditorWindow::saveCurrent()
527 if(ui
->editorTabs
->currentIndex() >= 0)
528 dynamic_cast<TabContent
*>(ui
->editorTabs
->currentWidget())->save();
531 void EditorWindow::saveCurrentAs()
533 if(ui
->editorTabs
->currentIndex() >= 0)
534 dynamic_cast<TabContent
*>(ui
->editorTabs
->currentWidget())->saveAs();
537 void EditorWindow::exportProject()
539 QDir dir
= project
->getSetting("themebase", "");
541 QString file
= project
->getSetting("configfile", "").split("/").
542 last().split(".").first() + ".zip";
543 file
= dir
.filePath(file
);
545 file
= QFileDialog::getSaveFileName(this, tr("Export Project"),
546 file
, "Zip Files (*.zip *.ZIP);;"
551 ProjectExporter
* exporter
= new ProjectExporter(file
, project
, this);
556 void EditorWindow::openFile()
558 QStringList fileNames
;
561 settings
.beginGroup("SkinDocument");
562 QString directory
= settings
.value("defaultDirectory", "").toString();
563 fileNames
= QFileDialog::getOpenFileNames(this, tr("Open Files"), directory
,
564 SkinDocument::fileFilter());
566 for(int i
= 0; i
< fileNames
.count(); i
++)
568 if(!QFile::exists(fileNames
[i
]))
571 QString current
= fileNames
[i
];
573 loadTabFromSkinFile(current
);
575 /* And setting the new default directory */
576 current
.chop(current
.length() - current
.lastIndexOf('/') - 1);
577 settings
.setValue("defaultDirectory", current
);
584 void EditorWindow::openProject()
589 settings
.beginGroup("ProjectModel");
590 QString directory
= settings
.value("defaultDirectory", "").toString();
591 fileName
= QFileDialog::getOpenFileName(this, tr("Open Project"), directory
,
592 ProjectModel::fileFilter());
595 loadProjectFile(fileName
);
599 void EditorWindow::openRecentFile()
601 loadTabFromSkinFile(dynamic_cast<QAction
*>(QObject::sender())->text());
604 void EditorWindow::openRecentProject()
606 loadProjectFile(dynamic_cast<QAction
*>(QObject::sender())->text());
609 void EditorWindow::configFileChanged(QString configFile
)
612 if(QFile::exists(configFile
))
618 project
= new ProjectModel(configFile
, this);
619 ui
->projectTree
->setModel(project
);
621 QObject::connect(ui
->projectTree
, SIGNAL(activated(QModelIndex
)),
622 project
, SLOT(activated(QModelIndex
)));
624 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
626 TabContent
* doc
= dynamic_cast<TabContent
*>
627 (ui
->editorTabs
->widget(i
));
628 if(doc
->type() == TabContent::Skin
)
630 dynamic_cast<SkinDocument
*>(doc
)->setProject(project
);
631 if(i
== ui
->editorTabs
->currentIndex())
633 viewer
->connectSkin(dynamic_cast<SkinDocument
*>(doc
));
643 void EditorWindow::tabTitleChanged(QString title
)
645 TabContent
* sender
= dynamic_cast<TabContent
*>(QObject::sender());
646 ui
->editorTabs
->setTabText(ui
->editorTabs
->indexOf(sender
), title
);
649 void EditorWindow::showPanel()
651 if(sender() == ui
->actionFile_Panel
)
652 ui
->projectDock
->setVisible(true);
653 if(sender() == ui
->actionPreview_Panel
)
654 ui
->skinPreviewDock
->setVisible(true);
655 if(sender() == ui
->actionDisplay_Panel
)
656 ui
->parseTreeDock
->setVisible(true);
659 void EditorWindow::closeEvent(QCloseEvent
* event
)
664 /* Closing all the tabs */
665 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
667 if(!dynamic_cast<TabContent
*>
668 (ui
->editorTabs
->widget(i
))->requestClose())
678 void EditorWindow::updateCurrent()
680 if(ui
->editorTabs
->currentIndex() < 0)
683 dynamic_cast<SkinDocument
*>
684 (ui
->editorTabs
->currentWidget())->genCode();
687 void EditorWindow::lineChanged(int line
)
690 settings
.beginGroup("EditorWindow");
692 if(settings
.value("autoExpandTree", false).toBool())
694 ui
->parseTree
->collapseAll();
695 ParseTreeModel
* model
= dynamic_cast<ParseTreeModel
*>
696 (ui
->parseTree
->model());
697 parseTreeSelection
= new QItemSelectionModel(model
);
698 expandLine(model
, QModelIndex(), line
,
699 settings
.value("autoHighlightTree", false).toBool());
701 ui
->parseTree
->setSelectionModel(parseTreeSelection
);
707 void EditorWindow::undo()
709 TabContent
* doc
= dynamic_cast<TabContent
*>
710 (ui
->editorTabs
->currentWidget());
711 if(doc
->type() == TabContent::Skin
)
712 dynamic_cast<SkinDocument
*>(doc
)->getEditor()->undo();
715 void EditorWindow::redo()
717 TabContent
* doc
= dynamic_cast<TabContent
*>
718 (ui
->editorTabs
->currentWidget());
719 if(doc
->type() == TabContent::Skin
)
720 dynamic_cast<SkinDocument
*>(doc
)->getEditor()->redo();
724 void EditorWindow::cut()
726 TabContent
* doc
= dynamic_cast<TabContent
*>
727 (ui
->editorTabs
->currentWidget());
728 if(doc
->type() == TabContent::Skin
)
729 dynamic_cast<SkinDocument
*>(doc
)->getEditor()->cut();
732 void EditorWindow::copy()
734 TabContent
* doc
= dynamic_cast<TabContent
*>
735 (ui
->editorTabs
->currentWidget());
736 if(doc
->type() == TabContent::Skin
)
737 dynamic_cast<SkinDocument
*>(doc
)->getEditor()->copy();
740 void EditorWindow::paste()
742 TabContent
* doc
= dynamic_cast<TabContent
*>
743 (ui
->editorTabs
->currentWidget());
744 if(doc
->type() == TabContent::Skin
)
745 dynamic_cast<SkinDocument
*>(doc
)->getEditor()->paste();
748 void EditorWindow::findReplace()
750 TabContent
* doc
= dynamic_cast<TabContent
*>
751 (ui
->editorTabs
->currentWidget());
752 if(doc
->type() == TabContent::Skin
)
753 dynamic_cast<SkinDocument
*>(doc
)->showFind();
757 void EditorWindow::expandLine(ParseTreeModel
* model
, QModelIndex parent
,
758 int line
, bool highlight
)
760 for(int i
= 0; i
< model
->rowCount(parent
); i
++)
762 QModelIndex dataType
= model
->index(i
, ParseTreeModel::typeColumn
,
764 QModelIndex dataVal
= model
->index(i
, ParseTreeModel::valueColumn
,
766 QModelIndex data
= model
->index(i
, ParseTreeModel::lineColumn
, parent
);
767 QModelIndex recurse
= model
->index(i
, 0, parent
);
769 expandLine(model
, recurse
, line
, highlight
);
771 if(model
->data(data
, Qt::DisplayRole
) == line
)
773 ui
->parseTree
->expand(parent
);
774 ui
->parseTree
->expand(data
);
775 ui
->parseTree
->scrollTo(parent
, QAbstractItemView::PositionAtTop
);
779 parseTreeSelection
->select(data
,
780 QItemSelectionModel::Select
);
781 parseTreeSelection
->select(dataType
,
782 QItemSelectionModel::Select
);
783 parseTreeSelection
->select(dataVal
,
784 QItemSelectionModel::Select
);
791 void EditorWindow::sizeColumns()
793 /* Setting the column widths */
794 ui
->parseTree
->resizeColumnToContents(ParseTreeModel::lineColumn
);
795 ui
->parseTree
->resizeColumnToContents(ParseTreeModel::typeColumn
);
796 ui
->parseTree
->resizeColumnToContents(ParseTreeModel::valueColumn
);
799 void EditorWindow::loadProjectFile(QString fileName
)
802 settings
.beginGroup("ProjectModel");
804 if(QFile::exists(fileName
))
806 projectToTop(fileName
);
809 project
->deleteLater();
811 ui
->actionClose_Project
->setEnabled(true);
812 ui
->actionExport_Project
->setEnabled(true);
814 project
= new ProjectModel(fileName
, this);
815 ui
->projectTree
->setModel(project
);
817 /* Setting target info if necessary */
819 QString target
= project
->getSetting("#target", "");
820 if(target
!= "" && targets
.index(target
) >= 0)
822 int index
= targets
.index(target
);
824 QRect screen
= targets
.screenSize(index
);
825 deviceConfig
->setData("screenwidth", screen
.width());
826 deviceConfig
->setData("screenheight", screen
.height());
828 if(targets
.remoteDepth(index
) != TargetData::None
)
830 QRect remote
= targets
.remoteSize(index
);
831 deviceConfig
->setData("remotewidth", remote
.width());
832 deviceConfig
->setData("remoteheight", remote
.height());
835 deviceConfig
->setData("tp", targets
.fm(index
));
836 deviceConfig
->setData("Rp", targets
.canRecord(index
));
839 if(project
->getSetting("#screenwidth") != "")
840 deviceConfig
->setData("screenwidth",
841 project
->getSetting("#screenwidth"));
842 if(project
->getSetting("#screenheight") != "")
843 deviceConfig
->setData("screenheight",
844 project
->getSetting("#screenheight"));
846 QObject::connect(ui
->projectTree
, SIGNAL(activated(QModelIndex
)),
847 project
, SLOT(activated(QModelIndex
)));
849 fileName
.chop(fileName
.length() - fileName
.lastIndexOf('/') - 1);
850 settings
.setValue("defaultDirectory", fileName
);
852 for(int i
= 0; i
< ui
->editorTabs
->count(); i
++)
854 TabContent
* doc
= dynamic_cast<TabContent
*>
855 (ui
->editorTabs
->widget(i
));
856 if(doc
->type() == TabContent::Skin
)
858 dynamic_cast<SkinDocument
*>(doc
)->setProject(project
);
859 if(i
== ui
->editorTabs
->currentIndex())
861 viewer
->connectSkin(dynamic_cast<SkinDocument
*>(doc
));
872 void EditorWindow::createFile(QString filename
, QString contents
)
874 QFile
fout(filename
);
875 fout
.open(QFile::WriteOnly
);
877 fout
.write(contents
.toAscii());
882 void EditorWindow::docToTop(QString file
)
884 if(!QFile::exists(file
))
887 int index
= recentDocs
.indexOf(file
);
890 /* Bumping off the last file */
891 if(recentDocs
.count() >= numRecent
)
892 recentDocs
.removeLast();
893 recentDocs
.prepend(file
);
897 /* Shuffling file to the top of the list */
898 recentDocs
.removeAt(index
);
899 recentDocs
.prepend(file
);
902 refreshRecentMenus();
905 void EditorWindow::projectToTop(QString file
)
907 if(!QFile::exists(file
))
910 int index
= recentProjects
.indexOf(file
);
913 /* Bumping off the last project */
914 if(recentProjects
.count() >= numRecent
)
915 recentProjects
.removeLast();
916 recentProjects
.prepend(file
);
920 /* Shuffling file to the top of the list */
921 recentProjects
.removeAt(index
);
922 recentProjects
.prepend(file
);
925 refreshRecentMenus();
928 void EditorWindow::refreshRecentMenus()
930 /* Clearing any deleted documents */
931 for(int i
= 0; i
< recentDocs
.count(); i
++)
932 if(!QFile::exists(recentDocs
[i
]))
933 recentDocs
.removeAt(i
--);
935 /* Clearing any deleted projects */
936 for(int i
= 0; i
< recentProjects
.count(); i
++)
937 if(!QFile::exists(recentProjects
[i
]))
938 recentProjects
.removeAt(i
--);
940 /* First hiding all the menu items */
941 for(int i
= 0; i
< recentDocsMenu
.count(); i
++)
942 recentDocsMenu
[i
]->setVisible(false);
943 for(int i
= 0; i
< recentProjectsMenu
.count(); i
++)
944 recentProjectsMenu
[i
]->setVisible(false);
946 /* Then setting the text of and showing any available */
947 for(int i
= 0; i
< recentDocs
.count(); i
++)
949 recentDocsMenu
[i
]->setText(recentDocs
[i
]);
950 recentDocsMenu
[i
]->setVisible(true);
953 for(int i
= 0; i
< recentProjects
.count(); i
++)
955 recentProjectsMenu
[i
]->setText(recentProjects
[i
]);
956 recentProjectsMenu
[i
]->setVisible(true);