Skip to content

Commit

Permalink
Added an option in preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Collura committed Jul 28, 2011
1 parent 60a920f commit a962ddf
Show file tree
Hide file tree
Showing 8 changed files with 727 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ OPTIONS
add_executable (scratch ${VALA_C})

#TODO: Installation
#install (TARGETS scratch RUNTIME DESTINATION bin)
#install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/scratch.desktop DESTINATION /usr/share/applications)
install (TARGETS scratch RUNTIME DESTINATION bin)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/scratch.desktop DESTINATION /usr/share/applications)

#
# GSettings Schema
Expand Down
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions org.elementary.scratch.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,15 @@
<summary>Tab Size</summary>
<description>Specifies the number of spaces that should be displayed instead of Tab characters.</description>
</key>
<key name="use-system-font" type="b">
<default>true</default>
<summary>Use system font</summary>
<description>Whether Scratch should use the default system font</description>
</key>
<key name="font" type="s">
<default>'Droid Sans Mono 9'</default>
<summary>Preferred Font</summary>
<description>Set the preferred font.</description>
</key>
</schema>
</schemalist>
18 changes: 18 additions & 0 deletions src/Dialogs/preferences_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ namespace Scratch.Dialogs {
private HBox padding;

private Label editor_label;
private Label font_label;

private CheckButton line_numbers;
private CheckButton highlight_current_line;
private CheckButton spaces_instead_of_tabs;
private SpinButton indent_width;
private CheckButton use_system_font;
private FontButton select_font;

private Button close_button;

Expand Down Expand Up @@ -62,6 +65,10 @@ namespace Scratch.Dialogs {
editor_label = new Label ("Editor Settings");
editor_label.xalign = 0.0f;
editor_label.set_markup ("<b>Editor Settings</b>");

font_label = new Label ("Font Settings");
font_label.xalign = 0.0f;
font_label.set_markup ("<b>Font Settings</b>");

line_numbers = new CheckButton.with_label ("Show line numbers");
line_numbers.set_active (Scratch.settings.show_line_numbers);
Expand All @@ -79,6 +86,12 @@ namespace Scratch.Dialogs {
indent_width_box.pack_start (indent_width_l, false, true, 0);
indent_width_box.pack_start (indent_width, false, true, 0);

use_system_font = new CheckButton.with_label ("Use system font");
use_system_font.set_active (Scratch.settings.use_system_font);

select_font = new FontButton ();
select_font.set_font_name (Scratch.settings.font);

close_button = new Button.with_label ("Close");

var bottom_buttons = new HButtonBox ();
Expand All @@ -90,6 +103,9 @@ namespace Scratch.Dialogs {
content.pack_start (wrap_alignment (highlight_current_line, 0, 0, 0, 10), false, true, 0);
content.pack_start (wrap_alignment (spaces_instead_of_tabs, 0, 0, 0, 10), false, true, 0);
content.pack_start (wrap_alignment (indent_width_box, 0, 0, 0, 10), false, true, 0);
content.pack_start (font_label, false, true, 0);
content.pack_start (wrap_alignment (use_system_font, 0, 0, 0, 10), false, true, 0);
content.pack_start (wrap_alignment (select_font, 0, 0, 0, 10), false, true, 0);

content.pack_end (bottom_buttons, false, true, 10);

Expand Down Expand Up @@ -121,6 +137,8 @@ namespace Scratch.Dialogs {
Scratch.settings.highlight_current_line = highlight_current_line.get_active ();
Scratch.settings.spaces_instead_of_tabs = spaces_instead_of_tabs.get_active ();
Scratch.settings.indent_width = (int) indent_width.value;
Scratch.settings.use_system_font = use_system_font.get_active ();
Scratch.settings.font = select_font.font_name;

this.destroy ();

Expand Down
11 changes: 7 additions & 4 deletions src/Widgets/notebook.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ namespace Scratch.Widgets {

public class Tab : ScrolledWindow {

private MainWindow window;

public SourceView text_view;
public TabLabel label;
private ScratchNotebook notebook;
public string filename = null;
public bool saved = true;


public Tab (ScratchNotebook parent, string labeltext) {

public Tab (ScratchNotebook parent, string labeltext, MainWindow window) {

this.window = window;
this.notebook = parent;

set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
notebook.set_tab_reorderable (this, true);

text_view = new SourceView ();
text_view = new SourceView (window);
label = new TabLabel(this, labeltext);
add (text_view);
show_all();
Expand Down Expand Up @@ -264,7 +267,7 @@ namespace Scratch.Widgets {

public int add_tab (string labeltext="New file") {

var new_tab = new Tab (this, labeltext);
var new_tab = new Tab (this, labeltext, window);
return this.append_page (new_tab, new_tab.label);

}
Expand Down
17 changes: 11 additions & 6 deletions src/Widgets/sourceview.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ using GtkSource;
namespace Scratch.Widgets {

public class SourceView : View {

private MainWindow window;

public GtkSource.Buffer buffer;
public LanguageManager manager;

private string current_font;
public string current_font;

public SourceView () {
public SourceView (MainWindow window) {

this.window = window;

manager = new LanguageManager ();

use_default_font (true);
modify_font (Pango.FontDescription.from_string (current_font));

buffer = new Buffer (null);
set_buffer (buffer);
//buffer.set_language (manager.get_language ("c"));
Expand Down Expand Up @@ -91,6 +92,10 @@ namespace Scratch.Widgets {
highlight_current_line = Scratch.settings.highlight_current_line;
insert_spaces_instead_of_tabs = Scratch.settings.spaces_instead_of_tabs;
indent_width = Scratch.settings.indent_width;

current_font = Scratch.settings.font;
use_default_font (Scratch.settings.use_system_font);
modify_font (Pango.FontDescription.from_string (current_font));

}

Expand All @@ -100,7 +105,7 @@ namespace Scratch.Widgets {
Scratch.settings.highlight_current_line = highlight_current_line;
Scratch.settings.spaces_instead_of_tabs = insert_spaces_instead_of_tabs;
Scratch.settings.indent_width = indent_width;

Scratch.settings.font = current_font;

}

Expand Down
6 changes: 3 additions & 3 deletions src/scratch.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ namespace Scratch {
settings = new Settings ();

}

protected override void activate () {

if (get_windows () != null) {
// show window if app is already open
window.present ();
window.present ();

} else {

Expand All @@ -92,7 +92,7 @@ namespace Scratch {
}

public static int main (string[] args) {

return new Scratch ().run (args);

}
Expand Down
2 changes: 2 additions & 0 deletions src/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace Scratch {
public bool highlight_current_line { get; set; }
public bool spaces_instead_of_tabs { get; set; }
public int indent_width { get; set; }
public bool use_system_font { get; set; }
public string font { get; set; }

public Settings () {
base ("org.elementary.Scratch.Settings");
Expand Down

0 comments on commit a962ddf

Please sign in to comment.