1 // Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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>
27 ProjectWindow::ProjectWindow( QWidget
*parent
) :
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 );
49 QList
< QTreeWidgetItem
* > childList
= topItem
->takeChildren();
50 QListIterator
< QTreeWidgetItem
* > it( childList
);
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 );
66 QList
< QTreeWidgetItem
* > childList
= topItem
->takeChildren();
67 QListIterator
< QTreeWidgetItem
* > it( childList
);
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 );
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 );
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()
115 void ProjectWindow::onAddButtonClicked()
117 if( fileTree
->currentItem() == NULL
)
120 QTreeWidgetItem
*item
= fileTree
->currentItem();
121 QTreeWidgetItem
*parent
= item
->parent();
123 while( parent
!= NULL
)
126 parent
= parent
->parent();
130 QString newFile
= QInputDialog::getText( this,
131 tr( "Adding file to project" ),
132 tr( "Which file do you want to add?" ),
139 QTreeWidgetItem
*newItem
= new QTreeWidgetItem( item
);
140 newItem
->setText( 0, newFile
);
145 void ProjectWindow::onRemoveButtonClicked()
147 if( fileTree
->currentItem() == NULL
)
150 // Can't delete top-level item
151 if( fileTree
->currentItem()->parent() == NULL
)
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() );
170 void ProjectWindow::onOKButtonClicked()
176 filesChanged
= false;
177 Q_EMIT
projectFilesChanged();