OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
window.c File Reference
#include <stdlib.h>
#include <gtksourceview/gtksourcebuffer.h>
#include "mape/cpp-handles/version-handle.h"
#include "mape/fileicon.h"
#include "mape/configfile.h"
#include "mape/preferencesdialog.h"
#include "mape/header.h"
#include "mape/statusbar.h"
#include "mape/diskview.h"
#include "mape/mattexview.h"
#include "mape/editview.h"
#include "mape/preview.h"
#include "mape/window.h"
Include dependency graph for window.c:

Go to the source code of this file.

Functions

MapeWindowmape_window_new (int argc, char *argv[], GError **error)
 
void mape_window_destroy (MapeWindow *wnd)
 

Function Documentation

void mape_window_destroy ( MapeWindow wnd)

Definition at line 881 of file window.c.

References MapeWindow_::config, MapeWindow_::disk_view, MapeWindow_::edit_view, MapeWindow_::header, MapeWindow_::icon_set, MapeWindow_::last_path, mape_config_file_destroy(), mape_config_file_serialise(), mape_disk_view_destroy(), mape_edit_view_destroy(), mape_file_icon_set_destroy(), mape_header_destroy(), mape_mat_tex_view_destroy(), mape_pre_view_destroy(), MapeWindow_::mat_tex_view, and MapeWindow_::pre_view.

Referenced by main().

882 {
889 
892  g_free(wnd->last_path);
893  free(wnd);
894 }
MapeHeader * header
Definition: window.h:36
void mape_mat_tex_view_destroy(MapeMatTexView *view)
Definition: mattexview.c:80
void mape_disk_view_destroy(MapeDiskView *disk_view)
Definition: diskview.c:974
MapePreView * pre_view
Definition: window.h:42
MapeConfigFile * config
Definition: window.h:44
void mape_header_destroy(MapeHeader *header)
Definition: header.c:274
gboolean mape_config_file_serialise(MapeConfigFile *file, GError **error)
Definition: configfile.c:70
MapeEditView * edit_view
Definition: window.h:41
void mape_config_file_destroy(MapeConfigFile *file)
Definition: configfile.c:56
void mape_pre_view_destroy(MapePreView *view)
Definition: preview.c:47
void mape_file_icon_set_destroy(MapeFileIconSet *set)
Definition: fileicon.c:122
void mape_edit_view_destroy(MapeEditView *view)
Definition: editview.c:505
MapeDiskView * disk_view
Definition: window.h:39
MapeFileIconSet * icon_set
Definition: window.h:24
gchar * last_path
Definition: window.h:25
MapeMatTexView * mat_tex_view
Definition: window.h:40

Here is the call graph for this function:

Here is the caller graph for this function:

MapeWindow* mape_window_new ( int  argc,
char *  argv[],
GError **  error 
)

Definition at line 517 of file window.c.

References MapeHeader_::accel_group, MapeStatusbar_::bar, MapeWindow_::bottom_hbox, MapeWindow_::config, MapeWindow_::disk_view, MapeHeader_::edit_preferences, MapeHeader_::edit_redo, MapeHeader_::edit_undo, MapeWindow_::edit_view, MapeHeader_::file_new, MapeHeader_::file_open, MapeHeader_::file_quit, MapeHeader_::file_save, MapeHeader_::file_save_as, MapePreView_::frame, MapeWindow_::header, MapeHeader_::help_about, MapeWindow_::icon_set, MapeWindow_::last_path, mape_config_file_destroy(), mape_config_file_entry_get_value(), mape_config_file_get_entry_by_key(), mape_config_file_new(), mape_config_file_set_entry(), mape_disk_view_extend_to_path(), mape_disk_view_new(), mape_edit_view_apply_preferences(), mape_edit_view_destroy(), mape_edit_view_new(), mape_file_icon_set_destroy(), mape_file_icon_set_new(), mape_header_destroy(), mape_header_new(), mape_mat_tex_view_destroy(), mape_mat_tex_view_new(), mape_pre_view_apply_preferences(), mape_pre_view_destroy(), mape_pre_view_new(), mape_preferences_from_config(), mape_statusbar_destroy(), mape_statusbar_new(), MapeWindow_::mat_tex_view, MapeHeader_::menubar, MapeWindow_::menubar, MapeWindow_::mid_paned, MapeMatTexView_::notebook, MapeWindow_::pre_view, MapeWindow_::preferences, MapeWindow_::statusbar, MapeHeader_::toolbar, MapeWindow_::toolbar, MapeWindow_::topbox, MapeEditView_::view, MapeWindow_::window, MapeEditView_::window, and MapeDiskView_::window.

