<commit_before>#include "window.h"
#include "logging.h"
#include "singletons.h"

namespace sigc {
  SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
}

Window::Window() :
  window_box_(Gtk::ORIENTATION_VERTICAL) {
  INFO("Create Window");
  set_title("juCi++");
  set_default_size(600, 400);
  set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
  add(window_box_);
  auto menu=Singleton::menu();
  menu->action_group->add(Gtk::Action::create("FileQuit", "Quit juCi++"), Gtk::AccelKey(menu->key_map["quit"]), [this]() {
    OnWindowHide();
  });
  menu->action_group->add(Gtk::Action::create("FileOpenFile", "Open file"), Gtk::AccelKey(menu->key_map["open_file"]), [this]() {
    OnOpenFile();
  });
  menu->action_group->add(Gtk::Action::create("FileOpenFolder", "Open folder"), Gtk::AccelKey(menu->key_map["open_folder"]), [this]() {
    OnFileOpenFolder();
  });
  menu->action_group->add(Gtk::Action::create("FileSaveAs", "Save as"), Gtk::AccelKey(menu->key_map["save_as"]), [this]() {
	  SaveFileAs();
	});

  menu->action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu->key_map["save"]), [this]() {
	  SaveFile();
	});
  
  menu->action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(menu->key_map["compile_and_run"]), [this]() {
	  SaveFile();
	  if (running.try_lock()) {
	    std::thread execute([this]() {
		std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
		size_t pos = path.find_last_of("/\\");
		if(pos != std::string::npos) {
		  path.erase(path.begin()+pos,path.end());
		  Singleton::terminal()->SetFolderCommand(path);
		}
		Singleton::terminal()->Compile();
		std::string executable = Singleton::notebook()->directories.
		  GetCmakeVarValue(path,"add_executable");
		Singleton::terminal()->Run(executable);
                running.unlock();
	      });
	    execute.detach();
	  }
	});
   
  menu->action_group->add(Gtk::Action::create("ProjectCompile", "Compile"), Gtk::AccelKey(menu->key_map["compile"]), [this]() {
    SaveFile();
    if (running.try_lock()) {
      std::thread execute([this]() {		  
          std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
          size_t pos = path.find_last_of("/\\");
          if(pos != std::string::npos){
            path.erase(path.begin()+pos,path.end());
            Singleton::terminal()->SetFolderCommand(path);
          }
          Singleton::terminal()->Compile();
          running.unlock();
        });
      execute.detach();
    }
  });

  add_accel_group(menu->ui_manager->get_accel_group());
  menu->build();

  window_box_.pack_start(menu->get_widget(), Gtk::PACK_SHRINK);

  window_box_.pack_start(Singleton::notebook()->entry_box, Gtk::PACK_SHRINK);
  paned_.set_position(300);
  paned_.pack1(Singleton::notebook()->view, true, false);
  paned_.pack2(Singleton::terminal()->view, true, true);
  window_box_.pack_end(paned_);
  show_all_children();
  
  Singleton::notebook()->entry_box.signal_show().connect([this](){
    std::vector<Gtk::Widget*> focus_chain;
    focus_chain.emplace_back(&Singleton::notebook()->entry_box);
    window_box_.set_focus_chain(focus_chain);
  });
  Singleton::notebook()->entry_box.signal_hide().connect([this](){
    window_box_.unset_focus_chain();
  });
  
  INFO("Window created");
} // Window constructor

