<commit_before>#include "window.h"
#include "config.h"
#include "menu.h"
#include "directories.h"
//#include "api.h"
#include "dialogs.h"
#include "filesystem.h"
#include "project.h"
#include "entrybox.h"
#include "info.h"

namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
  template <typename Functor>
  struct functor_trait<Functor, false> {
    typedef decltype (::sigc::mem_fun(std::declval<Functor&>(),
                                      &Functor::operator())) _intermediate;
    typedef typename _intermediate::result_type result_type;
    typedef Functor functor_type;
  };
#else
  SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
#endif
}

Window::Window() {
  set_title("juCi++");
  set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK|Gdk::LEAVE_NOTIFY_MASK);
  
  set_menu_actions();
  configure();
  activate_menu_items(false);
  
  set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second);
  
  directories_scrolled_window.add(Directories::get());
  directory_and_notebook_panes.pack1(directories_scrolled_window, Gtk::SHRINK);
  notebook_vbox.pack_start(Notebook::get());
  notebook_vbox.pack_end(EntryBox::get(), Gtk::PACK_SHRINK);
  directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK);
  directory_and_notebook_panes.set_position(static_cast<int>(0.2*Config::get().window.default_size.first));
  vpaned.set_position(static_cast<int>(0.75*Config::get().window.default_size.second));
  vpaned.pack1(directory_and_notebook_panes, true, false);
  
  terminal_scrolled_window.add(Terminal::get());
  terminal_vbox.pack_start(terminal_scrolled_window);
    
  info_and_status_hbox.pack_start(Notebook::get().info, Gtk::PACK_SHRINK);
  
#if GTK_VERSION_GE(3, 12)
  info_and_status_hbox.set_center_widget(Project::debug_status_label());
#else
  Project::debug_status_label().set_halign(Gtk::Align::ALIGN_CENTER);
  info_and_status_hbox.pack_start(Project::debug_status_label());
#endif
  info_and_status_hbox.pack_end(Notebook::get().status, Gtk::PACK_SHRINK);
  terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
  vpaned.pack2(terminal_vbox, true, true);
  
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION==3 && GTKMM_MINOR_VERSION>=14)
  overlay_vbox.set_hexpand(false);
  overlay_vbox.set_halign(Gtk::Align::ALIGN_START);
  overlay_hbox.set_hexpand(false);
  overlay_hbox.set_halign(Gtk::Align::ALIGN_END);
  overlay_vbox.pack_start(Info::get(), Gtk::PACK_SHRINK, 20);
  overlay_hbox.pack_end(overlay_vbox, Gtk::PACK_SHRINK, 20);
  overlay.add(vpaned);
  overlay.add_overlay(overlay_hbox);
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION==3 && GTKMM_MINOR_VERSION>=18)
  overlay.set_overlay_pass_through(overlay_hbox, true);
#endif
  add(overlay);
#else
  add(vpaned);
#endif
  
  show_all_children();
  Info::get().hide();

  Directories::get().on_row_activated=[this](const boost::filesystem::path &path) {
    Notebook::get().open(path);
  };

  //Scroll to end of terminal whenever info is printed
  Terminal::get().signal_size_allocate().connect([this](Gtk::Allocation& allocation){
    auto adjustment=terminal_scrolled_window.get_vadjustment();
    adjustment->set_value(adjustment->get_upper()-adjustment->get_page_size());
    Terminal::get().queue_draw();
  });

  EntryBox::get().signal_show().connect([this](){
    vpaned.set_focus_chain({&directory_and_notebook_panes});
    directory_and_notebook_panes.set_focus_chain({&notebook_vbox});
    notebook_vbox.set_focus_chain({&EntryBox::get()});
  });
  EntryBox::get().signal_hide().connect([this](){
    vpaned.unset_focus_chain();
    directory_and_notebook_panes.unset_focus_chain();
    notebook_vbox.unset_focus_chain();
  });
  EntryBox::get().signal_hide().connect([this]() {
    if(auto view=Notebook::get().get_current_view())
      view->grab_focus();
  });

  Notebook::get().on_switch_page=[this] {
    if(auto view=Notebook::get().get_current_view()) {
      if(search_entry_shown && EntryBox::get().labels.size()>0) {
        view->update_search_occurrences=[this](int number){
          EntryBox::get().labels.begin()->update(0, std::to_string(number));
        };
        view->search_highlight(last_search, case_sensitive_search, regex_search);
      }

      activate_menu_items();
      
      Directories::get().select(view->file_path);
      
      if(view->full_reparse_needed) {
        if(!view->full_reparse())
          Terminal::get().async_print("Error: failed to reparse "+view->file_path.string()+". Please reopen the file manually.\n", true);
      }
      else if(view->soft_reparse_needed)
        view->soft_reparse();
      
      view->set_status(view->status);
      view->set_info(view->info);
    }
  };
  Notebook::get().on_page_removed=[] {
    EntryBox::get().hide();
  };
  
  about.signal_response().connect([this](int d){
    about.hide();
  });
  
  about.set_version(Config::get().window.version);
  about.set_authors({"(in order of appearance)",
                     "<NAME>", 
                     "<NAME>",
                     "<NAME>",
                     "<NAME>"});
  about.set_name("About juCi++");
  about.set_program_name("juCi++");<commit_msg>Debug: now shows stop line if existing in a newly opened file<commit_after>#include "window.h"
#include "config.h"
#include "menu.h"
#include "directories.h"
//#include "api.h"
#include "dialogs.h"
#include "filesystem.h"
#include "project.h"
#include "entrybox.h"
#include "info.h"

namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
  template <typename Functor>
  struct functor_trait<Functor, false> {
    typedef decltype (::sigc::mem_fun(std::declval<Functor&>(),
                                      &Functor::operator())) _intermediate;
    typedef typename _intermediate::result_type result_type;
    typedef Functor functor_type;
  };
#else
  SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
#endif
}

Window::Window() {
  set_title("juCi++");
  set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK|Gdk::LEAVE_NOTIFY_MASK);
  
  set_menu_actions();
  configure();
  activate_menu_items(false);
  
  set_default_size(Config::get().window.default_size.first, Config::get().window.default_size.second);
  
  directories_scrolled_window.add(Directories::get());
  directory_and_notebook_panes.pack1(directories_scrolled_window, Gtk::SHRINK);
  notebook_vbox.pack_start(Notebook::get());
  notebook_vbox.pack_end(EntryBox::get(), Gtk::PACK_SHRINK);
  directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK);
  directory_and_notebook_panes.set_position(static_cast<int>(0.2*Config::get().window.default_size.first));
  vpaned.set_position(static_cast<int>(0.75*Config::get().window.default_size.second));
  vpaned.pack1(directory_and_notebook_panes, true, false);
  
  terminal_scrolled_window.add(Terminal::get());
  terminal_vbox.pack_start(terminal_scrolled_window);
    
  info_and_status_hbox.pack_start(Notebook::get().info, Gtk::PACK_SHRINK);
  
#if GTK_VERSION_GE(3, 12)
  info_and_status_hbox.set_center_widget(Project::debug_status_label());
#else
  Project::debug_status_label().set_halign(Gtk::Align::ALIGN_CENTER);
  info_and_status_hbox.pack_start(Project::debug_status_label());
#endif
  info_and_status_hbox.pack_end(Notebook::get().status, Gtk::PACK_SHRINK);
  terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
  vpaned.pack2(terminal_vbox, true, true);
  
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION==3 && GTKMM_MINOR_VERSION>=14)
  overlay_vbox.set_hexpand(false);
  overlay_vbox.set_halign(Gtk::Align::ALIGN_START);
  overlay_hbox.set_hexpand(false);
  overlay_hbox.set_halign(Gtk::Align::ALIGN_END);
  overlay_vbox.pack_start(Info::get(), Gtk::PACK_SHRINK, 20);
  overlay_hbox.pack_end(overlay_vbox, Gtk::PACK_SHRINK, 20);
  overlay.add(vpaned);
  overlay.add_overlay(overlay_hbox);
#if GTKMM_MAJOR_VERSION>3 || (GTKMM_MAJOR_VERSION==3 && GTKMM_MINOR_VERSION>=18)
  overlay.set_overlay_pass_through(overlay_hbox, true);
#endif
  add(overlay);
#else
  add(vpaned);
#endif
  
  show_all_children();
  Info::get().hide();

  Directories::get().on_row_activated=[this](const boost::filesystem::path &path) {
    Notebook::get().open(path);
  };

  //Scroll to end of terminal whenever info is printed
  Terminal::get().signal_size_allocate().connect([this](Gtk::Allocation& allocation){
    auto adjustment=terminal_scrolled_window.get_vadjustment();
    adjustment->set_value(adjustment->get_upper()-adjustment->get_page_size());
    Terminal::get().queue_draw();
  });

  EntryBox::get().signal_show().connect([this](){
    vpaned.set_focus_chain({&directory_and_notebook_panes});
    directory_and_notebook_panes.set_focus_chain({&notebook_vbox});
    notebook_vbox.set_focus_chain({&EntryBox::get()});
  });
  EntryBox::get().signal_hide().connect([this](){
    vpaned.unset_focus_chain();
    directory_and_notebook_panes.unset_focus_chain();
    notebook_vbox.unset_focus_chain();
  });
  EntryBox::get().signal_hide().connect([this]() {
    if(auto view=Notebook::get().get_current_view())
      view->grab_focus();
  });

  Notebook::get().on_switch_page=[this] {
    if(auto view=Notebook::get().get_current_view()) {
      if(search_entry_shown && EntryBox::get().labels.size()>0) {
        view->update_search_occurrences=[this](int number){
          EntryBox::get().labels.begin()->update(0, std::to_string(number));
        };
        view->search_highlight(last_search, case_sensitive_search, regex_search);
      }

      activate_menu_items();
      
      Directories::get().select(view->file_path);
      
      if(view->full_reparse_needed) {
        if(!view->full_reparse())
          Terminal::get().async_print("Error: failed to reparse "+view->file_path.string()+". Please reopen the file manually.\n", true);
      }
      else if(view->soft_reparse_needed)
        view->soft_reparse();
      
      view->set_status(view->status);
      view->set_info(view->info);
      
#ifdef JUCI_ENABLE_DEBUG
      if(Project::debugging) {
        if(view->file_path==Project::debug_stop.first &&
           Project::debug_stop.second.first-1<view->get_buffer()->get_line_count())
          view->get_source_buffer()->create_source_mark("debug_stop", view->get_buffer()->get_iter_at_line(Project::debug_stop.second.first-1));
      }
#endif
    }
  };
  Notebook::get().on_page_removed=[] {
    EntryBox::get().hide();
  };
  
  about.signal_response().connect([this](int d){
    about.hide();
  });
  
  about.set_version(Config::get().window.version);
  about.set_authors({"(in order of appearance)",
                     "<NAME>", 
                     "<NAME>",
                     "<NAME>",
                     "<NAME>"});
  about.set_name("About juCi++");
  about.set_program_name("juCi++");
{'fraction_non_alphanumeric': 0.15694444444444444, 'fraction_numerical': 0.005, 'mean_word_length': 5.147410358565737, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4460444', 'n_tokens_mistral': 3893, 'n_tokens_neox': 3820, 'n_words': 406}