Skip to content

Commit 0907685

Browse files
authored
Merge pull request #940 from kevinaboos/file_upload_improvements
Improve File Upload Modal to look quite a bit nicer
2 parents 0cfb7a3 + cfa481a commit 0907685

8 files changed

Lines changed: 760 additions & 390 deletions

File tree

Cargo.lock

Lines changed: 85 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ metadata.makepad-auto-version = "zqpv-Yj-K7WNVK2I8h5Okhho46Q="
1717
# makepad-widgets = { git = "https://github.com/makepad/makepad", branch = "dev", features = ["serde"] }
1818
# makepad-code-editor = { git = "https://github.com/makepad/makepad", branch = "dev" }
1919

20-
makepad-widgets = { git = "https://github.com/kevinaboos/makepad", branch = "ime_composition_preview", features = ["serde"] }
21-
makepad-code-editor = { git = "https://github.com/kevinaboos/makepad", branch = "ime_composition_preview" }
20+
makepad-widgets = { git = "https://github.com/kevinaboos/makepad", branch = "code_editor_fix", features = ["serde"] }
21+
makepad-code-editor = { git = "https://github.com/kevinaboos/makepad", branch = "code_editor_fix" }
2222

2323

2424
## Including this crate automatically configures all `robius-*` crates to work with Makepad.

src/app.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
VerificationModalWidgetRefExt,
2222
}
2323
};
24-
use crate::shared::file_upload_modal::{FileUploadModalWidgetRefExt, FilePreviewerAction};
24+
use crate::shared::file_upload_modal::{FileUploadModalWidgetRefExt, FileUploadModalAction};
2525

