1 static EditProject _EditProject;
3 public class EditProject : Object
6 private EditProject _this;
8 public static EditProject singleton()
10 if (_EditProject == null) {
11 _EditProject= new EditProject();
15 public Xcls_ok_btn ok_btn;
16 public Xcls_type_lbl type_lbl;
17 public Xcls_type_dd type_dd;
18 public Xcls_parent_lbl parent_lbl;
19 public Xcls_parent_dd parent_dd;
20 public Xcls_folder_lbl folder_lbl;
21 public Xcls_folder_dd folder_dd;
22 public Xcls_name_lbl name_lbl;
23 public Xcls_name_entry name_entry;
24 public Xcls_ptype_lbl ptype_lbl;
25 public Xcls_ptype_dd ptype_dd;
28 public WindowState? windowstate;
29 public signal void canceled ();
30 public signal void selected (Project.Project? proj);
36 this.el = new Gtk.Window();
39 this.windowstate = null;
42 this.el.title = "New Project";
43 this.el.name = "EditProject";
44 this.el.default_width = 600;
45 this.el.deletable = true;
47 var child_1 = new Xcls_HeaderBar2( _this );
48 this.el.titlebar = child_1.el;
49 var child_2 = new Xcls_Box5( _this );
50 this.el.child = child_2.el;
53 // user defined functions
58 _this.type_dd.el.selected = Gtk.INVALID_LIST_POSITION;
59 _this.folder_dd.el.selected = Gtk.INVALID_LIST_POSITION;
60 _this.ptype_dd.el.selected = Gtk.INVALID_LIST_POSITION;
61 _this.parent_dd.extra_value = "";
62 //[ 'xtype' ].forEach(function(k) {
63 // _this.get(k).setValue(typeof(c[k]) == 'undefined' ? '' : c[k]);
70 public void hideAll () {
71 _this.parent_lbl.el.hide();
72 _this.parent_dd.el.hide();
74 _this.folder_lbl.el.hide();
75 _this.folder_dd.el.hide();
76 _this.name_lbl.el.hide();
77 _this.name_entry.el.hide();
78 _this.ptype_lbl.el.hide();
79 _this.ptype_dd.el.hide();
80 _this.ok_btn.el.hide();
83 public class Xcls_HeaderBar2 : Object
85 public Gtk.HeaderBar el;
86 private EditProject _this;
92 public Xcls_HeaderBar2(EditProject _owner )
95 this.el = new Gtk.HeaderBar();
100 this.el.show_title_buttons = false;
101 var child_1 = new Xcls_Button3( _this );
103 this.el.pack_start ( child_1.el );
104 new Xcls_ok_btn( _this );
105 this.el.pack_end ( _this.ok_btn.el );
108 // user defined functions
110 public class Xcls_Button3 : Object
112 public Gtk.Button el;
113 private EditProject _this;
119 public Xcls_Button3(EditProject _owner )
122 this.el = new Gtk.Button();
126 // set gobject values
127 this.el.halign = Gtk.Align.END;
128 this.el.hexpand = false;
129 this.el.label = "Cancel";
132 this.el.clicked.connect( ( ) => {
141 // user defined functions
144 public class Xcls_ok_btn : Object
146 public Gtk.Button el;
147 private EditProject _this;
153 public Xcls_ok_btn(EditProject _owner )
157 this.el = new Gtk.Button();
161 // set gobject values
162 this.el.halign = Gtk.Align.START;
163 this.el.hexpand = false;
164 this.el.css_classes = { "suggested-action" };
165 this.el.label = "OK";
168 this.el.clicked.connect( ( ) => {
169 var err_dialog = Xcls_StandardErrorDialog.singleton();
172 if (_this.ptype_dd.getValue().length < 1) {
173 err_dialog.show(_this.el,"You have to set Project type");
176 var fn = _this.parent_dd.getValue();
177 var is_existing = false;
178 var is_new_folder = false;
179 switch (_this.type_dd.getValue()) {
180 case "Existing Folder":
181 if (_this.folder_dd.getValue().length < 1) {
182 err_dialog.show(_this.el,"You have to set Folder");
185 fn += "/" + _this.folder_dd.getValue();
190 if (_this.name_entry.getValue().length < 1) {
191 err_dialog.show(_this.el,"You have enter a Project Name");
194 fn += "/" + _this.name_entry.getValue();
196 if (FileUtils.test( fn ,FileTest.EXISTS)) {
197 err_dialog.show(_this.el,"That folder already exists");
200 var dir = File.new_for_path(fn);
202 dir.make_directory();
204 GLib.error("Failed to make directory %s", fn);
206 is_new_folder = true;
222 GLib.debug("add %s\n" , fn);
224 var project = Project.Project.factory(_this.ptype_dd.getValue(), fn);
226 project.initialize();
233 Project.Project.saveProjectList();
234 _this.selected(project); // this should trigger a load()
235 if (is_new_folder || is_existing) {
236 _this.windowstate.projectPopoverShow(_this.el, project);
241 GLib.debug("got error? %s" , e.message);
248 // user defined functions
252 public class Xcls_Box5 : Object
255 private EditProject _this;
262 public Xcls_Box5(EditProject _owner )
265 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
270 // set gobject values
271 this.el.homogeneous = false;
272 this.el.margin_end = 10;
273 this.el.margin_start = 10;
274 this.el.margin_bottom = 10;
275 this.el.margin_top = 10;
276 var child_1 = new Xcls_Grid6( _this );
278 this.el.append( child_1.el );
281 // user defined functions
283 public class Xcls_Grid6 : Object
286 private EditProject _this;
292 public Xcls_Grid6(EditProject _owner )
295 this.el = new Gtk.Grid();
299 // set gobject values
300 this.el.column_spacing = 4;
301 this.el.row_spacing = 4;
302 this.el.margin_bottom = 20;
303 new Xcls_type_lbl( _this );
304 this.el.attach( _this.type_lbl.el, 0, 0, 1, 1 );
305 new Xcls_type_dd( _this );
306 this.el.attach( _this.type_dd.el, 1, 0, 1, 1 );
307 new Xcls_parent_lbl( _this );
308 this.el.attach( _this.parent_lbl.el, 0, 1, 1, 1 );
309 new Xcls_parent_dd( _this );
310 this.el.attach( _this.parent_dd.el, 1, 1, 1, 1 );
311 new Xcls_folder_lbl( _this );
312 this.el.attach( _this.folder_lbl.el, 0, 2, 1, 1 );
313 new Xcls_folder_dd( _this );
314 this.el.attach( _this.folder_dd.el, 1, 2, 1, 1 );
315 new Xcls_name_lbl( _this );
316 this.el.attach( _this.name_lbl.el, 0, 3, 1, 1 );
317 new Xcls_name_entry( _this );
318 this.el.attach( _this.name_entry.el, 1, 3, 1, 1 );
319 new Xcls_ptype_lbl( _this );
320 this.el.attach( _this.ptype_lbl.el, 0, 4, 1, 1 );
321 new Xcls_ptype_dd( _this );
322 this.el.attach( _this.ptype_dd.el, 1, 4, 1, 1 );
325 // user defined functions
327 public class Xcls_type_lbl : Object
330 private EditProject _this;
336 public Xcls_type_lbl(EditProject _owner )
339 _this.type_lbl = this;
340 this.el = new Gtk.Label( "Create a Project from:" );
344 // set gobject values
345 this.el.halign = Gtk.Align.START;
348 // user defined functions
351 public class Xcls_type_dd : Object
353 public Gtk.DropDown el;
354 private EditProject _this;
360 public Xcls_type_dd(EditProject _owner )
363 _this.type_dd = this;
364 var child_1 = new Xcls_StringList9( _this );
366 this.el = new Gtk.DropDown( child_1.el, null );
370 // set gobject values
371 this.el.hexpand = true;
372 this.el.selected = Gtk.INVALID_LIST_POSITION;
381 this.el.notify["selected"].connect( ( ) => {
383 if (this.el.selected == Gtk.INVALID_LIST_POSITION) {
386 var m = (Gtk.StringList) this.el.model;
387 GLib.debug("selected item: %s", m.get_string(this.el.selected));
390 _this.parent_lbl.el.show();
391 _this.parent_dd.el.show();
392 _this.parent_dd.load();
396 switch (m.get_string(this.el.selected)) {
398 _this.name_lbl.el.show();
399 _this.name_entry.el.show();
401 case "Existing Folder":
402 _this.folder_lbl.el.show();
403 _this.folder_dd.el.show();
406 case "Checkout from git":
407 _this.name_lbl.el.show();
408 _this.name_entry.el.show();
426 // user defined functions
427 public string getValue () {
428 var m = (Gtk.StringList) this.el.model;
429 return m.get_string(this.el.selected);
433 public class Xcls_StringList9 : Object
435 public Gtk.StringList el;
436 private EditProject _this;
442 public Xcls_StringList9(EditProject _owner )
445 this.el = new Gtk.StringList( { "New Folder", "Existing Folder" /*, "Checkout from git" */ } );
449 // set gobject values
452 // user defined functions
456 public class Xcls_parent_lbl : Object
459 private EditProject _this;
465 public Xcls_parent_lbl(EditProject _owner )
468 _this.parent_lbl = this;
469 this.el = new Gtk.Label( "In Folder:" );
473 // set gobject values
474 this.el.halign = Gtk.Align.START;
477 // user defined functions
480 public class Xcls_parent_dd : Object
482 public Gtk.DropDown el;
483 private EditProject _this;
487 public string extra_value;
490 public Xcls_parent_dd(EditProject _owner )
493 _this.parent_dd = this;
494 var child_1 = new Xcls_StringList12( _this );
496 this.el = new Gtk.DropDown( child_1.el, null );
500 // set gobject values
501 this.el.hexpand = true;
504 this.el.notify["selected"].connect( ( ) => {
505 if (this.el.selected == Gtk.INVALID_LIST_POSITION) {
507 _this.parent_lbl.el.show();
508 _this.parent_dd.el.show();
515 if (this.getValue() == "Select Folder") {
516 var fd = new Gtk.FileDialog();
517 fd.title = "Select Folder";
520 fd.select_folder.begin(_this.el, null, (obj, res) => {
522 var f = fd.select_folder.end(res);
523 this.extra_value = f.get_path();
524 var sl = (Gtk.StringList) this.el.model;
526 sl.remove(sl.get_n_items()-1);
528 sl.append(this.extra_value);
529 sl.append("Select Folder");
530 this.el.selected = sl.get_n_items()-2;
531 } catch (GLib.Error e) {
540 _this.parent_lbl.el.show();
541 _this.parent_dd.el.show();
544 _this.ptype_lbl.el.show();
545 _this.ptype_dd.el.show();
546 // folder selected...
547 switch(_this.type_dd.getValue()) {
549 _this.name_lbl.el.show();
550 _this.name_entry.el.show();
551 _this.name_entry.el.text = "";
552 _this.ptype_lbl.el.show();
553 _this.ptype_dd.el.show();
556 case "Existing Folder":
557 _this.folder_lbl.el.show();
558 _this.folder_dd.el.show();
559 _this.folder_dd.load();
563 case "Checkout from git":
564 _this.name_lbl.el.show();
565 _this.name_entry.el.show();
566 _this.name_lbl.el.label= "not yet";
567 _this.name_entry.el.text = "this is not supported yet";
578 // user defined functions
579 public string getValue () {
580 var m = (Gtk.StringList) this.el.model;
581 return m.get_string(this.el.selected);
584 public void load () {
586 var sl = (Gtk.StringList) this.el.model;
587 var hd = GLib.Environment.get_home_dir();
588 while(sl.get_n_items() > 0) {
591 if (FileUtils.test(hd + "/gitlive" ,FileTest.IS_DIR)) {
592 sl.append(hd + "/gitlive");
594 if (FileUtils.test(hd + "/Projects" ,FileTest.IS_DIR)) {
595 sl.append(hd + "/Projects");
597 if (this.extra_value != "" && FileUtils.test(this.extra_value ,FileTest.IS_DIR)) {
598 sl.append(this.extra_value);
601 sl.append("Select Folder");
602 this.el.selected = Gtk.INVALID_LIST_POSITION;
606 public class Xcls_StringList12 : Object
608 public Gtk.StringList el;
609 private EditProject _this;
615 public Xcls_StringList12(EditProject _owner )
618 this.el = new Gtk.StringList( { "gitlive", "Projects", "Select" } );
622 // set gobject values
625 // user defined functions
629 public class Xcls_folder_lbl : Object
632 private EditProject _this;
638 public Xcls_folder_lbl(EditProject _owner )
641 _this.folder_lbl = this;
642 this.el = new Gtk.Label( "Add Folder" );
646 // set gobject values
647 this.el.halign = Gtk.Align.START;
650 // user defined functions
653 public class Xcls_folder_dd : Object
655 public Gtk.DropDown el;
656 private EditProject _this;
662 public Xcls_folder_dd(EditProject _owner )
665 _this.folder_dd = this;
666 var child_1 = new Xcls_StringList15( _this );
668 this.el = new Gtk.DropDown( child_1.el, null );
672 // set gobject values
673 this.el.hexpand = true;
676 this.el.notify["selected"].connect( () => {
677 var fn = this.getValue();
681 var p = _this.parent_dd.getValue();
682 if (!FileUtils.test(p + "/" + fn + "/.roobuilder.jcfg" , GLib.FileTest.EXISTS)) {
685 var ty = Project.Project.peekProjectType(p + "/" + fn + "/.roobuilder.jcfg" );
689 _this.ptype_dd.setValue(ty);
694 // user defined functions
695 public string getValue () {
696 var m = (Gtk.StringList) this.el.model;
697 return this.el.selected == Gtk.INVALID_LIST_POSITION ?
698 "" : m.get_string(this.el.selected);
701 public void load () {
702 var p = _this.parent_dd.getValue();
703 var f = File.new_for_path(p);
704 var sl = (Gtk.StringList) this.el.model;
705 while(sl.get_n_items() > 0) {
708 var gstr = new Gee.ArrayList<string>();
712 var file_enum = f.enumerate_children(
713 GLib.FileAttribute.STANDARD_DISPLAY_NAME,
714 GLib.FileQueryInfoFlags.NONE, null);
720 while ((next_file = file_enum.next_file(null)) != null) {
721 var fn = next_file.get_display_name();
723 if (fn[0] == '.') { // skip hidden
727 if (!FileUtils.test(p + "/" + fn, GLib.FileTest.IS_DIR)) {
730 if (null != Project.Project.getProjectByPath(p + "/" + fn)) {
736 } catch (GLib.Error e) {
740 return Posix.strcmp(a.down(), b.down());
743 foreach(var str in gstr) {
749 public class Xcls_StringList15 : Object
751 public Gtk.StringList el;
752 private EditProject _this;
758 public Xcls_StringList15(EditProject _owner )
761 this.el = new Gtk.StringList( { "gitlive", "Projects", "Select" } );
765 // set gobject values
768 // user defined functions
772 public class Xcls_name_lbl : Object
775 private EditProject _this;
781 public Xcls_name_lbl(EditProject _owner )
784 _this.name_lbl = this;
785 this.el = new Gtk.Label( "Named (New Folder Name)" );
789 // set gobject values
790 this.el.halign = Gtk.Align.START;
793 // user defined functions
796 public class Xcls_name_entry : Object
799 private EditProject _this;
805 public Xcls_name_entry(EditProject _owner )
808 _this.name_entry = this;
809 this.el = new Gtk.Entry();
813 // set gobject values
814 this.el.hexpand = true;
817 // user defined functions
818 public string getValue () {
823 public class Xcls_ptype_lbl : Object
826 private EditProject _this;
832 public Xcls_ptype_lbl(EditProject _owner )
835 _this.ptype_lbl = this;
836 this.el = new Gtk.Label( "Project type :" );
840 // set gobject values
841 this.el.halign = Gtk.Align.START;
844 // user defined functions
847 public class Xcls_ptype_dd : Object
849 public Gtk.DropDown el;
850 private EditProject _this;
856 public Xcls_ptype_dd(EditProject _owner )
859 _this.ptype_dd = this;
860 var child_1 = new Xcls_StringList20( _this );
862 this.el = new Gtk.DropDown( child_1.el, null );
866 // set gobject values
867 this.el.hexpand = true;
870 this.el.notify["selected"].connect( ( ) => {
872 _this.ok_btn.el.hide();
873 if (this.getValue() != "") {
874 _this.ok_btn.el.show();
880 // user defined functions
881 public string getValue () {
882 var m = (Gtk.StringList) this.el.model;
883 return this.el.selected == Gtk.INVALID_LIST_POSITION ?
884 "" : m.get_string(this.el.selected);
887 public void setValue (string val) {
888 var m = (Gtk.StringList) this.el.model;
889 for(var i = 0; i < m.get_n_items();i++) {
890 if (m.get_string(i) == val) {
891 this.el.selected = i;
895 this.el.selected = Gtk.INVALID_LIST_POSITION;
899 public class Xcls_StringList20 : Object
901 public Gtk.StringList el;
902 private EditProject _this;
908 public Xcls_StringList20(EditProject _owner )
911 this.el = new Gtk.StringList( { "Roo", "Gtk" /*, "WrappedGtk", "Flutter" */ } );
915 // set gobject values
918 // user defined functions