mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Added a basic Pieces Library dialog for Linux.
This commit is contained in:
parent
7930ff85ac
commit
57eb62bb71
4 changed files with 629 additions and 87 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "config.h"
|
||||
#include "message.h"
|
||||
#include "project.h"
|
||||
#include "libdlg.h"
|
||||
|
||||
// =============================================================================
|
||||
// Modal dialog helper functions
|
||||
|
@ -1128,6 +1129,7 @@ static void imageoptsdlg_ok(GtkWidget *widget, gpointer data)
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
Sys_ProfileSaveInt ("Default", "Image Options", image);
|
||||
Sys_ProfileSaveInt ("Default", "Image Width", opts->width);
|
||||
Sys_ProfileSaveInt ("Default", "Image Height", opts->height);
|
||||
|
@ -2788,55 +2790,101 @@ int groupdlg_execute(void* param)
|
|||
// =============================================================================
|
||||
// Piece Library Dialog
|
||||
|
||||
#if 0
|
||||
#include "library.h"
|
||||
#include "pieceinf.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
static void librarydlg_update_list (GtkWidget *dlg)
|
||||
{
|
||||
PiecesLibrary *lib = project->GetPiecesLibrary();
|
||||
GtkCTree *ctree = GTK_CTREE (gtk_object_get_data (GTK_OBJECT (dlg), "tree"));
|
||||
GtkCList *clist = GTK_CLIST (gtk_object_get_data (GTK_OBJECT (dlg), "list"));
|
||||
int row, sel = GTK_CLIST (ctree)->focus_row;
|
||||
PiecesLibrary* Lib = g_App->GetPiecesLibrary();
|
||||
GtkCTree* ctree = GTK_CTREE(gtk_object_get_data(GTK_OBJECT(dlg), "tree"));
|
||||
GtkCList* clist = GTK_CLIST(gtk_object_get_data(GTK_OBJECT(dlg), "list"));
|
||||
int row;
|
||||
|
||||
gtk_clist_freeze (clist);
|
||||
gtk_clist_clear (clist);
|
||||
gchar* CategoryName = GTK_CELL_TEXT(GTK_CTREE_ROW(gtk_ctree_node_nth(ctree, GTK_CLIST(ctree)->focus_row))->row.cell[0])->text;
|
||||
int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
|
||||
|
||||
PtrArray<PieceInfo> SinglePieces, GroupedPieces;
|
||||
lib->GetCategoryEntries(sel, false, SinglePieces, GroupedPieces);
|
||||
gtk_clist_freeze (clist);
|
||||
gtk_clist_clear (clist);
|
||||
|
||||
for (int i = 0; i < SinglePieces.GetSize(); i++)
|
||||
{
|
||||
PieceInfo* info = SinglePieces[i];
|
||||
if (CategoryIndex != -1)
|
||||
{
|
||||
PtrArray<PieceInfo> SinglePieces, GroupedPieces;
|
||||
|
||||
char *text = info->m_strDescription;
|
||||
row = gtk_clist_append (clist, &text);
|
||||
gtk_clist_set_row_data (clist, row, info);
|
||||
}
|
||||
Lib->GetCategoryEntries(CategoryIndex, false, SinglePieces, GroupedPieces);
|
||||
|
||||
gtk_clist_thaw (clist);
|
||||
clist->focus_row = 0;
|
||||
gtk_clist_select_row (clist, 0, 0);
|
||||
for (int i = 0; i < SinglePieces.GetSize(); i++)
|
||||
{
|
||||
PieceInfo* Info = SinglePieces[i];
|
||||
|
||||
char *text = Info->m_strDescription;
|
||||
row = gtk_clist_append(clist, &text);
|
||||
gtk_clist_set_row_data(clist, row, Info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!strcmp(CategoryName, "Unassigned"))
|
||||
{
|
||||
// Test each piece against all categories.
|
||||
for (int i = 0; i < Lib->GetPieceCount(); i++)
|
||||
{
|
||||
PieceInfo* Info = Lib->GetPieceInfo(i);
|
||||
int j;
|
||||
|
||||
for (j = 0; j < Lib->GetNumCategories(); j++)
|
||||
{
|
||||
if (Lib->PieceInCategory(Info, Lib->GetCategoryKeywords(j)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (j == Lib->GetNumCategories())
|
||||
{
|
||||
char *text = Info->m_strDescription;
|
||||
row = gtk_clist_append(clist, &text);
|
||||
gtk_clist_set_row_data(clist, row, Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!strcmp(CategoryName, "Pieces"))
|
||||
{
|
||||
for (int i = 0; i < Lib->GetPieceCount(); i++)
|
||||
{
|
||||
PieceInfo* Info = Lib->GetPieceInfo(i);
|
||||
|
||||
char *text = Info->m_strDescription;
|
||||
row = gtk_clist_append(clist, &text);
|
||||
gtk_clist_set_row_data(clist, row, Info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gtk_clist_thaw(clist);
|
||||
clist->focus_row = 0;
|
||||
gtk_clist_select_row(clist, 0, 0);
|
||||
}
|
||||
|
||||
static void librarydlg_update_tree (GtkWidget *dlg)
|
||||
{
|
||||
PiecesLibrary *lib = project->GetPiecesLibrary();
|
||||
PiecesLibrary *lib = g_App->GetPiecesLibrary();
|
||||
GtkCTree *ctree = GTK_CTREE (gtk_object_get_data (GTK_OBJECT (dlg), "tree"));
|
||||
GtkCTreeNode *parent;
|
||||
char *text = "Groups";
|
||||
const char *text = "Pieces";
|
||||
|
||||
gtk_clist_freeze (GTK_CLIST (ctree));
|
||||
gtk_clist_clear (GTK_CLIST (ctree));
|
||||
|
||||
parent = gtk_ctree_insert_node (ctree, NULL, NULL, &text, 0, NULL, NULL, NULL, NULL, FALSE, TRUE);
|
||||
parent = gtk_ctree_insert_node (ctree, NULL, NULL, (gchar**)&text, 0, NULL, NULL, NULL, NULL, FALSE, TRUE);
|
||||
|
||||
for (int i = 0; i < lib->GetNumCategories(); i++)
|
||||
{
|
||||
text = lib->GetCategoryName(i);
|
||||
gtk_ctree_insert_node (ctree, parent, NULL, &text, 0, NULL, NULL, NULL, NULL, TRUE, TRUE);
|
||||
gtk_ctree_insert_node (ctree, parent, NULL, (gchar**)&text, 0, NULL, NULL, NULL, NULL, TRUE, TRUE);
|
||||
}
|
||||
|
||||
text = "Unassigned";
|
||||
gtk_ctree_insert_node (ctree, parent, NULL, (gchar**)&text, 0, NULL, NULL, NULL, NULL, TRUE, TRUE);
|
||||
|
||||
gtk_clist_thaw (GTK_CLIST (ctree));
|
||||
}
|
||||
|
||||
|
@ -2845,24 +2893,25 @@ static void librarydlg_treefocus (GtkCTree *ctree, GtkCTreeNode *row, gint colum
|
|||
librarydlg_update_list (GTK_WIDGET (data));
|
||||
}
|
||||
|
||||
static GtkWidget *last_dlg = NULL;
|
||||
|
||||
static void librarydlg_command (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
/*
|
||||
GtkWidget *parent = gtk_widget_get_toplevel (widget);
|
||||
LibraryDialog *dlg = (LibraryDialog*) gtk_object_get_data (GTK_OBJECT (parent), "lib");
|
||||
LibraryDialog *dlg = (LibraryDialog*) gtk_object_get_data (GTK_OBJECT (parent), "menu_file_import_piece");
|
||||
int id = GPOINTER_TO_INT (data);
|
||||
|
||||
dlg = (LibraryDialog *)last_dlg;
|
||||
|
||||
dlg->HandleCommand (id);
|
||||
*/
|
||||
}
|
||||
|
||||
int librarydlg_execute (void *param)
|
||||
{
|
||||
#if 0
|
||||
GtkWidget *dlg, *vbox, *clist, *scr, *ctree, *hsplit, *item, *menu, *menubar, *handle;
|
||||
GtkAccelGroup *accel, *menu_accel;
|
||||
GtkAccelGroup *accel;
|
||||
int loop = 1, ret = LC_CANCEL;
|
||||
LibraryManager lib;
|
||||
PiecesLibrary *lib = g_App->GetPiecesLibrary();
|
||||
|
||||
dlg = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (((GtkWidget*)(*main_window))));
|
||||
|
@ -2874,7 +2923,10 @@ int librarydlg_execute (void *param)
|
|||
gtk_object_set_data (GTK_OBJECT (dlg), "loop", &loop);
|
||||
gtk_object_set_data (GTK_OBJECT (dlg), "ret", &ret);
|
||||
gtk_window_set_default_size (GTK_WINDOW (dlg), 500, 250);
|
||||
accel = gtk_accel_group_get_default ();
|
||||
|
||||
accel = gtk_accel_group_new();
|
||||
gtk_window_add_accel_group(GTK_WINDOW(dlg), accel);
|
||||
// accel = gtk_accel_group_get_default ();
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 5);
|
||||
gtk_widget_show (vbox);
|
||||
|
@ -2889,70 +2941,73 @@ int librarydlg_execute (void *param)
|
|||
gtk_widget_show (menubar);
|
||||
|
||||
// File menu
|
||||
menu = create_sub_menu (menubar, "_File", accel, &menu_accel);
|
||||
menu = create_sub_menu (menubar, "_File", accel);
|
||||
menu_tearoff (menu);
|
||||
/*
|
||||
create_menu_item (menu, "_Reset", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_RESET);
|
||||
create_menu_item (menu, "_Open...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_OPEN);
|
||||
create_menu_item (menu, "_Save", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_SAVE);
|
||||
create_menu_item (menu, "Save _As...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_SAVEAS);
|
||||
/*
|
||||
create_menu_item (menu, "_Reset", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_RESET, "menu_file_reset");
|
||||
create_menu_item (menu, "_Open...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_OPEN, "menu_file_open");
|
||||
create_menu_item (menu, "_Save", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_SAVE, "menu_file_save");
|
||||
create_menu_item (menu, "Save _As...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_SAVEAS, "menu_file_save_as");
|
||||
menu_separator (menu);
|
||||
item = create_menu_item (menu, "_Print Catalog...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_PRINTCATALOG);
|
||||
item = create_menu_item (menu, "_Print Catalog...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_PRINTCATALOG, "menu_print_catalog");
|
||||
gtk_widget_set_sensitive (item, FALSE);
|
||||
item = create_menu_item (menu, "Load _Update...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_MERGEUPDATE);
|
||||
item = create_menu_item (menu, "_Import Piece...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_IMPORTPIECE);
|
||||
*/
|
||||
item = create_menu_item (menu, "Load _Update...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_MERGEUPDATE, "menu_file_merge_update");
|
||||
item = create_menu_item (menu, "_Import Piece...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_IMPORTPIECE, "menu_file_import_piece");
|
||||
/*
|
||||
menu_separator (menu);
|
||||
item = create_menu_item (menu, "Re_turn", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_RETURN);
|
||||
item = create_menu_item (menu, "_Cancel", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_FILE_CANCEL);
|
||||
*/
|
||||
item = create_menu_item (menu, "Re_turn", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_RETURN, "menu_file_return");
|
||||
item = create_menu_item (menu, "_Cancel", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_FILE_CANCEL, "menu_file_cancel");
|
||||
// Group menu
|
||||
menu = create_sub_menu (menubar, "_Group", accel, &menu_accel);
|
||||
menu = create_sub_menu (menubar, "_Group", accel);
|
||||
menu_tearoff (menu);
|
||||
/*
|
||||
create_menu_item (menu, "Insert...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_GROUP_INSERT);
|
||||
create_menu_item (menu, "Delete", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_GROUP_DELETE);
|
||||
create_menu_item (menu, "Edit...", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_GROUP_EDIT);
|
||||
create_menu_item (menu, "Insert...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_GROUP_INSERT, "menu_group_insert");
|
||||
create_menu_item (menu, "Delete", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_GROUP_DELETE, "menu_group_delete");
|
||||
create_menu_item (menu, "Edit...", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_GROUP_EDIT, "menu_group_edit");
|
||||
menu_separator (menu);
|
||||
create_menu_item (menu, "Move Up", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_GROUP_MOVEUP);
|
||||
create_menu_item (menu, "Move Down", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_GROUP_MOVEDOWN);
|
||||
*/
|
||||
create_menu_item (menu, "Move Up", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_GROUP_MOVEUP, "menu_group_moveup");
|
||||
create_menu_item (menu, "Move Down", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_GROUP_MOVEDOWN, "menu_group_down");
|
||||
// Piece menu
|
||||
menu = create_sub_menu (menubar, "_Piece", accel, &menu_accel);
|
||||
menu = create_sub_menu (menubar, "_Piece", accel);
|
||||
menu_tearoff (menu);
|
||||
/*
|
||||
item = create_menu_item (menu, "_New", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_PIECE_NEW);
|
||||
item = create_menu_item (menu, "_New", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_PIECE_NEW, "menu_piece_new");
|
||||
gtk_widget_set_sensitive (item, FALSE);
|
||||
item = create_menu_item (menu, "_Edit", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_PIECE_EDIT);
|
||||
item = create_menu_item (menu, "_Edit", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_PIECE_EDIT, "menu_piece_edit");
|
||||
gtk_widget_set_sensitive (item, FALSE);
|
||||
create_menu_item (menu, "_Delete", menu_accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), LC_LIBDLG_PIECE_DELETE);
|
||||
*/
|
||||
create_menu_item (menu, "_Delete", accel,
|
||||
GTK_SIGNAL_FUNC (librarydlg_command), GTK_OBJECT (dlg), LC_LIBDLG_PIECE_DELETE, "menu_piece_delete");
|
||||
*/
|
||||
hsplit = gtk_hpaned_new ();
|
||||
gtk_paned_set_gutter_size (GTK_PANED (hsplit), 12);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hsplit, TRUE, TRUE, 0);
|
||||
gtk_widget_show (hsplit);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (hsplit), 5);
|
||||
|
||||
scr = gtk_scrolled_window_new ((GtkAdjustment*)NULL, (GtkAdjustment*)NULL);
|
||||
gtk_widget_show (scr);
|
||||
gtk_paned_add1 (GTK_PANED (hsplit), scr);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scr), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
|
||||
|
||||
ctree = gtk_ctree_new (1, 0);
|
||||
gtk_object_set_data (GTK_OBJECT (dlg), "ctree", ctree);
|
||||
gtk_widget_show (ctree);
|
||||
gtk_paned_add1 (GTK_PANED (hsplit), ctree);
|
||||
gtk_container_add (GTK_CONTAINER (scr), ctree);
|
||||
gtk_clist_column_titles_hide (GTK_CLIST (ctree));
|
||||
gtk_clist_set_selection_mode (GTK_CLIST (ctree), GTK_SELECTION_BROWSE);
|
||||
gtk_signal_connect (GTK_OBJECT (ctree), "tree_select_row",
|
||||
|
@ -2982,6 +3037,8 @@ int librarydlg_execute (void *param)
|
|||
gtk_grab_add (dlg);
|
||||
gtk_widget_show (dlg);
|
||||
|
||||
last_dlg = dlg;
|
||||
|
||||
while (loop)
|
||||
gtk_main_iteration ();
|
||||
|
||||
|
@ -2994,20 +3051,8 @@ int librarydlg_execute (void *param)
|
|||
gtk_widget_destroy (dlg);
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
return LC_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int librarydlg_execute (void *param)
|
||||
{
|
||||
// TODO: FIXME !
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// =============================================================================
|
||||
// Modify Dialog
|
||||
|
||||
|
|
457
linux/libdlg.cpp
Executable file
457
linux/libdlg.cpp
Executable file
|
@ -0,0 +1,457 @@
|
|||
// LibDlg.cpp : implementation file
|
||||
//
|
||||
|
||||
#include <limits.h>
|
||||
//#include "lc_global.h"
|
||||
//#include "leocad.h"
|
||||
#include "libdlg.h"
|
||||
//#include "GroupDlg.h"
|
||||
//#include "Print.h"
|
||||
//#include "Tools.h"
|
||||
#include "project.h"
|
||||
#include "pieceinf.h"
|
||||
#include "system.h"
|
||||
#include "library.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
bool LibraryDialog::HandleCommand(int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case LC_LIBDLG_FILE_OPEN:
|
||||
{
|
||||
lcGetPiecesLibrary()->LoadCategories(NULL);
|
||||
// UpdateTree();
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_FILE_SAVE:
|
||||
{
|
||||
lcGetPiecesLibrary()->DoSaveCategories(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_FILE_SAVEAS:
|
||||
{
|
||||
lcGetPiecesLibrary()->DoSaveCategories(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
case LC_LIBDLG_FILE_PRINTCATALOG:
|
||||
{
|
||||
PRINT_PARAMS* param = (PRINT_PARAMS*)malloc(sizeof(PRINT_PARAMS));
|
||||
param->pParent = this;
|
||||
param->pMainFrame = (CFrameWnd*)AfxGetMainWnd();
|
||||
AfxBeginThread(PrintCatalogFunction, param);
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
case LC_LIBDLG_FILE_MERGEUPDATE:
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
LC_FILEOPENDLG_OPTS opts;
|
||||
|
||||
strcpy(opts.path, "");
|
||||
opts.type = LC_FILEOPENDLG_LUP;
|
||||
|
||||
if (SystemDoDialog(LC_DLG_FILE_OPEN, filename))
|
||||
{
|
||||
lcGetPiecesLibrary()->LoadUpdate(filename);
|
||||
// UpdateTree();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_FILE_IMPORTPIECE:
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
LC_FILEOPENDLG_OPTS opts;
|
||||
|
||||
strcpy(opts.path, Sys_ProfileLoadString ("Default", "LDraw Pieces Path", ""));
|
||||
opts.type = LC_FILEOPENDLG_DAT;
|
||||
|
||||
if (SystemDoDialog (LC_DLG_FILE_OPEN, filename))
|
||||
{
|
||||
/*
|
||||
for (int i = 0; i < opts.numfiles; i++)
|
||||
{
|
||||
lcGetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
|
||||
free (opts.filenames[i]);
|
||||
}
|
||||
free (opts.filenames);
|
||||
*/
|
||||
FileDisk newbin, newidx, oldbin, oldidx;
|
||||
char file1[LC_MAXPATH], file2[LC_MAXPATH];
|
||||
|
||||
strcpy(file1, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(file1, "pieces-b.old");
|
||||
remove(file1);
|
||||
strcpy(file2, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(file2, "pieces.bin");
|
||||
rename(file2, file1);
|
||||
|
||||
if ((!oldbin.Open(file1, "rb")) || (!newbin.Open(file2, "wb")))
|
||||
break;
|
||||
|
||||
strcpy(file1, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(file1, "pieces-i.old");
|
||||
remove(file1);
|
||||
strcpy(file2, lcGetPiecesLibrary()->GetLibraryPath());
|
||||
strcat(file2, "pieces.idx");
|
||||
rename(file2, file1);
|
||||
|
||||
if ((!oldidx.Open(file1, "rb")) || (!newidx.Open(file2, "wb")))
|
||||
break;
|
||||
|
||||
if (!lcGetPiecesLibrary()->ImportLDrawPiece(filename, &newidx, &newbin, &oldidx, &oldbin))
|
||||
break;
|
||||
|
||||
// Sys_ProfileSaveString ("Default", "LDraw Pieces Path", filename);
|
||||
|
||||
// UpdateList();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
case LC_LIBDLG_FILE_TEXTURES:
|
||||
{
|
||||
CTexturesDlg dlg;
|
||||
dlg.DoModal();
|
||||
} break;
|
||||
*/
|
||||
|
||||
case LC_LIBDLG_CATEGORY_RESET:
|
||||
{
|
||||
if (SystemDoMessageBox("Are you sure you want to reset the categories?", LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
|
||||
{
|
||||
lcGetPiecesLibrary()->ResetCategories();
|
||||
|
||||
// UpdateList();
|
||||
// UpdateTree();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_CATEGORY_NEW:
|
||||
{
|
||||
LC_CATEGORYDLG_OPTS Opts;
|
||||
Opts.Name = "New Category";
|
||||
Opts.Keywords = "";
|
||||
|
||||
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
|
||||
{
|
||||
lcGetPiecesLibrary()->AddCategory(Opts.Name, Opts.Keywords);
|
||||
}
|
||||
|
||||
// UpdateTree();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_CATEGORY_REMOVE:
|
||||
{
|
||||
/*
|
||||
HTREEITEM Item = m_Tree.GetSelectedItem();
|
||||
|
||||
if (Item == NULL)
|
||||
break;
|
||||
|
||||
PiecesLibrary* Lib = lcGetPiecesLibrary();
|
||||
CString CategoryName = m_Tree.GetItemText(Item);
|
||||
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
|
||||
|
||||
if (Index == -1)
|
||||
break;
|
||||
|
||||
char Msg[1024];
|
||||
String Name = Lib->GetCategoryName(Index);
|
||||
sprintf(Msg, "Are you sure you want to remove the %s category?", Name);
|
||||
|
||||
if (SystemDoMessageBox(Msg, LC_MB_YESNO | LC_MB_ICONQUESTION) == LC_YES)
|
||||
{
|
||||
Lib->RemoveCategory(Index);
|
||||
}
|
||||
|
||||
UpdateTree();
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_CATEGORY_EDIT:
|
||||
{
|
||||
/*
|
||||
HTREEITEM Item = m_Tree.GetSelectedItem();
|
||||
|
||||
if (Item == NULL)
|
||||
break;
|
||||
|
||||
PiecesLibrary* Lib = lcGetPiecesLibrary();
|
||||
CString CategoryName = m_Tree.GetItemText(Item);
|
||||
int Index = Lib->FindCategoryIndex((const char*)CategoryName);
|
||||
|
||||
if (Index == -1)
|
||||
break;
|
||||
|
||||
LC_CATEGORYDLG_OPTS Opts;
|
||||
Opts.Name = Lib->GetCategoryName(Index);
|
||||
Opts.Keywords = Lib->GetCategoryKeywords(Index);
|
||||
|
||||
if (SystemDoDialog(LC_DLG_EDITCATEGORY, &Opts))
|
||||
{
|
||||
String OldName = Lib->GetCategoryName(Index);
|
||||
Lib->SetCategory(Index, Opts.Name, Opts.Keywords);
|
||||
}
|
||||
|
||||
UpdateTree();
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_PIECE_NEW:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_PIECE_EDIT:
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
case LC_LIBDLG_PIECE_DELETE:
|
||||
{
|
||||
/*
|
||||
PtrArray<PieceInfo> Pieces;
|
||||
|
||||
for (int i = 0; i < m_List.GetItemCount(); i++)
|
||||
{
|
||||
if (m_List.GetItemState(i, LVIS_SELECTED))
|
||||
Pieces.Add((PieceInfo*)m_List.GetItemData(i));
|
||||
}
|
||||
|
||||
if (Pieces.GetSize() == 0)
|
||||
return true;
|
||||
|
||||
if (SystemDoMessageBox ("Are you sure you want to permanently delete the selected pieces?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
|
||||
return true;
|
||||
|
||||
lcGetPiecesLibrary()->DeletePieces(Pieces);
|
||||
|
||||
UpdateList();
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// return CDialog::OnCommand(wParam, lParam);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
void CLibraryDlg::UpdateList()
|
||||
{
|
||||
m_List.DeleteAllItems();
|
||||
m_List.SetRedraw(false);
|
||||
|
||||
PiecesLibrary *Lib = lcGetPiecesLibrary();
|
||||
|
||||
HTREEITEM CategoryItem = m_Tree.GetSelectedItem();
|
||||
CString CategoryName = m_Tree.GetItemText(CategoryItem);
|
||||
int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName);
|
||||
|
||||
if (CategoryIndex != -1)
|
||||
{
|
||||
PtrArray<PieceInfo> SinglePieces, GroupedPieces;
|
||||
|
||||
Lib->GetCategoryEntries(CategoryIndex, false, SinglePieces, GroupedPieces);
|
||||
|
||||
for (int i = 0; i < SinglePieces.GetSize(); i++)
|
||||
{
|
||||
PieceInfo* Info = SinglePieces[i];
|
||||
|
||||
LVITEM lvi;
|
||||
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
||||
lvi.iItem = 0;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.lParam = (LPARAM)Info;
|
||||
lvi.pszText = Info->m_strDescription;
|
||||
int idx = m_List.InsertItem(&lvi);
|
||||
|
||||
m_List.SetItemText(idx, 1, Info->m_strName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CategoryName == "Unassigned")
|
||||
{
|
||||
// Test each piece against all categories.
|
||||
for (int i = 0; i < Lib->GetPieceCount(); i++)
|
||||
{
|
||||
PieceInfo* Info = Lib->GetPieceInfo(i);
|
||||
|
||||
for (int j = 0; j < Lib->GetNumCategories(); j++)
|
||||
{
|
||||
if (Lib->PieceInCategory(Info, Lib->GetCategoryKeywords(j)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (j == Lib->GetNumCategories())
|
||||
{
|
||||
LVITEM lvi;
|
||||
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
||||
lvi.iItem = 0;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.lParam = (LPARAM)Info;
|
||||
lvi.pszText = Info->m_strDescription;
|
||||
int idx = m_List.InsertItem(&lvi);
|
||||
|
||||
m_List.SetItemText(idx, 1, Info->m_strName);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (CategoryName == "Pieces")
|
||||
{
|
||||
for (int i = 0; i < Lib->GetPieceCount(); i++)
|
||||
{
|
||||
PieceInfo* Info = Lib->GetPieceInfo(i);
|
||||
|
||||
LVITEM lvi;
|
||||
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
||||
lvi.iItem = 0;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.lParam = (LPARAM)Info;
|
||||
lvi.pszText = Info->m_strDescription;
|
||||
int idx = m_List.InsertItem(&lvi);
|
||||
|
||||
m_List.SetItemText(idx, 1, Info->m_strName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_List.SortItems((PFNLVCOMPARE)ListCompare, m_SortColumn);
|
||||
m_List.SetRedraw(true);
|
||||
}
|
||||
|
||||
void CLibraryDlg::UpdateTree()
|
||||
{
|
||||
m_Tree.SetRedraw(false);
|
||||
m_Tree.DeleteAllItems();
|
||||
|
||||
HTREEITEM Root = m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT, "Pieces", 0, 1, 0, 0, 0, TVI_ROOT, TVI_SORT);
|
||||
|
||||
PiecesLibrary *Lib = lcGetPiecesLibrary();
|
||||
for (int i = 0; i < Lib->GetNumCategories(); i++)
|
||||
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 1, 0, 0, 0, Root, TVI_SORT);
|
||||
|
||||
m_Tree.InsertItem(TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM|TVIF_TEXT, "Unassigned", 0, 1, 0, 0, 0, Root, TVI_LAST);
|
||||
|
||||
m_Tree.Expand(Root, TVE_EXPAND);
|
||||
m_Tree.SetRedraw(true);
|
||||
m_Tree.Invalidate();
|
||||
}
|
||||
|
||||
void CLibraryDlg::OnSelChangedTree(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
||||
UpdateList();
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
void CLibraryDlg::OnCancel()
|
||||
{
|
||||
// Check if it's ok to close the dialog
|
||||
if (!lcGetPiecesLibrary()->SaveCategories())
|
||||
return;
|
||||
|
||||
CDialog::OnCancel();
|
||||
}
|
||||
|
||||
void CLibraryDlg::OnOK()
|
||||
{
|
||||
// Check if it's ok to close the dialog
|
||||
if (!lcGetPiecesLibrary()->SaveCategories())
|
||||
return;
|
||||
|
||||
CDialog::OnOK();
|
||||
}
|
||||
|
||||
BOOL CLibraryDlg::ContinueModal()
|
||||
{
|
||||
HTREEITEM h = m_Tree.GetSelectedItem();
|
||||
BOOL bValid = (h != m_Tree.GetRootItem()) && (h != NULL);
|
||||
|
||||
EnableControl(LC_LIBDLG_GROUP_RENAME, bValid);
|
||||
EnableControl(LC_LIBDLG_GROUP_DELETE, bValid);
|
||||
|
||||
return CDialog::ContinueModal();
|
||||
}
|
||||
|
||||
void CLibraryDlg::EnableControl(UINT nID, BOOL bEnable)
|
||||
{
|
||||
GetMenu()->GetSubMenu(1)->EnableMenuItem(nID, MF_BYCOMMAND | (bEnable ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
|
||||
int state = m_wndToolBar.GetToolBarCtrl().GetState(nID) & ~TBSTATE_ENABLED;
|
||||
if (bEnable)
|
||||
state |= TBSTATE_ENABLED;
|
||||
m_wndToolBar.GetToolBarCtrl().SetState(nID, state);
|
||||
}
|
||||
|
||||
BOOL CLibraryDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
|
||||
|
||||
// allow top level routing frame to handle the message
|
||||
if (GetRoutingFrame() != NULL)
|
||||
return false;
|
||||
|
||||
// need to handle both ANSI and UNICODE versions of the message
|
||||
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
|
||||
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
|
||||
CString cstTipText;
|
||||
UINT nID = pNMHDR->idFrom;
|
||||
|
||||
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
|
||||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
|
||||
{
|
||||
// idFrom is actually the HWND of the tool
|
||||
nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));
|
||||
}
|
||||
|
||||
if (nID != 0) // will be zero on a separator
|
||||
{
|
||||
cstTipText.LoadString(nID);
|
||||
}
|
||||
|
||||
// Non-UNICODE Strings only are shown in the tooltip window...
|
||||
if (pNMHDR->code == TTN_NEEDTEXTA)
|
||||
lstrcpyn(pTTTA->szText, cstTipText, (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));
|
||||
else
|
||||
_mbstowcsz(pTTTW->szText, cstTipText, (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));
|
||||
|
||||
*pResult = 0;
|
||||
|
||||
// bring the tooltip window above other popup windows
|
||||
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,
|
||||
SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);
|
||||
|
||||
return true; // message was handled
|
||||
}
|
||||
|
||||
void CLibraryDlg::OnListColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
|
||||
{
|
||||
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
|
||||
|
||||
// Save the column index.
|
||||
m_SortColumn = pNMListView->iSubItem;
|
||||
|
||||
m_List.SortItems((PFNLVCOMPARE)ListCompare, m_SortColumn);
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
*/
|
40
linux/libdlg.h
Executable file
40
linux/libdlg.h
Executable file
|
@ -0,0 +1,40 @@
|
|||
#ifndef _LIBDLG_H_
|
||||
#define _LIBDLG_H_
|
||||
|
||||
class PieceInfo;
|
||||
|
||||
// =============================================================================
|
||||
// LibraryDialog class
|
||||
|
||||
enum
|
||||
{
|
||||
LC_LIBDLG_FILE_RESET,
|
||||
LC_LIBDLG_FILE_OPEN,
|
||||
LC_LIBDLG_FILE_SAVE,
|
||||
LC_LIBDLG_FILE_SAVEAS,
|
||||
LC_LIBDLG_FILE_PRINTCATALOG,
|
||||
LC_LIBDLG_FILE_MERGEUPDATE,
|
||||
LC_LIBDLG_FILE_IMPORTPIECE,
|
||||
LC_LIBDLG_FILE_RETURN,
|
||||
LC_LIBDLG_FILE_CANCEL,
|
||||
LC_LIBDLG_CATEGORY_NEW,
|
||||
LC_LIBDLG_CATEGORY_REMOVE,
|
||||
LC_LIBDLG_CATEGORY_EDIT,
|
||||
LC_LIBDLG_CATEGORY_RESET,
|
||||
LC_LIBDLG_GROUP_INSERT,
|
||||
LC_LIBDLG_GROUP_DELETE,
|
||||
LC_LIBDLG_GROUP_EDIT,
|
||||
LC_LIBDLG_GROUP_MOVEUP,
|
||||
LC_LIBDLG_GROUP_MOVEDOWN,
|
||||
LC_LIBDLG_PIECE_NEW,
|
||||
LC_LIBDLG_PIECE_EDIT,
|
||||
LC_LIBDLG_PIECE_DELETE,
|
||||
};
|
||||
|
||||
class LibraryDialog
|
||||
{
|
||||
public:
|
||||
bool HandleCommand(int id);
|
||||
};
|
||||
|
||||
#endif // _LIBDLG_H_
|
|
@ -2,4 +2,4 @@ SRC += linux/profile.cpp \
|
|||
linux/dialogs.cpp linux/dlgpiece.cpp linux/dlgfile.cpp \
|
||||
linux/gtktools.cpp linux/main.cpp linux/menu.cpp \
|
||||
linux/system.cpp linux/toolbar.cpp linux/gtkmisc.cpp \
|
||||
linux/linux_gl.cpp linux/basewnd.cpp linux/glwindow.cpp
|
||||
linux/linux_gl.cpp linux/basewnd.cpp linux/glwindow.cpp linux/libdlg.cpp
|
||||
|
|
Loading…
Add table
Reference in a new issue