summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-22 17:30:50 (UTC)
committer llornkcor <llornkcor>2002-12-22 17:30:50 (UTC)
commita907eb4d3c6ca142dcab7889d8932ccb452bf07c (patch) (unidiff)
tree985933c8c2dd1f49dee60c898b3b951f99f4eaf3
parentd7859bf6df42c36f87ecaa560754b3b3b3c2e78e (diff)
downloadopie-a907eb4d3c6ca142dcab7889d8932ccb452bf07c.zip
opie-a907eb4d3c6ca142dcab7889d8932ccb452bf07c.tar.gz
opie-a907eb4d3c6ca142dcab7889d8932ccb452bf07c.tar.bz2
add fileName to tab instead of BLAH
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tinykate/tinykate.cpp161
1 files changed, 81 insertions, 80 deletions
diff --git a/noncore/apps/tinykate/tinykate.cpp b/noncore/apps/tinykate/tinykate.cpp
index f177e47..a823530 100644
--- a/noncore/apps/tinykate/tinykate.cpp
+++ b/noncore/apps/tinykate/tinykate.cpp
@@ -1,213 +1,214 @@
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 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#include <qwidget.h> 17#include <qwidget.h>
18#include <qaction.h> 18#include <qaction.h>
19#include <qlayout.h> 19#include <qlayout.h>
20#include <qpe/qpetoolbar.h> 20#include <qpe/qpetoolbar.h>
21#include <qpe/qpemenubar.h> 21#include <qpe/qpemenubar.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25 25
26#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
27 27
28#include "tinykate.h" 28#include "tinykate.h"
29#include "pics/file-new.xpm" 29#include "pics/file-new.xpm"
30#include "pics/file-open.xpm" 30#include "pics/file-open.xpm"
31#include "pics/file-save.xpm" 31#include "pics/file-save.xpm"
32#include "pics/edit-undo.xpm" 32#include "pics/edit-undo.xpm"
33#include "pics/edit-redo.xpm" 33#include "pics/edit-redo.xpm"
34 34
35#include <katedocument.h> 35#include <katedocument.h>
36#include <katehighlight.h> 36#include <katehighlight.h>
37 37
38TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : 38TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) :
39 QMainWindow( parent, name, f ) 39 QMainWindow( parent, name, f )
40 { 40{
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 45
46 setToolBarsMovable(FALSE); 46 setToolBarsMovable(FALSE);
47 47
48 QPEToolBar *bar = new QPEToolBar( this ); 48 QPEToolBar *bar = new QPEToolBar( this );
49 bar->setHorizontalStretchable( TRUE ); 49 bar->setHorizontalStretchable( TRUE );
50 QPEMenuBar *mb = new QPEMenuBar( bar ); 50 QPEMenuBar *mb = new QPEMenuBar( bar );
51 mb->setMargin( 0 ); 51 mb->setMargin( 0 );
52 52
53 tabwidget=new OTabWidget(this); 53 tabwidget=new OTabWidget(this);
54 setCentralWidget(tabwidget); 54 setCentralWidget(tabwidget);
55 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *))); 55 connect(tabwidget,SIGNAL(currentChanged( QWidget *)),this,SLOT(slotCurrentChanged(QWidget *)));
56 56
57//FILE ACTIONS 57//FILE ACTIONS
58 QPopupMenu *popup = new QPopupMenu( this ); 58 QPopupMenu *popup = new QPopupMenu( this );
59 59
60 // Action for creating a new document 60 // Action for creating a new document
61 QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 ); 61 QAction *a = new QAction( tr( "New" ), QPixmap((const char**)file_new_xpm ), QString::null, 0, this, 0 );
62 a->addTo( popup ); 62 a->addTo( popup );
63 connect(a, SIGNAL(activated()), this, SLOT(slotNew())); 63 connect(a, SIGNAL(activated()), this, SLOT(slotNew()));
64 64
65 // Action for opening an exisiting document 65 // Action for opening an exisiting document
66 a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 ); 66 a = new QAction( tr( "Open" ), QPixmap((const char**)file_open_xpm), QString::null, 0, this, 0 );
67 a->addTo(popup); 67 a->addTo(popup);
68 connect(a, SIGNAL(activated()), this, SLOT(slotOpen())); 68 connect(a, SIGNAL(activated()), this, SLOT(slotOpen()));
69 69
70 70
71 // Action for saving document 71 // Action for saving document
72 a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); 72 a = new QAction( tr( "Save" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
73 a->addTo(popup); 73 a->addTo(popup);
74 74
75 // Action for saving document to a new name 75 // Action for saving document to a new name
76 a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 ); 76 a = new QAction( tr( "Save As" ), QPixmap((const char**)file_save_xpm), QString::null, 0, this, 0 );
77 a->addTo(popup); 77 a->addTo(popup);
78 78
79 // Action for closing the currently active document 79 // Action for closing the currently active document
80 a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 ); 80 a = new QAction( tr( "Close" ), QPixmap(), QString::null, 0, this, 0 );
81 a->addTo(popup); 81 a->addTo(popup);
82 connect(a, SIGNAL(activated()), this, SLOT(slotClose())); 82 connect(a, SIGNAL(activated()), this, SLOT(slotClose()));
83 83
84 84
85 mb->insertItem(tr("File"),popup); 85 mb->insertItem(tr("File"),popup);
86 86
87//EDIT ACTIONS 87//EDIT ACTIONS
88 88
89 // Action for cutting text 89 // Action for cutting text
90 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 90 editCut = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
91 editCut->addTo( bar ); 91 editCut->addTo( bar );
92 92
93 // Action for Copying text 93 // Action for Copying text
94 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 94 editCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
95 editCopy->addTo( bar ); 95 editCopy->addTo( bar );
96 96
97 // Action for pasting text 97 // Action for pasting text
98 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 98 editPaste = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
99 editPaste->addTo( bar ); 99 editPaste->addTo( bar );
100 100
101 101
102 // Action for finding / replacing text 102 // Action for finding / replacing text
103 editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 ); 103 editFindReplace = new QAction( tr( "Find/Replace" ), Resource::loadPixmap("find"), QString::null, 0, this, 0 );
104 editFindReplace->addTo( bar ); 104 editFindReplace->addTo( bar );
105 105
106 // Action for undo 106 // Action for undo
107 editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 ); 107 editUndo = new QAction( tr( "Undo" ), QPixmap((const char**)edit_undo_xpm), QString::null, 0, this, 0 );
108 editUndo->addTo( bar ); 108 editUndo->addTo( bar );
109 109
110 // Action for redo 110 // Action for redo
111 editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 ); 111 editRedo = new QAction( tr( "Redo" ), QPixmap((const char**)edit_redo_xpm), QString::null, 0, this, 0 );
112 editRedo->addTo( bar ); 112 editRedo->addTo( bar );
113 113
114//VIEW ACITONS 114//VIEW ACITONS
115 popup = new QPopupMenu( this ); 115 popup = new QPopupMenu( this );
116 116
117 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 ); 117 viewIncFontSizes = new QAction( tr( "Font +" ), QString::null, 0, this, 0 );
118 viewIncFontSizes->addTo( popup ); 118 viewIncFontSizes->addTo( popup );
119 119
120 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 ); 120 viewDecFontSizes = new QAction( tr( "Font -" ), QString::null, 0, this, 0 );
121 viewDecFontSizes->addTo( popup ); 121 viewDecFontSizes->addTo( popup );
122 122
123 mb->insertItem(tr("View"),popup); 123 mb->insertItem(tr("View"),popup);
124 124
125 125
126 126
127 popup = new QPopupMenu( this ); 127 popup = new QPopupMenu( this );
128 mb->insertItem(tr("Utils"),popup); 128 mb->insertItem(tr("Utils"),popup);
129 129
130//Highlight management 130//Highlight management
131 hlmenu=new QPopupMenu(this); 131 hlmenu=new QPopupMenu(this);
132 HlManager *hlm=HlManager::self(); 132 HlManager *hlm=HlManager::self();
133 for (int i=0;i<hlm->highlights();i++) 133 for (int i=0;i<hlm->highlights();i++)
134 { 134 {
135 hlmenu->insertItem(hlm->hlName(i),i); 135 hlmenu->insertItem(hlm->hlName(i),i);
136 } 136 }
137 popup->insertItem(tr("Highlighting"),hlmenu); 137 popup->insertItem(tr("Highlighting"),hlmenu);
138 138
139 139
140 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 ); 140 utilSettings = new QAction( tr( "Settings" ), QString::null, 0, this, 0 );
141 utilSettings->addTo( popup); 141 utilSettings->addTo( popup);
142 142
143 if( qApp->argc() > 1) open(qApp->argv()[1]); 143 if( qApp->argc() > 1) open(qApp->argv()[1]);
144 else slotNew(); 144 else slotNew();
145 145
146} 146}
147 147
148 148
149void TinyKate::slotOpen( ) 149void TinyKate::slotOpen( )
150{ 150{
151 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL); 151 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED_ALL);
152 if (!filename.isEmpty()) { 152 if (!filename.isEmpty()) {
153 open(filename); 153 open(filename);
154 } 154 }
155} 155}
156 156
157void TinyKate::open(const QString & filename) 157void TinyKate::open(const QString & filename)
158{ 158{
159 KateDocument *kd= new KateDocument(false, false, this,0,this); 159 KateDocument *kd= new KateDocument(false, false, this,0,this);
160 KTextEditor::View *kv; 160 KTextEditor::View *kv;
161 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate","BLAH"); 161 QFileInfo fi(filename);
162 qDebug(filename); 162 tabwidget->addTab(kv=kd->createView(tabwidget,"bLAH"),"tinykate/tinykate",fi.fileName());
163 kd->open(filename); 163 qDebug(filename);
164 viewCount++; 164 kd->open(filename);
165 viewCount++;
165} 166}
166 167
167void TinyKate::slotCurrentChanged( QWidget * view) 168void TinyKate::slotCurrentChanged( QWidget * view)
168{ 169{
169 if (currentView) { 170 if (currentView) {
170 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 171 disconnect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
171 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 172 disconnect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
172 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 173 disconnect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
173 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 174 disconnect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
174 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 175 disconnect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
175 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 176 disconnect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
176 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 177 disconnect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
177 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 178 disconnect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
178 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 179 disconnect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
179 } 180 }
180 181
181 currentView=(KTextEditor::View*)view; 182 currentView=(KTextEditor::View*)view;
182 183
183 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy())); 184 connect(editCopy,SIGNAL(activated()),currentView,SLOT(copy()));
184 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut())); 185 connect(editCut,SIGNAL(activated()),currentView,SLOT(cut()));
185 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste())); 186 connect(editPaste,SIGNAL(activated()),currentView,SLOT(paste()));
186 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo())); 187 connect(editUndo,SIGNAL(activated()),currentView,SLOT(undo()));
187 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo())); 188 connect(editRedo,SIGNAL(activated()),currentView,SLOT(redo()));
188 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes())); 189 connect(viewIncFontSizes,SIGNAL(activated()), currentView,SLOT(slotIncFontSizes()));
189 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes())); 190 connect(viewDecFontSizes,SIGNAL(activated()), currentView,SLOT(slotDecFontSizes()));
190 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int))); 191 connect(hlmenu,SIGNAL(activated(int)), currentView,SLOT(setHl(int)));
191 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog())); 192 connect(utilSettings,SIGNAL(activated()), currentView,SLOT(configDialog()));
192 193
193} 194}
194 195
195void TinyKate::slotNew( ) 196void TinyKate::slotNew( )
196{ 197{
197 KateDocument *kd= new KateDocument(false, false, this,0,this); 198 KateDocument *kd= new KateDocument(false, false, this,0,this);
198 KTextEditor::View *kv; 199 KTextEditor::View *kv;
199 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"tinykate/tinykate",tr("Unnamed %1").arg(nextUnnamed++)); 200 tabwidget->addTab(kv=kd->createView(tabwidget,"BLAH"),"tinykate/tinykate",tr("Unnamed %1").arg(nextUnnamed++));
200 viewCount++; 201 viewCount++;
201} 202}
202 203
203void TinyKate::slotClose( ) 204void TinyKate::slotClose( )
204{ 205{
205 if (currentView==0) return; 206 if (currentView==0) return;
206 KTextEditor::View *dv=currentView; 207 KTextEditor::View *dv=currentView;
207 currentView=0; 208 currentView=0;
208 tabwidget->removePage(dv); 209 tabwidget->removePage(dv);
209 delete dv->document(); 210 delete dv->document();
210 viewCount--; 211 viewCount--;
211 if (!viewCount) slotNew(); 212 if (!viewCount) slotNew();
212} 213}
213 214