├── resource ├── codefad.png ├── window.png ├── codefad_128.png ├── codefad_32.png ├── codefad_64.png ├── old_window.png ├── yeah_codefad.png ├── GitHub-Mark-64px.png └── GitHub-Mark-Light-32px.png ├── codefad.desktop ├── uninstall.sh ├── README.md ├── make.sh ├── install.sh ├── src ├── Terminal.vala ├── EntryCompletion.vala ├── FileOperations.vala ├── CommandParser.vala ├── Settings.vala └── CodeFad.vala └── LICENSE /resource/codefad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/codefad.png -------------------------------------------------------------------------------- /resource/window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/window.png -------------------------------------------------------------------------------- /resource/codefad_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/codefad_128.png -------------------------------------------------------------------------------- /resource/codefad_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/codefad_32.png -------------------------------------------------------------------------------- /resource/codefad_64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/codefad_64.png -------------------------------------------------------------------------------- /resource/old_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/old_window.png -------------------------------------------------------------------------------- /resource/yeah_codefad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/yeah_codefad.png -------------------------------------------------------------------------------- /resource/GitHub-Mark-64px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/GitHub-Mark-64px.png -------------------------------------------------------------------------------- /resource/GitHub-Mark-Light-32px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferhatgec/codefad/HEAD/resource/GitHub-Mark-Light-32px.png -------------------------------------------------------------------------------- /codefad.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Fegeya CodeFad 3 | Exec=codefad %U 4 | Icon=/usr/share/pixmaps/codefad/codefad.png 5 | Type=Application 6 | Categories=GTK;GNOME;Code Editor; 7 | Terminal=false 8 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Required Vala to C compiler, GTK3 library, GtkSourceView (devel) and GCC. 4 | rm -rf ~.config/codefad/ 5 | 6 | sudo rm -f /bin/codefad 7 | 8 | sudo rm -rf /usr/share/pixmaps/codefad/ 9 | 10 | sudo rm -f /usr/share/applications/codefad.desktop 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fegeya CodeFad 2 | ## Fegeya CodeFad is code editor for everyone. 3 | 4 | ![Meet with CodeFad!](resource/window.png) 5 | 6 | ### Written in Vala. 7 | 8 | ### Required Vala, GTK, GtkSourceView (devel) and GCC. 9 | 10 | ### Fegeya CodeFad licensed under the terms of MIT License. 11 | -------------------------------------------------------------------------------- /make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Required Vala to C compiler, GTK3 library, GtkSourceView (devel) and GCC. 4 | valac --pkg gtk+-3.0 --pkg gtksourceview-4 --pkg vte-2.91 ./src/FileOperations.vala ./src/EntryCompletion.vala ./src/Terminal.vala ./src/CommandParser.vala ./src/Settings.vala ./src/CodeFad.vala -o codefad 5 | 6 | sudo mkdir /usr/share/pixmaps/codefad/ 7 | sudo cp resource/*.png /usr/share/pixmaps/codefad/ 8 | sudo cp codefad.desktop /usr/share/applications/ 9 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Required Vala to C compiler, GTK3 library, GtkSourceView (devel) and GCC. 4 | sudo valac --pkg gtk+-3.0 --pkg gtksourceview-4 --pkg vte-2.91 ./src/FileOperations.vala ./src/EntryCompletion.vala ./src/CommandParser.vala ./src/Terminal.vala ./src/Settings.vala ./src/CodeFad.vala -o /bin/codefad 5 | 6 | sudo mkdir /usr/share/pixmaps/codefad/ 7 | sudo cp resource/*.png /usr/share/pixmaps/codefad/ 8 | sudo cp codefad.desktop /usr/share/applications/ 9 | -------------------------------------------------------------------------------- /src/Terminal.vala: -------------------------------------------------------------------------------- 1 | 2 | /* MIT License 3 | # 4 | # Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved. 5 | # Distributed under the terms of the MIT License. 6 | # 7 | # */ 8 | 9 | public class FadTerminal { 10 | public void init_fadterminal(Vte.Terminal terminal, Gtk.Frame frame) { 11 | terminal.cursor_blink_mode = Vte.CursorBlinkMode.ON; 12 | terminal.cursor_shape = Vte.CursorShape.BLOCK; 13 | terminal.input_enabled = true; 14 | terminal.allow_bold = true; 15 | 16 | Gdk.RGBA background = Gdk.RGBA(); 17 | background.parse("#2d2d2d"); 18 | 19 | Gdk.RGBA foreground = Gdk.RGBA(); 20 | foreground.parse("#ffffff"); 21 | terminal.set_colors(foreground,background,null); 22 | 23 | unowned string arg = GLib.Environment.get_variable("SHELL"); 24 | 25 | try { 26 | terminal.spawn_sync( 27 | Vte.PtyFlags.DEFAULT, 28 | null, 29 | { arg }, 30 | null, 31 | SpawnFlags.DO_NOT_REAP_CHILD, 32 | null, 33 | null, 34 | null); 35 | } catch (Error e) { 36 | stderr.printf("Error: %s\n", e.message); 37 | } 38 | 39 | frame.show_all(); 40 | terminal.grab_focus(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ferhat Geçdoğan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/EntryCompletion.vala: -------------------------------------------------------------------------------- 1 | /* MIT License 2 | # 3 | # Copyright (c) 2020-2021 Ferhat Geçdoğan All Rights Reserved. 4 | # Distributed under the terms of the MIT License. 5 | # 6 | # */ 7 | 8 | public class EntryCompletion : Gtk.Window { 9 | private Gtk.ListStore liststore; 10 | private Gtk.EntryCompletion entrycompletion; 11 | 12 | private string line; 13 | 14 | public void EntryCompletion(Gtk.Entry entry) { 15 | liststore = new Gtk.ListStore(1, typeof(string)); 16 | 17 | /* Default items */ 18 | Gtk.TreeIter iter; 19 | 20 | File file = File.new_for_path (GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad"); 21 | 22 | try { 23 | FileInputStream @is = file.read (); 24 | DataInputStream dis = new DataInputStream (@is); 25 | 26 | while ((line = dis.read_line ()) != null) { 27 | liststore.append(out iter); 28 | liststore.set(iter, 0, line); 29 | } 30 | } catch (Error e) { 31 | print ("Error: %s\n", e.message); 32 | } 33 | 34 | entrycompletion = new Gtk.EntryCompletion(); 35 | entrycompletion.set_model(liststore); 36 | entrycompletion.set_text_column(0); 37 | entrycompletion.set_popup_completion(true); 38 | entry.set_completion(entrycompletion); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/FileOperations.vala: -------------------------------------------------------------------------------- 1 | 2 | /* MIT License 3 | # 4 | # Copyright (c) 2020 Ferhat Geçdoğan All Rights Reserved. 5 | # Distributed under the terms of the MIT License. 6 | # 7 | # */ 8 | 9 | public class FileOperations { 10 | public string line; 11 | 12 | public string GetStringFromFile(string _file, string _str) { 13 | File file = File.new_for_path (_file); 14 | 15 | try { 16 | FileInputStream @is = file.read (); 17 | DataInputStream dis = new DataInputStream (@is); 18 | 19 | while ((line = dis.read_line ()) != null) { 20 | if(line.contains(_str) == true) { 21 | return line; 22 | } 23 | } 24 | } catch (Error e) { 25 | print ("Error: %s\n", e.message); 26 | } 27 | 28 | return line; 29 | } 30 | 31 | public void CreateDirectory(string _directory) { 32 | File file = File.new_for_path(_directory); 33 | file.make_directory(); 34 | } 35 | 36 | public void CreateFile(string _directory, string _data) { 37 | File file = File.new_for_path(_directory); 38 | FileOutputStream os = file.create (FileCreateFlags.PRIVATE); 39 | os.write (_data.data); 40 | } 41 | 42 | public bool IsExist(string _directory) { 43 | if (GLib.FileUtils.test(_directory, GLib.FileTest.EXISTS)) { 44 | return true; 45 | } 46 | 47 | return false; 48 | } 49 | 50 | public void AddText(string _directory, string data) { 51 | try { 52 | FileUtils.set_contents(_directory, data); 53 | } catch(Error e) { 54 | stderr.printf ("Error: %s\n", e.message); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/CommandParser.vala: -------------------------------------------------------------------------------- 1 | /* MIT License 2 | # 3 | # Copyright (c) 2020-2021 Ferhat Geçdoğan All Rights Reserved. 4 | # Distributed under the terms of the MIT License. 5 | # 6 | # */ 7 | 8 | class CommandParser { 9 | FileOperations _op; 10 | Settings _set; 11 | 12 | public string line; 13 | public string _data; 14 | 15 | string ReadAndChange(string _cmd, string _change_with) { 16 | File file = File.new_for_path (GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad"); 17 | StringBuilder build = new StringBuilder(); 18 | 19 | try { 20 | FileInputStream @is = file.read (); 21 | DataInputStream dis = new DataInputStream (@is); 22 | 23 | while ((line = dis.read_line ()) != null) { 24 | if(line.contains(_cmd) == true) { 25 | build.append(_change_with + "\n"); 26 | } else { 27 | build.append(line + "\n"); 28 | } 29 | } 30 | } catch (Error e) { 31 | print ("Error: %s\n", e.message); 32 | } 33 | 34 | return build.str; 35 | } 36 | 37 | public void ChangeSettings(string _str, string _command) { 38 | File file = File.new_for_path (GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad"); 39 | string _str_ = ReadAndChange(_str, _command); 40 | 41 | print(_str_); 42 | try { 43 | file.replace_contents (_str_.data, null, false, FileCreateFlags.NONE, null); 44 | } catch(Error e) { 45 | stderr.printf ("Error: %s\n", e.message); 46 | } 47 | } 48 | 49 | public void GetCommand(string _command) { 50 | if(_command.contains("tab_width: ") == true) { 51 | ChangeSettings("tab_width: ", _command); 52 | } else if(_command.contains("show_line_numbers: ") == true) { 53 | ChangeSettings("show_line_numbers: ", _command); 54 | } else if(_command.contains("left_margin: ") == true) { 55 | ChangeSettings("left_margin: ", _command); 56 | } else if(_command.contains("right_margin: ") == true) { 57 | ChangeSettings("right_margin: ", _command); 58 | } else if(_command.contains("highlight_current_line: ") == true) { 59 | ChangeSettings("highlight_current_line: ", _command); 60 | } 61 | } 62 | 63 | public void Apply(Gtk.SourceView view) { 64 | _set.SetAll(view); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Settings.vala: -------------------------------------------------------------------------------- 1 | 2 | /* MIT License 3 | # 4 | # Copyright (c) 2020-2021 Ferhat Geçdoğan All Rights Reserved. 5 | # Distributed under the terms of the MIT License. 6 | # 7 | # */ 8 | 9 | public class Settings { 10 | FileOperations _operations = new FileOperations(); 11 | 12 | public void Write() { 13 | if(_operations.IsExist(GLib.Environment.get_home_dir() + "/.config/codefad") == false) { 14 | _operations.CreateDirectory(GLib.Environment.get_home_dir() + "/.config/codefad"); 15 | } 16 | 17 | if(_operations.IsExist(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad") == false) { 18 | _operations.CreateFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "tab_width: 4\nshow_line_numbers: true\nleft_margin: 0\nright_margin: 0\nhighlight_current_line: true\nlast_file: "); 19 | } 20 | } 21 | 22 | public void SetAll(Gtk.SourceView source_view) { 23 | string tab_width = _operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "tab_width: "); 24 | string left_margin = _operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "left_margin: "); 25 | string right_margin = _operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "right_margin: "); 26 | string show_line_numbers = _operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "show_line_numbers: "); 27 | string highlight_current_line = _operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "highlight_current_line: "); 28 | 29 | 30 | 31 | bool _line_numbers = true; 32 | bool _highlight_current_line = false; 33 | 34 | /* Erase commands */ 35 | tab_width = tab_width.replace("tab_width: ", ""); 36 | left_margin = left_margin.replace("left_margin: ", ""); 37 | right_margin = right_margin.replace("right_margin: ", ""); 38 | show_line_numbers = show_line_numbers.replace("show_line_numbers: ", ""); 39 | highlight_current_line = show_line_numbers.replace("highlight_current_line: ", ""); 40 | 41 | if(show_line_numbers == "false") { 42 | _line_numbers = false; 43 | } 44 | 45 | stdout.printf(highlight_current_line); 46 | if(highlight_current_line == "false") { 47 | // _highlight_current_line = false; 48 | } 49 | 50 | /* SourceView */ 51 | source_view.set_wrap_mode (Gtk.WrapMode.WORD); 52 | source_view.buffer.text = ""; 53 | source_view.editable = true; 54 | source_view.cursor_visible = true; 55 | source_view.smart_backspace = true; 56 | source_view.left_margin = int.parse(left_margin); 57 | source_view.right_margin = int.parse(right_margin); 58 | //source_view.set_highlight_current_line(true); 59 | source_view.set_tab_width(int.parse(tab_width)); 60 | source_view.set_show_line_numbers(_line_numbers); 61 | source_view.set_highlight_current_line(false); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/CodeFad.vala: -------------------------------------------------------------------------------- 1 | 2 | /* MIT License 3 | # 4 | # Copyright (c) 2020-2021 Ferhat Geçdoğan All Rights Reserved. 5 | # Distributed under the terms of the MIT License. 6 | # 7 | # */ 8 | 9 | /* Use Gtk namespace */ 10 | using Gtk; 11 | 12 | /* CodeFad class */ 13 | public class CodeFad : Window { 14 | Settings settings = new Settings(); 15 | FadTerminal fadterm = new FadTerminal(); 16 | 17 | Gtk.HeaderBar headerBar = new Gtk.HeaderBar(); 18 | FileOperations operations = new FileOperations(); 19 | CommandParser cmd = new CommandParser(); 20 | EntryCompletion completion = new EntryCompletion(); 21 | 22 | /* Buttons */ 23 | Gtk.ToolButton openButton; 24 | Gtk.Button saveButton; 25 | Gtk.Button menuButton; 26 | 27 | /* Menu & Menu Item */ 28 | GLib.Menu menu = new GLib.Menu(); 29 | GLib.MenuItem about = new GLib.MenuItem("About", null); 30 | GLib.MenuItem saveAs = new GLib.MenuItem("Save as..", null); 31 | 32 | /* Menu Popover */ 33 | Gtk.Popover menu_popover; 34 | 35 | private SourceFile file; 36 | Gtk.Label label; 37 | 38 | private SourceView source_view; 39 | private Gtk.SourceLanguageManager language_manager; 40 | 41 | private Gtk.Entry entry = new Gtk.Entry (); 42 | 43 | private Vte.Terminal terminal = new Vte.Terminal(); 44 | private Gtk.Frame frame = new Gtk.Frame(null); 45 | 46 | public static string argument = null; 47 | 48 | construct { 49 | settings.Write(); 50 | entry.set_width_chars(32); 51 | entry.set_placeholder_text("Welcome! I am CodeFad console."); 52 | entry.set_icon_from_icon_name(PRIMARY, "system-search-symbolic"); 53 | entry.set_icon_from_icon_name (SECONDARY, "edit-clear"); 54 | } 55 | 56 | /* show_all */ 57 | public CodeFad() { 58 | /* Title */ 59 | this.title = "CodeFad"; 60 | 61 | /* Window pos. */ 62 | this.window_position = WindowPosition.CENTER; 63 | 64 | /* Default window size */ 65 | set_default_size (800, 500); 66 | 67 | /* Headerbar button */ 68 | Gtk.Image img = new Gtk.Image.from_file("/usr/share/pixmaps/codefad/codefad_32.png"); 69 | openButton = new Gtk.ToolButton(img, null); 70 | saveButton = new Gtk.Button.with_label("Save"); 71 | menuButton = new Gtk.Button.from_icon_name("open-menu-symbolic", Gtk.IconSize.SMALL_TOOLBAR); 72 | entry.set_icon_from_icon_name (Gtk.EntryIconPosition.PRIMARY, "system-search"); 73 | 74 | /* Title. */ 75 | headerBar.set_title(title); 76 | 77 | /* Set subtitle with variable */ 78 | headerBar.set_subtitle("Programming for everyone, everytime."); 79 | 80 | /* Show close button */ 81 | headerBar.set_show_close_button (true); 82 | 83 | /* Append */ 84 | headerBar.pack_start(openButton); 85 | headerBar.pack_end(menuButton); 86 | headerBar.pack_end(saveButton); 87 | 88 | headerBar.pack_end(entry); 89 | 90 | menu.append_item(saveAs); 91 | menu.append_item(about); 92 | 93 | /* Settings */ 94 | source_view = new Gtk.SourceView(); 95 | settings.SetAll(source_view); 96 | language_manager = Gtk.SourceLanguageManager.get_default(); 97 | 98 | fadterm.init_fadterminal(terminal, frame); 99 | 100 | frame.add(terminal); 101 | 102 | completion.EntryCompletion(entry); 103 | 104 | /* Set new bar */ 105 | this.set_titlebar(headerBar); 106 | 107 | /* Icon of button */ 108 | var open_icon = new Gtk.Image.from_icon_name ("document-open", 109 | IconSize.SMALL_TOOLBAR); 110 | 111 | menu_popover = new Gtk.Popover(menuButton); 112 | menu_popover.position = Gtk.PositionType.BOTTOM; 113 | menu_popover.set_size_request (256, -1); 114 | menu_popover.modal = false; 115 | menu_popover.bind_model (menu, null); 116 | 117 | if(argument != null) { 118 | open_file(argument); 119 | } 120 | 121 | string last_file = operations.GetStringFromFile(GLib.Environment.get_home_dir() + "/.config/codefad/settings_code.fad", "last_file: "); 122 | 123 | if(last_file.length > 11) { 124 | open_file(last_file.replace("last_file: ", "")); 125 | } 126 | 127 | /* Action */ 128 | openButton.clicked.connect(on_open_clicked); 129 | saveButton.clicked.connect(on_save_clicked); 130 | menuButton.clicked.connect(on_menu_clicked); 131 | entry.activate.connect(on_entry_inputted); 132 | 133 | this.entry.icon_press.connect((pos, event) => { 134 | if (pos == SECONDARY) { 135 | entry.set_text(""); 136 | } else if(pos == PRIMARY) { 137 | cmd.GetCommand(entry.text); 138 | } 139 | }); 140 | 141 | this.language_manager = Gtk.SourceLanguageManager.get_default (); 142 | 143 | /* Scroll */ 144 | var scroll = new ScrolledWindow (null, null); 145 | scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC); 146 | scroll.add (this.source_view); 147 | 148 | //this.add(frame); 149 | 150 | var vbox = new Box (Orientation.VERTICAL, 5); 151 | vbox.set_homogeneous(true); 152 | vbox.pack_start (scroll, true, true, 0); 153 | vbox.pack_start(frame, true, true, 5); 154 | add(vbox); 155 | 156 | /* Connect */ 157 | source_view.populate_popup.connect (on_populate_menu); 158 | } 159 | 160 | /* Action */ 161 | private void on_open_clicked () { 162 | /* FileChooser */ 163 | Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ( 164 | "Select a file to edit", this, Gtk.FileChooserAction.OPEN, 165 | "_Cancel", 166 | Gtk.ResponseType.CANCEL, 167 | "_Open", 168 | Gtk.ResponseType.ACCEPT); 169 | chooser.set_select_multiple (false); 170 | chooser.run (); 171 | chooser.close (); 172 | 173 | /* Check */ 174 | if (chooser.get_file () != null) { 175 | file = new Gtk.SourceFile(); 176 | file.location = chooser.get_file(); 177 | 178 | var file_loader = new Gtk.SourceFileLoader(source_view.buffer as Gtk.SourceBuffer, file); 179 | 180 | entry.editable = true; 181 | SetEntryName(chooser.get_filename()); 182 | 183 | try { 184 | file_loader.load_async.begin(Priority.DEFAULT, null, null); 185 | } catch (Error e) { 186 | stdout.printf ("Error: %s\n", e.message); 187 | } 188 | 189 | cmd.ChangeSettings("last_file: ", "last_file: " + chooser.get_filename()); 190 | } 191 | } 192 | 193 | public void open_file(string _file) { 194 | File gfile = File.new_for_path(_file); 195 | 196 | file = new Gtk.SourceFile(); 197 | file.location = gfile; 198 | 199 | var file_loader = new Gtk.SourceFileLoader(source_view.buffer as Gtk.SourceBuffer, file); 200 | entry.editable = true; 201 | SetEntryName(_file); 202 | 203 | try { 204 | file_loader.load_async.begin(Priority.DEFAULT, null, null); 205 | } catch (Error e) { 206 | stdout.printf ("Error: %s\n", e.message); 207 | } 208 | 209 | cmd.ChangeSettings("last_file: ", "last_file: " + _file); 210 | } 211 | 212 | /* Action */ 213 | private void on_save_clicked () { 214 | if (file != null) { 215 | var file_saver = new Gtk.SourceFileSaver(source_view.buffer as Gtk.SourceBuffer, file); 216 | try { 217 | file_saver.save_async.begin(Priority.DEFAULT, null, null); 218 | } catch (Error e) { 219 | stdout.printf ("Error: %s\n", e.message); 220 | } 221 | } 222 | } 223 | 224 | private void on_menu_clicked() { 225 | menu_popover.set_visible (true); 226 | } 227 | 228 | private void on_entry_inputted() { 229 | cmd.GetCommand(entry.text); 230 | } 231 | 232 | void SetEntryName(string str) { 233 | headerBar.set_subtitle(str); 234 | } 235 | 236 | void on_populate_menu (Gtk.Menu menu) { 237 | var language_menu = new Gtk.MenuItem(); 238 | var submenu = new Gtk.Menu (); 239 | 240 | language_menu.set_label ("Language"); 241 | language_menu.set_submenu (submenu); 242 | 243 | /* Create the list of language items */ 244 | unowned SList group = null; 245 | Gtk.RadioMenuItem? item = null; 246 | 247 | /* Add an entry with No Language, or normal. */ 248 | item = new Gtk.RadioMenuItem (group); 249 | 250 | item.set_label ("Normal Text"); 251 | 252 | item.toggled.connect (() => { 253 | /* Normal text edit. */ 254 | (source_view.buffer as Gtk.SourceBuffer).set_language (null); 255 | }); 256 | 257 | submenu.add (item); 258 | 259 | /* Set the Language entries */ 260 | var ids = language_manager.get_language_ids (); 261 | foreach (var id in ids) { 262 | var lang = language_manager.get_language (id); 263 | group = item.get_group (); 264 | item = new Gtk.RadioMenuItem (group); 265 | item.set_label (lang.name); 266 | 267 | submenu.add (item); 268 | item.toggled.connect (() => { 269 | (source_view.buffer as Gtk.SourceBuffer).set_language (lang); 270 | }); 271 | 272 | // Active item 273 | if ((source_view.buffer as Gtk.SourceBuffer).language != null && id == (source_view.buffer as Gtk.SourceBuffer).language.id) { 274 | item.active = true; 275 | } 276 | } 277 | 278 | /* Add our Language selection menu to the menu provided in the callback */ 279 | menu.add(language_menu); 280 | menu.show_all(); 281 | } 282 | 283 | public static int main(string[] args) { 284 | Gtk.init (ref args); 285 | 286 | if(args[1] != null) { argument = args[1]; } 287 | 288 | var window = new CodeFad(); 289 | window.destroy.connect(Gtk.main_quit); 290 | window.show_all(); 291 | 292 | Gtk.main(); 293 | 294 | return 0; 295 | } 296 | } 297 | --------------------------------------------------------------------------------