[doc_tool] Moved executing of external programms from Model to FSHelper
[hsd_doku_tool.git] / src / View.cxx
1 ///////////////////////////////////////////////////////////////////////////
2 // Workfile: View.cxx
3 // Author: Daniel Giritzer <daniel@giritzer.eu>
4 // Date: 26.04.2018
5 // Description: Diese Klasse stellt eine platformunabhängige Visualisierung
6 //              des Models zur verfügung.
7 // Remarks: -
8 ///////////////////////////////////////////////////////////////////////////
9 #include "View.h"
10 #include "Author.h"
11 #include "Chapter.h"
12 #include "FSHelper.h"
13 #include <FL/Fl_File_Chooser.H>
14 #include <iostream>
15 #include <cstring>
16
17 View::View(ControllerIF::SPtr contr, ModelIF::SPtr model)
18 {
19     mController = contr;
20     mModel = model;
21     mEditorChapterLabel = nullptr;
22     subscribeSubject(mModel.get());
23 }
24
25 View::~View()
26 {
27     win_doctool->hide();
28     win_chapt_add->hide();
29     win_settings->hide();
30     win_auth_coord->hide();
31     win_depart_coord->hide();
32     win_log_view->hide();
33
34     // Ressourcen freigeben
35     Fl::delete_widget(win_doctool);
36     Fl::delete_widget(win_chapt_add);
37     Fl::delete_widget(win_settings);
38     Fl::delete_widget(win_auth_coord);
39     Fl::delete_widget(win_depart_coord);
40     Fl::delete_widget(win_log_view);
41     unsubscribeSubject(mModel.get());
42     delete[] mEditorChapterLabel;
43 }
44
45 void View::activate()
46 {
47
48     // Author
49     cb_author->activate();
50     ti_name->activate();
51     ti_est_time->activate();
52     ti_needed_time->activate();
53     btn_save_author->activate();
54     br_chapters->activate();
55
56     // Kapitel schnellauswahl
57     // + status
58     chb_finished->activate();
59     btn_next->activate();
60     pb_progress->activate();
61
62     // Dokumentname
63     ti_doc_name->activate();
64
65     // Abteilung
66     ti_department->activate();
67
68     // Rechtsklick Menüs
69     menu_editor->activate();
70     menu_author->activate();
71     menu_chapter->activate();
72     menu_department->activate();
73
74     // Kaptielmanipulation
75     btn_up_chpt->activate();
76     btn_down_chpt->activate();
77
78     // Menüleiste
79     menu_settings->activate();
80     menu_gen_templ->activate();
81     menu_out_dir->activate();
82
83     // Deaktiviere Laden menüs
84     menu_new_templ->deactivate();
85     menu_open_template->deactivate();
86 }
87
88 void View::updatedBySubject(Subject* s)
89 {
90     if(s == nullptr)
91         throw std::string("Nullpointer given as Subject!");
92
93
94     if(mModel->getChapterNames().size() != 0)
95     {
96         try
97         {
98
99             // Lösche bereits eingetragene Werte
100             br_chapters->clear();
101             cb_author->clear();
102
103             // Author einstellungen
104             for(auto curAuthor : mModel->getAuthorNames())
105                 cb_author->add(curAuthor.c_str());
106
107             cb_author->value(mModel->getAuthorNum());
108             ti_name->value(mModel->getSelAuthor()->GetName().c_str());
109             ti_est_time->value(mModel->getSelAuthor()->GetTimeEstimated().c_str());
110             ti_needed_time->value(mModel->getSelAuthor()->GetTimeSpent().c_str());
111
112             // Kapitel
113             for(auto curChapter : mModel->getChapterNames())
114                 br_chapters->add(curChapter.c_str());
115
116
117             br_chapters->select(mModel->getChapterNum());
118             chb_finished->value(mModel->getSelChapter()->GetDone());
119
120             // progressbar
121             pb_progress->maximum(mModel->getNumChapters());
122             pb_progress->value(mModel->getNumFinishedChapters());
123
124
125             // Aktiviere/Deaktiviere textfeld
126             // je nachdem ob kapitel als abgeschlossen
127             // markiert wurde
128             if(mModel->getSelChapter()->GetDone())
129             {
130                 tb_editor->clear_active();
131                 menu_editor->deactivate();
132             }
133             else
134             {
135                 tb_editor->activate();
136                 menu_editor->activate();
137             }
138
139
140             // Generate Button
141             if(mModel->getGenerateEnable())
142                 btn_generate->activate();
143             else
144                 btn_generate->clear_active();
145
146             // Kopiere C String für Label
147             if(mEditorChapterLabel!=nullptr) delete[] mEditorChapterLabel;
148             mEditorChapterLabel = new char [mModel->getSelChapter()->GetPrettyName().length()+1];
149             std::strcpy (mEditorChapterLabel, mModel->getSelChapter()->GetPrettyName().c_str());
150             tb_editor->label(mEditorChapterLabel);
151             win_doctool->label(mModel->getSubjectName().c_str());
152
153             // Quellcode Einstellungen
154             if(mModel->shouldAddSource() || mModel->shouldGenDoxygen())
155             {
156                 ot_src_dir->activate();
157                 btn_open_src_dir->activate();
158                 ot_src_dir->value(mModel->getSourceDir().c_str());
159             }
160             else
161             {
162                 ot_src_dir->deactivate();
163                 btn_open_src_dir->deactivate();
164                 ot_src_dir->value("");
165             }
166
167             // Titelblatt Einstellungen
168             if(mModel->shouldAddCoverSheet())
169             {
170                 ot_cov_sheet->activate();
171                 btn_open_cov_sheet->activate();
172                 ot_cov_sheet->value(mModel->getCovSheet().c_str());
173             }
174             else
175             {
176                 ot_cov_sheet->deactivate();
177                 btn_open_cov_sheet->deactivate();
178                 ot_cov_sheet->value("");
179             }
180
181             // Dokomenten Name
182             ti_doc_name->value(mModel->getDocName().c_str());
183
184             // Einstellungen Menü
185             chb_add_covpage->value(mModel->shouldAddCoverSheet());
186             chb_add_src->value(mModel->shouldAddSource());
187             chb_gen_doxygen->value(mModel->shouldGenDoxygen());
188             ti_doxy_chapt_name->value(mModel->getDoxygenName().c_str());
189             ti_source_chapt_name->value(mModel->getSourceChapterName().c_str());
190             ti_settings_subject_name->value(mModel->getSubjectName().c_str());
191             ti_location->value(mModel->getLocation().c_str());
192
193             // Koordinaten für in titelblatt eingefügte texte
194             vi_spenttime_x->value(mModel->getSelAuthor()->GetXTimeSpentCoordinate());
195             vi_spenttime_y->value(mModel->getSelAuthor()->GetYTimeSpentCoordinate());
196             vi_authname_x->value(mModel->getSelAuthor()->GetXNameCoordinate());
197             vi_authname_y->value(mModel->getSelAuthor()->GetYNameCoordinate());
198             vi_esttime_x->value(mModel->getSelAuthor()->GetXTimeEstimatedCoordinate());
199             vi_esttime_y->value(mModel->getSelAuthor()->GetYTimeEstimatedCoordinate());
200
201             vi_depart_x->value(mModel->getDepartmentX());
202             vi_depart_y->value(mModel->getDepartmentY());
203
204             ti_header_ext->value(mModel->getHeaderFileExtension().c_str());
205             ti_src_ext->value(mModel->getSourceFileExtension().c_str());
206
207             // Lade text in textbuffer von tb_editor
208             mTextBuf->text(mModel->getSelChapter()->GetText().c_str());
209
210             win_doctool->redraw();
211         }
212         // ----------- Exception Handling ------------
213         catch(std::string& e)
214         {
215             std::cerr << e << std::endl;
216             fl_alert(e.c_str()); //Textbox mit fehlermeldung
217         }
218     }
219 }
220
221 void View::show()
222 {
223     // Setze fenster style
224     Fl::scheme("gtk+");
225
226     // definiere callback funktionen
227     chb_finished->callback((Fl_Callback*)chb_finished_cb, (void*)(this));
228     btn_next->callback((Fl_Callback*)btn_next_cb, (void*)(this) );
229     btn_generate->callback((Fl_Callback*)btn_generate_cb, (void*)(this));
230     br_chapters->callback((Fl_Callback*)br_chapters_cb, (void*)(this));
231     menu_open_template->callback( (Fl_Callback*)menu_open_template_cb, (void*)(this));
232     menu_editor->callback((Fl_Callback*)menu_editor_cb, (void*)(this));
233     menu_chapter->callback((Fl_Callback*)menu_chapter_cb, (void*)(this));
234     menu_author->callback((Fl_Callback*)menu_author_cb, (void*)(this));
235     menu_department->callback((Fl_Callback*)menu_department_cb, (void*)(this));
236     btn_up_chpt->callback((Fl_Callback*)btn_up_chpt_cb, (void*)(this) );
237     btn_down_chpt->callback((Fl_Callback*)btn_down_chpt_cb, (void*)(this) );
238     btn_save_author->callback((Fl_Callback*)btn_save_author_cb, (void*)(this));
239     cb_author->callback((Fl_Callback*)cb_author_cb, (void*)(this));
240     btn_chapt_insert->callback((Fl_Callback*)btn_chapt_insert_cb, (void*)(this));
241     menu_out_dir->callback((Fl_Callback*)menu_out_dir_cb, (void*)(this));
242     btn_open_src_dir->callback((Fl_Callback*)ot_src_dir_cb, (void*)(this));
243     btn_open_cov_sheet->callback((Fl_Callback*)ot_cov_sheet_cb, (void*)(this));
244     win_doctool->callback((Fl_Callback*)win_close_cb, (void*)(this));
245     menu_exit->callback((Fl_Callback*)win_close_cb, (void*)(this));
246     btn_ok_author->callback((Fl_Callback*)btn_ok_author_cb, (void*)(this));
247     menu_settings->callback((Fl_Callback*)menu_settings_cb, (void*)(this));
248     btn_save_settings->callback((Fl_Callback*)btn_save_settings_cb, (void*)(this));
249     menu_new_templ->callback((Fl_Callback*)menu_new_templ_cb, (void*)(this));
250     menu_gen_templ->callback((Fl_Callback*)menu_gen_templ_cb, (void*)(this));
251     btn_ok_depart->callback((Fl_Callback*)btn_ok_depart_cb, (void*)(this));
252     ti_department->callback((Fl_Callback*)save_texts_cb, (void*)(this));
253     ti_doc_name->callback((Fl_Callback*)save_texts_cb, (void*)(this));
254
255
256     // Textfeld initialisieren
257     mTextBuf = new Fl_Text_Buffer();
258     tb_editor->buffer(mTextBuf);
259     tb_editor->clear_active();
260
261     mLogBuf = new Fl_Text_Buffer();
262     td_log_view->buffer(mLogBuf);
263
264     //widget einstellungen
265     br_chapters->type(FL_HOLD_BROWSER);
266     pb_progress->color(FL_WHITE, FL_DARK_GREEN);
267
268     //Rechtsklick menüs
269     menu_editor->type(Fl_Menu_Button::POPUP3);
270     menu_author->type(Fl_Menu_Button::POPUP3);
271     menu_chapter->type(Fl_Menu_Button::POPUP3);
272     menu_department->type(Fl_Menu_Button::POPUP3);
273
274     // Zeichne GUI
275     win_doctool->show();
276 }
277
278
279 void View::saveBuffer()
280 {
281     mController->setDocName(ti_doc_name->value());
282     mController->setDepartment(ti_department->value());
283     char* text = mTextBuf->text();
284     mController->saveWrittenText(text);
285     free(text); // Hier muss free verwendet werde, da mTextBuf->text() speicher mit malloc allokiert
286 }
287
288 // -------------------------------------------------
289 // ----------- FLTK Callback Funktionen ------------
290 // -------------------------------------------------
291 void View::chb_finished_cb(Fl_Check_Button* btn, void* view)
292 {
293     try
294     {
295         View* thisView = static_cast<View*>(view);
296         thisView->saveBuffer();
297         thisView->mController->setCurrentChapterFinished(thisView->chb_finished->value());
298     }
299     // ----------- Exception Handling ------------
300     catch(std::string& e)
301     {
302         std::cerr << e << std::endl;
303         fl_alert(e.c_str()); //Textbox mit fehlermeldung
304     }
305     catch(...)
306     {
307         fl_alert("Unknown error occured!");
308         std::cerr << "Unknown error occured!" << std::endl;
309     }
310 }
311
312 void View::btn_next_cb(Fl_Button* btn, void* view)
313 {
314
315     try
316     {
317         View* thisView = static_cast<View*>(view);
318         thisView->saveBuffer();
319         int selectedNum=1;
320         for (selectedNum=1 ; selectedNum<=thisView->br_chapters->size(); selectedNum++ )
321             if (thisView->br_chapters->selected(selectedNum)) break;
322
323
324         if(selectedNum < thisView->br_chapters->size())
325             thisView->mController->selectedChapter(selectedNum+1);
326     }
327     // ----------- Exception Handling ------------
328     catch(std::string& e)
329     {
330         std::cerr << e << std::endl;
331         fl_alert(e.c_str()); //Textbox mit fehlermeldung
332     }
333     catch(...)
334     {
335         fl_alert("Unknown error occured!");
336         std::cerr << "Unknown error occured!" << std::endl;
337     }
338 }
339
340
341 void View::btn_generate_cb(Fl_Button* btn, void* view)
342 {
343     try
344     {
345         View* thisView = static_cast<View*>(view);
346         thisView->saveBuffer();
347         thisView->win_doctool->deactivate();
348         thisView->win_doctool->cursor(FL_CURSOR_WAIT);
349
350
351         Fl::check();
352         thisView->mController->generateDocument();
353
354         if(thisView->mLogBuf->loadfile(std::string(thisView->mModel->getOutPath() + thisView->mModel->getLogFile()).c_str()) != 0)
355             throw std::string("Error opening Logfile!");
356
357         thisView->win_log_view->show();
358         thisView->win_doctool->activate();
359         thisView->win_doctool->cursor(FL_CURSOR_DEFAULT);
360     }
361     // ----------- Exception Handling ------------
362     catch(std::string& e)
363     {
364         std::cerr << e << std::endl;
365         fl_alert(e.c_str()); //Textbox mit fehlermeldung
366         View* thisView = static_cast<View*>(view);
367         thisView->win_doctool->activate();
368         thisView->win_doctool->cursor(FL_CURSOR_DEFAULT);
369     }
370     catch(...)
371     {
372         fl_alert("Unknown error occured!");
373         std::cerr << "Unknown error occured!" << std::endl;
374         View* thisView = static_cast<View*>(view);
375         thisView->win_doctool->activate();
376         thisView->win_doctool->cursor(FL_CURSOR_DEFAULT);
377     }
378 }
379
380
381 void View::br_chapters_cb(Fl_Browser* br, void* view)
382 {
383     try
384     {
385         View* thisView = static_cast<View*>(view);
386
387         thisView->saveBuffer();
388
389         int selectedNum=1;
390         for (selectedNum =1 ; selectedNum<thisView->br_chapters->size(); selectedNum++ )
391             if (thisView->br_chapters->selected(selectedNum)) break;
392
393         thisView->mController->selectedChapter(selectedNum);
394     }
395     // ----------- Exception Handling ------------
396     catch(std::string& e)
397     {
398         std::cerr << e << std::endl;
399         fl_alert(e.c_str()); //Textbox mit fehlermeldung
400     }
401     catch(...)
402     {
403         fl_alert("Unknown error occured!");
404         std::cerr << "Unknown error occured!" << std::endl;
405     }
406 }
407
408 void View::menu_open_template_cb(Fl_Menu_* menu, void* view)
409 {
410     try
411     {
412         View* thisView = static_cast<View*>(view);
413
414         // File browser dialog
415         Fl_File_Chooser chooser(thisView->mModel->getConfDir().c_str(),
416                                 "Template Files (*.xml)",
417                                 Fl_File_Chooser::SINGLE,
418                                 "Select Template...");
419         chooser.show();
420
421         // Warte bis benutzer datei ausgewählt hat
422         while(chooser.shown())
423             Fl::wait();
424
425         if ( chooser.value() != nullptr )
426         {
427             thisView->mController->setTemplate(chooser.value());
428
429             while(thisView->mModel->getOutPath().empty())
430                 thisView->menu_out_dir->do_callback(nullptr);
431
432             thisView->activate();
433         }
434     }
435     // ----------- Exception Handling ------------
436     catch(std::string& e)
437     {
438         std::cerr << e << std::endl;
439         fl_alert(e.c_str()); //Textbox mit fehlermeldung
440     }
441     catch(...)
442     {
443         fl_alert("Illegal config file!");
444         std::cerr << "Illegal config file!" << std::endl;
445     }
446 }
447
448 void View::menu_editor_cb(Fl_Menu_* menu, void* view)
449 {
450     try
451     {
452         View* thisView = static_cast<View*>(view);
453
454         // Ermittle gewähltes menü
455         const char *text = menu->text();
456         if ( !text ) return;
457         if ( strcmp(text, "h1") == 0 )
458         {
459             thisView->tb_editor->insert("\\section{}");
460         }
461         if ( strcmp(text, "h2") == 0 )
462         {
463             thisView->tb_editor->insert("\\subsection{}");
464         }
465         if ( strcmp(text, "h3") == 0 )
466         {
467             thisView->tb_editor->insert("\\subsubsection{}");
468         }
469         if ( strcmp(text, "List") == 0 )
470         {
471             thisView->tb_editor->insert("\\begin{itemize}\n\\item One\n\\item Two\n\\end{itemize}");
472         }
473     }
474     // ----------- Exception Handling ------------
475     catch(std::string& e)
476     {
477         std::cerr << e << std::endl;
478         fl_alert(e.c_str()); //Textbox mit fehlermeldung
479     }
480     catch(...)
481     {
482         fl_alert("Unknown error occured!");
483         std::cerr << "Unknown error occured!" << std::endl;
484     }
485 }
486
487 void View::menu_author_cb(Fl_Menu_* menu, void* view)
488 {
489     try
490     {
491         View* thisView = static_cast<View*>(view);
492
493         // Ermittle gewähltes menü
494         const char *text = menu->text();
495         if ( !text ) return;
496         if ( strcmp(text, "Add author") == 0 )
497         {
498             thisView->mController->addAuthor();
499         }
500         if ( strcmp(text, "Remove author") == 0 )
501         {
502             thisView->mController->remAuthor();
503         }
504         if ( strcmp(text, "Edit coordinates") == 0 )
505         {
506             if(!thisView->mModel->shouldAddCoverSheet())
507                 throw std::string("No need to set coordinates without cover page!");
508
509             thisView->win_auth_coord->show();
510         }
511     }
512     // ----------- Exception Handling ------------
513     catch(std::string& e)
514     {
515         std::cerr << e << std::endl;
516         fl_alert(e.c_str()); //Textbox mit fehlermeldung
517     }
518     catch(...)
519     {
520         fl_alert("Unknown error occured!");
521         std::cerr << "Unknown error occured!" << std::endl;
522     }
523 }
524
525 void View::menu_chapter_cb(Fl_Menu_* menu, void* view)
526 {
527     try
528     {
529         View* thisView = static_cast<View*>(view);
530
531         // Ermittle gewähltes menü
532         const char *text = menu->text();
533         if ( !text ) return;
534         if ( strcmp(text, "Add chapter") == 0 )
535         {
536             thisView->win_chapt_add->show();
537         }
538         if ( strcmp(text, "Remove chapter") == 0 )
539         {
540             thisView->mController->remChapter();
541         }
542     }
543     // ----------- Exception Handling ------------
544     catch(std::string& e)
545     {
546         std::cerr << e << std::endl;
547         fl_alert(e.c_str()); //Textbox mit fehlermeldung
548     }
549     catch(...)
550     {
551         fl_alert("Unknown error occured!");
552         std::cerr << "Unknown error occured!" << std::endl;
553     }
554 }
555
556 void View::btn_up_chpt_cb(Fl_Button* btn, void* view)
557 {
558     try
559     {
560         View* thisView = static_cast<View*>(view);
561         thisView->saveBuffer();
562         thisView->mController->upChapter();
563     }
564     // ----------- Exception Handling ------------
565     catch(std::string& e)
566     {
567         std::cerr << e << std::endl;
568         fl_alert(e.c_str()); //Textbox mit fehlermeldung
569     }
570     catch(...)
571     {
572         fl_alert("Unknown error occured!");
573         std::cerr << "Unknown error occured!" << std::endl;
574     }
575 }
576
577 void View::btn_down_chpt_cb(Fl_Button* btn, void* view)
578 {
579     try
580     {
581         View* thisView = static_cast<View*>(view);
582         thisView->saveBuffer();
583         thisView->mController->downChapter();
584     }
585     // ----------- Exception Handling ------------
586     catch(std::string& e)
587     {
588         std::cerr << e << std::endl;
589         fl_alert(e.c_str()); //Textbox mit fehlermeldung
590     }
591     catch(...)
592     {
593         fl_alert("Unknown error occured!");
594         std::cerr << "Unknown error occured!" << std::endl;
595     }
596 }
597
598 void View::btn_save_author_cb(Fl_Button* btn, void* view)
599 {
600     try
601     {
602         View* thisView = static_cast<View*>(view);
603         thisView->mController->saveAuthorName(thisView->ti_name->value());
604         thisView->mController->saveAuthorEstTime(thisView->ti_est_time->value());
605         thisView->mController->saveAuthorSpentTime(thisView->ti_needed_time->value());
606         thisView->mController->forceNotify();
607     }
608     // ----------- Exception Handling ------------
609     catch(std::string& e)
610     {
611         std::cerr << e << std::endl;
612         fl_alert(e.c_str()); //Textbox mit fehlermeldung
613     }
614     catch(...)
615     {
616         fl_alert("Unknown error occured!");
617         std::cerr << "Unknown error occured!" << std::endl;
618     }
619 }
620
621 void View::cb_author_cb(Fl_Choice* cb, void* view)
622 {
623     try
624     {
625         View* thisView = static_cast<View*>(view);
626         thisView->mController->selectedAuthor(thisView->cb_author->value());
627     }
628     // ----------- Exception Handling ------------
629     catch(std::string& e)
630     {
631         std::cerr << e << std::endl;
632         fl_alert(e.c_str()); //Textbox mit fehlermeldung
633     }
634     catch(...)
635     {
636         fl_alert("Unknown error occured!");
637         std::cerr << "Unknown error occured!" << std::endl;
638     }
639 }
640
641 void View::btn_chapt_insert_cb(Fl_Button* btn, void* view)
642 {
643     try
644     {
645         View* thisView = static_cast<View*>(view);
646
647         std::string chaptName = thisView->add_chapt_chaptname->value();
648         std::string fileName = thisView->add_chapt_fname->value();
649
650
651         if(!thisView->mFSHelp.validFileName(fileName))
652             throw std::string("Filename contains illegal characters.");
653
654         if(chaptName.empty())
655             throw std::string("Enter a chapter name.");
656
657         if(fileName.empty())
658             throw std::string("Enter a filename.");
659
660
661         thisView->mController->addChapter(chaptName, fileName);
662         thisView->add_chapt_chaptname->value("");
663         thisView->add_chapt_fname->value("");
664         thisView->win_chapt_add->hide();
665     }
666     // ----------- Exception Handling ------------
667     catch(std::string& e)
668     {
669         std::cerr << e << std::endl;
670         fl_alert(e.c_str()); //Textbox mit fehlermeldung
671     }
672     catch(...)
673     {
674         fl_alert("Unknown error occured!");
675         std::cerr << "Unknown error occured!" << std::endl;
676     }
677 }
678
679 void View::menu_out_dir_cb(Fl_Menu_* menu, void* view)
680 {
681     try
682     {
683         View* thisView = static_cast<View*>(view);
684
685         // File browser dialog
686         Fl_File_Chooser chooser(".",
687                                 "*",
688                                 Fl_File_Chooser::DIRECTORY,
689                                 "Select output directory...");
690         chooser.newButton->activate();
691         chooser.show();
692
693         // Warte bis benutzer datei ausgewählt hat
694         while(chooser.shown())
695             Fl::wait();
696
697
698
699         // Abbruch gedrückt
700         if ( chooser.value() != nullptr )
701         {
702             thisView->mController->setOutDir(chooser.value());
703         }
704     }
705     // ----------- Exception Handling ------------
706     catch(std::string& e)
707     {
708         std::cerr << e << std::endl;
709         fl_alert(e.c_str()); //Textbox mit fehlermeldung
710     }
711     catch(...)
712     {
713         fl_alert("Unknown error occured!");
714         std::cerr << "Unknown error occured!" << std::endl;
715     }
716 }
717
718 void View::ot_src_dir_cb(Fl_Output *out, void* view)
719 {
720     try
721     {
722         View* thisView = static_cast<View*>(view);
723         // File browser dialog
724         Fl_File_Chooser chooser(".",
725                                 "*",
726                                 Fl_File_Chooser::DIRECTORY,
727                                 "Select source directory...");
728         chooser.show();
729
730         // Warte bis benutzer datei ausgewählt hat
731         while(chooser.shown())
732             Fl::wait();
733
734         // Abbruch gedrückt
735         if ( chooser.value() != nullptr )
736         {
737             thisView->mController->saveSourceDir(chooser.value());
738         }
739     }
740     // ----------- Exception Handling ------------
741     catch(std::string& e)
742     {
743         std::cerr << e << std::endl;
744         fl_alert(e.c_str()); //Textbox mit fehlermeldung
745     }
746     catch(...)
747     {
748         fl_alert("Unknown error occured!");
749         std::cerr << "Unknown error occured!" << std::endl;
750     }
751 }
752
753
754 void View::ot_cov_sheet_cb(Fl_Output *out, void* view)
755 {
756     try
757     {
758         View* thisView = static_cast<View*>(view);
759
760         // File browser dialog
761         Fl_File_Chooser chooser(".",
762                                 "Cover Sheet (*.pdf)",
763                                 Fl_File_Chooser::SINGLE,
764                                 "Select cover sheet...");
765         chooser.show();
766
767         // Warte bis benutzer datei ausgewählt hat
768         while(chooser.shown())
769             Fl::wait();
770
771         // Abbruch gedrückt
772         if ( chooser.value() != nullptr )
773         {
774             thisView->mController->saveCoverSheet(chooser.value());
775         }
776     }
777     // ----------- Exception Handling ------------
778     catch(std::string& e)
779     {
780         std::cerr << e << std::endl;
781         fl_alert(e.c_str()); //Textbox mit fehlermeldung
782     }
783     catch(...)
784     {
785         fl_alert("Unknown error occured!");
786         std::cerr << "Unknown error occured!" << std::endl;
787     }
788 }
789
790 void View::win_close_cb(Fl_Window* win, void* view)
791 {
792     try
793     {
794         View* thisView = static_cast<View*>(view);
795
796         switch ( fl_choice("Do you really want to exit?", "No", "Yes", 0) )
797         {
798         case 0:
799             ;
800             break;
801         case 1:
802             thisView->mController->saveAllWrittenTextsToFiles();
803             thisView->win_chapt_add->hide();
804             exit(0);
805             break;
806         default:
807             break;
808         }
809     }
810     // ----------- Exception Handling ------------
811     catch(std::string& e)
812     {
813         std::cerr << e << std::endl;
814         fl_alert(e.c_str()); //Textbox mit fehlermeldung
815     }
816     catch(...)
817     {
818         fl_alert("Unknown error occured!");
819         std::cerr << "Unknown error occured!" << std::endl;
820     }
821 }
822
823 void View::btn_ok_author_cb(Fl_Button* btn, void* view)
824 {
825     try
826     {
827         View* thisView = static_cast<View*>(view);
828         thisView->mController->saveAuthorEstTimeCoordiantes(thisView->vi_esttime_x->value(),thisView->vi_esttime_y->value());
829         thisView->mController->saveAuthorNameCoordinates(thisView->vi_authname_x->value(),thisView->vi_authname_y->value());
830         thisView->mController->saveAuthorSpentTimeCoordinates(thisView->vi_spenttime_x->value(),thisView->vi_spenttime_y->value());
831         thisView->win_auth_coord->hide();
832     }
833     // ----------- Exception Handling ------------
834     catch(std::string& e)
835     {
836         std::cerr << e << std::endl;
837         fl_alert(e.c_str()); //Textbox mit fehlermeldung
838     }
839     catch(...)
840     {
841         fl_alert("Unknown error occured!");
842         std::cerr << "Unknown error occured!" << std::endl;
843     }
844 }
845
846 void View::menu_settings_cb(Fl_Menu_* menu, void* view)
847 {
848     try
849     {
850         View* thisView = static_cast<View*>(view);
851         thisView->win_settings->show();
852     }
853     // ----------- Exception Handling ------------
854     catch(std::string& e)
855     {
856         std::cerr << e << std::endl;
857         fl_alert(e.c_str()); //Textbox mit fehlermeldung
858     }
859     catch(...)
860     {
861         fl_alert("Unknown error occured!");
862         std::cerr << "Unknown error occured!" << std::endl;
863     }
864 }
865
866 void View::btn_save_settings_cb(Fl_Button* btn, void* view)
867 {
868     try
869     {
870         View* thisView = static_cast<View*>(view);
871
872         std::string sourceChaptName = thisView->ti_source_chapt_name->value();
873         std::string doxyChaptName = thisView->ti_doxy_chapt_name->value();
874         std::string subjectName = thisView->ti_settings_subject_name->value();
875         std::string location = thisView->ti_location->value();
876         std::string header = thisView->ti_header_ext->value();
877         std::string source = thisView->ti_src_ext->value();
878
879         if(thisView->chb_add_src->value() && sourceChaptName.empty())
880             throw std::string("Please enter a source chapter name.");
881
882         if(thisView->chb_gen_doxygen->value() && doxyChaptName.empty())
883             throw std::string("Please enter a doxygen documentation chapter name.");
884
885         if(header.empty())
886             throw std::string("Please enter a header file extension.");
887
888         if(source.empty())
889             throw std::string("Please enter a source file extension.");
890
891         if(subjectName.empty())
892             throw std::string("Please enter a subject name.");
893
894         if(location.empty())
895             throw std::string("Please enter a location.");
896
897         thisView->mController->setAddCoverSheet(thisView->chb_add_covpage->value());
898         thisView->mController->setAddSource(thisView->chb_add_src->value());
899         thisView->mController->setGenDoxygen(thisView->chb_gen_doxygen->value());
900
901         thisView->mController->setSourceChapterName(sourceChaptName);
902         thisView->mController->setDoxygenName(doxyChaptName);
903         thisView->mController->setSubjectName(subjectName);
904         thisView->mController->setLocation(location);
905
906         thisView->mController->setFileExtensions(header, source);
907
908
909         thisView->win_settings->hide();
910         thisView->mController->forceNotify();
911
912     }
913     // ----------- Exception Handling ------------
914     catch(std::string& e)
915     {
916         std::cerr << e << std::endl;
917         fl_alert(e.c_str()); //Textbox mit fehlermeldung
918     }
919     catch(...)
920     {
921         fl_alert("Unknown error occured!");
922         std::cerr << "Unknown error occured!" << std::endl;
923     }
924 }
925
926 void View::menu_new_templ_cb(Fl_Menu_* menu, void* view)
927 {
928     try
929     {
930         View* thisView = static_cast<View*>(view);
931         thisView->menu_out_dir->do_callback(nullptr);
932
933         if(thisView->mModel->getOutPath().empty())
934             throw std::string("An output directory has to be set!");
935
936         menu_settings->do_callback(nullptr);
937
938         // Warte bis benutzer einstellungen eingegeben hat
939         while(thisView->win_settings->shown())
940             Fl::wait();
941
942         std::string subjName = thisView->ti_settings_subject_name->value();
943         if(!subjName.empty())
944         {
945             thisView->activate();
946             thisView->mController->startNewTemplate(subjName);
947         }
948     }
949     // ----------- Exception Handling ------------
950     catch(std::string& e)
951     {
952         std::cerr << e << std::endl;
953         fl_alert(e.c_str()); //Textbox mit fehlermeldung
954     }
955     catch(...)
956     {
957         fl_alert("Unknown error occured!");
958         std::cerr << "Unknown error occured!" << std::endl;
959     }
960 }
961
962 void View::menu_gen_templ_cb(Fl_Menu_* menu, void* view)
963 {
964     try
965     {
966         View* thisView = static_cast<View*>(view);
967         thisView->mController->saveAsTemplate();
968         fl_alert(std::string("Successfully saved template to: " + thisView->mModel->getOutPath()).c_str());
969     }
970     // ----------- Exception Handling ------------
971     catch(std::string& e)
972     {
973         std::cerr << e << std::endl;
974         fl_alert(e.c_str()); //Textbox mit fehlermeldung
975     }
976     catch(...)
977     {
978         fl_alert("Unknown error occured!");
979         std::cerr << "Unknown error occured!" << std::endl;
980     }
981 }
982
983 void View::menu_department_cb(Fl_Menu_* menu, void* view)
984 {
985     try
986     {
987         View* thisView = static_cast<View*>(view);
988
989         // Ermittle gewähltes menü
990         const char *text = menu->text();
991         if ( !text ) return;
992         if ( strcmp(text, "Edit coordinates") == 0 )
993         {
994             if(!thisView->mModel->shouldAddCoverSheet())
995                 throw std::string("No need to set coordinates without cover page!");
996
997             thisView->win_depart_coord->show();
998         }
999     }
1000     // ----------- Exception Handling ------------
1001     catch(std::string& e)
1002     {
1003         std::cerr << e << std::endl;
1004         fl_alert(e.c_str()); //Textbox mit fehlermeldung
1005     }
1006     catch(...)
1007     {
1008         fl_alert("Unknown error occured!");
1009         std::cerr << "Unknown error occured!" << std::endl;
1010     }
1011 }
1012
1013 void View::btn_ok_depart_cb(Fl_Button* cb, void* view)
1014 {
1015     try
1016     {
1017         View* thisView = static_cast<View*>(view);
1018         thisView->mController->setDepartmentCoordiantes(thisView->vi_depart_x->value(),thisView->vi_depart_y->value());
1019         thisView->win_depart_coord->hide();
1020     }
1021     // ----------- Exception Handling ------------
1022     catch(std::string& e)
1023     {
1024         std::cerr << e << std::endl;
1025         fl_alert(e.c_str()); //Textbox mit fehlermeldung
1026     }
1027     catch(...)
1028     {
1029         fl_alert("Unknown error occured!");
1030         std::cerr << "Unknown error occured!" << std::endl;
1031     }
1032 }
1033
1034 void View::save_texts_cb(Fl_Input * in, void* view)
1035 {
1036     try
1037     {
1038         View* thisView = static_cast<View*>(view);
1039         thisView->saveBuffer();
1040         thisView->mController->forceNotify();
1041     }
1042     // ----------- Exception Handling ------------
1043     catch(std::string& e)
1044     {
1045         std::cerr << e << std::endl;
1046         fl_alert(e.c_str()); //Textbox mit fehlermeldung
1047     }
1048     catch(...)
1049     {
1050         fl_alert("Unknown error occured!");
1051         std::cerr << "Unknown error occured!" << std::endl;
1052     }
1053 }