Referenced by main().

520 {
521  MapeWindow* wnd;
522  MapeConfigFileEntry* entry;
523  gchar* config_path;
524  gchar* material_path;
525  gchar* current_dir;
526  gchar* landscape_path;
527  gchar* basename;
528  int i;
529 
530  wnd = malloc(sizeof(MapeWindow) );
531 
532  /* Load preferences */
533  config_path = g_build_filename(g_get_home_dir(), ".mape", NULL);
534  wnd->config = mape_config_file_new(config_path);
535  g_free(config_path);
536 
537  current_dir = g_get_current_dir();
538  landscape_path = NULL;
539 
540  for(i = 1; i < argc; ++ i)
541  {
542  basename = g_path_get_basename(argv[i]);
543  if(g_strcasecmp(basename, "Material.ocg") == 0)
544  {
545  if(!g_path_is_absolute(argv[i]))
546  {
547  material_path = g_build_filename(
548  current_dir,
549  argv[i],
550  NULL
551  );
552  }
553  else
554  {
555  material_path = g_strdup(argv[i]);
556  }
557 
559  wnd->config,
560  "material_path",
561  material_path
562  );
563 
564  g_free(material_path);
565  }
566  else
567  {
568  g_free(landscape_path);
569 
570  if(!g_path_is_absolute(argv[i]))
571  {
572  landscape_path = g_build_filename(
573  current_dir,
574  argv[i],
575  NULL
576  );
577  }
578  else
579  {
580  landscape_path = g_strdup(argv[i]);
581  }
582  }
583 
584  g_free(basename);
585  }
586 
587  g_free(current_dir);
588 
590 
591  wnd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
593  wnd->last_path = NULL;
594 
595  wnd->header = mape_header_new();
596  wnd->statusbar = mape_statusbar_new();
597 
598  wnd->mat_tex_view = mape_mat_tex_view_new(wnd->icon_set, error);
599  if(wnd->mat_tex_view == NULL)
600  goto mat_tex_error;
601 
602  wnd->pre_view = mape_pre_view_new(wnd->mat_tex_view, error);
603  if(wnd->pre_view == NULL)
604  goto pre_view_error;
605 
607  wnd->pre_view,
608  wnd->statusbar,
609  error
610  );
611  if(wnd->edit_view == NULL)
612  goto edit_view_error;
613 
615  wnd->icon_set,
616  wnd->mat_tex_view,
617  wnd->edit_view,
618  wnd->config,
619  error
620  );
621 
622  if(wnd->disk_view == NULL)
623  goto disk_view_error;
624 
625  wnd->menubar = wnd->header->menubar;
626  gtk_widget_show(wnd->menubar);
627 
628  wnd->toolbar = wnd->header->toolbar;
629  gtk_toolbar_set_style(GTK_TOOLBAR(wnd->toolbar), GTK_TOOLBAR_ICONS);
630  gtk_widget_show(wnd->toolbar);
631 
632  wnd->mid_paned = gtk_hpaned_new();
633  gtk_paned_pack1(
634  GTK_PANED(wnd->mid_paned),
635  wnd->disk_view->window,
636  TRUE,
637  FALSE
638  );
639 
640  gtk_paned_pack2(
641  GTK_PANED(wnd->mid_paned),
642  wnd->edit_view->window,
643  TRUE,
644  FALSE
645  );
646 
647  gtk_widget_show(wnd->mid_paned);
648 
649  wnd->bottom_hbox = gtk_hbox_new(FALSE, 5);
650  gtk_box_pack_start(
651  GTK_BOX(wnd->bottom_hbox),
652  wnd->mat_tex_view->notebook,
653  TRUE,
654  TRUE,
655  0
656  );
657 
658  gtk_box_pack_start(
659  GTK_BOX(wnd->bottom_hbox),
660  wnd->pre_view->frame,
661  FALSE,
662  FALSE,
663  0
664  );
665  gtk_widget_show(wnd->bottom_hbox);
666 
667  wnd->topbox = gtk_vbox_new(FALSE, 0);
668  gtk_box_pack_start(
669  GTK_BOX(wnd->topbox),
670  wnd->menubar,
671  FALSE,
672  TRUE,
673  0
674  );
675 
676  gtk_box_pack_start(
677  GTK_BOX(wnd->topbox),
678  wnd->toolbar,
679  FALSE,
680  TRUE,
681  0
682  );
683 
684  gtk_box_pack_start(
685  GTK_BOX(wnd->topbox),
686  wnd->mid_paned,
687  TRUE,
688  TRUE,
689  0
690  );
691 
692  gtk_box_pack_start(
693  GTK_BOX(wnd->topbox),
694  wnd->bottom_hbox,
695  FALSE,
696  TRUE,
697  0
698  );
699 
700  gtk_box_pack_start(
701  GTK_BOX(wnd->topbox),
702  wnd->statusbar->bar,
703  FALSE,
704  TRUE,
705  0
706  );
707 
708  gtk_widget_show(wnd->topbox);
709 
710  gtk_container_add(
711  GTK_CONTAINER(wnd->window),
712  wnd->topbox
713  );
714 
715  gtk_window_add_accel_group(
716  GTK_WINDOW(wnd->window),
717  wnd->header->accel_group
718  );
719 
720  g_signal_connect(
721  G_OBJECT(wnd->window),
722  "realize",
723  G_CALLBACK(mape_window_cb_realize),
724  wnd
725  );
726 
727  g_signal_connect(
728  G_OBJECT(wnd->window),
729  "delete-event",
730  G_CALLBACK(mape_window_cb_delete_event),
731  wnd
732  );
733 
734  gtk_widget_grab_focus(wnd->edit_view->view);
735 
736  g_signal_connect(
737  G_OBJECT(wnd->header->file_new),
738  "activate",
739  G_CALLBACK(mape_window_cb_file_new),
740  wnd
741  );
742 
743  g_signal_connect(
744  G_OBJECT(wnd->header->file_open),
745  "activate",
746  G_CALLBACK(mape_window_cb_file_open),
747  wnd
748  );
749 
750  g_signal_connect(
751  G_OBJECT(wnd->header->file_save),
752  "activate",
753  G_CALLBACK(mape_window_cb_file_save),
754  wnd
755  );
756 
757  g_signal_connect(
758  G_OBJECT(wnd->header->file_save_as),
759  "activate",
760  G_CALLBACK(mape_window_cb_file_save_as),
761  wnd
762  );
763 
764  g_signal_connect(
765  G_OBJECT(wnd->header->file_quit),
766  "activate",
767  G_CALLBACK(mape_window_cb_file_quit),
768  wnd
769  );
770 
771  g_signal_connect(
772  G_OBJECT(wnd->header->edit_undo),
773  "activate",
774  G_CALLBACK(mape_window_cb_edit_undo),
775  wnd
776  );
777 
778  g_signal_connect(
779  G_OBJECT(wnd->header->edit_redo),
780  "activate",
781  G_CALLBACK(mape_window_cb_edit_redo),
782  wnd
783  );
784 
785  g_signal_connect(
786  G_OBJECT(
787  gtk_text_view_get_buffer(
788  GTK_TEXT_VIEW(wnd->edit_view->view)
789  )
790  ),
791  "notify::can-undo",
792  G_CALLBACK(mape_window_cb_edit_can_undo),
793  wnd
794  );
795 
796  g_signal_connect(
797  G_OBJECT(
798  gtk_text_view_get_buffer(
799  GTK_TEXT_VIEW(wnd->edit_view->view)
800  )
801  ),
802  "notify::can-redo",
803  G_CALLBACK(mape_window_cb_edit_can_redo),
804  wnd
805  );
806 
807  g_signal_connect(
808  G_OBJECT(wnd->header->edit_preferences),
809  "activate",
810  G_CALLBACK(mape_window_cb_edit_preferences),
811  wnd
812  );
813 
814  g_signal_connect(
815  G_OBJECT(wnd->header->help_about),
816  "activate",
817  G_CALLBACK(mape_window_cb_help_about),
818  wnd
819  );
820 
821  gtk_action_set_sensitive(wnd->header->edit_undo, FALSE);
822  gtk_action_set_sensitive(wnd->header->edit_redo, FALSE);
823 
826 
827  /* Load initial path in disk view, if any. Note this needs to go
828  * after applying preferences in edit_view, so that the map size is
829  * correct in case the newly loaded Material.ocg triggers a map update. */
831  wnd->config,
832  "material_path"
833  );
834 
835  if(entry != NULL)
836  {
838  wnd->disk_view,
840  NULL
841  );
842  }
843 
844  gtk_window_set_title(GTK_WINDOW(wnd->window), "Mape");
845  gtk_window_set_default_size(GTK_WINDOW(wnd->window), 640, 480);
846 
847  /* Load initial landscape */
848  if(landscape_path != NULL)
849  {
850  mape_window_file_load(wnd, landscape_path);
851  g_free(landscape_path);
852  }
853 
854  gtk_widget_show(wnd->window);
855 
856  return wnd;
857 
858 disk_view_error:
860 
861 edit_view_error:
863 
864 pre_view_error:
866 
867 mat_tex_error:
868  g_free(landscape_path);
869 
872 
874  gtk_widget_destroy(wnd->window);
876  free(wnd);
877 
878  return NULL;
879 }
GtkAction * file_save
Definition: header.h:32
GtkAction * edit_preferences
Definition: header.h:39
MapeMatTexView * mape_mat_tex_view_new(MapeFileIconSet *icon_set, GError **error)
Definition: mattexview.c:24
GtkWidget * mid_paned
Definition: window.h:30
GtkWidget * menubar
Definition: window.h:33
GtkAction * file_open
Definition: header.h:31
GtkWidget * toolbar
Definition: header.h:27
GtkWidget * topbox
Definition: window.h:29
const gchar * mape_config_file_entry_get_value(MapeConfigFileEntry *entry)
Definition: configfile.c:174
GtkAction * file_quit
Definition: header.h:34
GtkWidget * frame
Definition: preview.h:29
MapeHeader * header
Definition: window.h:36
GtkWidget * window
Definition: editview.h:32
void mape_mat_tex_view_destroy(MapeMatTexView *view)
Definition: mattexview.c:80
MapePreView * pre_view
Definition: window.h:42
void mape_statusbar_destroy(MapeStatusbar *bar)
Definition: statusbar.c:42
MapeEditView * mape_edit_view_new(MapePreView *pre_view, MapeStatusbar *statusbar, GError **error)
Definition: editview.c:393
MapeHeader * mape_header_new(void)
Definition: header.c:148
void mape_edit_view_apply_preferences(MapeEditView *edit_view, MapePreferences *preferences)
Definition: editview.c:704
MapePreferences preferences
Definition: window.h:45
GtkAction * file_save_as
Definition: header.h:33
GtkWidget * view
Definition: editview.h:33
GtkWidget * window
Definition: diskview.h:39
MapeDiskView * mape_disk_view_new(MapeFileIconSet *icon_set, MapeMatTexView *mat_tex, MapeEditView *edit_view, MapeConfigFile *config, GError **error)
Definition: diskview.c:823
MapeConfigFile * config
Definition: window.h:44
void mape_header_destroy(MapeHeader *header)
Definition: header.c:274
MapeConfigFileEntry * mape_config_file_get_entry_by_key(MapeConfigFile *file, const gchar *key)
Definition: configfile.c:132
gboolean mape_disk_view_extend_to_path(MapeDiskView *disk_view, const gchar *filepath, GError **error)
Definition: diskview.c:989
MapeEditView * edit_view
Definition: window.h:41
GtkAction * edit_undo
Definition: header.h:37
void mape_config_file_destroy(MapeConfigFile *file)
Definition: configfile.c:56
MapeStatusbar * mape_statusbar_new(void)
Definition: statusbar.c:20
void mape_pre_view_destroy(MapePreView *view)
Definition: preview.c:47
GtkWidget * toolbar
Definition: window.h:34
MapeConfigFile * mape_config_file_new(const gchar *filename)
Definition: configfile.c:21
GtkAccelGroup * accel_group
Definition: header.h:24
void mape_config_file_set_entry(MapeConfigFile *file, const gchar *key, const gchar *value)
Definition: configfile.c:143
void mape_file_icon_set_destroy(MapeFileIconSet *set)
Definition: fileicon.c:122
void mape_edit_view_destroy(MapeEditView *view)
Definition: editview.c:505
MapeDiskView * disk_view
Definition: window.h:39
GtkWidget * menubar
Definition: header.h:26
GtkAction * file_new
Definition: header.h:30
Definition: configfile.h:22
MapeFileIconSet * mape_file_icon_set_new(GtkWidget *widget)
Definition: fileicon.c:109
GtkAction * edit_redo
Definition: header.h:38
void mape_preferences_from_config(MapePreferences *preferences, MapeConfigFile *config)
Definition: preferences.c:84
MapeStatusbar * statusbar
Definition: window.h:37
GtkWidget * bar
Definition: statusbar.h:23
GtkWidget * notebook
Definition: mattexview.h:27
void mape_pre_view_apply_preferences(MapePreView *view, MapePreferences *preferences)
Definition: preview.c:64
MapeFileIconSet * icon_set
Definition: window.h:24
GtkWidget * window
Definition: window.h:27
GtkWidget * bottom_hbox
Definition: window.h:31
GtkAction * help_about
Definition: header.h:42
gchar * last_path
Definition: window.h:25
MapePreView * mape_pre_view_new(MapeMatTexView *mat_tex, GError **error)
Definition: preview.c:21
MapeMatTexView * mat_tex_view
Definition: window.h:40

Here is the call graph for this function:

Here is the caller graph for this function: