@@ -40,23 +40,6 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
4040 modified_icon = new ThemedIcon (" emblem-git-modified-symbolic" );
4141 }
4242
43- private void branch_or_name_changed () {
44- if (monitored_repo != null ) {
45- // As SourceList items are not widgets we have to use markup to change appearance of text.
46- if (monitored_repo. head_is_branch) {
47- markup = " %s\n <span size='small' weight='normal'>%s </span>" . printf (
48- name, monitored_repo. branch_name
49- );
50- } else { // Distinguish detached heads visually
51- markup = " %s\n <span size='small' weight='normal' style='italic'>%s </span>" . printf (
52- name, monitored_repo. branch_name
53- );
54- }
55-
56- checkout_local_branch_action. set_state (monitored_repo. branch_name);
57- }
58- }
59-
6043 construct {
6144 monitored_repo = Scratch . Services . GitManager . get_instance (). add_project (this );
6245 notify[" name" ]. connect (branch_or_name_changed);
@@ -81,14 +64,6 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
8164 }
8265 }
8366
84- protected override void on_changed (GLib .File source , GLib .File ? dest , GLib .FileMonitorEvent event ) {
85- if (source. equal (file. file) && event == DELETED ) {
86- closed ();
87- } else {
88- base . on_changed (source, dest, event);
89- }
90- }
91-
9267 public void child_folder_changed (FolderItem folder ) {
9368 if (monitored_repo != null ) {
9469 monitored_repo. update_status_map ();
@@ -290,98 +265,6 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
290265 return menu_model;
291266 }
292267
293- protected GLib .MenuItem create_submenu_for_branch () {
294- // Ensures that action for relevant project is being used
295- view. actions. add_action (checkout_local_branch_action);
296- view. actions. add_action (checkout_remote_branch_action);
297-
298- unowned var local_branches = monitored_repo. get_local_branches ();
299- var local_branch_submenu = new Menu ();
300- var local_branch_menu = new Menu ();
301- if (local_branches. length () > 0 ) {
302- local_branch_submenu. append_submenu (_(" Local" ), local_branch_menu);
303- foreach (unowned var branch_name in local_branches) {
304- local_branch_menu. append (
305- branch_name,
306- GLib . Action . print_detailed_name (
307- FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_LOCAL_BRANCH ,
308- branch_name
309- )
310- );
311- }
312- }
313-
314-
315- unowned var remote_branches = monitored_repo. get_remote_branches ();
316- var remote_branch_submenu = new Menu ();
317- var remote_branch_menu = new Menu ();
318- if (remote_branches. length () > 0 ) {
319- remote_branch_submenu. append_submenu (_(" Remote" ), remote_branch_menu);
320- foreach (unowned var branch_name in remote_branches) {
321- remote_branch_menu. append (
322- branch_name,
323- GLib . Action . print_detailed_name (
324- FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_REMOTE_BRANCH ,
325- branch_name
326- )
327- );
328- }
329-
330-
331- }
332-
333- var new_branch_item = new GLib .MenuItem (
334- _(" New Branch…" ),
335- GLib . Action . print_detailed_name (
336- MainWindow . ACTION_PREFIX + MainWindow . ACTION_NEW_BRANCH ,
337- file. path
338- )
339- );
340-
341- new_branch_item. set_attribute_value (
342- " accel" ,
343- Utils . get_accel_for_action (
344- GLib . Action . print_detailed_name (
345- MainWindow . ACTION_PREFIX + MainWindow . ACTION_NEW_BRANCH ,
346- " "
347- )
348- )
349- );
350-
351- GLib . Menu bottom_section = new GLib .Menu ();
352- bottom_section. append_item (new_branch_item);
353-
354- var menu = new GLib .Menu ();
355- menu. append_section (null , local_branch_submenu);
356- menu. append_section (null , remote_branch_submenu);
357- menu. append_section (null , bottom_section);
358-
359- var menu_item = new GLib .MenuItem .submenu (_(" Branch" ), menu);
360- return menu_item;
361- }
362-
363- private void handle_checkout_local_branch_action (GLib .Variant ? param ) {
364- var branch_name = param != null ? param. get_string () : " " ;
365- try {
366- monitored_repo. change_local_branch (branch_name);
367- } catch (GLib . Error e) {
368- warning (" Failed to change branch to %s. %s " , branch_name, e. message);
369- }
370- }
371-
372- private void handle_checkout_remote_branch_action (GLib .Variant ? param ) {
373- var branch_name = param != null ? param. get_string () : " " ;
374- if (branch_name == " " ) {
375- return ;
376- }
377-
378- try {
379- monitored_repo. checkout_remote_branch (branch_name);
380- } catch (GLib . Error e) {
381- warning (" Failed to change branch to %s. %s " , branch_name, e. message);
382- }
383- }
384-
385268 public void update_item_status (FolderItem ? start_folder ) {
386269 if (monitored_repo == null ) {
387270 debug (" Ignore non-git folders" );
@@ -426,45 +309,6 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
426309 return file. file. get_relative_path (descendant) != null ;
427310 }
428311
429- private void deprioritize_git_ignored () requires (monitored_repo != null ) {
430- visible_item_list. @foreach ((visible_item) = > {
431- var item = visible_item. item;
432- try {
433- if (monitored_repo. path_is_ignored (visible_item. rel_path)) {
434- item. markup = Markup . printf_escaped (" <span fgalpha='75%'><i>%s </i></span>" , item. name);
435- } else {
436- item. markup = item. name;
437- }
438- } catch (Error e) {
439- warning (" An error occurred while checking if item '%s ' is git-ignored: %s " , item. name, e. message);
440- }
441- });
442- }
443-
444- public void new_branch (string branch_name ) {
445- try {
446- if (monitored_repo. head_is_branch) {
447- monitored_repo. create_new_branch (branch_name);
448- } else {
449- throw new IOError .NOT_FOUND (" Cannot create a new branch when head is detached" );
450- }
451- } catch (Error e) {
452- var dialog = new Granite .MessageDialog (
453- _(" Error while creating new branch: “%s ”" ). printf (branch_name),
454- e. message,
455- new ThemedIcon (" git" ),
456- Gtk . ButtonsType . CLOSE
457- ) {
458- badge_icon = new ThemedIcon (" dialog-error" )
459- };
460- dialog. transient_for = (Gtk . Window )(view. get_toplevel ());
461- dialog. response. connect (() = > {
462- dialog. destroy ();
463- });
464- dialog. run ();
465- }
466- }
467-
468312 public unowned List<string> get_branch_names () {
469313 return is_git_repo ? monitored_repo. get_local_branches () : null ;
470314 }
@@ -622,6 +466,166 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
622466 return ;
623467 }
624468
469+ public void refresh_diff (ref Gee .HashMap<int, Services . VCStatus > line_status_map , string doc_path ) {
470+ monitored_repo. refresh_diff (doc_path, ref line_status_map);
471+ }
472+
473+ protected override void on_changed (GLib .File source , GLib .File ? dest , GLib .FileMonitorEvent event ) {
474+ if (source. equal (file. file) && event == DELETED ) {
475+ closed ();
476+ } else {
477+ base . on_changed (source, dest, event);
478+ }
479+ }
480+
481+ protected GLib .MenuItem create_submenu_for_branch () {
482+ // Ensures that action for relevant project is being used
483+ view. actions. add_action (checkout_local_branch_action);
484+ view. actions. add_action (checkout_remote_branch_action);
485+
486+ unowned var local_branches = monitored_repo. get_local_branches ();
487+ var local_branch_submenu = new Menu ();
488+ var local_branch_menu = new Menu ();
489+ if (local_branches. length () > 0 ) {
490+ local_branch_submenu. append_submenu (_(" Local" ), local_branch_menu);
491+ foreach (unowned var branch_name in local_branches) {
492+ local_branch_menu. append (
493+ branch_name,
494+ GLib . Action . print_detailed_name (
495+ FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_LOCAL_BRANCH ,
496+ branch_name
497+ )
498+ );
499+ }
500+ }
501+
502+
503+ unowned var remote_branches = monitored_repo. get_remote_branches ();
504+ var remote_branch_submenu = new Menu ();
505+ var remote_branch_menu = new Menu ();
506+ if (remote_branches. length () > 0 ) {
507+ remote_branch_submenu. append_submenu (_(" Remote" ), remote_branch_menu);
508+ foreach (unowned var branch_name in remote_branches) {
509+ remote_branch_menu. append (
510+ branch_name,
511+ GLib . Action . print_detailed_name (
512+ FileView . ACTION_PREFIX + FileView . ACTION_CHECKOUT_REMOTE_BRANCH ,
513+ branch_name
514+ )
515+ );
516+ }
517+
518+
519+ }
520+
521+ var new_branch_item = new GLib .MenuItem (
522+ _(" New Branch…" ),
523+ GLib . Action . print_detailed_name (
524+ MainWindow . ACTION_PREFIX + MainWindow . ACTION_NEW_BRANCH ,
525+ file. path
526+ )
527+ );
528+
529+ new_branch_item. set_attribute_value (
530+ " accel" ,
531+ Utils . get_accel_for_action (
532+ GLib . Action . print_detailed_name (
533+ MainWindow . ACTION_PREFIX + MainWindow . ACTION_NEW_BRANCH ,
534+ " "
535+ )
536+ )
537+ );
538+
539+ GLib . Menu bottom_section = new GLib .Menu ();
540+ bottom_section. append_item (new_branch_item);
541+
542+ var menu = new GLib .Menu ();
543+ menu. append_section (null , local_branch_submenu);
544+ menu. append_section (null , remote_branch_submenu);
545+ menu. append_section (null , bottom_section);
546+
547+ var menu_item = new GLib .MenuItem .submenu (_(" Branch" ), menu);
548+ return menu_item;
549+ }
550+
551+ private void branch_or_name_changed () {
552+ if (monitored_repo != null ) {
553+ // As SourceList items are not widgets we have to use markup to change appearance of text.
554+ if (monitored_repo. head_is_branch) {
555+ markup = " %s\n <span size='small' weight='normal'>%s </span>" . printf (
556+ name, monitored_repo. branch_name
557+ );
558+ } else { // Distinguish detached heads visually
559+ markup = " %s\n <span size='small' weight='normal' style='italic'>%s </span>" . printf (
560+ name, monitored_repo. branch_name
561+ );
562+ }
563+
564+ checkout_local_branch_action. set_state (monitored_repo. branch_name);
565+ }
566+ }
567+
568+ private void handle_checkout_local_branch_action (GLib .Variant ? param ) {
569+ var branch_name = param != null ? param. get_string () : " " ;
570+ try {
571+ monitored_repo. change_local_branch (branch_name);
572+ } catch (GLib . Error e) {
573+ warning (" Failed to change branch to %s. %s " , branch_name, e. message);
574+ }
575+ }
576+
577+ private void handle_checkout_remote_branch_action (GLib .Variant ? param ) {
578+ var branch_name = param != null ? param. get_string () : " " ;
579+ if (branch_name == " " ) {
580+ return ;
581+ }
582+
583+ try {
584+ monitored_repo. checkout_remote_branch (branch_name);
585+ } catch (GLib . Error e) {
586+ warning (" Failed to change branch to %s. %s " , branch_name, e. message);
587+ }
588+ }
589+
590+ private void deprioritize_git_ignored () requires (monitored_repo != null ) {
591+ visible_item_list. @foreach ((visible_item) = > {
592+ var item = visible_item. item;
593+ try {
594+ if (monitored_repo. path_is_ignored (visible_item. rel_path)) {
595+ item. markup = Markup . printf_escaped (" <span fgalpha='75%'><i>%s </i></span>" , item. name);
596+ } else {
597+ item. markup = item. name;
598+ }
599+ } catch (Error e) {
600+ warning (" An error occurred while checking if item '%s ' is git-ignored: %s " , item. name, e. message);
601+ }
602+ });
603+ }
604+
605+ public void new_branch (string branch_name ) {
606+ try {
607+ if (monitored_repo. head_is_branch) {
608+ monitored_repo. create_new_branch (branch_name);
609+ } else {
610+ throw new IOError .NOT_FOUND (" Cannot create a new branch when head is detached" );
611+ }
612+ } catch (Error e) {
613+ var dialog = new Granite .MessageDialog (
614+ _(" Error while creating new branch: “%s ”" ). printf (branch_name),
615+ e. message,
616+ new ThemedIcon (" git" ),
617+ Gtk . ButtonsType . CLOSE
618+ ) {
619+ badge_icon = new ThemedIcon (" dialog-error" )
620+ };
621+ dialog. transient_for = (Gtk . Window )(view. get_toplevel ());
622+ dialog. response. connect (() = > {
623+ dialog. destroy ();
624+ });
625+ dialog. run ();
626+ }
627+ }
628+
625629 private void search_folder_children (GLib .File start_folder , Regex pattern , bool recurse_subfolders ) {
626630 try {
627631 var enumerator = start_folder. enumerate_children (
@@ -712,8 +716,4 @@ public class Scratch.FolderManager.ProjectFolderItem : FolderItem {
712716
713717 return ;
714718 }
715-
716- public void refresh_diff (ref Gee .HashMap<int, Services . VCStatus > line_status_map , string doc_path ) {
717- monitored_repo. refresh_diff (doc_path, ref line_status_map);
718- }
719719}
0 commit comments