New lua versions
[ryzomcore.git] / studio / src / plugins / gui_editor / project_window.cpp
blobd9d50fba39a20b2f713cfeac12fceab73e84e63f
1 // Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "project_window.h"
22 #include <QInputDialog>
23 #include <QMessageBox>
25 namespace GUIEditor
27 ProjectWindow::ProjectWindow( QWidget *parent ) :
28 QWidget( parent )
30 setupUi( this );
31 filesChanged = false;
33 connect( okButton, SIGNAL( clicked(bool) ), this, SLOT( onOKButtonClicked() ) );
34 connect( cancelButton, SIGNAL( clicked(bool) ), this, SLOT( hide() ) );
36 connect( addButton, SIGNAL( clicked(bool) ), this, SLOT( onAddButtonClicked() ) );
37 connect( removeButton, SIGNAL( clicked(bool) ), this, SLOT( onRemoveButtonClicked() ) );
40 ProjectWindow::~ProjectWindow()
44 void ProjectWindow::setupFiles( SProjectFiles &projectFiles )
46 QTreeWidgetItem *topItem = fileTree->topLevelItem( 0 );
47 if( topItem != NULL )
49 QList< QTreeWidgetItem* > childList = topItem->takeChildren();
50 QListIterator< QTreeWidgetItem* > it( childList );
51 while( it.hasNext() )
52 delete it.next();
53 childList.clear();
55 std::vector< std::string >::iterator itr;
56 for( itr = projectFiles.guiFiles.begin(); itr != projectFiles.guiFiles.end(); ++itr )
58 QTreeWidgetItem *item = new QTreeWidgetItem( topItem );
59 item->setText( 0, itr->c_str() );
63 topItem = fileTree->topLevelItem( 1 );
64 if( topItem != NULL )
66 QList< QTreeWidgetItem* > childList = topItem->takeChildren();
67 QListIterator< QTreeWidgetItem* > it( childList );
68 while( it.hasNext() )
69 delete it.next();
70 childList.clear();
72 std::vector< std::string >::iterator itr;
73 for( itr = projectFiles.mapFiles.begin(); itr != projectFiles.mapFiles.end(); ++itr )
75 QTreeWidgetItem *item = new QTreeWidgetItem( topItem );
76 item->setText( 0, itr->c_str() );
81 void ProjectWindow::updateFiles( SProjectFiles &projectFiles )
83 projectFiles.clearFiles();
85 QTreeWidgetItem *topItem;
87 topItem = fileTree->topLevelItem( 0 );
88 if( topItem != NULL )
90 int c = topItem->childCount();
91 for( int i = 0; i < c; i++ )
93 QTreeWidgetItem *item = topItem->child( i );
94 projectFiles.guiFiles.push_back( item->text( 0 ).toUtf8().constData() );
98 topItem = fileTree->topLevelItem( 1 );
99 if( topItem != NULL )
101 int c = topItem->childCount();
102 for( int i = 0; i < c; i++ )
104 QTreeWidgetItem *item = topItem->child( i );
105 projectFiles.mapFiles.push_back( item->text( 0 ).toUtf8().constData() );
110 void ProjectWindow::clear()
112 fileTree->clear();
115 void ProjectWindow::onAddButtonClicked()
117 if( fileTree->currentItem() == NULL )
118 return;
120 QTreeWidgetItem *item = fileTree->currentItem();
121 QTreeWidgetItem *parent = item->parent();
123 while( parent != NULL )
125 item = parent;
126 parent = parent->parent();
129 bool ok;
130 QString newFile = QInputDialog::getText( this,
131 tr( "Adding file to project" ),
132 tr( "Which file do you want to add?" ),
133 QLineEdit::Normal,
134 QString(),
135 &ok );
137 if( ok )
139 QTreeWidgetItem *newItem = new QTreeWidgetItem( item );
140 newItem->setText( 0, newFile );
141 filesChanged = true;
145 void ProjectWindow::onRemoveButtonClicked()
147 if( fileTree->currentItem() == NULL )
148 return;
150 // Can't delete top-level item
151 if( fileTree->currentItem()->parent() == NULL )
152 return;
154 QMessageBox::StandardButton reply;
155 QString text = fileTree->currentItem()->text( 0 );
157 reply = QMessageBox::question( this,
158 tr( "Removing file from project" ),
159 tr( "Are you sure you want to remove '%1' from the project?" ).arg( text ),
160 QMessageBox::Yes | QMessageBox::Cancel );
162 if( reply == QMessageBox::Yes )
164 fileTree->currentItem()->parent()->removeChild( fileTree->currentItem() );
165 filesChanged = true;
170 void ProjectWindow::onOKButtonClicked()
172 hide();
174 if( filesChanged )
176 filesChanged = false;
177 Q_EMIT projectFilesChanged();