Переглянути джерело

Spreadsheet: Cut instead of copy when dragging a cell's items

Use cut instead of copy when dragging one or many cells' contents.
This is more intuitive as most other spreadsheet applications
handle the drag in this manner instead of as a copy operation.
martinfalisse 3 роки тому
батько
коміт
2f2a705a8e

+ 6 - 1
Userland/Applications/Spreadsheet/Spreadsheet.cpp

@@ -294,6 +294,10 @@ Position Sheet::offset_relative_to(const Position& base, const Position& offset,
 
 
 void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Position> resolve_relative_to, CopyOperation copy_operation)
 void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Position> resolve_relative_to, CopyOperation copy_operation)
 {
 {
+    Vector<Position> target_cells;
+    for (auto& position : from)
+        target_cells.append(resolve_relative_to.has_value() ? offset_relative_to(to.first(), position, resolve_relative_to.value()) : to.first());
+
     auto copy_to = [&](auto& source_position, Position target_position) {
     auto copy_to = [&](auto& source_position, Position target_position) {
         auto& target_cell = ensure(target_position);
         auto& target_cell = ensure(target_position);
         auto* source_cell = at(source_position);
         auto* source_cell = at(source_position);
@@ -305,7 +309,8 @@ void Sheet::copy_cells(Vector<Position> from, Vector<Position> to, Optional<Posi
 
 
         target_cell.copy_from(*source_cell);
         target_cell.copy_from(*source_cell);
         if (copy_operation == CopyOperation::Cut)
         if (copy_operation == CopyOperation::Cut)
-            source_cell->set_data("");
+            if (!target_cells.contains_slow(source_position))
+                source_cell->set_data("");
     };
     };
 
 
     if (from.size() == to.size()) {
     if (from.size() == to.size()) {

+ 6 - 6
Userland/Applications/Spreadsheet/SpreadsheetView.cpp

@@ -125,7 +125,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
             }
             }
         }
         }
 
 
-        if (m_is_hovering_cut_zone || m_is_dragging_for_copy)
+        if (m_is_hovering_cut_zone || m_is_dragging_for_cut)
             set_override_cursor(Gfx::StandardCursor::Drag);
             set_override_cursor(Gfx::StandardCursor::Drag);
         else if (m_is_hovering_extend_zone)
         else if (m_is_hovering_extend_zone)
             set_override_cursor(Gfx::StandardCursor::Crosshair);
             set_override_cursor(Gfx::StandardCursor::Crosshair);
@@ -133,7 +133,7 @@ void InfinitelyScrollableTableView::mousemove_event(GUI::MouseEvent& event)
             set_override_cursor(Gfx::StandardCursor::Arrow);
             set_override_cursor(Gfx::StandardCursor::Arrow);
 
 
         auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Primary);
         auto holding_left_button = !!(event.buttons() & GUI::MouseButton::Primary);
-        if (m_is_dragging_for_copy) {
+        if (m_is_dragging_for_cut) {
             m_is_dragging_for_select = false;
             m_is_dragging_for_select = false;
             if (holding_left_button) {
             if (holding_left_button) {
                 m_has_committed_to_cutting = true;
                 m_has_committed_to_cutting = true;
@@ -176,7 +176,7 @@ void InfinitelyScrollableTableView::mousedown_event(GUI::MouseEvent& event)
     // when m_is_hovering_cut_zone as it can be the case that the user is targetting
     // when m_is_hovering_cut_zone as it can be the case that the user is targetting
     // a cell yet be outside of its bounding box due to the select_padding.
     // a cell yet be outside of its bounding box due to the select_padding.
     if (m_is_hovering_cut_zone) {
     if (m_is_hovering_cut_zone) {
-        m_is_dragging_for_copy = true;
+        m_is_dragging_for_cut = true;
         auto rect = content_rect(m_target_cell);
         auto rect = content_rect(m_target_cell);
         GUI::MouseEvent adjusted_event = { (GUI::Event::Type)event.type(), rect.center(), event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y() };
         GUI::MouseEvent adjusted_event = { (GUI::Event::Type)event.type(), rect.center(), event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y() };
         AbstractTableView::mousedown_event(adjusted_event);
         AbstractTableView::mousedown_event(adjusted_event);
@@ -190,7 +190,7 @@ void InfinitelyScrollableTableView::mousedown_event(GUI::MouseEvent& event)
 void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
 void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
 {
 {
     m_is_dragging_for_select = false;
     m_is_dragging_for_select = false;
-    m_is_dragging_for_copy = false;
+    m_is_dragging_for_cut = false;
     m_has_committed_to_cutting = false;
     m_has_committed_to_cutting = false;
     if (m_is_hovering_cut_zone) {
     if (m_is_hovering_cut_zone) {
         auto rect = content_rect(m_target_cell);
         auto rect = content_rect(m_target_cell);
@@ -204,7 +204,7 @@ void InfinitelyScrollableTableView::mouseup_event(GUI::MouseEvent& event)
 void InfinitelyScrollableTableView::drop_event(GUI::DropEvent& event)
 void InfinitelyScrollableTableView::drop_event(GUI::DropEvent& event)
 {
 {
     TableView::drop_event(event);
     TableView::drop_event(event);
-    m_is_dragging_for_copy = false;
+    m_is_dragging_for_cut = false;
     set_override_cursor(Gfx::StandardCursor::Arrow);
     set_override_cursor(Gfx::StandardCursor::Arrow);
     auto drop_index = index_at_event_position(event.position());
     auto drop_index = index_at_event_position(event.position());
     if (selection().size() > 0) {
     if (selection().size() > 0) {
@@ -377,7 +377,7 @@ SpreadsheetView::SpreadsheetView(Sheet& sheet)
                 return;
                 return;
 
 
             auto first_position = source_positions.take_first();
             auto first_position = source_positions.take_first();
-            m_sheet->copy_cells(move(source_positions), move(target_positions), first_position);
+            m_sheet->copy_cells(move(source_positions), move(target_positions), first_position, Spreadsheet::Sheet::CopyOperation::Cut);
 
 
             return;
             return;
         }
         }

+ 1 - 1
Userland/Applications/Spreadsheet/SpreadsheetView.h

@@ -79,7 +79,7 @@ private:
     virtual void drop_event(GUI::DropEvent&) override;
     virtual void drop_event(GUI::DropEvent&) override;
 
 
     bool m_is_dragging_for_select { false };
     bool m_is_dragging_for_select { false };
-    bool m_is_dragging_for_copy { false };
+    bool m_is_dragging_for_cut { false };
     bool m_has_committed_to_cutting { false };
     bool m_has_committed_to_cutting { false };
     bool m_is_hovering_extend_zone { false };
     bool m_is_hovering_extend_zone { false };
     bool m_is_hovering_cut_zone { false };
     bool m_is_hovering_cut_zone { false };