2007-11-17 02:25:45 +08:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2011-01-19 07:49:53 +08:00
|
|
|
* Copyright (C) 2001-2011 David Capello
|
2007-09-19 07:57:02 +08:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <allegro/gfx.h>
|
|
|
|
|
#include <allegro/unicode.h>
|
|
|
|
|
|
2010-09-26 04:20:59 +08:00
|
|
|
#include "base/bind.h"
|
2011-01-31 06:12:10 +08:00
|
|
|
#include "gui/gui.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
#include "dialogs/repo.h"
|
2011-06-30 09:51:46 +08:00
|
|
|
#include "ini_file.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "modules/gui.h"
|
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void fill_listbox(RepoDlg *repo_dlg);
|
|
|
|
|
static void kill_listbox(RepoDlg *repo_dlg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static int repo_listbox_type();
|
2011-04-03 00:14:07 +08:00
|
|
|
static bool repo_listbox_msg_proc(JWidget widget, Message* msg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
static void use_command(Button* widget, RepoDlg* repo_dlg);
|
|
|
|
|
static void add_command(Button* widget, RepoDlg* repo_dlg);
|
|
|
|
|
static void delete_command(Button* widget, RepoDlg* repo_dlg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
void ji_show_repo_dlg(RepoDlg *repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2010-01-26 08:38:05 +08:00
|
|
|
Frame* window = new Frame(false, repo_dlg->title);
|
2011-01-25 06:48:09 +08:00
|
|
|
Box* box1 = new Box(JI_HORIZONTAL);
|
|
|
|
|
Box* box2 = new Box(JI_VERTICAL);
|
2011-02-21 05:35:21 +08:00
|
|
|
View* view = new View();
|
2008-01-07 23:10:17 +08:00
|
|
|
repo_dlg->listbox = jlistbox_new();
|
2010-08-24 04:41:19 +08:00
|
|
|
repo_dlg->button_use = new Button(repo_dlg->use_text);
|
2010-09-19 10:54:56 +08:00
|
|
|
repo_dlg->button_add = new Button("&Add");
|
|
|
|
|
repo_dlg->button_delete = new Button("&Delete");
|
|
|
|
|
Button* button_close = new Button("&Close");
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_add_hook(repo_dlg->listbox, repo_listbox_type(),
|
|
|
|
|
repo_listbox_msg_proc, repo_dlg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-09-26 04:20:59 +08:00
|
|
|
repo_dlg->button_use->Click.connect(Bind<void>(&use_command, repo_dlg->button_use, repo_dlg));
|
|
|
|
|
repo_dlg->button_add->Click.connect(Bind<void>(&add_command, repo_dlg->button_add, repo_dlg));
|
|
|
|
|
repo_dlg->button_delete->Click.connect(Bind<void>(&delete_command, repo_dlg->button_delete, repo_dlg));
|
|
|
|
|
button_close->Click.connect(Bind<void>(&Frame::closeWindow, window, button_close));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-01-31 00:43:13 +08:00
|
|
|
jwidget_magnetic(repo_dlg->button_use, true);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-01-31 00:43:13 +08:00
|
|
|
jwidget_expansive(view, true);
|
2011-02-21 05:35:21 +08:00
|
|
|
view->attachToView(repo_dlg->listbox);
|
2007-12-07 04:05:32 +08:00
|
|
|
jwidget_set_min_size(view, JI_SCREEN_W*25/100, JI_SCREEN_H*25/100);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* fill the list */
|
2008-01-07 23:10:17 +08:00
|
|
|
fill_listbox(repo_dlg);
|
|
|
|
|
jlistbox_select_index(repo_dlg->listbox, 0);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* no items? */
|
2008-01-07 23:10:17 +08:00
|
|
|
if (jlistbox_get_selected_index(repo_dlg->listbox) != 0) {
|
2010-07-04 02:26:27 +08:00
|
|
|
repo_dlg->button_use->setEnabled(false);
|
|
|
|
|
repo_dlg->button_delete->setEnabled(false);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* hierarchy */
|
2011-03-30 08:35:17 +08:00
|
|
|
box2->addChild(repo_dlg->button_use);
|
|
|
|
|
box2->addChild(repo_dlg->button_add);
|
|
|
|
|
box2->addChild(repo_dlg->button_delete);
|
|
|
|
|
box2->addChild(button_close);
|
|
|
|
|
box1->addChild(box2);
|
|
|
|
|
box1->addChild(view);
|
|
|
|
|
window->addChild(box1);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* default position */
|
2010-01-26 08:38:05 +08:00
|
|
|
window->remap_window();
|
|
|
|
|
window->center_window();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* load window configuration */
|
2008-01-07 23:10:17 +08:00
|
|
|
load_window_pos(window, repo_dlg->config_section);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* open window */
|
2010-01-26 08:38:05 +08:00
|
|
|
window->open_window_fg();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* kill the list */
|
2008-01-07 23:10:17 +08:00
|
|
|
kill_listbox(repo_dlg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* save window configuration */
|
2008-01-07 23:10:17 +08:00
|
|
|
save_window_pos(window, repo_dlg->config_section);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_free(window);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void fill_listbox(RepoDlg *repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
/* no item selected (ID=0) */
|
|
|
|
|
repo_dlg->listitem = 0;
|
|
|
|
|
|
|
|
|
|
/* load the entries */
|
|
|
|
|
if (repo_dlg->load_listbox)
|
2008-01-07 23:10:17 +08:00
|
|
|
(*repo_dlg->load_listbox)(repo_dlg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-02-21 05:35:21 +08:00
|
|
|
View::getView(repo_dlg->listbox)->updateView();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void kill_listbox(RepoDlg *repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
JWidget listbox = repo_dlg->listbox;
|
|
|
|
|
JWidget listitem;
|
|
|
|
|
JLink link, next;
|
|
|
|
|
|
|
|
|
|
/* save the entries */
|
|
|
|
|
if (repo_dlg->save_listbox)
|
|
|
|
|
(*repo_dlg->save_listbox) (repo_dlg);
|
|
|
|
|
|
|
|
|
|
/* remove all items */
|
|
|
|
|
JI_LIST_FOR_EACH_SAFE(listbox->children, link, next) {
|
2008-10-01 05:01:54 +08:00
|
|
|
listitem = reinterpret_cast<JWidget>(link->data);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-03-30 08:35:17 +08:00
|
|
|
repo_dlg->listbox->removeChild(listitem);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
if (repo_dlg->free_listitem) {
|
|
|
|
|
repo_dlg->listitem = listitem;
|
|
|
|
|
(*repo_dlg->free_listitem) (repo_dlg);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_free(listitem);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static int repo_listbox_type()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
static int type = 0;
|
|
|
|
|
if (!type)
|
|
|
|
|
type = ji_register_widget_type();
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-03 00:14:07 +08:00
|
|
|
static bool repo_listbox_msg_proc(JWidget widget, Message* msg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-10-01 05:01:54 +08:00
|
|
|
RepoDlg* repo_dlg = reinterpret_cast<RepoDlg*>(jwidget_get_data(widget, repo_listbox_type()));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
switch (msg->type) {
|
|
|
|
|
|
|
|
|
|
case JM_DESTROY:
|
|
|
|
|
/* do nothing (don't free repo_dlg) */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case JM_SIGNAL:
|
|
|
|
|
switch (msg->signal.num) {
|
|
|
|
|
|
|
|
|
|
case JI_SIGNAL_LISTBOX_CHANGE:
|
|
|
|
|
repo_dlg->listitem = jlistbox_get_selected_child(widget);
|
|
|
|
|
|
2010-07-04 02:26:27 +08:00
|
|
|
repo_dlg->button_use->setEnabled(true);
|
|
|
|
|
repo_dlg->button_delete->setEnabled(true);
|
2007-09-19 07:57:02 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case JI_SIGNAL_LISTBOX_SELECT:
|
|
|
|
|
if (repo_dlg->use_listitem)
|
|
|
|
|
if (!(*repo_dlg->use_listitem)(repo_dlg))
|
2011-01-22 10:49:07 +08:00
|
|
|
widget->closeWindow();
|
2007-09-19 07:57:02 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-31 00:43:13 +08:00
|
|
|
return false;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
static void use_command(Button* widget, RepoDlg* repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
if (repo_dlg->use_listitem) {
|
|
|
|
|
if (!(*repo_dlg->use_listitem)(repo_dlg))
|
2011-01-22 10:49:07 +08:00
|
|
|
widget->closeWindow();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
static void add_command(Button* widget, RepoDlg* repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
int ret, added;
|
|
|
|
|
|
|
|
|
|
if (repo_dlg->add_listitem) {
|
2010-01-31 00:43:13 +08:00
|
|
|
added = false;
|
2007-09-19 07:57:02 +08:00
|
|
|
ret = (*repo_dlg->add_listitem)(repo_dlg, &added);
|
|
|
|
|
|
|
|
|
|
if (added) {
|
|
|
|
|
/* update the list-box */
|
2011-02-21 05:35:21 +08:00
|
|
|
View::getView(repo_dlg->listbox)->updateView();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* select the last item */
|
2008-01-07 23:10:17 +08:00
|
|
|
jlistbox_select_index(repo_dlg->listbox,
|
|
|
|
|
jlist_length(repo_dlg->listbox->children)-1);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ret)
|
2011-01-22 10:49:07 +08:00
|
|
|
widget->closeWindow();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
static void delete_command(Button* widget, RepoDlg* repo_dlg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
|
int ret, kill, index, last;
|
|
|
|
|
|
|
|
|
|
if (repo_dlg->delete_listitem) {
|
2010-01-31 00:43:13 +08:00
|
|
|
kill = false;
|
2007-09-19 07:57:02 +08:00
|
|
|
ret = (*repo_dlg->delete_listitem) (repo_dlg, &kill);
|
|
|
|
|
|
|
|
|
|
if (kill) {
|
2008-01-07 23:10:17 +08:00
|
|
|
index = jlistbox_get_selected_index(repo_dlg->listbox);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* delete "repo_dlg->listitem" */
|
2011-03-30 08:35:17 +08:00
|
|
|
repo_dlg->listbox->removeChild(repo_dlg->listitem);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
if (repo_dlg->free_listitem)
|
|
|
|
|
(*repo_dlg->free_listitem) (repo_dlg);
|
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_free(repo_dlg->listitem);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
|
/* disable buttons */
|
|
|
|
|
if (!repo_dlg->listbox->children) {
|
2010-07-04 02:26:27 +08:00
|
|
|
repo_dlg->button_use->setEnabled(false);
|
|
|
|
|
repo_dlg->button_delete->setEnabled(false);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
/* select other item */
|
|
|
|
|
else {
|
2008-01-07 23:10:17 +08:00
|
|
|
last = jlist_length(repo_dlg->listbox->children)-1;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jlistbox_select_index(repo_dlg->listbox,
|
|
|
|
|
index > last ? last: index);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update the list-box */
|
2011-02-21 05:35:21 +08:00
|
|
|
View::getView(repo_dlg->listbox)->updateView();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ret)
|
2011-01-22 10:49:07 +08:00
|
|
|
widget->closeWindow();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
}
|