mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
TextEditor: Handle drop events
We now handle drop events with data type "url-list". This makes it possible to drop a file from FileManager on TextEditor to open it.
This commit is contained in:
parent
cfcb38dff1
commit
6425b8714a
2 changed files with 21 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "TextEditorWidget.h"
|
#include "TextEditorWidget.h"
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <AK/URL.h>
|
||||||
#include <LibCore/CFile.h>
|
#include <LibCore/CFile.h>
|
||||||
#include <LibDraw/PNGLoader.h>
|
#include <LibDraw/PNGLoader.h>
|
||||||
#include <LibGUI/GAboutDialog.h>
|
#include <LibGUI/GAboutDialog.h>
|
||||||
|
@ -302,3 +303,21 @@ bool TextEditorWidget::request_close()
|
||||||
auto result = GMessageBox::show("The document has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window());
|
auto result = GMessageBox::show("The document has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window());
|
||||||
return result == GMessageBox::ExecOK;
|
return result == GMessageBox::ExecOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::drop_event(GDropEvent& event)
|
||||||
|
{
|
||||||
|
event.accept();
|
||||||
|
window()->move_to_front();
|
||||||
|
|
||||||
|
if (event.data_type() == "url-list") {
|
||||||
|
auto lines = event.data().split_view('\n');
|
||||||
|
if (lines.is_empty())
|
||||||
|
return;
|
||||||
|
if (lines.size() > 1) {
|
||||||
|
GMessageBox::show("TextEditor can only open one file at a time!", "One at a time please!", GMessageBox::Type::Error, GMessageBox::InputType::OK, window());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
URL url(lines[0]);
|
||||||
|
open_sesame(url.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ private:
|
||||||
void set_path(const FileSystemPath& file);
|
void set_path(const FileSystemPath& file);
|
||||||
void update_title();
|
void update_title();
|
||||||
|
|
||||||
|
virtual void drop_event(GDropEvent&) override;
|
||||||
|
|
||||||
RefPtr<GTextEditor> m_editor;
|
RefPtr<GTextEditor> m_editor;
|
||||||
String m_path;
|
String m_path;
|
||||||
String m_name;
|
String m_name;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue