Merge lp:~gcollura/scratch/scratch into lp:~registry/scratch/scratch
- scratch
- Merge into scratch
Proposed by
Giulio Collura
Status: | Merged |
---|---|
Approved by: | Mario Guerriero |
Approved revision: | 13 |
Merge reported by: | Mario Guerriero |
Merged at revision: | not available |
Proposed branch: | lp:~gcollura/scratch/scratch |
Merge into: | lp:~registry/scratch/scratch |
Diff against target: |
1287 lines (+596/-631) 10 files modified
CMakeLists.txt (+5/-3) src/Dialogs/preferences_dialog.vala (+43/-0) src/Widgets/menu.vala (+45/-0) src/Widgets/notebook.vala (+133/-0) src/Widgets/toolbar.vala (+100/-0) src/entry.vala (+0/-191) src/main_window.vala (+184/-269) src/menu.vala (+0/-38) src/notebook.vala (+0/-130) src/scratch.vala (+86/-0) |
To merge this branch: | bzr merge lp:~gcollura/scratch/scratch |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mario Guerriero (community) | Approve | ||
Review via email: mp+69170@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
lp:~gcollura/scratch/scratch
updated
- 13. By Giulio Collura
-
Added pref dialog, improved toolbar, still need a lot of work...
Revision history for this message
Mario Guerriero (mefrio-g) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2011-07-25 18:52:59 +0000 |
3 | +++ CMakeLists.txt 2011-07-25 23:31:27 +0000 |
4 | @@ -43,9 +43,11 @@ |
5 | include (ValaPrecompile) |
6 | vala_precompile (VALA_C |
7 | src/main_window.vala |
8 | - src/menu.vala |
9 | - src/notebook.vala |
10 | - src/entry.vala |
11 | + src/scratch.vala |
12 | + src/Widgets/menu.vala |
13 | + src/Widgets/notebook.vala |
14 | + src/Widgets/toolbar.vala |
15 | + src/Dialogs/preferences_dialog.vala |
16 | PACKAGES |
17 | ${SCRATCH_DEPS} |
18 | CUSTOM_VAPIS |
19 | |
20 | === added directory 'src/Dialogs' |
21 | === added file 'src/Dialogs/preferences_dialog.vala' |
22 | --- src/Dialogs/preferences_dialog.vala 1970-01-01 00:00:00 +0000 |
23 | +++ src/Dialogs/preferences_dialog.vala 2011-07-25 23:31:27 +0000 |
24 | @@ -0,0 +1,43 @@ |
25 | +/*** |
26 | + BEGIN LICENSE |
27 | + |
28 | + Copyright (C) 2011 Giulio Collura <random.cpp@gmail.com> |
29 | + This program is free software: you can redistribute it and/or modify it |
30 | + under the terms of the GNU Lesser General Public License version 3, as published |
31 | + by the Free Software Foundation. |
32 | + |
33 | + This program is distributed in the hope that it will be useful, but |
34 | + WITHOUT ANY WARRANTY; without even the implied warranties of |
35 | + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
36 | + PURPOSE. See the GNU General Public License for more details. |
37 | + |
38 | + You should have received a copy of the GNU General Public License along |
39 | + with this program. If not, see <http://www.gnu.org/licenses/> |
40 | + |
41 | + END LICENSE |
42 | +***/ |
43 | + |
44 | + |
45 | +using Gtk; |
46 | + |
47 | +namespace Scratch.Dialogs { |
48 | + |
49 | + public class Preferences : Dialog { |
50 | + |
51 | + public Preferences (string? title, MainWindow? window) { |
52 | + |
53 | + this.title = title; |
54 | + this.parent = window; |
55 | + this.window_position = WindowPosition.CENTER; |
56 | + this.type_hint = Gdk.WindowTypeHint.DIALOG; |
57 | + this.set_modal(true); |
58 | + // this.set_transient_for(); |
59 | + |
60 | + set_default_size (400, 300); |
61 | + show_all (); |
62 | + |
63 | + } |
64 | + |
65 | + } |
66 | + |
67 | +} // Namespace |
68 | |
69 | === added directory 'src/Widgets' |
70 | === added file 'src/Widgets/menu.vala' |
71 | --- src/Widgets/menu.vala 1970-01-01 00:00:00 +0000 |
72 | +++ src/Widgets/menu.vala 2011-07-25 23:31:27 +0000 |
73 | @@ -0,0 +1,45 @@ |
74 | +/*** |
75 | + BEGIN LICENSE |
76 | + |
77 | + Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com> |
78 | + This program is free software: you can redistribute it and/or modify it |
79 | + under the terms of the GNU Lesser General Public License version 3, as published |
80 | + by the Free Software Foundation. |
81 | + |
82 | + This program is distributed in the hope that it will be useful, but |
83 | + WITHOUT ANY WARRANTY; without even the implied warranties of |
84 | + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
85 | + PURPOSE. See the GNU General Public License for more details. |
86 | + |
87 | + You should have received a copy of the GNU General Public License along |
88 | + with this program. If not, see <http://www.gnu.org/licenses/> |
89 | + |
90 | + END LICENSE |
91 | +***/ |
92 | + |
93 | +using Gtk; |
94 | + |
95 | +namespace Scratch.Widgets { |
96 | + |
97 | + public class MenuProperties : Menu { |
98 | + |
99 | + private ImageMenuItem preferences; |
100 | + |
101 | + public MenuProperties () { |
102 | + create (); |
103 | + } |
104 | + |
105 | + public void create () { |
106 | + |
107 | + this.preferences = new ImageMenuItem.from_stock (Stock.PREFERENCES, null); |
108 | + this.append (preferences); |
109 | + preferences.show(); |
110 | + |
111 | + preferences.activate.connect (() => {new Dialogs.Preferences ("Preferences", null);}); |
112 | + |
113 | + } |
114 | + |
115 | + |
116 | + } |
117 | + |
118 | +} // Namespace |
119 | |
120 | === added file 'src/Widgets/notebook.vala' |
121 | --- src/Widgets/notebook.vala 1970-01-01 00:00:00 +0000 |
122 | +++ src/Widgets/notebook.vala 2011-07-25 23:31:27 +0000 |
123 | @@ -0,0 +1,133 @@ |
124 | +/*** |
125 | + BEGIN LICENSE |
126 | + |
127 | + Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com> |
128 | + This program is free software: you can redistribute it and/or modify it |
129 | + under the terms of the GNU Lesser General Public License version 3, as published |
130 | + by the Free Software Foundation. |
131 | + |
132 | + This program is distributed in the hope that it will be useful, but |
133 | + WITHOUT ANY WARRANTY; without even the implied warranties of |
134 | + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
135 | + PURPOSE. See the GNU General Public License for more details. |
136 | + |
137 | + You should have received a copy of the GNU General Public License along |
138 | + with this program. If not, see <http://www.gnu.org/licenses/> |
139 | + |
140 | + END LICENSE |
141 | +***/ |
142 | + |
143 | +using Gtk; |
144 | +using Pango; |
145 | +using GtkSource; |
146 | + |
147 | +namespace Scratch.Widgets { |
148 | + |
149 | + public class Tab : ScrolledWindow { |
150 | + |
151 | + public TextView text_view; |
152 | + public Label label; |
153 | + public string filename; |
154 | + |
155 | + public Tab() { |
156 | + |
157 | + var s = new View (); |
158 | + |
159 | + this.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC); |
160 | + this.text_view = new TextView (); |
161 | + this.add (text_view); |
162 | + this.label = new Label ("New file"); |
163 | + this.filename = null; |
164 | + this.show_all(); |
165 | + |
166 | + } |
167 | + |
168 | + } |
169 | + /* |
170 | + public class TabLabel : HBox { |
171 | + |
172 | + public HBox tablabel; |
173 | + public Label label; |
174 | + public Button close; |
175 | + |
176 | + public TabLabel(string label) { |
177 | + |
178 | + this.label = new Label (label); |
179 | + |
180 | + var image = new Image.from_stock(Stock.CLOSE, IconSize.MENU); |
181 | + this.close = new Button (); |
182 | + this.close.clicked.connect (on_close_clicked); |
183 | + this.close.set_relief (ReliefStyle.NONE); |
184 | + this.close.set_image (image); |
185 | + |
186 | + this.hbox.pack_start (this.label, false, false, 0); |
187 | + this.hbox.pack_start (this.close, false, false, 0); |
188 | + |
189 | + this.show_all (); |
190 | + } |
191 | + |
192 | + public void on_close_clicked() { |
193 | + |
194 | + return; |
195 | + |
196 | + } |
197 | + |
198 | + public void change_label(string label) { |
199 | + |
200 | + this.label.set_text (label); |
201 | + |
202 | + } |
203 | + |
204 | + } |
205 | + */ |
206 | + public class ScratchNotebook : Notebook { |
207 | + |
208 | + //widgets for the label |
209 | + public HBox tablabel; |
210 | + public Label label; |
211 | + public Button close; |
212 | + |
213 | + public int add_tab(string tabtext="New file") { |
214 | + |
215 | + //tab label |
216 | + this.tablabel = new HBox (false, 0); |
217 | + |
218 | + this.label = new Label (tabtext); |
219 | + |
220 | + var image = new Image.from_stock(Stock.CLOSE, IconSize.MENU); |
221 | + this.close = new Button (); |
222 | + this.close.clicked.connect (on_close_clicked); |
223 | + this.close.set_relief (ReliefStyle.NONE); |
224 | + this.close.set_image (image); |
225 | + |
226 | + this.tablabel.pack_start (this.label, false, false, 0); |
227 | + this.tablabel.pack_start (this.close, false, false, 0); |
228 | + |
229 | + this.tablabel.show_all (); |
230 | + |
231 | + //create the tab |
232 | + var new_tab = new Tab(); |
233 | + this.set_tab_reorderable (new_tab, true); |
234 | + return this.append_page (new_tab, this.tablabel); |
235 | + } |
236 | + |
237 | + public void change_label(string label) { |
238 | + |
239 | + this.label.set_text (label); |
240 | + |
241 | + } |
242 | + |
243 | + //events |
244 | + public void on_close_clicked () { |
245 | + |
246 | + return; |
247 | + |
248 | + } |
249 | + |
250 | + public ScratchNotebook() { |
251 | + this.set_scrollable (true); |
252 | + } |
253 | + |
254 | + |
255 | + } |
256 | +} // Namespace |
257 | |
258 | === added file 'src/Widgets/toolbar.vala' |
259 | --- src/Widgets/toolbar.vala 1970-01-01 00:00:00 +0000 |
260 | +++ src/Widgets/toolbar.vala 2011-07-25 23:31:27 +0000 |
261 | @@ -0,0 +1,100 @@ |
262 | +/*** |
263 | + BEGIN LICENSE |
264 | + |
265 | + Copyright (C) 2011 Giulio Collura <random.cpp@gmail.com> |
266 | + This program is free software: you can redistribute it and/or modify it |
267 | + under the terms of the GNU Lesser General Public License version 3, as published |
268 | + by the Free Software Foundation. |
269 | + |
270 | + This program is distributed in the hope that it will be useful, but |
271 | + WITHOUT ANY WARRANTY; without even the implied warranties of |
272 | + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
273 | + PURPOSE. See the GNU General Public License for more details. |
274 | + |
275 | + You should have received a copy of the GNU General Public License along |
276 | + with this program. If not, see <http://www.gnu.org/licenses/> |
277 | + |
278 | + END LICENSE |
279 | +***/ |
280 | + |
281 | +using Gtk; |
282 | +using Granite.Widgets; |
283 | + |
284 | +namespace Scratch.Widgets { |
285 | + |
286 | + public class Toolbar : Gtk.Toolbar { |
287 | + |
288 | + MainWindow parent; |
289 | + |
290 | + public ToolButton new_button; |
291 | + public ToolButton open_button; |
292 | + public ToolButton save_button; |
293 | + public ToolButton undo_button; |
294 | + public ToolButton repeat_button; |
295 | + public ComboBox combobox; |
296 | + |
297 | + public Entry entry; |
298 | + public AppMenu app_menu; |
299 | + |
300 | + |
301 | + public Toolbar (MainWindow parent) { |
302 | + |
303 | + this.parent = parent; |
304 | + |
305 | + // Toolbar properties |
306 | + // compliant with elementary HIG |
307 | + get_style_context ().add_class ("primary-toolbar"); |
308 | + |
309 | + new_button = new ToolButton.from_stock (Stock.NEW); |
310 | + open_button = new ToolButton.from_stock (Stock.OPEN); |
311 | + save_button = new ToolButton.from_stock (Stock.SAVE); |
312 | + undo_button = new ToolButton.from_stock (Stock.UNDO); |
313 | + repeat_button = new ToolButton.from_stock (Stock.REDO); |
314 | + |
315 | + combobox = new ComboBox (); |
316 | + |
317 | + add (new_button); |
318 | + add (open_button); |
319 | + add (save_button); |
320 | + add (new SeparatorToolItem ()); |
321 | + add (undo_button); |
322 | + add (repeat_button); |
323 | + |
324 | + add (add_spacer ()); |
325 | + add (toolitem (combobox)); |
326 | + |
327 | + entry = new SearchBar ("Search in the text..."); |
328 | + |
329 | + var menu = new MenuProperties (); |
330 | + app_menu = new AppMenu (menu); |
331 | + |
332 | + add (add_spacer ()); |
333 | + add (toolitem (entry)); |
334 | + add (app_menu); |
335 | + |
336 | + } |
337 | + |
338 | + private ToolItem add_spacer () { |
339 | + |
340 | + var spacer = new ToolItem (); |
341 | + spacer.set_expand (true); |
342 | + |
343 | + return spacer; |
344 | + |
345 | + } |
346 | + |
347 | + private ToolItem toolitem (Widget widget, bool expand = true, int border_width = 0) { |
348 | + |
349 | + var new_tool_item = new ToolItem (); |
350 | + new_tool_item.add (widget); |
351 | + |
352 | + if (border_width > 0) { |
353 | + new_tool_item.set_border_width (border_width); |
354 | + } |
355 | + new_tool_item.set_expand (expand); |
356 | + |
357 | + return new_tool_item; |
358 | + |
359 | + } |
360 | + } |
361 | +} // Namespace |
362 | |
363 | === removed file 'src/entry.vala' |
364 | --- src/entry.vala 2011-07-25 20:14:39 +0000 |
365 | +++ src/entry.vala 1970-01-01 00:00:00 +0000 |
366 | @@ -1,191 +0,0 @@ |
367 | -/*** |
368 | - BEGIN LICENSE |
369 | - |
370 | - Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com> |
371 | - This program is free software: you can redistribute it and/or modify it |
372 | - under the terms of the GNU Lesser General Public License version 3, as published |
373 | - by the Free Software Foundation. |
374 | - |
375 | - This program is distributed in the hope that it will be useful, but |
376 | - WITHOUT ANY WARRANTY; without even the implied warranties of |
377 | - MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
378 | - PURPOSE. See the GNU General Public License for more details. |
379 | - |
380 | - You should have received a copy of the GNU General Public License along |
381 | - with this program. If not, see <http://www.gnu.org/licenses/> |
382 | - |
383 | - END LICENSE |
384 | -***/ |
385 | - |
386 | -public class ElementaryEntry : Gtk.Entry { |
387 | - |
388 | - public string hint_string; |
389 | - |
390 | - public ElementaryEntry (string hint_string) { |
391 | - |
392 | - this.hint_string = hint_string; |
393 | - |
394 | - this.hint (); |
395 | - this.focus_in_event.connect (on_focus_in); |
396 | - this.focus_out_event.connect (on_focus_out); |
397 | - |
398 | - } |
399 | - |
400 | - private bool on_focus_in () { |
401 | - |
402 | - if (get_text () == "") { |
403 | - unhint (); |
404 | - } |
405 | - return false; |
406 | - |
407 | - } |
408 | - |
409 | - private bool on_focus_out () { |
410 | - |
411 | - if (get_text () == "") { |
412 | - hint (); |
413 | - } |
414 | - return false; |
415 | - |
416 | - } |
417 | - |
418 | - protected void hint () { |
419 | - |
420 | - this.text = this.hint_string; |
421 | - grey_out (); |
422 | - |
423 | - } |
424 | - |
425 | - protected void unhint () { |
426 | - |
427 | - this.text = ""; |
428 | - reset_font (); |
429 | - |
430 | - } |
431 | - |
432 | - |
433 | - private void grey_out () { |
434 | - |
435 | - var color = Gdk.Color (); |
436 | - Gdk.Color.parse ("#999", out color); |
437 | - this.modify_text (Gtk.StateType.NORMAL, color); |
438 | - this.modify_font (Pango.FontDescription.from_string ("italic")); |
439 | - |
440 | - } |
441 | - |
442 | - private void reset_font () { |
443 | - |
444 | - var color = Gdk.Color (); |
445 | - Gdk.Color.parse ("#444", out color); |
446 | - this.modify_text (Gtk.StateType.NORMAL, color); |
447 | - this.modify_font (Pango.FontDescription.from_string ("normal")); |
448 | - |
449 | - } |
450 | - |
451 | - protected new string get_text () { |
452 | - |
453 | - text = this.text; |
454 | - if (text == this.hint_string) { |
455 | - return ""; |
456 | - } |
457 | - else { |
458 | - return text; |
459 | - } |
460 | - |
461 | - } |
462 | -} |
463 | - |
464 | -public class ElementarySearchEntry : ElementaryEntry { |
465 | - |
466 | - bool is_searching; |
467 | - |
468 | - public ElementarySearchEntry (string hint_string) { |
469 | - |
470 | - base(hint_string); |
471 | - this.set_icon_from_stock(Gtk.EntryIconPosition.PRIMARY, "gtk-find"); |
472 | - this.changed.connect (manage_icon); |
473 | - this.focus_in_event.connect (on_focus_in); |
474 | - this.focus_out_event.connect (on_focus_out); |
475 | - this.icon_press.connect (icon_pressed); |
476 | - setup_clear_icon (); |
477 | - this.is_searching = true; |
478 | - |
479 | - } |
480 | - |
481 | - private void setup_clear_icon () { |
482 | - |
483 | - var stock_item = Gtk.StockItem (); |
484 | - stock_item.stock_id = "edit-clear-symbolic"; |
485 | - stock_item.label = null; |
486 | - stock_item.modifier = 0; |
487 | - stock_item.keyval = 0; |
488 | - stock_item.translation_domain = Gtk.Stock.CLEAR; |
489 | - var factory = new Gtk.IconFactory (); |
490 | - var icon_set = new Gtk.IconSet (); |
491 | - var icon_source = new Gtk.IconSource (); |
492 | - icon_source.set_icon_name (Gtk.Stock.CLEAR); |
493 | - icon_set.add_source (icon_source); |
494 | - icon_source.set_icon_name ("edit-clear-symbolic"); |
495 | - icon_set.add_source (icon_source); |
496 | - factory.add ("edit-clear-symbolic", icon_set); |
497 | - Gtk.Stock.add ({stock_item}); |
498 | - factory.add_default (); |
499 | - |
500 | - } |
501 | - |
502 | - private new void hint () { |
503 | - |
504 | - this.is_searching = false; |
505 | - this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null); |
506 | - base.hint (); |
507 | - |
508 | - } |
509 | - |
510 | - private new bool on_focus_in () { |
511 | - |
512 | - if (!this.is_searching) { |
513 | - this.unhint (); |
514 | - this.is_searching = false; |
515 | - } |
516 | - return false; |
517 | - |
518 | - } |
519 | - |
520 | - private new bool on_focus_out () { |
521 | - |
522 | - if (this.get_text() == "") { |
523 | - this.hint (); |
524 | - this.is_searching = false; |
525 | - } |
526 | - return false; |
527 | - |
528 | - } |
529 | - |
530 | - private void manage_icon () { |
531 | - |
532 | - if (this.text != "") { |
533 | - this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, "edit-clear-symbolic"); |
534 | - } |
535 | - else { |
536 | - this.set_icon_from_stock (Gtk.EntryIconPosition.SECONDARY, null); |
537 | - } |
538 | - |
539 | - } |
540 | - |
541 | - private void icon_pressed (Gtk.EntryIconPosition icon_position) { |
542 | - |
543 | - if (icon_position == Gtk.EntryIconPosition.SECONDARY) { |
544 | - this.is_searching = false; |
545 | - this.text = ""; |
546 | - this.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, null); |
547 | - this.is_searching = true; |
548 | - } |
549 | - else { |
550 | - if (!this.is_focus) { |
551 | - this.is_searching = false; |
552 | - this.hint (); |
553 | - } |
554 | - } |
555 | - |
556 | - } |
557 | -} |
558 | |
559 | === modified file 'src/main_window.vala' |
560 | --- src/main_window.vala 2011-07-25 20:14:39 +0000 |
561 | +++ src/main_window.vala 2011-07-25 23:31:27 +0000 |
562 | @@ -20,272 +20,187 @@ |
563 | using Gtk; |
564 | using Granite.Widgets; |
565 | |
566 | -public class MainWindow : Window { |
567 | - |
568 | - private const string TITLE = "Scratch"; |
569 | - |
570 | - //widgets for the window |
571 | - public ScratchNotebook notebook; |
572 | - |
573 | - //widgets for the toolbars |
574 | - public Toolbar BasicToolbar; |
575 | - public Toolbar SearchToolbar; |
576 | - public HBox hbox; |
577 | - |
578 | - public ToolButton new_; |
579 | - public ToolButton open_; |
580 | - public ToolButton save_; |
581 | - public SeparatorToolItem separator1; |
582 | - public ToolButton cancel_; |
583 | - public ToolButton repeat_; |
584 | - public ToolItem combo; |
585 | - public ComboBox cb; |
586 | - public SeparatorToolItem separator2; |
587 | - |
588 | - public SeparatorToolItem separator3; |
589 | - public ToolItem entry_cont; |
590 | - public Entry entry; |
591 | - public AppMenu app_menu; |
592 | - |
593 | - //dialogs |
594 | - public FileChooserDialog filech; |
595 | - |
596 | - public MainWindow (string arg="") { |
597 | - if (arg == "") { |
598 | - this.title = this.TITLE; |
599 | - } |
600 | - else { |
601 | - this.title = arg; |
602 | - } |
603 | - |
604 | - load_file (arg); |
605 | - |
606 | - this.set_default_size (800, 500); |
607 | - //this.set_icon ("text-editor"); |
608 | - //this.maximize (); |
609 | - |
610 | - //create_window(); |
611 | - //connect_signals(); |
612 | - } |
613 | - |
614 | - public void create_window () { |
615 | - create_toolbars (); |
616 | - //notebook, textview and its scrolledwindow |
617 | - this.notebook = new ScratchNotebook (); |
618 | - this.notebook.add_tab(); |
619 | - |
620 | - //addingo all to the vbox |
621 | - var vbox = new VBox (false, 0); |
622 | - vbox.pack_start (hbox, false, false, 0); |
623 | - vbox.pack_start (notebook, true, true, 0); |
624 | - |
625 | - this.add (vbox); |
626 | - |
627 | - } |
628 | - |
629 | - public void connect_signals () { |
630 | - //signals for the window |
631 | - this.destroy.connect (Gtk.main_quit); |
632 | - //signals for the toolbars |
633 | - this.new_.clicked.connect (on_new_clicked); |
634 | - this.open_.clicked.connect (on_open_clicked); |
635 | - this.save_.clicked.connect (on_save_clicked); |
636 | - |
637 | - } |
638 | - |
639 | - public void create_toolbars () { |
640 | - // |
641 | - // FIRST TOOLBAR |
642 | - // |
643 | - this.BasicToolbar = new Toolbar (); |
644 | - |
645 | - this.new_ = new ToolButton.from_stock(Stock.NEW); |
646 | - this.open_ = new ToolButton.from_stock (Stock.OPEN); |
647 | - this.save_ = new ToolButton.from_stock (Stock.SAVE); |
648 | - this.separator1 = new SeparatorToolItem (); |
649 | - this.cancel_ = new ToolButton.from_stock (Stock.UNDO); |
650 | - this.repeat_ = new ToolButton.from_stock (Stock.REDO); |
651 | - this.separator2 = new SeparatorToolItem (); |
652 | - this.combo = new ToolItem (); |
653 | - |
654 | - this.cb = new ComboBox (); |
655 | - this.combo.add (cb); |
656 | - this.combo.set_expand (false); |
657 | - |
658 | - BasicToolbar.add (new_); |
659 | - BasicToolbar.add (open_); |
660 | - BasicToolbar.add (save_); |
661 | - BasicToolbar.add (separator1); |
662 | - BasicToolbar.add (cancel_); |
663 | - BasicToolbar.add (repeat_); |
664 | - BasicToolbar.add (separator2); |
665 | - BasicToolbar.add (combo); |
666 | - |
667 | - // |
668 | - // SECOND TOOLBAR |
669 | - // |
670 | - this.SearchToolbar = new Toolbar (); |
671 | - |
672 | - this.separator3 = new SeparatorToolItem (); |
673 | - |
674 | - this.entry = new SearchBar ("Search in the text..."); |
675 | - this.entry_cont = new ToolItem (); |
676 | - this.entry_cont.add (entry); |
677 | - this.entry_cont.set_expand (true); |
678 | - |
679 | - //var image = new Image.from_stock (Stock.PROPERTIES, IconSize.LARGE_TOOLBAR); |
680 | - var menu = new MenuProperties (); |
681 | - |
682 | - //var w = new MainWindow (); |
683 | - |
684 | - this.app_menu = new AppMenu (menu); |
685 | - |
686 | - SearchToolbar.add (separator3); |
687 | - SearchToolbar.add (entry_cont); |
688 | - SearchToolbar.add (app_menu); |
689 | - //////////// |
690 | - this.hbox = new HBox (false, 0); |
691 | - |
692 | - hbox.pack_start (BasicToolbar, true, true, 0); |
693 | - hbox.pack_end (SearchToolbar, true, true, 0); |
694 | - |
695 | - } |
696 | - |
697 | - //signals functions |
698 | - public void on_new_clicked () { |
699 | - int new_tab_index = notebook.add_tab(); |
700 | - notebook.set_current_page(new_tab_index); |
701 | - } |
702 | - |
703 | - public void on_open_clicked () { |
704 | - this.filech = new FileChooserDialog ("Open a file", this, FileChooserAction.OPEN); |
705 | - filech.add_button (Stock.CANCEL, ResponseType.CANCEL); |
706 | - filech.add_button (Stock.OPEN, ResponseType.ACCEPT); |
707 | - filech.set_default_response (ResponseType.ACCEPT); |
708 | - |
709 | - //if (filech.run () == ResponseType.OK) { |
710 | - // stdout.printf ("filename = %s\n".printf (filech.get_filename ())); |
711 | - //} |
712 | - filech.run (); |
713 | - filech.response.connect (on_response); |
714 | - |
715 | - } |
716 | - |
717 | - |
718 | - public void on_response (Dialog source, int response_id) { |
719 | - switch (response_id) { |
720 | - case ResponseType.ACCEPT: |
721 | - string filename = filech.get_filename(); |
722 | - if (filename != null) { |
723 | - stdout.printf ("opening: %s\n".printf (filech.get_filename ())); |
724 | - load_file ( filech.get_filename () ); |
725 | - } |
726 | - |
727 | - filech.close (); |
728 | - break; |
729 | - case ResponseType.CANCEL: |
730 | - filech.close (); |
731 | - break; |
732 | - } |
733 | - |
734 | - } |
735 | - |
736 | - |
737 | - public void on_save_clicked() { |
738 | - var current_tab = (Tab) notebook.get_nth_page (notebook.get_current_page()); |
739 | - |
740 | - if (current_tab.filename == null) { |
741 | - |
742 | - this.filech = new FileChooserDialog ("Save as", this, FileChooserAction.SAVE); |
743 | - filech.add_button (Stock.CANCEL, ResponseType.CANCEL); |
744 | - filech.add_button (Stock.SAVE, ResponseType.ACCEPT); |
745 | - filech.set_default_response (ResponseType.ACCEPT); |
746 | - |
747 | - filech.run (); |
748 | - filech.response.connect (on_save_response); |
749 | - |
750 | - //TODO "save as" dialog |
751 | - } |
752 | - |
753 | - save_file (current_tab.filename, current_tab.text_view.buffer.text); |
754 | - } |
755 | - |
756 | - |
757 | - public void on_save_response(Dialog source, int response_id) { |
758 | - switch (response_id) { |
759 | - case ResponseType.ACCEPT: |
760 | - string filename = filech.get_filename(); |
761 | - var current_tab = (Tab) notebook.get_nth_page (notebook.get_current_page()); |
762 | - save_file (filename, current_tab.text_view.buffer.text); |
763 | - break; |
764 | - } |
765 | - } |
766 | - |
767 | - //generic functions |
768 | - public void load_file (string filename) { |
769 | - if (filename != "") { |
770 | - try { |
771 | - string text; |
772 | - FileUtils.get_contents (filename, out text); |
773 | - |
774 | - //get the filename from strig filename =) |
775 | - var name = filename.split("/"); |
776 | - |
777 | - //create new tab |
778 | - int tab_index = notebook.add_tab(name[name.length-1]); |
779 | - notebook.set_current_page(tab_index); |
780 | - var new_tab = (Tab) notebook.get_nth_page (tab_index); |
781 | - |
782 | - //set new values |
783 | - new_tab.text_view.buffer.text = text; |
784 | - new_tab.filename = filename; |
785 | - this.title = this.TITLE + " - " + filename; |
786 | - |
787 | - } catch (Error e) { |
788 | - stderr.printf ("Error: %s\n", e.message); |
789 | - } |
790 | - } |
791 | - |
792 | - } |
793 | - |
794 | - public int save_file (string filename, string contents) { |
795 | - |
796 | - if (filename != "") { |
797 | - try { |
798 | - FileUtils.set_contents (filename, contents); |
799 | - var name = filename.split("/"); |
800 | - notebook.change_label (name[name.length-1]); |
801 | - return 0; |
802 | - } catch (Error e) { |
803 | - stderr.printf ("Error: %s\n", e.message); |
804 | - return 1; |
805 | - } |
806 | - |
807 | - } else return 1; |
808 | - |
809 | - } |
810 | - |
811 | - public static void main (string[] args) { |
812 | - //TO DO: modify the if loop |
813 | - if (args[1] != null) { |
814 | - Gtk.init (ref args); |
815 | - var window =new MainWindow (args[1]); |
816 | - window.create_window(); |
817 | - window.connect_signals(); |
818 | - window.show_all (); |
819 | - Gtk.main (); |
820 | - } |
821 | - |
822 | - else { |
823 | - Gtk.init (ref args); |
824 | - var window =new MainWindow (""); |
825 | - window.create_window(); |
826 | - window.connect_signals(); |
827 | - window.show_all (); |
828 | - Gtk.main (); |
829 | - } |
830 | - |
831 | - } |
832 | - |
833 | -} |
834 | - |
835 | +using Scratch.Widgets; |
836 | +using Scratch.Dialogs; |
837 | + |
838 | +namespace Scratch { |
839 | + |
840 | + public class MainWindow : Window { |
841 | + |
842 | + private const string TITLE = "Scratch"; |
843 | + |
844 | + //widgets for the window |
845 | + public ScratchNotebook notebook; |
846 | + |
847 | + //widgets for the toolbars |
848 | + public Widgets.Toolbar toolbar; |
849 | + |
850 | + //dialogs |
851 | + public FileChooserDialog filech; |
852 | + public Preferences preferences; |
853 | + |
854 | + public MainWindow (string arg="") { |
855 | + if (arg == "") { |
856 | + this.title = this.TITLE; |
857 | + } |
858 | + else { |
859 | + this.title = arg; |
860 | + } |
861 | + |
862 | + load_file (arg); |
863 | + |
864 | + this.set_default_size (800, 500); |
865 | + //this.set_icon ("text-editor"); |
866 | + //this.maximize (); |
867 | + |
868 | + //create_window(); |
869 | + //connect_signals(); |
870 | + } |
871 | + |
872 | + public void create_window () { |
873 | + |
874 | + //notebook, textview and its scrolledwindow |
875 | + this.notebook = new ScratchNotebook (); |
876 | + this.notebook.add_tab(); |
877 | + |
878 | + this.toolbar = new Widgets.Toolbar (this); |
879 | + |
880 | + //adding all to the vbox |
881 | + var vbox = new VBox (false, 0); |
882 | + vbox.pack_start (toolbar, false, false, 0); |
883 | + vbox.pack_start (notebook, true, true, 0); |
884 | + |
885 | + this.add (vbox); |
886 | + |
887 | + } |
888 | + |
889 | + public void connect_signals () { |
890 | + |
891 | + //signals for the window |
892 | + this.destroy.connect (Gtk.main_quit); |
893 | + |
894 | + //signals for the toolbar |
895 | + toolbar.new_button.clicked.connect (on_new_clicked); |
896 | + toolbar.open_button.clicked.connect (on_open_clicked); |
897 | + toolbar.save_button.clicked.connect (on_save_clicked); |
898 | + |
899 | + } |
900 | + |
901 | + |
902 | + //signals functions |
903 | + public void on_new_clicked () { |
904 | + int new_tab_index = notebook.add_tab (); |
905 | + notebook.set_current_page (new_tab_index); |
906 | + } |
907 | + |
908 | + public void on_open_clicked () { |
909 | + |
910 | + this.filech = new FileChooserDialog ("Open a file", this, FileChooserAction.OPEN); |
911 | + filech.add_button (Stock.CANCEL, ResponseType.CANCEL); |
912 | + filech.add_button (Stock.OPEN, ResponseType.ACCEPT); |
913 | + filech.set_default_response (ResponseType.ACCEPT); |
914 | + |
915 | + //if (filech.run () == ResponseType.OK) { |
916 | + // stdout.printf ("filename = %s\n".printf (filech.get_filename ())); |
917 | + //} |
918 | + filech.run (); |
919 | + filech.response.connect (on_response); |
920 | + |
921 | + } |
922 | + |
923 | + |
924 | + public void on_response (Dialog source, int response_id) { |
925 | + switch (response_id) { |
926 | + case ResponseType.ACCEPT: |
927 | + string filename = filech.get_filename(); |
928 | + if (filename != null) { |
929 | + stdout.printf ("opening: %s\n".printf (filech.get_filename ())); |
930 | + load_file ( filech.get_filename () ); |
931 | + } |
932 | + |
933 | + filech.close (); |
934 | + break; |
935 | + case ResponseType.CANCEL: |
936 | + filech.close (); |
937 | + break; |
938 | + } |
939 | + |
940 | + } |
941 | + |
942 | + |
943 | + public void on_save_clicked() { |
944 | + var current_tab = (Tab) notebook.get_nth_page (notebook.get_current_page()); |
945 | + |
946 | + if (current_tab.filename == null) { |
947 | + |
948 | + this.filech = new FileChooserDialog ("Save as", this, FileChooserAction.SAVE); |
949 | + filech.add_button (Stock.CANCEL, ResponseType.CANCEL); |
950 | + filech.add_button (Stock.SAVE, ResponseType.ACCEPT); |
951 | + filech.set_default_response (ResponseType.ACCEPT); |
952 | + |
953 | + filech.run (); |
954 | + filech.response.connect (on_save_response); |
955 | + |
956 | + //TODO "save as" dialog |
957 | + } |
958 | + |
959 | + save_file (current_tab.filename, current_tab.text_view.buffer.text); |
960 | + } |
961 | + |
962 | + |
963 | + public void on_save_response(Dialog source, int response_id) { |
964 | + switch (response_id) { |
965 | + case ResponseType.ACCEPT: |
966 | + string filename = filech.get_filename(); |
967 | + var current_tab = (Tab) notebook.get_nth_page (notebook.get_current_page()); |
968 | + save_file (filename, current_tab.text_view.buffer.text); |
969 | + break; |
970 | + } |
971 | + } |
972 | + |
973 | + //generic functions |
974 | + public void load_file (string filename) { |
975 | + if (filename != "") { |
976 | + try { |
977 | + string text; |
978 | + FileUtils.get_contents (filename, out text); |
979 | + |
980 | + //get the filename from strig filename =) |
981 | + var name = filename.split("/"); |
982 | + |
983 | + //create new tab |
984 | + int tab_index = notebook.add_tab(name[name.length-1]); |
985 | + notebook.set_current_page(tab_index); |
986 | + var new_tab = (Tab) notebook.get_nth_page (tab_index); |
987 | + |
988 | + //set new values |
989 | + new_tab.text_view.buffer.text = text; |
990 | + new_tab.filename = filename; |
991 | + this.title = this.TITLE + " - " + filename; |
992 | + |
993 | + } catch (Error e) { |
994 | + stderr.printf ("Error: %s\n", e.message); |
995 | + } |
996 | + } |
997 | + |
998 | + } |
999 | + |
1000 | + public int save_file (string filename, string contents) { |
1001 | + |
1002 | + if (filename != "") { |
1003 | + try { |
1004 | + FileUtils.set_contents (filename, contents); |
1005 | + var name = filename.split("/"); |
1006 | + notebook.change_label (name[name.length-1]); |
1007 | + return 0; |
1008 | + } catch (Error e) { |
1009 | + stderr.printf ("Error: %s\n", e.message); |
1010 | + return 1; |
1011 | + } |
1012 | + |
1013 | + } else return 1; |
1014 | + |
1015 | + } |
1016 | + |
1017 | + } |
1018 | +} // Namespace |
1019 | |
1020 | === removed file 'src/menu.vala' |
1021 | --- src/menu.vala 2011-07-25 08:59:21 +0000 |
1022 | +++ src/menu.vala 1970-01-01 00:00:00 +0000 |
1023 | @@ -1,38 +0,0 @@ |
1024 | -/*** |
1025 | - BEGIN LICENSE |
1026 | - |
1027 | - Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com> |
1028 | - This program is free software: you can redistribute it and/or modify it |
1029 | - under the terms of the GNU Lesser General Public License version 3, as published |
1030 | - by the Free Software Foundation. |
1031 | - |
1032 | - This program is distributed in the hope that it will be useful, but |
1033 | - WITHOUT ANY WARRANTY; without even the implied warranties of |
1034 | - MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1035 | - PURPOSE. See the GNU General Public License for more details. |
1036 | - |
1037 | - You should have received a copy of the GNU General Public License along |
1038 | - with this program. If not, see <http://www.gnu.org/licenses/> |
1039 | - |
1040 | - END LICENSE |
1041 | -***/ |
1042 | - |
1043 | -using Gtk; |
1044 | - |
1045 | -public class MenuProperties : Menu { |
1046 | - |
1047 | - private ImageMenuItem preferences; |
1048 | - |
1049 | - public MenuProperties () { |
1050 | - create (); |
1051 | - } |
1052 | - |
1053 | - public void create () { |
1054 | - this.preferences = new ImageMenuItem.from_stock (Stock.PREFERENCES, null); |
1055 | - |
1056 | - this.append (preferences); |
1057 | - preferences.show(); |
1058 | - } |
1059 | - |
1060 | - |
1061 | -} |
1062 | |
1063 | === removed file 'src/notebook.vala' |
1064 | --- src/notebook.vala 2011-07-25 20:14:39 +0000 |
1065 | +++ src/notebook.vala 1970-01-01 00:00:00 +0000 |
1066 | @@ -1,130 +0,0 @@ |
1067 | -/*** |
1068 | - BEGIN LICENSE |
1069 | - |
1070 | - Copyright (C) 2011 Mario Guerriero <mefrio.g@gmail.com> |
1071 | - This program is free software: you can redistribute it and/or modify it |
1072 | - under the terms of the GNU Lesser General Public License version 3, as published |
1073 | - by the Free Software Foundation. |
1074 | - |
1075 | - This program is distributed in the hope that it will be useful, but |
1076 | - WITHOUT ANY WARRANTY; without even the implied warranties of |
1077 | - MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1078 | - PURPOSE. See the GNU General Public License for more details. |
1079 | - |
1080 | - You should have received a copy of the GNU General Public License along |
1081 | - with this program. If not, see <http://www.gnu.org/licenses/> |
1082 | - |
1083 | - END LICENSE |
1084 | -***/ |
1085 | - |
1086 | -using Gtk; |
1087 | -using Pango; |
1088 | -using GtkSource; |
1089 | - |
1090 | -public class Tab : ScrolledWindow { |
1091 | - |
1092 | - public TextView text_view; |
1093 | - public Label label; |
1094 | - public string filename; |
1095 | - |
1096 | - public Tab() { |
1097 | - |
1098 | - var s = new View (); |
1099 | - |
1100 | - this.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC); |
1101 | - this.text_view = new TextView (); |
1102 | - this.add (text_view); |
1103 | - this.label = new Label ("New file"); |
1104 | - this.filename = null; |
1105 | - this.show_all(); |
1106 | - |
1107 | - } |
1108 | - |
1109 | -} |
1110 | -/* |
1111 | -public class TabLabel : HBox { |
1112 | - |
1113 | - public HBox tablabel; |
1114 | - public Label label; |
1115 | - public Button close; |
1116 | - |
1117 | - public TabLabel(string label) { |
1118 | - |
1119 | - this.label = new Label (label); |
1120 | - |
1121 | - var image = new Image.from_stock(Stock.CLOSE, IconSize.MENU); |
1122 | - this.close = new Button (); |
1123 | - this.close.clicked.connect (on_close_clicked); |
1124 | - this.close.set_relief (ReliefStyle.NONE); |
1125 | - this.close.set_image (image); |
1126 | - |
1127 | - this.hbox.pack_start (this.label, false, false, 0); |
1128 | - this.hbox.pack_start (this.close, false, false, 0); |
1129 | - |
1130 | - this.show_all (); |
1131 | - } |
1132 | - |
1133 | - public void on_close_clicked() { |
1134 | - |
1135 | - return; |
1136 | - |
1137 | - } |
1138 | - |
1139 | - public void change_label(string label) { |
1140 | - |
1141 | - this.label.set_text (label); |
1142 | - |
1143 | - } |
1144 | - |
1145 | -} |
1146 | -*/ |
1147 | -public class ScratchNotebook : Notebook { |
1148 | - |
1149 | - //widgets for the label |
1150 | - public HBox tablabel; |
1151 | - public Label label; |
1152 | - public Button close; |
1153 | - |
1154 | - public int add_tab(string tabtext="New file") { |
1155 | - |
1156 | - //tab label |
1157 | - this.tablabel = new HBox (false, 0); |
1158 | - |
1159 | - this.label = new Label (tabtext); |
1160 | - |
1161 | - var image = new Image.from_stock(Stock.CLOSE, IconSize.MENU); |
1162 | - this.close = new Button (); |
1163 | - this.close.clicked.connect (on_close_clicked); |
1164 | - this.close.set_relief (ReliefStyle.NONE); |
1165 | - this.close.set_image (image); |
1166 | - |
1167 | - this.tablabel.pack_start (this.label, false, false, 0); |
1168 | - this.tablabel.pack_start (this.close, false, false, 0); |
1169 | - |
1170 | - this.tablabel.show_all (); |
1171 | - |
1172 | - //create the tab |
1173 | - var new_tab = new Tab(); |
1174 | - this.set_tab_reorderable (new_tab, true); |
1175 | - return this.append_page (new_tab, this.tablabel); |
1176 | - } |
1177 | - |
1178 | - public void change_label(string label) { |
1179 | - |
1180 | - this.label.set_text (label); |
1181 | - |
1182 | - } |
1183 | - |
1184 | - //events |
1185 | - public void on_close_clicked () { |
1186 | - |
1187 | - return; |
1188 | - |
1189 | - } |
1190 | - |
1191 | - public ScratchNotebook() { |
1192 | - this.set_scrollable (true); |
1193 | - } |
1194 | - |
1195 | - |
1196 | -} |
1197 | |
1198 | === added file 'src/scratch.vala' |
1199 | --- src/scratch.vala 1970-01-01 00:00:00 +0000 |
1200 | +++ src/scratch.vala 2011-07-25 23:31:27 +0000 |
1201 | @@ -0,0 +1,86 @@ |
1202 | +/*** |
1203 | + BEGIN LICENSE |
1204 | + |
1205 | + Copyright (C) 2011 Giulio Collura <random.cpp@gmail.com> |
1206 | + This program is free software: you can redistribute it and/or modify it |
1207 | + under the terms of the GNU Lesser General Public License version 3, as published |
1208 | + by the Free Software Foundation. |
1209 | + |
1210 | + This program is distributed in the hope that it will be useful, but |
1211 | + WITHOUT ANY WARRANTY; without even the implied warranties of |
1212 | + MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1213 | + PURPOSE. See the GNU General Public License for more details. |
1214 | + |
1215 | + You should have received a copy of the GNU General Public License along |
1216 | + with this program. If not, see <http://www.gnu.org/licenses/> |
1217 | + |
1218 | + END LICENSE |
1219 | +***/ |
1220 | + |
1221 | + |
1222 | +using Gtk; |
1223 | +using Gdk; |
1224 | + |
1225 | +using Granite; |
1226 | + |
1227 | +namespace Scratch { |
1228 | + |
1229 | + public class Scratch : Granite.Application { |
1230 | + |
1231 | + private MainWindow window = null; |
1232 | + |
1233 | + construct { |
1234 | + |
1235 | + build_data_dir = Constants.DATADIR; |
1236 | + build_pkg_data_dir = Constants.PKGDATADIR; |
1237 | + build_release_name = Constants.RELEASE_NAME; |
1238 | + build_version = Constants.VERSION; |
1239 | + build_version_info = Constants.VERSION_INFO; |
1240 | + |
1241 | + program_name = "Scratch"; |
1242 | + exec_name = "scratch"; |
1243 | + app_copyright = "GPLv3"; |
1244 | + app_icon = "text-editor"; |
1245 | + app_launcher = "scratch.desktop"; |
1246 | + application_id = "net.launchpad.scratch"; |
1247 | + main_url = "https://launchpad.net/scratch"; |
1248 | + bug_url = "https://bugs.launchpad.net/scratch"; |
1249 | + help_url = "https://answers.launchpad.net/scratch"; |
1250 | + translate_url = "https://translations.launchpad.net/scratch"; |
1251 | + |
1252 | + about_authors = {"Mario Guerriero <mefrio.g@gmail.com>", |
1253 | + "Giulio Collura <random.cpp@gmail.com>"}; |
1254 | + |
1255 | + about_documenters = {"",""}; |
1256 | + about_artists = {"Mario Guerriero <mefrio.g@gmail.com>"}; |
1257 | + about_translators = ""; |
1258 | + |
1259 | + |
1260 | + } |
1261 | + |
1262 | + protected override void activate () { |
1263 | + |
1264 | + if (get_windows () != null) { |
1265 | + // show window if app is already open |
1266 | + window.present (); |
1267 | + |
1268 | + } else { |
1269 | + |
1270 | + // if not, create a new one. |
1271 | + window = new MainWindow (); |
1272 | + window.set_application (this); |
1273 | + window.create_window(); |
1274 | + window.connect_signals(); |
1275 | + |
1276 | + window.show_all (); |
1277 | + |
1278 | + } |
1279 | + } |
1280 | + |
1281 | + public static int main (string[] args) { |
1282 | + |
1283 | + return new Scratch ().run (args); |
1284 | + |
1285 | + } |
1286 | + } |
1287 | +} |