-rw-r--r-- | noncore/apps/tinykate/tinykate.cpp | 161 |
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 | |||
@@ -36,106 +36,106 @@ | |||
36 | #include <katehighlight.h> | 36 | #include <katehighlight.h> |
37 | 37 | ||
38 | TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | 38 | TinyKate::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); |
@@ -147,67 +147,68 @@ TinyKate::TinyKate( QWidget *parent, const char *name, WFlags f) : | |||
147 | 147 | ||
148 | 148 | ||
149 | void TinyKate::slotOpen( ) | 149 | void 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 | ||
157 | void TinyKate::open(const QString & filename) | 157 | void 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 | ||
167 | void TinyKate::slotCurrentChanged( QWidget * view) | 168 | void 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 | ||
195 | void TinyKate::slotNew( ) | 196 | void 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 | ||
203 | void TinyKate::slotClose( ) | 204 | void 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 | ||