Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / PickCategoryLine.cc
blobb13dbe4eec2a8eca961b7ae0999ae686dc146969
1 /*
2 * Copyright (c) 2002 Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <robertc@hotmail.com>
16 #include "PickCategoryLine.h"
17 #include "package_db.h"
18 #include "PickView.h"
19 #include "window.h"
20 #include "package_meta.h"
21 #include "resource.h"
22 #include <sstream>
24 const std::wstring
25 PickCategoryLine::get_text (int col_num) const
27 if (col_num == pkgname_col)
29 std::ostringstream s;
30 s << cat_tree->category().first;
31 if (pkgcount)
32 s << " (" << pkgcount << ")";
33 return string_to_wstring(s.str());
35 else if (col_num == new_col)
37 return LoadStringW(packagemeta::action_caption (cat_tree->action()));
39 return L"";
42 int
43 PickCategoryLine::do_action(int col_num, int action_id)
45 if (col_num == pkgname_col)
47 cat_tree->collapsed() = ! cat_tree->collapsed();
48 theView.refresh();
50 else if (col_num == new_col)
52 theView.GetParent ()->SetBusy ();
53 int u = cat_tree->do_action((packagemeta::_actions)(action_id), theView.deftrust);
54 theView.GetParent ()->ClearBusy ();
55 return u;
57 return 1;
60 int
61 PickCategoryLine::do_default_action(int col_num)
63 return 0;
66 ActionList *
67 PickCategoryLine::get_actions(int col) const
69 ActionList *al = new ActionList();
70 packagemeta::_actions current_default = cat_tree->action();
72 al->add(IDS_ACTION_DEFAULT, (int)packagemeta::NoChange_action, (current_default == packagemeta::NoChange_action), TRUE);
73 al->add(IDS_ACTION_INSTALL, (int)packagemeta::Install_action, (current_default == packagemeta::Install_action), TRUE);
74 al->add(packagedb::task == PackageDB_Install ? IDS_ACTION_REINSTALL : IDS_ACTION_RETRIEVE,
75 (int)packagemeta::Reinstall_action, (current_default == packagemeta::Reinstall_action), TRUE);
76 al->add(IDS_ACTION_UNINSTALL, (int)packagemeta::Uninstall_action, (current_default == packagemeta::Uninstall_action), TRUE);
78 return al;
81 ListViewLine::State
82 PickCategoryLine::get_state() const
84 return cat_tree->collapsed() ? State::collapsed : State::expanded;
87 int
88 PickCategoryLine::get_indent() const
90 return indent;
93 const std::string
94 PickCategoryLine::get_tooltip(int col_num) const
96 return "";
99 int
100 PickCategoryLine::map_key_to_action(WORD vkey, int modkeys, int & col_num,
101 int & action_id) const
103 switch (vkey)
105 case VK_SPACE: // expand <> collapse category
106 col_num = pkgname_col;
107 return Action::Direct;
108 case VK_APPS: // install/reinstall/uninstall context menu for category
109 col_num = new_col;
110 return Action::PopUp;
113 return Action::None;