Browse Source

Added Window->Split Source Buffer

merge-requests/399/head
eidheim 6 years ago
parent
commit
bc71859699
  1. 2
      CMakeLists.txt
  2. 3
      src/files.h
  3. 4
      src/menu.cc
  4. 19
      src/notebook.cc
  5. 2
      src/notebook.h
  6. 14
      src/window.cc
  7. 2
      tests/stubs/notebook.cc

2
CMakeLists.txt

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 2.8.8) cmake_minimum_required (VERSION 2.8.8)
project(juci) project(juci)
set(JUCI_VERSION "1.5.0.2") set(JUCI_VERSION "1.5.0.3")
set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_NAME "jucipp")
set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim <eidheim@gmail.com>")

3
src/files.h

@ -153,7 +153,8 @@ const std::string default_config_file = R"RAW({
#endif #endif
R"RAW( R"RAW(
"window_close_tab": "<primary>w", "window_close_tab": "<primary>w",
"window_toggle_split": "",)RAW" "window_toggle_split": "",
"window_split_source_buffer": "",)RAW"
#ifdef __APPLE__ #ifdef __APPLE__
R"RAW( R"RAW(
"window_toggle_full_screen": "<primary><control>f",)RAW" "window_toggle_full_screen": "<primary><control>f",)RAW"

4
src/menu.cc

@ -489,6 +489,10 @@ const Glib::ustring menu_xml = R"RAW(<interface>
<attribute name='label' translatable='yes'>_Toggle _Split</attribute> <attribute name='label' translatable='yes'>_Toggle _Split</attribute>
<attribute name='action'>app.window_toggle_split</attribute> <attribute name='action'>app.window_toggle_split</attribute>
</item> </item>
<item>
<attribute name='label' translatable='yes'>_Split _Source _Buffer</attribute>
<attribute name='action'>app.window_split_source_buffer</attribute>
</item>
</section> </section>
<section> <section>
<item> <item>

19
src/notebook.cc

@ -103,7 +103,7 @@ std::vector<Source::View *> &Notebook::get_views() {
return source_views; return source_views;
} }
void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_index) { void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_index, bool copy) {
auto file_path = filesystem::get_normal_path(file_path_); auto file_path = filesystem::get_normal_path(file_path_);
if(notebook_index == 1 && !split) if(notebook_index == 1 && !split)
@ -114,6 +114,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
auto canonical_file_path = boost::filesystem::canonical(file_path, ec); auto canonical_file_path = boost::filesystem::canonical(file_path, ec);
if(ec) if(ec)
canonical_file_path = file_path; canonical_file_path = file_path;
if(!copy) {
for(size_t c = 0; c < size(); c++) { for(size_t c = 0; c < size(); c++) {
bool equal; bool equal;
{ {
@ -127,6 +128,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
return; return;
} }
} }
}
if(boost::filesystem::exists(file_path)) { if(boost::filesystem::exists(file_path)) {
std::ifstream can_read(file_path.string()); std::ifstream can_read(file_path.string());
@ -162,6 +164,21 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
source_views.emplace_back(new Source::GenericView(file_path, language)); source_views.emplace_back(new Source::GenericView(file_path, language));
auto view = source_views.back(); auto view = source_views.back();
if(copy) {
auto previous_view = get_current_view();
if(previous_view) {
view->replace_text(previous_view->get_buffer()->get_text());
if(!split)
toggle_split();
else {
auto pair = get_notebook_page(get_index(previous_view));
if(pair.second != -1)
notebook_index = pair.first == 0 ? 1 : 0;
}
}
}
view->configure(); view->configure();
view->scroll_to_cursor_delayed = [this](Source::BaseView *view, bool center, bool show_tooltips) { view->scroll_to_cursor_delayed = [this](Source::BaseView *view, bool center, bool show_tooltips) {

2
src/notebook.h

@ -34,7 +34,7 @@ public:
Source::View *get_current_view(); Source::View *get_current_view();
std::vector<Source::View *> &get_views(); std::vector<Source::View *> &get_views();
void open(const boost::filesystem::path &file_path, size_t notebook_index = -1); void open(const boost::filesystem::path &file_path, size_t notebook_index = -1, bool copy = false);
void open_uri(const std::string &uri); void open_uri(const std::string &uri);
void configure(size_t index); void configure(size_t index);
bool save(size_t index); bool save(size_t index);

14
src/window.cc

@ -1426,6 +1426,20 @@ void Window::set_menu_actions() {
menu.add_action("window_toggle_split", [] { menu.add_action("window_toggle_split", [] {
Notebook::get().toggle_split(); Notebook::get().toggle_split();
}); });
menu.add_action("window_split_source_buffer", [] {
auto view = Notebook::get().get_current_view();
if(!view) {
Info::get().print("No source buffers found");
return;
}
auto iter = view->get_buffer()->get_insert()->get_iter();
Notebook::get().open(view->file_path, -1, true);
auto new_view = Notebook::get().get_current_view();
new_view->place_cursor_at_line_offset(iter.get_line(), iter.get_line_offset());
new_view->scroll_to_cursor_delayed(new_view, true, false);
});
menu.add_action("window_toggle_full_screen", [this] { menu.add_action("window_toggle_full_screen", [this] {
if(this->get_window()->get_state() & Gdk::WindowState::WINDOW_STATE_FULLSCREEN) if(this->get_window()->get_state() & Gdk::WindowState::WINDOW_STATE_FULLSCREEN)
unfullscreen(); unfullscreen();

2
tests/stubs/notebook.cc

@ -6,4 +6,4 @@ Source::View *Notebook::get_current_view() {
return nullptr; return nullptr;
} }
void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index) {} void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index, bool copy) {}

Loading…
Cancel
Save