]> git.lyx.org Git - lyx.git/blob - src/frontends/kde/FormDocument.C
Move LaTeX and VC logs to GUI-I on xforms
[lyx.git] / src / frontends / kde / FormDocument.C
1 /*
2  * FormDocument.C
3  * (C) 2001 LyX Team
4  * John Levon, moz@compsoc.man.ac.uk
5  */
6
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15
16 #include <config.h>
17
18 #include "docdlg.h"
19
20 #include "Dialogs.h"
21 #include "FormDocument.h"
22
23 #include "CutAndPaste.h" 
24 #include "buffer.h"
25 #include "Liason.h"
26
27 #include "QtLyXView.h"
28 #include "debug.h"
29
30 #ifdef CXX_WORKING_NAMESPACES
31 using Liason::setMinibuffer;
32 #endif
33
34 FormDocument::FormDocument(LyXView *v, Dialogs *d)
35         : dialog_(0), lv_(v), d_(d), h_(0)
36 {
37         // let the dialog be shown
38         // This is a permanent connection so we won't bother
39         // storing a copy because we won't be disconnecting.
40         d->showLayoutDocument.connect(slot(this, &FormDocument::show));
41 }
42
43 FormDocument::~FormDocument()
44 {
45         delete dialog_;
46 }
47
48 void FormDocument::update(bool switched)
49 {
50         if (switched) {
51                 hide();
52                 return;
53         }
54         
55         if (!lv_->view()->available())
56                 return;
57
58         Buffer *buf = lv_->buffer();
59
60         if (readonly!=buf->isReadonly()) {
61                 readonly = buf->isReadonly();
62                 dialog_->setReadOnly(readonly);
63         }
64
65         dialog_->setFromParams(buf->params);
66 }
67
68 void FormDocument::apply()
69 {
70         if (readonly)
71                 return;
72         
73         if (!lv_->view()->available())
74                 return;
75
76         BufferParams & params = lv_->buffer()->params;
77
78         if (dialog_->updateParams(params))
79                 lv_->view()->redoCurrentBuffer();
80
81         lv_->buffer()->markDirty();
82         setMinibuffer(lv_, _("Document layout set"));
83 }
84
85 void FormDocument::show()
86 {
87         if (!dialog_)
88                 dialog_ = new DocDialog(this, 0, _("LyX: Document Options"), false);
89
90         if (!dialog_->isVisible())
91                 h_ = d_->hideBufferDependent.connect(slot(this, &FormDocument::hide));
92
93
94         dialog_->raise();
95         dialog_->setActiveWindow();
96         update();
97  
98         dialog_->show();
99 }
100
101 bool FormDocument::changeClass(BufferParams & params, int new_class)
102 {
103         if (textclasslist.Load(new_class)) {
104                 // successfully loaded
105                 setMinibuffer(lv_, _("Converting document to new document class..."));
106
107                 CutAndPaste cap;
108                 int ret = cap.SwitchLayoutsBetweenClasses(
109                         params.textclass, new_class,
110                         lv_->buffer()->paragraph);
111                 if (ret) {
112                         /* FIXME: error message */
113                 }
114
115                 params.textclass = new_class;
116         } else
117                 return false;
118
119         return true;
120 }
121  
122 void FormDocument::close()
123 {
124         h_.disconnect();
125 }
126
127 void FormDocument::hide()
128 {
129         dialog_->hide();
130         close();
131 }