2626
script_mod! {
2727
use mod.prelude.widgets.*
@@ -298,19 +298,12 @@ impl MatchEvent for App {
298298
// which will open the login_status_modal to show the failure message.
299299
}
300300

301-
// Handle file upload modal actions
302-
match action.downcast_ref() {
303-
Some(FilePreviewerAction::Show { upload }) => {
304-
self.ui.file_upload_modal(cx, ids!(file_upload_modal.content))
305-
.set_upload(cx, upload.clone());
306-
self.ui.modal(cx, ids!(file_upload_modal)).open(cx);
307-
continue;
308-
}
309-
Some(FilePreviewerAction::Hide) => {
310-
self.ui.modal(cx, ids!(file_upload_modal)).close(cx);
311-
continue;
312-
}
313-
_ => {}
301+
// Handle actions for the file upload modal.
302+
if let Some(action) = action.downcast_ref::<FileUploadModalAction>() {
303+
let outer_modal = self.ui.modal(cx, ids!(file_upload_modal));
304+
self.ui.file_upload_modal(cx, ids!(file_upload_modal.content))
305+
.handle_file_previewer_action(cx, outer_modal, action);
306+
continue;
314307
}
315308

316309
// Handle an action requesting to open the new message context menu.

src/home/event_source_modal.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,14 @@ script_mod! {
179179
// align the left side of the border frame with the left side of the room id / event id rows
180180
padding: 6
181181

182-
// The code editor content (drawn first, behind the overlay)
183-
code_view := mod.widgets.CodeView {
182+
// The code editor content (drawn first, behind the overlay).
183+
code_view := mod.widgets.LightCodeView {
184184
editor +: {
185185
margin: 12,
186186
width: Fill,
187-
height: Fit,
187+
height: Fit { max: 1500 }
188188
word_wrap: true
189-
draw_bg +: { color: (COLOR_TRANSPARENT) }
190189
draw_text +: { text_style +: { font_size: 11 } }
191-
192-
// Light mode syntax highlighting (inspired by GitHub Light / VS Code Light+)
193-
token_colors +: {
194-
whitespace: #x6a737d, // Gray for whitespace markers
195-
delimiter: #x24292e, // Dark gray for punctuation
196-
delimiter_highlight: #x005cc5, // Blue for highlighted delimiters
197-
error_decoration: #xcb2431, // Red for errors
198-
warning_decoration: #xb08800, // Dark yellow/amber for warnings
199-
200-
unknown: #x24292e, // Default dark text
201-
branch_keyword: #xd73a49, // Red/pink for keywords (if, else, match)
202-
constant: #x005cc5, // Blue for constants
203-
identifier: #x24292e, // Dark gray for variables
204-
loop_keyword: #xd73a49, // Red/pink for loop keywords
205-
number: #x005cc5, // Blue for numbers
206-
other_keyword: #xd73a49, // Red/pink for other keywords
207-
punctuator: #x24292e, // Dark gray for punctuation
208-
string: #x22863a, // Green for strings
209-
function: #x6f42c1, // Purple for functions
210-
typename: #xe36209, // Orange for types
211-
comment: #x6a737d, // Gray for comments
212-
}
213190
}
214191
text: "<Unknown Event Source>"
215192
}

src/room/room_input_bar.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use matrix_sdk::room::reply::{EnforceThread, Reply};
2222
use ruma::events::room::message::AddMentions;
2323
use matrix_sdk_ui::timeline::{EmbeddedEvent, EventTimelineItem, TimelineEventItemId};
2424
use ruma::{events::room::message::{LocationMessageEventContent, MessageType, ReplyWithinThread, RoomMessageEventContent}, OwnedEventId, OwnedRoomId};
25-
use crate::{home::{editing_pane::{EditingPaneState, EditingPaneWidgetExt, EditingPaneWidgetRefExt}, location_preview::{LocationPreviewWidgetExt, LocationPreviewWidgetRefExt}, room_screen::{MessageAction, RoomScreenProps, populate_preview_of_timeline_item}, tombstone_footer::{SuccessorRoomDetails, TombstoneFooterWidgetExt}, upload_progress::UploadProgressViewWidgetRefExt}, location::init_location_subscriber, settings::app_preferences::{AppPreferencesAction, AppPreferencesGlobal}, shared::{avatar::AvatarWidgetRefExt, file_upload_modal::{AttachmentUpload, FilePreviewerAction, FileUploadAttemptId, load_selected_file}, html_or_plaintext::HtmlOrPlaintextWidgetRefExt, mentionable_text_input::MentionableTextInputWidgetExt, popup_list::{PopupKind, enqueue_popup_notification}, room_input_popup_menu::RoomInputPopupMenuAction, styles::*}, sliding_sync::{MatrixRequest, TimelineKind, UserPowerLevels, submit_async_request}, utils};
25+
use crate::{home::{editing_pane::{EditingPaneState, EditingPaneWidgetExt, EditingPaneWidgetRefExt}, location_preview::{LocationPreviewWidgetExt, LocationPreviewWidgetRefExt}, room_screen::{MessageAction, RoomScreenProps, populate_preview_of_timeline_item}, tombstone_footer::{SuccessorRoomDetails, TombstoneFooterWidgetExt}, upload_progress::UploadProgressViewWidgetRefExt}, location::init_location_subscriber, settings::app_preferences::{AppPreferencesAction, AppPreferencesGlobal}, shared::{avatar::AvatarWidgetRefExt, file_upload_modal::{AttachmentUpload, FileUploadModalAction, FileUploadAttemptId, PreviewPayload, load_file_metadata}, html_or_plaintext::HtmlOrPlaintextWidgetRefExt, mentionable_text_input::MentionableTextInputWidgetExt, popup_list::{PopupKind, enqueue_popup_notification}, room_input_popup_menu::RoomInputPopupMenuAction, styles::*}, sliding_sync::{MatrixRequest, TimelineKind, UserPowerLevels, submit_async_request}, utils};
2626

2727
script_mod! {
2828
use mod.prelude.widgets.*
@@ -694,15 +694,23 @@ impl RoomInputBar {
694694
match result {
695695
Ok(Some(picked)) => match picked.into_local_file() {
696696
Ok(local_file) => {
697-
let loaded = load_selected_file(
697+
match load_file_metadata(
698698
local_file,
699699
timeline_kind,
700700
in_reply_to,
701701
#[cfg(feature = "tsp")]
702702
sign_with_tsp,
703-
);
704-
match loaded {
705-
Ok(upload) => Cx::post_action(FilePreviewerAction::Show { upload }),
703+
) {
704+
Ok((upload, preview_source, preview_id)) => {
705+
// Show the preview modal instantly, and then re-use this bg thread
706+
// to read the file and generate the preview.
707+
Cx::post_action(FileUploadModalAction::Show { upload, preview_id });
708+
let preview = preview_source.build();
709+
Cx::post_action(FileUploadModalAction::PreviewReady {
710+
preview_id,
711+
preview: PreviewPayload::new(preview),
712+
});
713+
}
706714
Err(e) => enqueue_popup_notification(e, PopupKind::Error, None),
707715
}
708716
}

0 commit comments

Comments
 (0)