author | paule <paule> | 2007-01-13 07:34:07 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-13 07:34:07 (UTC) |
commit | b1075202780c1d807c9d9f5286a2ffa7714bae51 (patch) (unidiff) | |
tree | 6d37dc6d7f7b45d39f7f379c8654fd085d63e895 | |
parent | ee43ea083b2abea078507677ee30c7af88d248c4 (diff) | |
download | opie-b1075202780c1d807c9d9f5286a2ffa7714bae51.zip opie-b1075202780c1d807c9d9f5286a2ffa7714bae51.tar.gz opie-b1075202780c1d807c9d9f5286a2ffa7714bae51.tar.bz2 |
Prompt user to save on closing a modified file; prompt user on Save As if specified file already exists; change tab to show filename when saving a new file
-rw-r--r-- | noncore/apps/tinykate/mainwindow/tinykate.cpp | 136 | ||||
-rw-r--r-- | noncore/apps/tinykate/mainwindow/tinykate.h | 5 |
2 files changed, 116 insertions, 25 deletions
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.cpp b/noncore/apps/tinykate/mainwindow/tinykate.cpp index b1b88e9..e87464e 100644 --- a/noncore/apps/tinykate/mainwindow/tinykate.cpp +++ b/noncore/apps/tinykate/mainwindow/tinykate.cpp | |||
@@ -1,341 +1,427 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.cpp | 2 | tinykate.cpp |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free softwaSre; you can redistribute it and/or modify * | 11 | * This program is free softwaSre; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #include "tinykate.h" | 18 | #include "tinykate.h" |
19 | 19 | ||
20 | #include "katedocument.h" | 20 | #include "katedocument.h" |
21 | #include "kglobal.h" | 21 | #include "kglobal.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <opie2/odebug.h> | 24 | #include <opie2/odebug.h> |
25 | #include <opie2/ofiledialog.h> | 25 | #include <opie2/ofiledialog.h> |
26 | #include <opie2/oresource.h> | 26 | #include <opie2/oresource.h> |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | 28 | ||
29 | /* QT */ | 29 | /* QT */ |
30 | #include <qaction.h> | 30 | #include <qaction.h> |
31 | #include <qtoolbutton.h> | 31 | #include <qtoolbutton.h> |
32 | #include <qmenubar.h> | 32 | #include <qmenubar.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | 34 | ||
35 | 35 | ||
36 | using namespace Opie::Ui; | 36 | using namespace Opie::Ui; |
37 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 37 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : |
38 | QMainWindow( parent, name, f ) | 38 | QMainWindow( parent, name, f ) |
39 | { | 39 | { |
40 | shutDown=false; | 40 | shutDown=false; |
41 | nextUnnamed=0; | 41 | nextUnnamed=0; |
42 | currentView=0; | 42 | currentView=0; |
43 | viewCount=0; | 43 | viewCount=0; |
44 | setCaption(tr("TinyKATE")); | 44 | setCaption(tr("TinyKATE")); |
45 | KGlobal::setAppName("TinyKATE"); | 45 | KGlobal::setAppName("TinyKATE"); |
46 | 46 | ||
47 | QMenuBar *mb = new QMenuBar( this ); | 47 | QMenuBar *mb = new QMenuBar( this ); |
48 | mb->setMargin( 0 ); | 48 | mb->setMargin( 0 ); |
49 | 49 | ||
50 | tabwidget=new OTabWidget(this); | 50 | tabwidget=new OTabWidget(this); |
51 | setCentralWidget(tabwidget); | 51 | setCentralWidget(tabwidget); |
52 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); | 52 | connect(tabwidget,SIGNAL(currentChanged(QWidget*)),this,SLOT(slotCurrentChanged(QWidget*))); |
53 | 53 | ||
54 | //FILE ACTIONS | 54 | //FILE ACTIONS |
55 | QPopupMenu *popup = new QPopupMenu( this ); | 55 | QPopupMenu *popup = new QPopupMenu( this ); |
56 | 56 | ||
57 | // Action for creating a new document | 57 | // Action for creating a new document |
58 | QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 58 | QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
59 | QString::null, 0, this, 0 ); | 59 | QString::null, 0, this, 0 ); |
60 | a->addTo( popup ); | 60 | a->addTo( popup ); |
61 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); | 61 | connect(a, SIGNAL(activated()), this, SLOT(slotNew())); |
62 | 62 | ||
63 | // Action for opening an exisiting document | 63 | // Action for opening an exisiting document |
64 | a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ), | 64 | a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ), |
65 | QString::null, 0, this, 0 ); | 65 | QString::null, 0, this, 0 ); |
66 | a->addTo(popup); | 66 | a->addTo(popup); |
67 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); | 67 | connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); |
68 | 68 | ||
69 | 69 | ||
70 | // Action for saving document | 70 | // Action for saving document |
71 | a = new QAction( tr( "Save" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), | 71 | a = new QAction( tr( "Save" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), |
72 | QString::null, 0, this, 0 ); | 72 | QString::null, 0, this, 0 ); |
73 | a->addTo(popup); | 73 | a->addTo(popup); |
74 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); | 74 | connect(a, SIGNAL(activated()), this, SLOT(slotSave())); |
75 | 75 | ||
76 | // Action for saving document to a new name | 76 | // Action for saving document to a new name |
77 | a = new QAction( tr( "Save As" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), | 77 | a = new QAction( tr( "Save As" ), Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), |
78 | QString::null, 0, this, 0 ); | 78 | QString::null, 0, this, 0 ); |
79 | a->addTo(popup); | 79 | a->addTo(popup); |
80 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); | 80 | connect(a, SIGNAL(activated()), this, SLOT(slotSaveAs())); |
81 | 81 | ||
82 | // Action for closing the currently active document | 82 | // Action for closing the currently active document |
83 | a = new QAction( tr( "Close" ), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ), | 83 | a = new QAction( tr( "Close" ), Opie::Core::OResource::loadPixmap( "quit_icon", Opie::Core::OResource::SmallIcon ), |
84 | QString::null, 0, this, 0 ); | 84 | QString::null, 0, this, 0 ); |
85 | a->addTo(popup); | 85 | a->addTo(popup); |
86 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); | 86 | connect(a, SIGNAL(activated()), this, SLOT(slotClose())); |
87 | 87 | ||
88 | 88 | ||
89 | mb->insertItem(tr("File"),popup); | 89 | mb->insertItem(tr("File"),popup); |
90 | 90 | ||
91 | //EDIT ACTIONS | 91 | //EDIT ACTIONS |
92 | popup = new QPopupMenu( this ); | 92 | popup = new QPopupMenu( this ); |
93 | bool useBigIcon = qApp->desktop()->size().width() > 330; | 93 | bool useBigIcon = qApp->desktop()->size().width() > 330; |
94 | 94 | ||
95 | // Action for cutting text | 95 | // Action for cutting text |
96 | editCut = new QToolButton( 0 ); | 96 | editCut = new QToolButton( 0 ); |
97 | editCut->setUsesBigPixmap( useBigIcon ); | 97 | editCut->setUsesBigPixmap( useBigIcon ); |
98 | editCut->setAutoRaise( true ); | 98 | editCut->setAutoRaise( true ); |
99 | editCut->setIconSet( Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ) ); | 99 | editCut->setIconSet( Opie::Core::OResource::loadPixmap( "cut", Opie::Core::OResource::SmallIcon ) ); |
100 | 100 | ||
101 | // Action for Copying text | 101 | // Action for Copying text |
102 | editCopy = new QToolButton( 0 ); | 102 | editCopy = new QToolButton( 0 ); |
103 | editCopy->setUsesBigPixmap( useBigIcon ); | 103 | editCopy->setUsesBigPixmap( useBigIcon ); |
104 | editCopy->setAutoRaise( true ); | 104 | editCopy->setAutoRaise( true ); |
105 | editCopy->setIconSet( Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ) ); | 105 | editCopy->setIconSet( Opie::Core::OResource::loadPixmap( "copy", Opie::Core::OResource::SmallIcon ) ); |
106 | 106 | ||
107 | // Action for pasting text | 107 | // Action for pasting text |
108 | editPaste = new QToolButton( 0 ); | 108 | editPaste = new QToolButton( 0 ); |
109 | editPaste->setUsesBigPixmap( useBigIcon ); | 109 | editPaste->setUsesBigPixmap( useBigIcon ); |
110 | editPaste->setAutoRaise( true ); | 110 | editPaste->setAutoRaise( true ); |
111 | editPaste->setIconSet( Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ) ); | 111 | editPaste->setIconSet( Opie::Core::OResource::loadPixmap( "paste", Opie::Core::OResource::SmallIcon ) ); |
112 | 112 | ||
113 | // Action for finding text | 113 | // Action for finding text |
114 | editFind = new QAction( tr( "Find..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), | 114 | editFind = new QAction( tr( "Find..." ), Opie::Core::OResource::loadPixmap( "find", Opie::Core::OResource::SmallIcon ), |
115 | QString::null, 0, this, 0 ); | 115 | QString::null, 0, this, 0 ); |
116 | editFind->addTo(popup); | 116 | editFind->addTo(popup); |
117 | 117 | ||
118 | // Action for replacing text | 118 | // Action for replacing text |
119 | editReplace = new QAction( tr( "Replace..." ), QString::null, 0, this, 0 ); | 119 | editReplace = new QAction( tr( "Replace..." ), QString::null, 0, this, 0 ); |
120 | editReplace->addTo(popup); | 120 | editReplace->addTo(popup); |
121 | 121 | ||
122 | // Action for going to a specific line | 122 | // Action for going to a specific line |
123 | editGotoLine = new QAction( tr( "Goto Line..." ), QString::null, 0, this, 0 ); | 123 | editGotoLine = new QAction( tr( "Goto Line..." ), QString::null, 0, this, 0 ); |
124 | editGotoLine->addTo(popup); | 124 | editGotoLine->addTo(popup); |
125 | 125 | ||
126 | // Action for undo | 126 | // Action for undo |
127 | editUndo = new QToolButton( 0 ); | 127 | editUndo = new QToolButton( 0 ); |
128 | editUndo->setUsesBigPixmap( useBigIcon ); | 128 | editUndo->setUsesBigPixmap( useBigIcon ); |
129 | editUndo->setAutoRaise( true ); | 129 | editUndo->setAutoRaise( true ); |
130 | editUndo->setIconSet( Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ) ); | 130 | editUndo->setIconSet( Opie::Core::OResource::loadPixmap( "undo", Opie::Core::OResource::SmallIcon ) ); |
131 | 131 | ||
132 | // Action for redo | 132 | // Action for redo |
133 | editRedo = new QToolButton( 0 ); | 133 | editRedo = new QToolButton( 0 ); |
134 | editRedo->setUsesBigPixmap( useBigIcon ); | 134 | editRedo->setUsesBigPixmap( useBigIcon ); |
135 | editRedo->setAutoRaise( true ); | 135 | editRedo->setAutoRaise( true ); |
136 | editRedo->setIconSet( Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ) ); | 136 | editRedo->setIconSet( Opie::Core::OResource::loadPixmap( "redo", Opie::Core::OResource::SmallIcon ) ); |
137 | 137 | ||
138 | mb->insertItem(tr("Edit"),popup); | 138 | mb->insertItem(tr("Edit"),popup); |
139 | 139 | ||
140 | //VIEW ACITONS | 140 | //VIEW ACITONS |
141 | popup = new QPopupMenu( this ); | 141 | popup = new QPopupMenu( this ); |
142 | 142 | ||
143 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); | 143 | viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); |
144 | viewIncFontSizes->addTo( popup ); | 144 | viewIncFontSizes->addTo( popup ); |
145 | 145 | ||
146 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); | 146 | viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); |
147 | viewDecFontSizes->addTo( popup ); | 147 | viewDecFontSizes->addTo( popup ); |
148 | 148 | ||
149 | mb->insertItem(tr("View"),popup); | 149 | mb->insertItem(tr("View"),popup); |
150 | 150 | ||
151 | popup = new QPopupMenu( this ); | 151 | popup = new QPopupMenu( this ); |
152 | mb->insertItem(tr("Utils"),popup); | 152 | mb->insertItem(tr("Utils"),popup); |
153 | 153 | ||
154 | 154 | ||
155 | mb->insertItem( editCut ); | 155 | mb->insertItem( editCut ); |
156 | mb->insertItem( editCopy ); | 156 | mb->insertItem( editCopy ); |
157 | mb->insertItem( editPaste ); | 157 | mb->insertItem( editPaste ); |
158 | mb->insertItem( editUndo ); | 158 | mb->insertItem( editUndo ); |
159 | mb->insertItem( editRedo ); | 159 | mb->insertItem( editRedo ); |
160 | 160 | ||
161 | 161 | ||
162 | //Highlight management | 162 | //Highlight management |
163 | hlmenu=new QPopupMenu(this); | 163 | hlmenu=new QPopupMenu(this); |
164 | HlManager *hlm=HlManager::self(); | 164 | HlManager *hlm=HlManager::self(); |
165 | for (int i=0;i<hlm->highlights();i++) | 165 | for (int i=0;i<hlm->highlights();i++) |
166 | { | 166 | { |
167 | hlmenu->insertItem(hlm->hlName(i),i); | 167 | hlmenu->insertItem(hlm->hlName(i),i); |
168 | } | 168 | } |
169 | popup->insertItem(tr("Highlighting"),hlmenu); | 169 | popup->insertItem(tr("Highlighting"),hlmenu); |
170 | 170 | ||
171 | 171 | ||
172 | utilSettings = new QAction( tr( "Settings" ), | 172 | utilSettings = new QAction( tr( "Settings" ), |
173 | Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), | 173 | Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), |
174 | QString::null, 0, this, 0 ); | 174 | QString::null, 0, this, 0 ); |
175 | utilSettings->addTo( popup); | 175 | utilSettings->addTo( popup); |
176 | 176 | ||
177 | if( qApp->argc() > 1) open(qApp->argv()[1]); | 177 | if( qApp->argc() > 1) open(qApp->argv()[1]); |
178 | else slotNew(); | 178 | else slotNew(); |
179 | 179 | ||
180 | } | 180 | } |
181 | 181 | ||
182 | TinyKate::~TinyKate( ) | 182 | TinyKate::~TinyKate( ) |
183 | { | 183 | { |
184 | owarn << "TinyKate destructor\n" << oendl; | 184 | owarn << "TinyKate destructor\n" << oendl; |
185 | 185 | ||
186 | shutDown=true; | ||
187 | while (currentView!=0) | ||
188 | { | ||
189 | slotClose(); | ||
190 | } | ||
191 | |||
192 | if( KGlobal::config() != 0 ) | 186 | if( KGlobal::config() != 0 ) |
193 | { | 187 | { |
194 | owarn << "deleting KateConfig object..\n" << oendl; | 188 | owarn << "deleting KateConfig object..\n" << oendl; |
195 | delete KGlobal::config(); | 189 | delete KGlobal::config(); |
196 | } | 190 | } |
197 | } | 191 | } |
198 | 192 | ||
199 | void TinyKate::slotOpen( ) | 193 | void TinyKate::slotOpen( ) |
200 | { | 194 | { |
201 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, | 195 | QString filename = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, |
202 | QString::null); | 196 | QString::null); |
203 | if (!filename.isEmpty()) | 197 | if (!filename.isEmpty()) |
204 | { | 198 | { |
205 | open(filename); | 199 | open(filename); |
206 | } | 200 | } |
207 | } | 201 | } |
208 | 202 | ||
209 | void TinyKate::open(const QString & filename) | 203 | void TinyKate::open(const QString & filename) |
210 | { | 204 | { |
211 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 205 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
212 | KTextEditor::View *kv; | 206 | KTextEditor::View *kv; |
213 | QString realFileName; | 207 | QString realFileName; |
214 | //check if filename is a .desktop file | 208 | //check if filename is a .desktop file |
215 | if ( filename.find( ".desktop", 0, true ) != -1 ) { | 209 | if ( filename.find( ".desktop", 0, true ) != -1 ) { |
216 | switch ( QMessageBox::warning( this, tr( "TinyKATE" ), | 210 | switch ( QMessageBox::warning( this, tr( "TinyKATE" ), |
217 | tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), | 211 | tr("TinyKATE has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?" ), |
218 | tr(".desktop File"), | 212 | tr(".desktop File"), |
219 | tr("Linked Document"), 0, 1, 1 ) ) | 213 | tr("Linked Document"), 0, 1, 1 ) ) |
220 | { | 214 | { |
221 | case 0: //desktop | 215 | case 0: //desktop |
222 | realFileName = filename; | 216 | realFileName = filename; |
223 | break; | 217 | break; |
224 | case 1: //linked | 218 | case 1: //linked |
225 | DocLnk docLnk( filename ); | 219 | DocLnk docLnk( filename ); |
226 | realFileName = docLnk.file(); | 220 | realFileName = docLnk.file(); |
227 | break; | 221 | break; |
228 | }; | 222 | }; |
229 | } else { | 223 | } else { |
230 | realFileName = filename; | 224 | realFileName = filename; |
231 | } | 225 | } |
232 | 226 | ||
233 | QFileInfo fileInfo( realFileName ); | 227 | QFileInfo fileInfo( realFileName ); |
234 | QString filenamed = fileInfo.fileName(); | 228 | QString filenamed = fileInfo.fileName(); |
235 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); | 229 | tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate", filenamed ); |
236 | odebug << realFileName << oendl; | 230 | odebug << realFileName << oendl; |
237 | 231 | ||
238 | kd->setDocName( filenamed); | 232 | kd->setDocName( filenamed); |
239 | kd->open( realFileName ); | 233 | kd->open( realFileName ); |
240 | viewCount++; | 234 | viewCount++; |
241 | } | 235 | } |
242 | 236 | ||
243 | void TinyKate::setDocument(const QString& fileref) | 237 | void TinyKate::setDocument(const QString& fileref) |
244 | { | 238 | { |
245 | open( fileref ); | 239 | open( fileref ); |
246 | } | 240 | } |
247 | 241 | ||
248 | void TinyKate::slotCurrentChanged( QWidget * view) | 242 | void TinyKate::slotCurrentChanged( QWidget * view) |
249 | { | 243 | { |
250 | if (currentView) | 244 | if (currentView) |
251 | { | 245 | { |
252 | 246 | ||
253 | disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 247 | disconnect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); |
254 | disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 248 | disconnect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); |
255 | disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 249 | disconnect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); |
256 | disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 250 | disconnect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); |
257 | disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 251 | disconnect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); |
258 | disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find())); | 252 | disconnect(editFind,SIGNAL(activated()),currentView,SLOT(find())); |
259 | disconnect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); | 253 | disconnect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); |
260 | disconnect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); | 254 | disconnect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); |
261 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 255 | disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
262 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 256 | disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
263 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 257 | disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
264 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 258 | disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
265 | } | 259 | } |
266 | 260 | ||
267 | currentView=(KTextEditor::View*)view; | 261 | currentView=(KTextEditor::View*)view; |
268 | 262 | ||
269 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); | 263 | connect(editCopy,SIGNAL(clicked()),currentView,SLOT(copy())); |
270 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); | 264 | connect(editCut,SIGNAL(clicked()),currentView,SLOT(cut())); |
271 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); | 265 | connect(editPaste,SIGNAL(clicked()),currentView,SLOT(paste())); |
272 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); | 266 | connect(editUndo,SIGNAL(clicked()),currentView,SLOT(undo())); |
273 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); | 267 | connect(editRedo,SIGNAL(clicked()),currentView,SLOT(redo())); |
274 | connect(editFind,SIGNAL(activated()),currentView,SLOT(find())); | 268 | connect(editFind,SIGNAL(activated()),currentView,SLOT(find())); |
275 | connect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); | 269 | connect(editReplace,SIGNAL(activated()),currentView,SLOT(replace())); |
276 | connect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); | 270 | connect(editGotoLine,SIGNAL(activated()),currentView,SLOT(gotoLine())); |
277 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); | 271 | connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); |
278 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); | 272 | connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); |
279 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); | 273 | connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); |
280 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); | 274 | connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); |
281 | 275 | ||
282 | } | 276 | } |
283 | 277 | ||
284 | void TinyKate::slotNew( ) | 278 | void TinyKate::slotNew( ) |
285 | { | 279 | { |
286 | KateDocument *kd= new KateDocument(false, false, this,0,this); | 280 | KateDocument *kd= new KateDocument(false, false, this,0,this); |
287 | KTextEditor::View *kv; | 281 | KTextEditor::View *kv; |
282 | |||
283 | kd->setDocName(tr("Unnamed %1").arg(nextUnnamed++)); | ||
284 | kd->setNewDoc(true); | ||
288 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), | 285 | tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"), |
289 | "tinykate/tinykate", | 286 | "tinykate/tinykate", |
290 | tr("Unnamed %1").arg(nextUnnamed++)); | 287 | kd->docName()); |
291 | viewCount++; | 288 | viewCount++; |
292 | } | 289 | } |
293 | 290 | ||
294 | void TinyKate::slotClose( ) | 291 | bool TinyKate::checkSave() { |
292 | if (currentView==0) return true; | ||
293 | |||
294 | KateView *kv = (KateView*) currentView; | ||
295 | if(kv->isModified()) { | ||
296 | KateDocument *kd = (KateDocument*) kv->document(); | ||
297 | switch( QMessageBox::information( 0, (tr("TinyKATE")), | ||
298 | (tr("Do you want to save\n" | ||
299 | "changes to the document\n" | ||
300 | "%1?\n").arg(kd->docName())), | ||
301 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | ||
302 | { | ||
303 | case 0: | ||
304 | { | ||
305 | return saveDocument(); | ||
306 | } | ||
307 | break; | ||
308 | |||
309 | case 1: | ||
310 | { | ||
311 | return true; | ||
312 | } | ||
313 | break; | ||
314 | |||
315 | default: | ||
316 | { | ||
317 | return false; | ||
318 | } | ||
319 | break; | ||
320 | }; | ||
321 | } | ||
322 | else { | ||
323 | return true; | ||
324 | } | ||
325 | } | ||
326 | |||
327 | bool TinyKate::closeDocument() | ||
295 | { | 328 | { |
296 | if (currentView==0) return; | 329 | if (currentView==0) return true; |
297 | KTextEditor::View *dv=currentView; | 330 | KTextEditor::View *dv=currentView; |
298 | currentView=0; | 331 | if(checkSave()) { |
299 | tabwidget->removePage(dv); | 332 | currentView=0; |
300 | delete dv->document(); | 333 | tabwidget->removePage(dv); |
301 | viewCount--; | 334 | delete dv->document(); |
302 | if ((!viewCount) && (!shutDown)) slotNew(); | 335 | viewCount--; |
336 | if ((!viewCount) && (!shutDown)) slotNew(); | ||
337 | return true; | ||
338 | } | ||
339 | else | ||
340 | return false; | ||
303 | } | 341 | } |
304 | 342 | ||
305 | void TinyKate::slotSave() | 343 | void TinyKate::slotClose( ) |
344 | { | ||
345 | closeDocument(); | ||
346 | } | ||
347 | |||
348 | bool TinyKate::saveDocument() | ||
306 | { | 349 | { |
307 | // feel free to make this how you want | 350 | // feel free to make this how you want |
308 | if (currentView==0) return; | 351 | if (currentView==0) return false; |
309 | 352 | ||
310 | // KateView *kv = (KateView*) currentView; | 353 | // KateView *kv = (KateView*) currentView; |
311 | KateDocument *kd = (KateDocument*) currentView->document(); | 354 | KateDocument *kd = (KateDocument*) currentView->document(); |
312 | // odebug << "saving file "+kd->docName() << oendl; | 355 | // odebug << "saving file "+kd->docName() << oendl; |
313 | if( kd->docName().isEmpty()) | 356 | if( kd->isNewDoc()) { |
314 | slotSaveAs(); | 357 | return saveDocumentAs(); |
358 | } | ||
315 | else | 359 | else |
316 | kd->saveFile(); | 360 | return kd->saveFile(); |
361 | // FIXME check result of saveFile and show message if failed? | ||
317 | // kv->save(); | 362 | // kv->save(); |
318 | // kd->saveFile(); | 363 | // kd->saveFile(); |
319 | } | 364 | } |
320 | 365 | ||
321 | void TinyKate::slotSaveAs() | 366 | bool TinyKate::saveDocumentAs() |
322 | { | 367 | { |
323 | if (currentView==0) return; | 368 | if (currentView==0) return false; |
369 | |||
370 | bool result = false; | ||
324 | KateDocument *kd = (KateDocument*) currentView->document(); | 371 | KateDocument *kd = (KateDocument*) currentView->document(); |
325 | 372 | ||
326 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, | 373 | QString filename= OFileDialog::getSaveFileName(OFileSelector::EXTENDED_ALL, |
327 | QString::null); | 374 | QString::null); |
328 | if (!filename.isEmpty()) | 375 | if (!filename.isEmpty()) |
329 | { | 376 | { |
330 | odebug << "saving file "+filename << oendl; | 377 | odebug << "saving file "+filename << oendl; |
331 | QFileInfo fi(filename); | 378 | QFileInfo fi(filename); |
379 | if(fi.exists()) { | ||
380 | if ( QMessageBox::warning(this,tr("TinyKATE"), | ||
381 | tr("The file %1\n" | ||
382 | "already exists.\n\n" | ||
383 | "Are you sure you want to\n" | ||
384 | "overwrite it?") | ||
385 | .arg(fi.fileName()), | ||
386 | tr("Yes"),tr("No"),0,0,1) != 0) { | ||
387 | return false; | ||
388 | } | ||
389 | } | ||
332 | QString filenamed = fi.fileName(); | 390 | QString filenamed = fi.fileName(); |
333 | kd->setDocFile( filename); | 391 | kd->setDocFile( filename); |
334 | kd->setDocName( filenamed); | 392 | kd->setDocName( filenamed); |
335 | kd->saveFile(); | 393 | kd->setNewDoc(false); |
336 | // KTextEditor::View *dv = currentView; | 394 | result = kd->saveFile(); |
337 | // tabwidget->changeTab( dv, filenamed); | 395 | // FIXME check result of saveFile and show message if failed? |
338 | // need to change tab label here | 396 | tabwidget->changeTab( tabwidget->currentWidget(), "tinykate/tinykate", filenamed ); |
397 | } | ||
398 | return result; | ||
399 | } | ||
400 | |||
401 | void TinyKate::slotSave() | ||
402 | { | ||
403 | saveDocument(); | ||
404 | } | ||
405 | |||
406 | void TinyKate::slotSaveAs() | ||
407 | { | ||
408 | saveDocumentAs(); | ||
409 | } | ||
410 | |||
411 | void TinyKate::closeEvent(QCloseEvent *e) { | ||
412 | // Close all documents | ||
413 | shutDown = true; | ||
414 | while (currentView!=0) | ||
415 | { | ||
416 | if(!closeDocument()) { | ||
417 | // User cancelled | ||
418 | shutDown=false; | ||
419 | break; | ||
420 | } | ||
339 | } | 421 | } |
340 | 422 | ||
423 | if(shutDown) | ||
424 | e->accept(); | ||
425 | else | ||
426 | e->ignore(); | ||
341 | } | 427 | } |
diff --git a/noncore/apps/tinykate/mainwindow/tinykate.h b/noncore/apps/tinykate/mainwindow/tinykate.h index 6e95d87..7d0c588 100644 --- a/noncore/apps/tinykate/mainwindow/tinykate.h +++ b/noncore/apps/tinykate/mainwindow/tinykate.h | |||
@@ -1,66 +1,71 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | tinykate.h | 2 | tinykate.h |
3 | Tiny KATE mainwindow | 3 | Tiny KATE mainwindow |
4 | ------------------- | 4 | ------------------- |
5 | begin : November 2002 | 5 | begin : November 2002 |
6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> | 6 | copyright : (C) 2002 by Joseph Wenninger <jowenn@kde.org> |
7 | ***************************************************************************/ | 7 | ***************************************************************************/ |
8 | 8 | ||
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
12 | * it under the terms of the GNU General Public License as published by * | 12 | * it under the terms of the GNU General Public License as published by * |
13 | * the Free Software Foundation. * | 13 | * the Free Software Foundation. * |
14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * | 14 | * ONLY VERSION 2 OF THE LICENSE IS APPLICABLE * |
15 | * * | 15 | * * |
16 | ***************************************************************************/ | 16 | ***************************************************************************/ |
17 | 17 | ||
18 | #ifndef __TINYKATE_H__ | 18 | #ifndef __TINYKATE_H__ |
19 | #define __TINYKATE_H__ | 19 | #define __TINYKATE_H__ |
20 | 20 | ||
21 | 21 | ||
22 | #include <qmainwindow.h> | 22 | #include <qmainwindow.h> |
23 | #include <opie2/otabwidget.h> | 23 | #include <opie2/otabwidget.h> |
24 | #include <ktexteditor.h> | 24 | #include <ktexteditor.h> |
25 | 25 | ||
26 | class QToolButton; | 26 | class QToolButton; |
27 | class QAction; | 27 | class QAction; |
28 | class QPopupMenu; | 28 | class QPopupMenu; |
29 | 29 | ||
30 | class TinyKate : public QMainWindow | 30 | class TinyKate : public QMainWindow |
31 | { | 31 | { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | public: | 33 | public: |
34 | TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); | 34 | TinyKate( QWidget *parent=0, const char *name=0, WFlags f = 0); |
35 | ~TinyKate( ); | 35 | ~TinyKate( ); |
36 | static QString appName() { return QString::fromLatin1( "tinykate" ); }; | 36 | static QString appName() { return QString::fromLatin1( "tinykate" ); }; |
37 | 37 | ||
38 | 38 | ||
39 | public slots: | 39 | public slots: |
40 | void slotNew(); | 40 | void slotNew(); |
41 | void setDocument(const QString& fileref); | 41 | void setDocument(const QString& fileref); |
42 | 42 | ||
43 | protected slots: | 43 | protected slots: |
44 | void slotOpen(); | 44 | void slotOpen(); |
45 | void slotClose(); | 45 | void slotClose(); |
46 | void slotCurrentChanged(QWidget *); | 46 | void slotCurrentChanged(QWidget *); |
47 | void slotSave(); | 47 | void slotSave(); |
48 | void slotSaveAs(); | 48 | void slotSaveAs(); |
49 | protected: | 49 | protected: |
50 | void open(const QString&); | 50 | void open(const QString&); |
51 | bool closeDocument(); | ||
52 | bool checkSave(); | ||
53 | bool saveDocument(); | ||
54 | bool saveDocumentAs(); | ||
55 | void closeEvent(QCloseEvent *e); | ||
51 | private: | 56 | private: |
52 | QString currentFileName; | 57 | QString currentFileName; |
53 | Opie::Ui::OTabWidget *tabwidget; | 58 | Opie::Ui::OTabWidget *tabwidget; |
54 | KTextEditor::View *currentView; | 59 | KTextEditor::View *currentView; |
55 | bool shutDown; | 60 | bool shutDown; |
56 | 61 | ||
57 | QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo; | 62 | QToolButton *editCopy, *editCut, *editPaste, *editUndo, *editRedo; |
58 | QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings, *editFind, *editReplace, *editGotoLine; | 63 | QAction *viewIncFontSizes, *viewDecFontSizes, *utilSettings, *editFind, *editReplace, *editGotoLine; |
59 | 64 | ||
60 | QPopupMenu *hlmenu; | 65 | QPopupMenu *hlmenu; |
61 | uint nextUnnamed; | 66 | uint nextUnnamed; |
62 | uint viewCount; | 67 | uint viewCount; |
63 | }; | 68 | }; |
64 | 69 | ||
65 | 70 | ||
66 | #endif // __TINYKATE_H__ | 71 | #endif // __TINYKATE_H__ |