Merge branch 'main' into chore/commitizen
commit
52ef47f6fd
|
@ -1,3 +1,7 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
pub mod imp;
|
pub mod imp;
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::lib::prelude::*;
|
||||||
|
|
||||||
use crate::components::editor::EchidnaCoreEditor;
|
use crate::components::editor::EchidnaCoreEditor;
|
||||||
use gio::Cancellable;
|
use gio::Cancellable;
|
||||||
use glib::{clone, Priority};
|
use glib::{clone, Priority};
|
||||||
|
@ -64,7 +66,7 @@ impl FileImplementedEditor for super::EchidnaWindow {
|
||||||
fn open_file(notebook: >k::Notebook, file_location: gio::File) {
|
fn open_file(notebook: >k::Notebook, file_location: gio::File) {
|
||||||
let file = File::builder().location(&file_location).build();
|
let file = File::builder().location(&file_location).build();
|
||||||
let editor_page = EchidnaCoreEditor::new(Some(file));
|
let editor_page = EchidnaCoreEditor::new(Some(file));
|
||||||
notebook.prepend_page(
|
notebook.prepend_closable_page(
|
||||||
&editor_page,
|
&editor_page,
|
||||||
Some(&Label::new(Some(
|
Some(&Label::new(Some(
|
||||||
&file_location
|
&file_location
|
||||||
|
|
|
@ -27,16 +27,6 @@
|
||||||
-->
|
-->
|
||||||
<object class="GtkNotebook" id="notebook">
|
<object class="GtkNotebook" id="notebook">
|
||||||
<property name="hexpand">1</property>
|
<property name="hexpand">1</property>
|
||||||
<child>
|
|
||||||
<object id="getting-started" class="GtkLabel">
|
|
||||||
<property name="label">Hello from Echidna!</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child type="tab">
|
|
||||||
<object class="GtkLabel" id="notebook-welcome">
|
|
||||||
<property name="label">Welcome</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
<!-- </child>
|
<!-- </child>
|
||||||
</object> -->
|
</object> -->
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use glib::IsA;
|
||||||
|
use gtk::{prelude::*, Box, Button, Widget};
|
||||||
|
|
||||||
|
pub trait ClosableTabImplementedNotebook {
|
||||||
|
fn prepend_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
||||||
|
&self,
|
||||||
|
child: &T,
|
||||||
|
tab_label: Option<&U>,
|
||||||
|
) -> u32;
|
||||||
|
fn append_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
||||||
|
&self,
|
||||||
|
child: &T,
|
||||||
|
tab_label: Option<&U>,
|
||||||
|
) -> u32;
|
||||||
|
|
||||||
|
fn create_closable_tab<U: IsA<Widget>>(tab_label: Option<&U>) -> (Box, Button);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClosableTabImplementedNotebook for gtk::Notebook {
|
||||||
|
fn create_closable_tab<U: IsA<Widget>>(tab_label: Option<&U>) -> (Box, Button) {
|
||||||
|
let tab = Box::new(gtk::Orientation::Horizontal, 5);
|
||||||
|
if tab_label.is_some() {
|
||||||
|
tab.append(tab_label.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
let button = gtk::Button::new();
|
||||||
|
|
||||||
|
button.set_icon_name("window-close-symbolic");
|
||||||
|
button.set_has_frame(false);
|
||||||
|
|
||||||
|
tab.append(&button);
|
||||||
|
|
||||||
|
(tab, button)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prepend_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
||||||
|
&self,
|
||||||
|
child: &T,
|
||||||
|
tab_label: Option<&U>,
|
||||||
|
) -> u32 {
|
||||||
|
let (tab, button) = &Self::create_closable_tab(tab_label);
|
||||||
|
let page = self.prepend_page(child, Some(tab));
|
||||||
|
|
||||||
|
button.connect_clicked(glib::clone!(@weak self as notebook =>
|
||||||
|
move |_| {
|
||||||
|
notebook.remove_page(Some(page));
|
||||||
|
}));
|
||||||
|
|
||||||
|
page
|
||||||
|
}
|
||||||
|
|
||||||
|
fn append_closable_page<T: IsA<Widget>, U: IsA<Widget>>(
|
||||||
|
&self,
|
||||||
|
child: &T,
|
||||||
|
tab_label: Option<&U>,
|
||||||
|
) -> u32 {
|
||||||
|
let (tab, button) = &Self::create_closable_tab(tab_label);
|
||||||
|
let page = self.append_page(child, Some(tab));
|
||||||
|
|
||||||
|
button.connect_clicked(glib::clone!(@weak self as notebook =>
|
||||||
|
move |_| {
|
||||||
|
notebook.remove_page(Some(page));
|
||||||
|
}));
|
||||||
|
|
||||||
|
page
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
pub mod closeable_tab;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use super::closeable_tab::ClosableTabImplementedNotebook;
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
mod components;
|
mod components;
|
||||||
|
pub mod lib;
|
||||||
use app::EchidnaEditor;
|
use app::EchidnaEditor;
|
||||||
use components::app;
|
use components::app;
|
||||||
use gtk::prelude::ApplicationExtManual;
|
use gtk::prelude::ApplicationExtManual;
|
||||||
|
|
Loading…
Reference in New Issue