bool Window::on_key_press_event(GdkEventKey *event) {
  if(event->keyval==GDK_KEY_Escape) {
    Singleton::notebook()->entry_box.hide();
    return true;
  }
  
#ifdef __APPLE__ //For Apple's Command-left, right, up, down keys
  if((event->state & GDK_META_MASK)>0) {
    if(event->keyval==GDK_KEY_Left) {
      event->keyval=GDK_KEY_Home;
      event->state=event->state & GDK_SHIFT_MASK;
      event->hardware_keycode=115;
    }
    else if(event->keyval==GDK_KEY_Right) {
      event->keyval=GDK_KEY_End;
      event->state=event->state & GDK_SHIFT_MASK;
      event->hardware_keycode=119;
    }
    else if(event->keyval==GDK_KEY_Up) {
      if(auto text_view=dynamic_cast<Gtk::TextView*>(get_focus())) {
        if(event->state & GDK_SHIFT_MASK)
          text_view->get_buffer()->select_range(text_view->get_buffer()->begin(), text_view->get_buffer()->get_insert()->get_iter());<commit_msg>Espace now again works on selection/completion dialogs.<commit_after>#include "window.h"
#include "logging.h"
#include "singletons.h"

namespace sigc {
  SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
}

Window::Window() :
  window_box_(Gtk::ORIENTATION_VERTICAL) {
  INFO("Create Window");
  set_title("juCi++");
  set_default_size(600, 400);
  set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
  add(window_box_);
  auto menu=Singleton::menu();
  menu->action_group->add(Gtk::Action::create("FileQuit", "Quit juCi++"), Gtk::AccelKey(menu->key_map["quit"]), [this]() {
    OnWindowHide();
  });
  menu->action_group->add(Gtk::Action::create("FileOpenFile", "Open file"), Gtk::AccelKey(menu->key_map["open_file"]), [this]() {
    OnOpenFile();
  });
  menu->action_group->add(Gtk::Action::create("FileOpenFolder", "Open folder"), Gtk::AccelKey(menu->key_map["open_folder"]), [this]() {
    OnFileOpenFolder();
  });
  menu->action_group->add(Gtk::Action::create("FileSaveAs", "Save as"), Gtk::AccelKey(menu->key_map["save_as"]), [this]() {
	  SaveFileAs();
	});

  menu->action_group->add(Gtk::Action::create("FileSave", "Save"), Gtk::AccelKey(menu->key_map["save"]), [this]() {
	  SaveFile();
	});
  
  menu->action_group->add(Gtk::Action::create("ProjectCompileAndRun", "Compile And Run"), Gtk::AccelKey(menu->key_map["compile_and_run"]), [this]() {
	  SaveFile();
	  if (running.try_lock()) {
	    std::thread execute([this]() {
		std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
		size_t pos = path.find_last_of("/\\");
		if(pos != std::string::npos) {
		  path.erase(path.begin()+pos,path.end());
		  Singleton::terminal()->SetFolderCommand(path);
		}
		Singleton::terminal()->Compile();
		std::string executable = Singleton::notebook()->directories.
		  GetCmakeVarValue(path,"add_executable");
		Singleton::terminal()->Run(executable);
                running.unlock();
	      });
	    execute.detach();
	  }
	});
   
  menu->action_group->add(Gtk::Action::create("ProjectCompile", "Compile"), Gtk::AccelKey(menu->key_map["compile"]), [this]() {
    SaveFile();
    if (running.try_lock()) {
      std::thread execute([this]() {		  
          std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
          size_t pos = path.find_last_of("/\\");
          if(pos != std::string::npos){
            path.erase(path.begin()+pos,path.end());
            Singleton::terminal()->SetFolderCommand(path);
          }
          Singleton::terminal()->Compile();
          running.unlock();
        });
      execute.detach();
    }
  });

  add_accel_group(menu->ui_manager->get_accel_group());
  menu->build();

  window_box_.pack_start(menu->get_widget(), Gtk::PACK_SHRINK);

  window_box_.pack_start(Singleton::notebook()->entry_box, Gtk::PACK_SHRINK);
  paned_.set_position(300);
  paned_.pack1(Singleton::notebook()->view, true, false);
  paned_.pack2(Singleton::terminal()->view, true, true);
  window_box_.pack_end(paned_);
  show_all_children();
  
  Singleton::notebook()->entry_box.signal_show().connect([this](){
    std::vector<Gtk::Widget*> focus_chain;
    focus_chain.emplace_back(&Singleton::notebook()->entry_box);
    window_box_.set_focus_chain(focus_chain);
  });
  Singleton::notebook()->entry_box.signal_hide().connect([this](){
    window_box_.unset_focus_chain();
  });
  
  INFO("Window created");
} // Window constructor

bool Window::on_key_press_event(GdkEventKey *event) {
  if(event->keyval==GDK_KEY_Escape)
    Singleton::notebook()->entry_box.hide();
#ifdef __APPLE__ //For Apple's Command-left, right, up, down keys
  else if((event->state & GDK_META_MASK)>0) {
    if(event->keyval==GDK_KEY_Left) {
      event->keyval=GDK_KEY_Home;
      event->state=event->state & GDK_SHIFT_MASK;
      event->hardware_keycode=115;
    }
    else if(event->keyval==GDK_KEY_Right) {
      event->keyval=GDK_KEY_End;
      event->state=event->state & GDK_SHIFT_MASK;
      event->hardware_keycode=119;
    }
    else if(event->keyval==GDK_KEY_Up) {
      if(auto text_view=dynamic_cast<Gtk::TextView*>(get_focus())) {
        if(event->state & GDK_SHIFT_MASK)
          text_view->get_buffer()->select_range(text_view->get_buffer()->begin(), text_view->get_buffer()->get_insert()->get_iter());
{'fraction_non_alphanumeric': 0.19461673493270917, 'fraction_numerical': 0.004212990052662376, 'mean_word_length': 4.86547700754976, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7608946', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2988, 'n_words': 330}